mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 23:08:05 -05:00
chore: make IZoneLoadingState return reference
This commit is contained in:
@ -28,13 +28,13 @@ namespace
|
||||
std::vector<menuDef_t*> menus;
|
||||
AssetRegistration<AssetMenuList> registration(assetName);
|
||||
|
||||
auto* zoneState = context.GetZoneAssetLoaderState<menu::MenuAssetZoneState>();
|
||||
auto* conversionState = context.GetZoneAssetLoaderState<MenuConversionZoneState>();
|
||||
auto& zoneState = context.GetZoneAssetLoaderState<menu::MenuAssetZoneState>();
|
||||
auto& conversionState = context.GetZoneAssetLoaderState<MenuConversionZoneState>();
|
||||
|
||||
std::deque<std::string> menuLoadQueue;
|
||||
const auto alreadyLoadedMenuListFileMenus = conversionState->m_menus_by_filename.find(assetName);
|
||||
const auto alreadyLoadedMenuListFileMenus = conversionState.m_menus_by_filename.find(assetName);
|
||||
|
||||
if (alreadyLoadedMenuListFileMenus == conversionState->m_menus_by_filename.end())
|
||||
if (alreadyLoadedMenuListFileMenus == conversionState.m_menus_by_filename.end())
|
||||
{
|
||||
const auto file = m_search_path.Open(assetName);
|
||||
if (!file.IsOpen())
|
||||
@ -43,12 +43,12 @@ namespace
|
||||
const auto menuListResult = ParseMenuFile(*file.m_stream, assetName, zoneState);
|
||||
if (menuListResult)
|
||||
{
|
||||
ProcessParsedResults(assetName, context, menuListResult.get(), zoneState, conversionState, menus, registration);
|
||||
ProcessParsedResults(assetName, context, *menuListResult, zoneState, conversionState, menus, registration);
|
||||
|
||||
for (const auto& menuToLoad : menuListResult->m_menus_to_load)
|
||||
menuLoadQueue.emplace_back(menuToLoad);
|
||||
|
||||
zoneState->AddMenusToLoad(assetName, std::move(menuListResult->m_menus_to_load));
|
||||
zoneState.AddMenusToLoad(assetName, std::move(menuListResult->m_menus_to_load));
|
||||
}
|
||||
else
|
||||
return AssetCreationResult::Failure();
|
||||
@ -74,19 +74,19 @@ namespace
|
||||
|
||||
void FinalizeZone(AssetCreationContext& context) override
|
||||
{
|
||||
context.GetZoneAssetLoaderState<MenuConversionZoneState>()->FinalizeSupportingData();
|
||||
context.GetZoneAssetLoaderState<MenuConversionZoneState>().FinalizeSupportingData();
|
||||
}
|
||||
|
||||
private:
|
||||
bool LoadMenuFileFromQueue(const std::string& menuFilePath,
|
||||
AssetCreationContext& context,
|
||||
menu::MenuAssetZoneState* zoneState,
|
||||
MenuConversionZoneState* conversionState,
|
||||
menu::MenuAssetZoneState& zoneState,
|
||||
MenuConversionZoneState& conversionState,
|
||||
std::vector<menuDef_t*>& menus,
|
||||
AssetRegistration<AssetMenuList>& registration)
|
||||
{
|
||||
const auto alreadyLoadedMenuFile = conversionState->m_menus_by_filename.find(menuFilePath);
|
||||
if (alreadyLoadedMenuFile != conversionState->m_menus_by_filename.end())
|
||||
const auto alreadyLoadedMenuFile = conversionState.m_menus_by_filename.find(menuFilePath);
|
||||
if (alreadyLoadedMenuFile != conversionState.m_menus_by_filename.end())
|
||||
{
|
||||
std::cout << std::format("Already loaded \"{}\", skipping\n", menuFilePath);
|
||||
for (auto* menu : alreadyLoadedMenuFile->second)
|
||||
@ -107,7 +107,7 @@ namespace
|
||||
const auto menuFileResult = ParseMenuFile(*file.m_stream, menuFilePath, zoneState);
|
||||
if (menuFileResult)
|
||||
{
|
||||
ProcessParsedResults(menuFilePath, context, menuFileResult.get(), zoneState, conversionState, menus, registration);
|
||||
ProcessParsedResults(menuFilePath, context, *menuFileResult, zoneState, conversionState, menus, registration);
|
||||
if (!menuFileResult->m_menus_to_load.empty())
|
||||
std::cout << std::format("WARNING: Menu file has menus to load even though it is not a menu list, ignoring: \"{}\"\n", menuFilePath);
|
||||
|
||||
@ -121,17 +121,17 @@ namespace
|
||||
|
||||
bool ProcessParsedResults(const std::string& fileName,
|
||||
AssetCreationContext& context,
|
||||
menu::ParsingResult* parsingResult,
|
||||
menu::MenuAssetZoneState* zoneState,
|
||||
MenuConversionZoneState* conversionState,
|
||||
menu::ParsingResult& parsingResult,
|
||||
menu::MenuAssetZoneState& zoneState,
|
||||
MenuConversionZoneState& conversionState,
|
||||
std::vector<menuDef_t*>& menus,
|
||||
AssetRegistration<AssetMenuList>& registration)
|
||||
{
|
||||
const auto menuCount = parsingResult->m_menus.size();
|
||||
const auto functionCount = parsingResult->m_functions.size();
|
||||
const auto menuLoadCount = parsingResult->m_menus_to_load.size();
|
||||
const auto menuCount = parsingResult.m_menus.size();
|
||||
const auto functionCount = parsingResult.m_functions.size();
|
||||
const auto menuLoadCount = parsingResult.m_menus_to_load.size();
|
||||
auto totalItemCount = 0u;
|
||||
for (const auto& menu : parsingResult->m_menus)
|
||||
for (const auto& menu : parsingResult.m_menus)
|
||||
totalItemCount += menu->m_items.size();
|
||||
|
||||
std::cout << std::format("Successfully read menu file \"{}\" ({} loads, {} menus, {} functions, {} items)\n",
|
||||
@ -142,15 +142,15 @@ namespace
|
||||
totalItemCount);
|
||||
|
||||
// Add all functions to the zone state to make them available for all menus to be converted
|
||||
for (auto& function : parsingResult->m_functions)
|
||||
zoneState->AddFunction(std::move(function));
|
||||
for (auto& function : parsingResult.m_functions)
|
||||
zoneState.AddFunction(std::move(function));
|
||||
|
||||
// Prepare a list of all menus of this file
|
||||
std::vector<XAssetInfo<menuDef_t>*> allMenusOfFile;
|
||||
allMenusOfFile.reserve(parsingResult->m_menus.size());
|
||||
allMenusOfFile.reserve(parsingResult.m_menus.size());
|
||||
|
||||
// Convert all menus and add them as assets
|
||||
for (auto& commonMenu : parsingResult->m_menus)
|
||||
for (auto& commonMenu : parsingResult.m_menus)
|
||||
{
|
||||
auto converter = IMenuConverter::Create(ObjLoading::Configuration.MenuNoOptimization, m_search_path, m_memory, context);
|
||||
|
||||
@ -173,11 +173,11 @@ namespace
|
||||
registration.AddDependency(menuAssetInfo);
|
||||
}
|
||||
|
||||
zoneState->AddMenu(std::move(commonMenu));
|
||||
zoneState.AddMenu(std::move(commonMenu));
|
||||
}
|
||||
|
||||
// Register this file with all loaded menus
|
||||
conversionState->AddLoadedFile(fileName, std::move(allMenusOfFile));
|
||||
conversionState.AddLoadedFile(fileName, std::move(allMenusOfFile));
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -196,7 +196,7 @@ namespace
|
||||
menuList.menus = nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<menu::ParsingResult> ParseMenuFile(std::istream& stream, const std::string& menuFileName, const menu::MenuAssetZoneState* zoneState)
|
||||
std::unique_ptr<menu::ParsingResult> ParseMenuFile(std::istream& stream, const std::string& menuFileName, const menu::MenuAssetZoneState& zoneState)
|
||||
{
|
||||
menu::MenuFileReader reader(stream, menuFileName, menu::FeatureLevel::IW5, m_search_path);
|
||||
|
||||
|
@ -125,7 +125,7 @@ namespace
|
||||
staticDvarIndexEntry.type = EET_OPERAND;
|
||||
staticDvarIndexEntry.data.operand.dataType = VAL_INT;
|
||||
staticDvarIndexEntry.data.operand.internals.intVal =
|
||||
static_cast<int>(m_conversion_zone_state->AddStaticDvar(*staticDvarNameExpressionValue.m_string_value));
|
||||
static_cast<int>(m_conversion_zone_state.AddStaticDvar(*staticDvarNameExpressionValue.m_string_value));
|
||||
entries.emplace_back(staticDvarIndexEntry);
|
||||
|
||||
expressionEntry parenRight{};
|
||||
@ -133,7 +133,7 @@ namespace
|
||||
parenRight.data.op = OP_RIGHTPAREN;
|
||||
entries.emplace_back(parenRight);
|
||||
|
||||
gameStatement->supportingData = m_conversion_zone_state->m_supporting_data;
|
||||
gameStatement->supportingData = m_conversion_zone_state.m_supporting_data;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -206,18 +206,18 @@ namespace
|
||||
std::string lowerCaseFunctionName(functionCall->m_function_name);
|
||||
utils::MakeStringLowerCase(lowerCaseFunctionName);
|
||||
|
||||
Statement_s* functionStatement = m_conversion_zone_state->FindFunction(lowerCaseFunctionName);
|
||||
Statement_s* functionStatement = m_conversion_zone_state.FindFunction(lowerCaseFunctionName);
|
||||
|
||||
if (functionStatement == nullptr)
|
||||
{
|
||||
// Function was not converted yet: Convert it now
|
||||
const auto foundCommonFunction = m_parsing_zone_state->m_functions_by_name.find(lowerCaseFunctionName);
|
||||
const auto foundCommonFunction = m_parsing_zone_state.m_functions_by_name.find(lowerCaseFunctionName);
|
||||
|
||||
if (foundCommonFunction == m_parsing_zone_state->m_functions_by_name.end())
|
||||
if (foundCommonFunction == m_parsing_zone_state.m_functions_by_name.end())
|
||||
throw MenuConversionException("Failed to find definition for custom function \"" + functionCall->m_function_name + "\"", menu, item);
|
||||
|
||||
functionStatement = ConvertExpression(foundCommonFunction->second->m_value.get(), menu, item);
|
||||
functionStatement = m_conversion_zone_state->AddFunction(lowerCaseFunctionName, functionStatement);
|
||||
functionStatement = m_conversion_zone_state.AddFunction(lowerCaseFunctionName, functionStatement);
|
||||
}
|
||||
|
||||
expressionEntry functionEntry{};
|
||||
@ -227,7 +227,7 @@ namespace
|
||||
entries.emplace_back(functionEntry);
|
||||
|
||||
// Statement uses custom function so it needs supporting data
|
||||
gameStatement->supportingData = m_conversion_zone_state->m_supporting_data;
|
||||
gameStatement->supportingData = m_conversion_zone_state.m_supporting_data;
|
||||
}
|
||||
|
||||
constexpr static expressionOperatorType_e UNARY_OPERATION_MAPPING[static_cast<unsigned>(SimpleUnaryOperationId::COUNT)]{
|
||||
@ -361,7 +361,7 @@ namespace
|
||||
else if (expressionValue->m_type == SimpleExpressionValue::Type::STRING)
|
||||
{
|
||||
entry.data.operand.dataType = VAL_STRING;
|
||||
entry.data.operand.internals.stringVal.string = m_conversion_zone_state->AddString(*expressionValue->m_string_value);
|
||||
entry.data.operand.internals.stringVal.string = m_conversion_zone_state.AddString(*expressionValue->m_string_value);
|
||||
}
|
||||
|
||||
entries.emplace_back(entry);
|
||||
@ -1123,8 +1123,6 @@ namespace
|
||||
m_conversion_zone_state(context.GetZoneAssetLoaderState<MenuConversionZoneState>()),
|
||||
m_parsing_zone_state(context.GetZoneAssetLoaderState<MenuAssetZoneState>())
|
||||
{
|
||||
assert(m_conversion_zone_state);
|
||||
assert(m_parsing_zone_state);
|
||||
}
|
||||
|
||||
void ConvertMenu(const menu::CommonMenuDef& commonMenu, menuDef_t& menu, AssetRegistration<AssetMenu>& registration) override
|
||||
@ -1177,7 +1175,7 @@ namespace
|
||||
menuData->onFocusDueToClose = ConvertEventHandlerSet(commonMenu.m_on_focus_due_to_close.get(), &commonMenu);
|
||||
menuData->onKey = ConvertKeyHandler(commonMenu.m_key_handlers, &commonMenu);
|
||||
menu.items = ConvertMenuItems(commonMenu, menu.itemCount);
|
||||
menuData->expressionData = m_conversion_zone_state->m_supporting_data;
|
||||
menuData->expressionData = m_conversion_zone_state.m_supporting_data;
|
||||
}
|
||||
catch (const MenuConversionException& e)
|
||||
{
|
||||
@ -1185,8 +1183,8 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
MenuConversionZoneState* m_conversion_zone_state;
|
||||
MenuAssetZoneState* m_parsing_zone_state;
|
||||
MenuConversionZoneState& m_conversion_zone_state;
|
||||
MenuAssetZoneState& m_parsing_zone_state;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
@ -822,11 +822,11 @@ namespace
|
||||
|
||||
bool LoadAccuracyGraphs(WeaponFullDef& weaponFullDef, MemoryManager& memory, ISearchPath& searchPath, AssetCreationContext& context)
|
||||
{
|
||||
auto* accuracyGraphLoader = context.GetZoneAssetLoaderState<AccuracyGraphLoader>();
|
||||
auto& accuracyGraphLoader = context.GetZoneAssetLoaderState<AccuracyGraphLoader>();
|
||||
|
||||
if (weaponFullDef.weapDef.aiVsAiAccuracyGraphName && weaponFullDef.weapDef.aiVsAiAccuracyGraphName[0])
|
||||
{
|
||||
const auto* graph = accuracyGraphLoader->LoadAiVsAiGraph(searchPath, weaponFullDef.weapDef.aiVsAiAccuracyGraphName);
|
||||
const auto* graph = accuracyGraphLoader.LoadAiVsAiGraph(searchPath, weaponFullDef.weapDef.aiVsAiAccuracyGraphName);
|
||||
if (!graph)
|
||||
return false;
|
||||
|
||||
@ -840,7 +840,7 @@ namespace
|
||||
|
||||
if (weaponFullDef.weapDef.aiVsPlayerAccuracyGraphName && weaponFullDef.weapDef.aiVsPlayerAccuracyGraphName[0])
|
||||
{
|
||||
const auto* graph = accuracyGraphLoader->LoadAiVsPlayerGraph(searchPath, weaponFullDef.weapDef.aiVsPlayerAccuracyGraphName);
|
||||
const auto* graph = accuracyGraphLoader.LoadAiVsPlayerGraph(searchPath, weaponFullDef.weapDef.aiVsPlayerAccuracyGraphName);
|
||||
if (!graph)
|
||||
return false;
|
||||
|
||||
|
Reference in New Issue
Block a user