chore: make IZoneLoadingState return reference

This commit is contained in:
Jan 2025-01-03 10:42:37 +01:00
parent fa6f9451d2
commit 9068e96dfa
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
14 changed files with 117 additions and 120 deletions

View File

@ -39,8 +39,8 @@ void AbstractImageIPakPostProcessor::FindNextObjContainer(AssetCreationContext&
if (objContainer.m_type != ZoneDefinitionObjContainerType::IPAK)
continue;
auto* ipakCreator = context.GetZoneAssetLoaderState<IPakCreator>();
m_current_ipak = ipakCreator->GetOrAddIPak(objContainer.m_name);
auto& ipakCreator = context.GetZoneAssetLoaderState<IPakCreator>();
m_current_ipak = ipakCreator.GetOrAddIPak(objContainer.m_name);
m_current_ipak_start_index = objContainer.m_asset_start;
m_current_ipak_end_index = objContainer.m_asset_end;
return;
@ -70,5 +70,5 @@ void AbstractImageIPakPostProcessor::PostProcessAsset(XAssetInfoGeneric& assetIn
void AbstractImageIPakPostProcessor::FinalizeZone(AssetCreationContext& context)
{
context.GetZoneAssetLoaderState<IPakCreator>()->Finalize(m_search_path, m_out_dir);
context.GetZoneAssetLoaderState<IPakCreator>().Finalize(m_search_path, m_out_dir);
}

View File

@ -40,8 +40,8 @@ void AbstractImageIwdPostProcessor::FindNextObjContainer(AssetCreationContext& c
if (objContainer.m_type != ZoneDefinitionObjContainerType::IWD)
continue;
auto* iwdCreator = context.GetZoneAssetLoaderState<IwdCreator>();
m_current_iwd = iwdCreator->GetOrAddIwd(objContainer.m_name);
auto& iwdCreator = context.GetZoneAssetLoaderState<IwdCreator>();
m_current_iwd = iwdCreator.GetOrAddIwd(objContainer.m_name);
m_current_iwd_start_index = objContainer.m_asset_start;
m_current_iwd_end_index = objContainer.m_asset_end;
return;
@ -71,5 +71,5 @@ void AbstractImageIwdPostProcessor::PostProcessAsset(XAssetInfoGeneric& assetInf
void AbstractImageIwdPostProcessor::FinalizeZone(AssetCreationContext& context)
{
context.GetZoneAssetLoaderState<IwdCreator>()->Finalize(m_search_path, m_out_dir);
context.GetZoneAssetLoaderState<IwdCreator>().Finalize(m_search_path, m_out_dir);
}

View File

@ -32,20 +32,21 @@ public:
{
}
template<typename T> T* GetZoneAssetLoaderState()
template<typename T> T& GetZoneAssetLoaderState()
{
static_assert(std::is_base_of_v<IZoneAssetLoaderState, T>, "T must inherit IZoneAssetLoaderState");
// T must also have a public default constructor
const auto foundEntry = m_zone_asset_loader_states.find(typeid(T));
if (foundEntry != m_zone_asset_loader_states.end())
return dynamic_cast<T*>(foundEntry->second.get());
return *dynamic_cast<T*>(foundEntry->second.get());
auto newState = std::make_unique<T>();
newState->SetZone(&m_zone);
auto* newStatePtr = newState.get();
m_zone_asset_loader_states.emplace(std::make_pair<std::type_index, std::unique_ptr<IZoneAssetLoaderState>>(typeid(T), std::move(newState)));
return newStatePtr;
return *newStatePtr;
}
protected:

View File

@ -792,7 +792,7 @@ namespace
m_registration.AddDependency(techset);
m_material.techniqueSet = techset->Asset();
auto* definitionCache = m_context.GetZoneAssetLoaderState<techset::TechsetDefinitionCache>();
auto& definitionCache = m_context.GetZoneAssetLoaderState<techset::TechsetDefinitionCache>();
bool failure = false;
const auto* techsetDefinition = m_techset_creator->LoadTechsetDefinition(techsetName, m_context, failure);
@ -855,7 +855,7 @@ namespace
_NODISCARD const state_map::StateMapDefinition* GetStateMapForTechnique(const std::string& techniqueName) const
{
const auto* preloadedStateMap = m_state_map_cache->GetStateMapForTechnique(techniqueName);
const auto* preloadedStateMap = m_state_map_cache.GetStateMapForTechnique(techniqueName);
if (preloadedStateMap)
return preloadedStateMap;
@ -868,13 +868,13 @@ namespace
const techset::TechniqueFileReader reader(*file.m_stream, techniqueFileName, &extractor);
if (!reader.ReadTechniqueDefinition())
{
m_state_map_cache->SetTechniqueUsesStateMap(techniqueName, nullptr);
m_state_map_cache.SetTechniqueUsesStateMap(techniqueName, nullptr);
return nullptr;
}
const auto stateMapName = extractor.RetrieveStateMap();
const auto* loadedStateMap = m_techset_creator->LoadStateMapDefinition(stateMapName, m_context);
m_state_map_cache->SetTechniqueUsesStateMap(techniqueName, loadedStateMap);
m_state_map_cache.SetTechniqueUsesStateMap(techniqueName, loadedStateMap);
return loadedStateMap;
}
@ -1306,7 +1306,7 @@ namespace
AssetCreationContext& m_context;
AssetRegistration<AssetMaterial>& m_registration;
techset::TechniqueStateMapCache* m_state_map_cache;
techset::TechniqueStateMapCache& m_state_map_cache;
std::unordered_map<const state_map::StateMapDefinition*, GfxStateBits> m_state_bits_per_state_map;
GfxStateBits m_base_state_bits;

View File

@ -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::IW4, m_search_path);

View File

@ -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(foundCommonFunction->second->m_name, functionStatement);
functionStatement = m_conversion_zone_state.AddFunction(foundCommonFunction->second->m_name, 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);
@ -1115,8 +1115,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
@ -1165,7 +1163,7 @@ namespace
menu.onESC = ConvertEventHandlerSet(commonMenu.m_on_esc.get(), &commonMenu);
menu.onKey = ConvertKeyHandler(commonMenu.m_key_handlers, &commonMenu);
menu.items = ConvertMenuItems(commonMenu, menu.itemCount);
menu.expressionData = m_conversion_zone_state->m_supporting_data;
menu.expressionData = m_conversion_zone_state.m_supporting_data;
}
catch (const MenuConversionException& e)
{
@ -1173,8 +1171,8 @@ namespace
}
}
MenuConversionZoneState* m_conversion_zone_state;
MenuAssetZoneState* m_parsing_zone_state;
MenuConversionZoneState& m_conversion_zone_state;
MenuAssetZoneState& m_parsing_zone_state;
};
} // namespace

View File

@ -425,7 +425,7 @@ namespace
return false;
}
m_state_map_cache->SetTechniqueUsesStateMap(m_technique_name, stateMap);
m_state_map_cache.SetTechniqueUsesStateMap(m_technique_name, stateMap);
return true;
}
@ -463,7 +463,7 @@ namespace
if (pass.m_vertex_shader->Asset()->name && pass.m_vertex_shader->Asset()->name[0] == ',')
{
pass.m_vertex_shader_info = m_shader_info_cache->LoadShaderInfoFromDisk(m_search_path, GetVertexShaderFileName(vertexShaderName));
pass.m_vertex_shader_info = m_shader_info_cache.LoadShaderInfoFromDisk(m_search_path, GetVertexShaderFileName(vertexShaderName));
}
else
{
@ -498,7 +498,7 @@ namespace
if (pass.m_pixel_shader->Asset()->name && pass.m_pixel_shader->Asset()->name[0] == ',')
{
pass.m_pixel_shader_info = m_shader_info_cache->LoadShaderInfoFromDisk(m_search_path, GetPixelShaderFileName(pixelShaderName));
pass.m_pixel_shader_info = m_shader_info_cache.LoadShaderInfoFromDisk(m_search_path, GetPixelShaderFileName(pixelShaderName));
}
else
{
@ -901,7 +901,7 @@ namespace
}
argument.dest = static_cast<uint16_t>(shaderConstant.m_register_index + registerOffset);
argument.u.literalConst = m_zone_state->GetAllocatedLiteral(m_memory, source);
argument.u.literalConst = m_zone_state.GetAllocatedLiteral(m_memory, source);
pass.m_arguments.emplace_back(argument);
if (shader == techset::ShaderSelector::VERTEX_SHADER)
@ -1021,9 +1021,9 @@ namespace
ISearchPath& m_search_path;
MemoryManager& m_memory;
AssetCreationContext& m_context;
TechniqueZoneLoadingState* m_zone_state;
techset::TechniqueStateMapCache* m_state_map_cache;
ShaderInfoFromFileSystemCacheState* m_shader_info_cache;
TechniqueZoneLoadingState& m_zone_state;
techset::TechniqueStateMapCache& m_state_map_cache;
ShaderInfoFromFileSystemCacheState& m_shader_info_cache;
ITechsetCreator* m_techset_creator;
};
@ -1041,7 +1041,7 @@ namespace
_NODISCARD const LoadedTechnique* LoadMaterialTechnique(const std::string& techniqueName) const
{
auto* technique = m_zone_state->FindLoadedTechnique(techniqueName);
auto* technique = m_zone_state.FindLoadedTechnique(techniqueName);
if (technique)
return technique;
@ -1050,7 +1050,7 @@ namespace
if (techniqueFromRaw == nullptr)
return nullptr;
return m_zone_state->AddLoadedTechnique(techniqueName, techniqueFromRaw, dependencies);
return m_zone_state.AddLoadedTechnique(techniqueName, techniqueFromRaw, dependencies);
}
private:
@ -1257,7 +1257,7 @@ namespace
ISearchPath& m_search_path;
MemoryManager& m_memory;
AssetCreationContext& m_context;
TechniqueZoneLoadingState* m_zone_state;
TechniqueZoneLoadingState& m_zone_state;
ITechsetCreator* m_techset_creator;
};
@ -1313,8 +1313,8 @@ namespace
techset::TechsetDefinition* LoadTechsetDefinition(const std::string& assetName, AssetCreationContext& context, bool& failure) override
{
failure = false;
auto* definitionCache = context.GetZoneAssetLoaderState<techset::TechsetDefinitionCache>();
auto* cachedTechsetDefinition = definitionCache->GetCachedTechsetDefinition(assetName);
auto& definitionCache = context.GetZoneAssetLoaderState<techset::TechsetDefinitionCache>();
auto* cachedTechsetDefinition = definitionCache.GetCachedTechsetDefinition(assetName);
if (cachedTechsetDefinition)
return cachedTechsetDefinition;
@ -1333,15 +1333,15 @@ namespace
auto* techsetDefinitionPtr = techsetDefinition.get();
definitionCache->AddTechsetDefinitionToCache(assetName, std::move(techsetDefinition));
definitionCache.AddTechsetDefinitionToCache(assetName, std::move(techsetDefinition));
return techsetDefinitionPtr;
}
const state_map::StateMapDefinition* LoadStateMapDefinition(const std::string& stateMapName, AssetCreationContext& context) override
{
auto* stateMapCache = context.GetZoneAssetLoaderState<techset::TechniqueStateMapCache>();
auto* cachedStateMap = stateMapCache->GetCachedStateMap(stateMapName);
auto& stateMapCache = context.GetZoneAssetLoaderState<techset::TechniqueStateMapCache>();
auto* cachedStateMap = stateMapCache.GetCachedStateMap(stateMapName);
if (cachedStateMap)
return cachedStateMap;
@ -1357,7 +1357,7 @@ namespace
const auto* stateMapDefinitionPtr = stateMapDefinition.get();
stateMapCache->AddStateMapToCache(std::move(stateMapDefinition));
stateMapCache.AddStateMapToCache(std::move(stateMapDefinition));
return stateMapDefinitionPtr;
}

View File

@ -392,11 +392,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;
@ -410,7 +410,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;

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -409,11 +409,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;
@ -427,7 +427,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;

View File

@ -100,9 +100,9 @@ std::unique_ptr<ParsingResult> MenuFileReader::CreateParsingResult(MenuFileParse
return result;
}
void MenuFileReader::IncludeZoneState(const MenuAssetZoneState* zoneState)
void MenuFileReader::IncludeZoneState(const MenuAssetZoneState& zoneState)
{
m_zone_state = zoneState;
m_zone_state = &zoneState;
}
void MenuFileReader::SetPermissiveMode(const bool usePermissiveMode)

View File

@ -19,7 +19,7 @@ namespace menu
public:
MenuFileReader(std::istream& stream, std::string fileName, FeatureLevel featureLevel, ISearchPath& searchPath);
void IncludeZoneState(const MenuAssetZoneState* zoneState);
void IncludeZoneState(const MenuAssetZoneState& zoneState);
void SetPermissiveMode(bool usePermissiveMode);
std::unique_ptr<ParsingResult> ReadMenuFile();