From 8b85cadb77e2f3cbd759928100f3b4b176995f88 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 2 May 2025 11:42:17 +0100 Subject: [PATCH] refactor: make memory from zone a reference instead of ptr --- src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp | 4 +-- src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp | 4 +-- src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp | 4 +-- src/ObjCompiling/Game/T5/ObjCompilerT5.cpp | 4 +-- src/ObjCompiling/Game/T6/ObjCompilerT6.cpp | 4 +-- src/ObjLoading/Game/IW3/ObjLoaderIW3.cpp | 4 +-- .../IW4/Menu/MenuConversionZoneStateIW4.cpp | 28 +++++++++---------- src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp | 4 +-- .../IW5/Menu/MenuConversionZoneStateIW5.cpp | 28 +++++++++---------- src/ObjLoading/Game/IW5/ObjLoaderIW5.cpp | 4 +-- src/ObjLoading/Game/T5/ObjLoaderT5.cpp | 4 +-- src/ObjLoading/Game/T6/ObjLoaderT6.cpp | 4 +-- .../Generating/Templates/ZoneLoadTemplate.cpp | 2 +- src/ZoneCommon/Zone/Zone.cpp | 12 ++++---- src/ZoneCommon/Zone/Zone.h | 12 ++++---- .../IW3/XAssets/gfximage/gfximage_actions.cpp | 2 +- .../loadedsound/loadedsound_actions.cpp | 2 +- .../IW4/XAssets/gfximage/gfximage_actions.cpp | 2 +- .../loadedsound/loadedsound_actions.cpp | 2 +- .../IW4/XAssets/xmodel/xmodel_actions.cpp | 2 +- .../XAssets/clipmap_t/clipmap_t_actions.cpp | 2 +- .../IW5/XAssets/gfximage/gfximage_actions.cpp | 2 +- .../loadedsound/loadedsound_actions.cpp | 2 +- .../IW5/XAssets/xmodel/xmodel_actions.cpp | 2 +- .../T5/XAssets/gfximage/gfximage_actions.cpp | 2 +- .../T6/XAssets/gfximage/gfximage_actions.cpp | 2 +- src/ZoneLoading/Loading/ContentLoaderBase.cpp | 4 +-- src/ZoneLoading/Loading/ZoneLoader.cpp | 2 +- .../Game/IW4/Menu/LoaderMenuListIW4Test.cpp | 6 ++-- 29 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp b/src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp index 69c47261..02e34655 100644 --- a/src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp +++ b/src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp @@ -11,7 +11,7 @@ namespace { void ConfigureCompilers(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); // No compilers yet } @@ -23,7 +23,7 @@ namespace ZoneAssetCreationStateContainer& zoneStates, IOutputPath& outDir) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); if (ImageIwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); diff --git a/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp b/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp index ed6b6963..9990d794 100644 --- a/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp +++ b/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp @@ -11,7 +11,7 @@ namespace { void ConfigureCompilers(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); // No compilers yet } @@ -23,7 +23,7 @@ namespace ZoneAssetCreationStateContainer& zoneStates, IOutputPath& outDir) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); if (ImageIwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); diff --git a/src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp b/src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp index e9faf12e..fe02ead8 100644 --- a/src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp +++ b/src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp @@ -11,7 +11,7 @@ namespace { void ConfigureCompilers(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); // No compilers yet } @@ -23,7 +23,7 @@ namespace ZoneAssetCreationStateContainer& zoneStates, IOutputPath& outDir) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); if (ImageIwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); diff --git a/src/ObjCompiling/Game/T5/ObjCompilerT5.cpp b/src/ObjCompiling/Game/T5/ObjCompilerT5.cpp index e08a010f..3ca4d416 100644 --- a/src/ObjCompiling/Game/T5/ObjCompilerT5.cpp +++ b/src/ObjCompiling/Game/T5/ObjCompilerT5.cpp @@ -11,7 +11,7 @@ namespace { void ConfigureCompilers(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); // No compilers yet } @@ -23,7 +23,7 @@ namespace ZoneAssetCreationStateContainer& zoneStates, IOutputPath& outDir) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); if (ImageIwdPostProcessor::AppliesToZoneDefinition(zoneDefinition)) collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); diff --git a/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp b/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp index 5052d5ab..eae90387 100644 --- a/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp +++ b/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp @@ -17,7 +17,7 @@ namespace ISearchPath& searchPath, ZoneAssetCreationStateContainer& zoneStates) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); collection.AddAssetCreator(CreateKeyValuePairsCompiler(memory, zone, zoneDefinition.m_zone_definition, zoneStates)); } @@ -29,7 +29,7 @@ namespace ZoneAssetCreationStateContainer& zoneStates, IOutputPath& outDir) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); if (ImageIPakPostProcessor::AppliesToZoneDefinition(zoneDefinition)) collection.AddAssetPostProcessor(std::make_unique>(zoneDefinition, searchPath, zoneStates, outDir)); diff --git a/src/ObjLoading/Game/IW3/ObjLoaderIW3.cpp b/src/ObjLoading/Game/IW3/ObjLoaderIW3.cpp index 8658c73e..eeb2d3a8 100644 --- a/src/ObjLoading/Game/IW3/ObjLoaderIW3.cpp +++ b/src/ObjLoading/Game/IW3/ObjLoaderIW3.cpp @@ -21,7 +21,7 @@ namespace { void ConfigureDefaultCreators(AssetCreatorCollection& collection, Zone& zone) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); collection.AddDefaultAssetCreator(std::make_unique>(memory)); collection.AddDefaultAssetCreator(std::make_unique>(memory)); @@ -85,7 +85,7 @@ namespace void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); diff --git a/src/ObjLoading/Game/IW4/Menu/MenuConversionZoneStateIW4.cpp b/src/ObjLoading/Game/IW4/Menu/MenuConversionZoneStateIW4.cpp index 68d9ebe8..ade6a824 100644 --- a/src/ObjLoading/Game/IW4/Menu/MenuConversionZoneStateIW4.cpp +++ b/src/ObjLoading/Game/IW4/Menu/MenuConversionZoneStateIW4.cpp @@ -12,10 +12,10 @@ MenuConversionZoneState::MenuConversionZoneState() void MenuConversionZoneState::Inject(ZoneAssetCreationInjection& inject) { - auto* memory = inject.m_zone.GetMemory(); + auto& memory = inject.m_zone.Memory(); m_zone = &inject.m_zone; - m_supporting_data = memory->Alloc(); + m_supporting_data = memory.Alloc(); } Statement_s* MenuConversionZoneState::FindFunction(const std::string& functionName) @@ -43,10 +43,10 @@ size_t MenuConversionZoneState::AddStaticDvar(const std::string& dvarName) if (foundDvar != m_dvars_by_name.end()) return foundDvar->second; - auto* memory = m_zone->GetMemory(); - auto* staticDvar = memory->Alloc(); + auto& memory = m_zone->Memory(); + auto* staticDvar = memory.Alloc(); - staticDvar->dvarName = memory->Dup(dvarName.c_str()); + staticDvar->dvarName = memory.Dup(dvarName.c_str()); staticDvar->dvar = nullptr; const auto staticDvarIndex = m_static_dvars.size(); @@ -63,8 +63,8 @@ const char* MenuConversionZoneState::AddString(const std::string& str) if (foundString != m_strings_by_value.end()) return foundString->second; - auto* memory = m_zone->GetMemory(); - const auto* strDuped = memory->Dup(str.c_str()); + auto& memory = m_zone->Memory(); + const auto* strDuped = memory.Dup(str.c_str()); m_strings.push_back(strDuped); m_strings_by_value.emplace(std::make_pair(str, strDuped)); @@ -79,24 +79,24 @@ void MenuConversionZoneState::AddLoadedFile(std::string loadedFileName, std::vec void MenuConversionZoneState::FinalizeSupportingData() const { - auto* memory = m_zone->GetMemory(); + auto& memory = m_zone->Memory(); m_supporting_data->uifunctions.totalFunctions = static_cast(m_functions.size()); m_supporting_data->staticDvarList.numStaticDvars = static_cast(m_static_dvars.size()); m_supporting_data->uiStrings.totalStrings = static_cast(m_strings.size()); if (m_supporting_data->uifunctions.functions) - memory->Free(m_supporting_data->uifunctions.functions); + memory.Free(m_supporting_data->uifunctions.functions); if (m_supporting_data->staticDvarList.staticDvars) - memory->Free(m_supporting_data->staticDvarList.staticDvars); + memory.Free(m_supporting_data->staticDvarList.staticDvars); if (m_supporting_data->uiStrings.strings) - memory->Free(m_supporting_data->uiStrings.strings); + memory.Free(m_supporting_data->uiStrings.strings); if (!m_functions.empty()) { - m_supporting_data->uifunctions.functions = memory->Alloc(m_functions.size()); + m_supporting_data->uifunctions.functions = memory.Alloc(m_functions.size()); memcpy(m_supporting_data->uifunctions.functions, m_functions.data(), sizeof(void*) * m_functions.size()); } else @@ -104,7 +104,7 @@ void MenuConversionZoneState::FinalizeSupportingData() const if (!m_static_dvars.empty()) { - m_supporting_data->staticDvarList.staticDvars = memory->Alloc(m_static_dvars.size()); + m_supporting_data->staticDvarList.staticDvars = memory.Alloc(m_static_dvars.size()); memcpy(m_supporting_data->staticDvarList.staticDvars, m_static_dvars.data(), sizeof(void*) * m_static_dvars.size()); } else @@ -112,7 +112,7 @@ void MenuConversionZoneState::FinalizeSupportingData() const if (!m_strings.empty()) { - m_supporting_data->uiStrings.strings = memory->Alloc(m_strings.size()); + m_supporting_data->uiStrings.strings = memory.Alloc(m_strings.size()); memcpy(m_supporting_data->uiStrings.strings, m_strings.data(), sizeof(void*) * m_strings.size()); } else diff --git a/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp b/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp index d3fc0d40..c124a7f9 100644 --- a/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp +++ b/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp @@ -34,7 +34,7 @@ namespace { void ConfigureDefaultCreators(AssetCreatorCollection& collection, Zone& zone) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); collection.AddDefaultAssetCreator(std::make_unique>(memory)); collection.AddDefaultAssetCreator(std::make_unique>(memory)); @@ -118,7 +118,7 @@ namespace void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); collection.AddAssetCreator(std::make_unique(memory, searchPath, zone)); collection.AddAssetCreator(std::make_unique(memory, gdt, zone)); diff --git a/src/ObjLoading/Game/IW5/Menu/MenuConversionZoneStateIW5.cpp b/src/ObjLoading/Game/IW5/Menu/MenuConversionZoneStateIW5.cpp index 58234579..ef55af7c 100644 --- a/src/ObjLoading/Game/IW5/Menu/MenuConversionZoneStateIW5.cpp +++ b/src/ObjLoading/Game/IW5/Menu/MenuConversionZoneStateIW5.cpp @@ -12,10 +12,10 @@ MenuConversionZoneState::MenuConversionZoneState() void MenuConversionZoneState::Inject(ZoneAssetCreationInjection& inject) { - auto* memory = inject.m_zone.GetMemory(); + auto& memory = inject.m_zone.Memory(); m_zone = &inject.m_zone; - m_supporting_data = memory->Alloc(); + m_supporting_data = memory.Alloc(); } Statement_s* MenuConversionZoneState::FindFunction(const std::string& functionName) @@ -43,10 +43,10 @@ size_t MenuConversionZoneState::AddStaticDvar(const std::string& dvarName) if (foundDvar != m_dvars_by_name.end()) return foundDvar->second; - auto* memory = m_zone->GetMemory(); - auto* staticDvar = memory->Alloc(); + auto& memory = m_zone->Memory(); + auto* staticDvar = memory.Alloc(); - staticDvar->dvarName = memory->Dup(dvarName.c_str()); + staticDvar->dvarName = memory.Dup(dvarName.c_str()); staticDvar->dvar = nullptr; const auto staticDvarIndex = m_static_dvars.size(); @@ -63,8 +63,8 @@ const char* MenuConversionZoneState::AddString(const std::string& str) if (foundString != m_strings_by_value.end()) return foundString->second; - auto* memory = m_zone->GetMemory(); - const auto* strDuped = memory->Dup(str.c_str()); + auto& memory = m_zone->Memory(); + const auto* strDuped = memory.Dup(str.c_str()); m_strings.push_back(strDuped); m_strings_by_value.emplace(std::make_pair(str, strDuped)); @@ -79,24 +79,24 @@ void MenuConversionZoneState::AddLoadedFile(std::string loadedFileName, std::vec void MenuConversionZoneState::FinalizeSupportingData() const { - auto* memory = m_zone->GetMemory(); + auto& memory = m_zone->Memory(); m_supporting_data->uifunctions.totalFunctions = static_cast(m_functions.size()); m_supporting_data->staticDvarList.numStaticDvars = static_cast(m_static_dvars.size()); m_supporting_data->uiStrings.totalStrings = static_cast(m_strings.size()); if (m_supporting_data->uifunctions.functions) - memory->Free(m_supporting_data->uifunctions.functions); + memory.Free(m_supporting_data->uifunctions.functions); if (m_supporting_data->staticDvarList.staticDvars) - memory->Free(m_supporting_data->staticDvarList.staticDvars); + memory.Free(m_supporting_data->staticDvarList.staticDvars); if (m_supporting_data->uiStrings.strings) - memory->Free(m_supporting_data->uiStrings.strings); + memory.Free(m_supporting_data->uiStrings.strings); if (!m_functions.empty()) { - m_supporting_data->uifunctions.functions = memory->Alloc(m_functions.size()); + m_supporting_data->uifunctions.functions = memory.Alloc(m_functions.size()); memcpy(m_supporting_data->uifunctions.functions, m_functions.data(), sizeof(void*) * m_functions.size()); } else @@ -104,7 +104,7 @@ void MenuConversionZoneState::FinalizeSupportingData() const if (!m_static_dvars.empty()) { - m_supporting_data->staticDvarList.staticDvars = memory->Alloc(m_static_dvars.size()); + m_supporting_data->staticDvarList.staticDvars = memory.Alloc(m_static_dvars.size()); memcpy(m_supporting_data->staticDvarList.staticDvars, m_static_dvars.data(), sizeof(void*) * m_static_dvars.size()); } else @@ -112,7 +112,7 @@ void MenuConversionZoneState::FinalizeSupportingData() const if (!m_strings.empty()) { - m_supporting_data->uiStrings.strings = memory->Alloc(m_strings.size()); + m_supporting_data->uiStrings.strings = memory.Alloc(m_strings.size()); memcpy(m_supporting_data->uiStrings.strings, m_strings.data(), sizeof(void*) * m_strings.size()); } else diff --git a/src/ObjLoading/Game/IW5/ObjLoaderIW5.cpp b/src/ObjLoading/Game/IW5/ObjLoaderIW5.cpp index 49aad040..4755450f 100644 --- a/src/ObjLoading/Game/IW5/ObjLoaderIW5.cpp +++ b/src/ObjLoading/Game/IW5/ObjLoaderIW5.cpp @@ -29,7 +29,7 @@ namespace { void ConfigureDefaultCreators(AssetCreatorCollection& collection, Zone& zone) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); collection.AddDefaultAssetCreator(std::make_unique>(memory)); collection.AddDefaultAssetCreator(std::make_unique>(memory)); @@ -119,7 +119,7 @@ namespace void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); diff --git a/src/ObjLoading/Game/T5/ObjLoaderT5.cpp b/src/ObjLoading/Game/T5/ObjLoaderT5.cpp index 8f317d2c..1f4d8132 100644 --- a/src/ObjLoading/Game/T5/ObjLoaderT5.cpp +++ b/src/ObjLoading/Game/T5/ObjLoaderT5.cpp @@ -21,7 +21,7 @@ namespace { void ConfigureDefaultCreators(AssetCreatorCollection& collection, Zone& zone) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); collection.AddDefaultAssetCreator(std::make_unique>(memory)); collection.AddDefaultAssetCreator(std::make_unique>(memory)); @@ -97,7 +97,7 @@ namespace void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); diff --git a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp index 9853b1ef..37afdf89 100644 --- a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp +++ b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp @@ -284,7 +284,7 @@ namespace T6 { void ConfigureDefaultCreators(AssetCreatorCollection& collection, Zone& zone) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); collection.AddDefaultAssetCreator(std::make_unique>(memory)); collection.AddDefaultAssetCreator(std::make_unique>(memory)); @@ -390,7 +390,7 @@ namespace T6 void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt) { - auto& memory = *zone.GetMemory(); + auto& memory = zone.Memory(); collection.AddAssetCreator(CreateRawPhysPresetLoader(memory, searchPath, zone)); collection.AddAssetCreator(CreateGdtPhysPresetLoader(memory, searchPath, gdt, zone)); diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp index 48b602fc..97efda87 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp @@ -1269,7 +1269,7 @@ namespace LINEF("{0} marker(m_zone);", MarkerClassName(m_env.m_asset)) LINE("marker.Mark(*pAsset);") LINE("") - LINEF("auto* reallocatedAsset = m_zone.GetMemory()->Alloc<{0}>();", info->m_definition->GetFullName()) + LINEF("auto* reallocatedAsset = m_zone.Memory().Alloc<{0}>();", info->m_definition->GetFullName()) LINEF("std::memcpy(reallocatedAsset, *pAsset, sizeof({0}));", info->m_definition->GetFullName()) LINE("") LINEF("m_asset_info = reinterpret_cast*>(LinkAsset(AssetNameAccessor<{1}>()(**pAsset), reallocatedAsset, marker.GetDependencies(), " diff --git a/src/ZoneCommon/Zone/Zone.cpp b/src/ZoneCommon/Zone/Zone.cpp index 5014120a..f5ee6af1 100644 --- a/src/ZoneCommon/Zone/Zone.cpp +++ b/src/ZoneCommon/Zone/Zone.cpp @@ -1,13 +1,13 @@ #include "Zone.h" Zone::Zone(std::string name, const zone_priority_t priority, IGame* game) - : m_memory(std::make_unique()), - m_registered(false), - m_name(std::move(name)), + : m_name(std::move(name)), m_priority(priority), m_language(GameLanguage::LANGUAGE_NONE), m_game(game), - m_pools(ZoneAssetPools::CreateForGame(game->GetId(), this, priority)) + m_pools(ZoneAssetPools::CreateForGame(game->GetId(), this, priority)), + m_memory(std::make_unique()), + m_registered(false) { } @@ -28,7 +28,7 @@ void Zone::Register() } } -ZoneMemory* Zone::GetMemory() const +ZoneMemory& Zone::Memory() const { - return m_memory.get(); + return *m_memory; } diff --git a/src/ZoneCommon/Zone/Zone.h b/src/ZoneCommon/Zone/Zone.h index 9f586b83..48c4d7d6 100644 --- a/src/ZoneCommon/Zone/Zone.h +++ b/src/ZoneCommon/Zone/Zone.h @@ -3,7 +3,6 @@ #include "Game/GameLanguage.h" #include "Game/IGame.h" #include "Pool/ZoneAssetPools.h" -#include "Utils/ClassUtils.h" #include "Zone/ZoneTypes.h" #include "ZoneMemory.h" #include "ZoneScriptStrings.h" @@ -16,10 +15,6 @@ class ZoneAssetPools; class Zone { - std::unique_ptr m_memory; - - bool m_registered; - public: std::string m_name; zone_priority_t m_priority; @@ -37,5 +32,10 @@ public: void Register(); - _NODISCARD ZoneMemory* GetMemory() const; + [[nodiscard]] ZoneMemory& Memory() const; + +private: + std::unique_ptr m_memory; + + bool m_registered; }; diff --git a/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.cpp b/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.cpp index 294ec7f6..b2585045 100644 --- a/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.cpp +++ b/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.cpp @@ -19,6 +19,6 @@ void Actions_GfxImage::LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) { const size_t loadDefSize = offsetof(IW3::GfxImageLoadDef, data) + loadDef->resourceSize; - image->texture.loadDef = static_cast(m_zone.GetMemory()->AllocRaw(loadDefSize)); + image->texture.loadDef = static_cast(m_zone.Memory().AllocRaw(loadDefSize)); memcpy(image->texture.loadDef, loadDef, loadDefSize); } diff --git a/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.cpp b/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.cpp index 26169d25..5d899987 100644 --- a/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.cpp +++ b/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.cpp @@ -14,7 +14,7 @@ void Actions_LoadedSound::SetSoundData(MssSound* sound) const if (sound->info.data_len > 0) { const auto* tempData = sound->data; - sound->data = m_zone.GetMemory()->Alloc(sound->info.data_len); + sound->data = m_zone.Memory().Alloc(sound->info.data_len); memcpy(sound->data, tempData, sound->info.data_len); } else diff --git a/src/ZoneLoading/Game/IW4/XAssets/gfximage/gfximage_actions.cpp b/src/ZoneLoading/Game/IW4/XAssets/gfximage/gfximage_actions.cpp index de0519f2..31e30897 100644 --- a/src/ZoneLoading/Game/IW4/XAssets/gfximage/gfximage_actions.cpp +++ b/src/ZoneLoading/Game/IW4/XAssets/gfximage/gfximage_actions.cpp @@ -19,6 +19,6 @@ void Actions_GfxImage::LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) { const size_t loadDefSize = offsetof(IW4::GfxImageLoadDef, data) + loadDef->resourceSize; - image->texture.loadDef = static_cast(m_zone.GetMemory()->AllocRaw(loadDefSize)); + image->texture.loadDef = static_cast(m_zone.Memory().AllocRaw(loadDefSize)); memcpy(image->texture.loadDef, loadDef, loadDefSize); } diff --git a/src/ZoneLoading/Game/IW4/XAssets/loadedsound/loadedsound_actions.cpp b/src/ZoneLoading/Game/IW4/XAssets/loadedsound/loadedsound_actions.cpp index 5b6549ed..9a3a571b 100644 --- a/src/ZoneLoading/Game/IW4/XAssets/loadedsound/loadedsound_actions.cpp +++ b/src/ZoneLoading/Game/IW4/XAssets/loadedsound/loadedsound_actions.cpp @@ -14,7 +14,7 @@ void Actions_LoadedSound::SetSoundData(MssSound* sound) const if (sound->info.data_len > 0) { const auto* tempData = sound->data; - sound->data = m_zone.GetMemory()->Alloc(sound->info.data_len); + sound->data = m_zone.Memory().Alloc(sound->info.data_len); memcpy(sound->data, tempData, sound->info.data_len); } else diff --git a/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.cpp b/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.cpp index 2966bfa1..be873394 100644 --- a/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.cpp +++ b/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.cpp @@ -13,7 +13,7 @@ void Actions_XModel::SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSur { if (modelSurfs) { - lodInfo->modelSurfs = m_zone.GetMemory()->Alloc(); + lodInfo->modelSurfs = m_zone.Memory().Alloc(); memcpy(lodInfo->modelSurfs, modelSurfs, sizeof(XModelSurfs)); } } diff --git a/src/ZoneLoading/Game/IW5/XAssets/clipmap_t/clipmap_t_actions.cpp b/src/ZoneLoading/Game/IW5/XAssets/clipmap_t/clipmap_t_actions.cpp index a75b267c..08492510 100644 --- a/src/ZoneLoading/Game/IW5/XAssets/clipmap_t/clipmap_t_actions.cpp +++ b/src/ZoneLoading/Game/IW5/XAssets/clipmap_t/clipmap_t_actions.cpp @@ -12,6 +12,6 @@ Actions_clipMap_t::Actions_clipMap_t(Zone& zone) void Actions_clipMap_t::ReallocClipInfo(const ClipInfo* clipInfo, clipMap_t* clipMap) const { - clipMap->pInfo = m_zone.GetMemory()->Alloc(); + clipMap->pInfo = m_zone.Memory().Alloc(); memcpy(clipMap->pInfo, clipInfo, sizeof(ClipInfo)); } diff --git a/src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.cpp b/src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.cpp index 5675ee3c..70b58e51 100644 --- a/src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.cpp +++ b/src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.cpp @@ -19,6 +19,6 @@ void Actions_GfxImage::LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) { const size_t loadDefSize = offsetof(IW5::GfxImageLoadDef, data) + loadDef->resourceSize; - image->texture.loadDef = static_cast(m_zone.GetMemory()->AllocRaw(loadDefSize)); + image->texture.loadDef = static_cast(m_zone.Memory().AllocRaw(loadDefSize)); memcpy(image->texture.loadDef, loadDef, loadDefSize); } diff --git a/src/ZoneLoading/Game/IW5/XAssets/loadedsound/loadedsound_actions.cpp b/src/ZoneLoading/Game/IW5/XAssets/loadedsound/loadedsound_actions.cpp index a462e4e5..d8fbad7a 100644 --- a/src/ZoneLoading/Game/IW5/XAssets/loadedsound/loadedsound_actions.cpp +++ b/src/ZoneLoading/Game/IW5/XAssets/loadedsound/loadedsound_actions.cpp @@ -14,7 +14,7 @@ void Actions_LoadedSound::SetSoundData(MssSound* sound) const if (sound->info.data_len > 0) { char* tempData = sound->data; - sound->data = m_zone.GetMemory()->Alloc(sound->info.data_len); + sound->data = m_zone.Memory().Alloc(sound->info.data_len); memcpy(sound->data, tempData, sound->info.data_len); } else diff --git a/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp b/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp index b54a996f..c082e8ed 100644 --- a/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp +++ b/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp @@ -13,7 +13,7 @@ void Actions_XModel::SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSur { if (modelSurfs) { - lodInfo->modelSurfs = m_zone.GetMemory()->Alloc(); + lodInfo->modelSurfs = m_zone.Memory().Alloc(); memcpy(lodInfo->modelSurfs, modelSurfs, sizeof(XModelSurfs)); } } diff --git a/src/ZoneLoading/Game/T5/XAssets/gfximage/gfximage_actions.cpp b/src/ZoneLoading/Game/T5/XAssets/gfximage/gfximage_actions.cpp index 32ef5280..dff82fb6 100644 --- a/src/ZoneLoading/Game/T5/XAssets/gfximage/gfximage_actions.cpp +++ b/src/ZoneLoading/Game/T5/XAssets/gfximage/gfximage_actions.cpp @@ -19,6 +19,6 @@ void Actions_GfxImage::LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) { const size_t loadDefSize = offsetof(GfxImageLoadDef, data) + loadDef->resourceSize; - image->texture.loadDef = static_cast(m_zone.GetMemory()->AllocRaw(loadDefSize)); + image->texture.loadDef = static_cast(m_zone.Memory().AllocRaw(loadDefSize)); memcpy(image->texture.loadDef, loadDef, loadDefSize); } diff --git a/src/ZoneLoading/Game/T6/XAssets/gfximage/gfximage_actions.cpp b/src/ZoneLoading/Game/T6/XAssets/gfximage/gfximage_actions.cpp index 96144dab..41763a0d 100644 --- a/src/ZoneLoading/Game/T6/XAssets/gfximage/gfximage_actions.cpp +++ b/src/ZoneLoading/Game/T6/XAssets/gfximage/gfximage_actions.cpp @@ -19,6 +19,6 @@ void Actions_GfxImage::LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) { const size_t loadDefSize = offsetof(T6::GfxImageLoadDef, data) + loadDef->resourceSize; - image->texture.loadDef = static_cast(m_zone.GetMemory()->AllocRaw(loadDefSize)); + image->texture.loadDef = static_cast(m_zone.Memory().AllocRaw(loadDefSize)); memcpy(image->texture.loadDef, loadDef, loadDefSize); } diff --git a/src/ZoneLoading/Loading/ContentLoaderBase.cpp b/src/ZoneLoading/Loading/ContentLoaderBase.cpp index 2fc499d3..dab7ada3 100644 --- a/src/ZoneLoading/Loading/ContentLoaderBase.cpp +++ b/src/ZoneLoading/Loading/ContentLoaderBase.cpp @@ -5,7 +5,7 @@ ContentLoaderBase::ContentLoaderBase(Zone& zone) : varXString(nullptr), m_zone(zone), - m_memory(*zone.GetMemory()), + m_memory(zone.Memory()), m_stream(nullptr) { } @@ -13,7 +13,7 @@ ContentLoaderBase::ContentLoaderBase(Zone& zone) ContentLoaderBase::ContentLoaderBase(Zone& zone, IZoneInputStream* stream) : varXString(nullptr), m_zone(zone), - m_memory(*zone.GetMemory()), + m_memory(zone.Memory()), m_stream(stream) { } diff --git a/src/ZoneLoading/Loading/ZoneLoader.cpp b/src/ZoneLoading/Loading/ZoneLoader.cpp index e3569b24..d626372a 100644 --- a/src/ZoneLoading/Loading/ZoneLoader.cpp +++ b/src/ZoneLoading/Loading/ZoneLoader.cpp @@ -36,7 +36,7 @@ void ZoneLoader::AddXBlock(std::unique_ptr block) return b1->m_index < b2->m_index; }); - m_zone->GetMemory()->AddBlock(std::move(block)); + m_zone->Memory().AddBlock(std::move(block)); } void ZoneLoader::AddLoadingStep(std::unique_ptr step) diff --git a/test/ObjLoadingTests/Game/IW4/Menu/LoaderMenuListIW4Test.cpp b/test/ObjLoadingTests/Game/IW4/Menu/LoaderMenuListIW4Test.cpp index c9029a9c..69021fe5 100644 --- a/test/ObjLoadingTests/Game/IW4/Menu/LoaderMenuListIW4Test.cpp +++ b/test/ObjLoadingTests/Game/IW4/Menu/LoaderMenuListIW4Test.cpp @@ -36,7 +36,7 @@ namespace test::game::iw4::menu::parsing::it m_ignored_asset_lookup(), m_context(m_zone, &m_creator_collection, &m_ignored_asset_lookup) { - m_asset_creator = CreateMenuListLoader(*m_zone.GetMemory(), m_search_path); + m_asset_creator = CreateMenuListLoader(m_zone.Memory(), m_search_path); } void AddFile(std::string fileName, std::string data) @@ -51,8 +51,8 @@ namespace test::game::iw4::menu::parsing::it Material* AddMaterial(const std::string& name) { - auto* material = m_zone.GetMemory()->Alloc(); - material->info.name = m_zone.GetMemory()->Dup(name.c_str()); + auto* material = m_zone.Memory().Alloc(); + material->info.name = m_zone.Memory().Dup(name.c_str()); m_context.AddAsset(name, material);