From 9e940a6f53a1ea339d5b432903dbd576878e6b3a Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 2 May 2025 11:19:52 +0100 Subject: [PATCH] refactor: use zone reference in AssetLoader --- .../Generating/Templates/ZoneLoadTemplate.cpp | 6 ++--- .../Generating/Templates/ZoneMarkTemplate.cpp | 4 +-- src/ZoneLoading/Game/IW3/ContentLoaderIW3.cpp | 12 ++++----- src/ZoneLoading/Game/IW3/ContentLoaderIW3.h | 14 +++++----- .../IW3/XAssets/gfximage/gfximage_actions.cpp | 4 +-- .../IW3/XAssets/gfximage/gfximage_actions.h | 2 +- .../loadedsound/loadedsound_actions.cpp | 4 +-- .../XAssets/loadedsound/loadedsound_actions.h | 2 +- .../Game/IW3/ZoneLoaderFactoryIW3.cpp | 4 +-- src/ZoneLoading/Game/IW4/ContentLoaderIW4.cpp | 12 ++++----- src/ZoneLoading/Game/IW4/ContentLoaderIW4.h | 4 +-- .../IW4/XAssets/gfximage/gfximage_actions.cpp | 4 +-- .../IW4/XAssets/gfximage/gfximage_actions.h | 2 +- .../loadedsound/loadedsound_actions.cpp | 4 +-- .../XAssets/loadedsound/loadedsound_actions.h | 2 +- .../IW4/XAssets/xmodel/xmodel_actions.cpp | 4 +-- .../Game/IW4/XAssets/xmodel/xmodel_actions.h | 2 +- .../Game/IW4/ZoneLoaderFactoryIW4.cpp | 4 +-- src/ZoneLoading/Game/IW5/ContentLoaderIW5.cpp | 12 ++++----- src/ZoneLoading/Game/IW5/ContentLoaderIW5.h | 14 +++++----- .../XAssets/clipmap_t/clipmap_t_actions.cpp | 4 +-- .../IW5/XAssets/clipmap_t/clipmap_t_actions.h | 2 +- .../IW5/XAssets/gfximage/gfximage_actions.cpp | 4 +-- .../IW5/XAssets/gfximage/gfximage_actions.h | 2 +- .../loadedsound/loadedsound_actions.cpp | 4 +-- .../XAssets/loadedsound/loadedsound_actions.h | 2 +- .../IW5/XAssets/xmodel/xmodel_actions.cpp | 4 +-- .../Game/IW5/XAssets/xmodel/xmodel_actions.h | 2 +- .../Game/IW5/ZoneLoaderFactoryIW5.cpp | 4 +-- src/ZoneLoading/Game/T5/ContentLoaderT5.cpp | 12 ++++----- src/ZoneLoading/Game/T5/ContentLoaderT5.h | 14 +++++----- .../T5/XAssets/gfximage/gfximage_actions.cpp | 4 +-- .../T5/XAssets/gfximage/gfximage_actions.h | 2 +- .../Game/T5/ZoneLoaderFactoryT5.cpp | 4 +-- src/ZoneLoading/Game/T6/ContentLoaderT6.cpp | 12 ++++----- src/ZoneLoading/Game/T6/ContentLoaderT6.h | 14 +++++----- .../T6/XAssets/gfximage/gfximage_actions.cpp | 4 +-- .../T6/XAssets/gfximage/gfximage_actions.h | 2 +- .../Game/T6/ZoneLoaderFactoryT6.cpp | 4 +-- src/ZoneLoading/Loading/AssetLoader.cpp | 10 +++---- src/ZoneLoading/Loading/AssetLoader.h | 14 +++++----- .../Loading/AssetLoadingActions.cpp | 4 +-- src/ZoneLoading/Loading/AssetLoadingActions.h | 8 +++--- src/ZoneLoading/Loading/AssetMarker.cpp | 12 ++++----- src/ZoneLoading/Loading/AssetMarker.h | 26 +++++++++---------- src/ZoneLoading/Loading/ContentLoaderBase.cpp | 11 ++++---- src/ZoneLoading/Loading/ContentLoaderBase.h | 22 +++++++++------- .../Loading/IContentLoadingEntryPoint.h | 8 ++++-- .../Loading/Steps/StepLoadZoneContent.cpp | 2 +- 49 files changed, 173 insertions(+), 160 deletions(-) diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp index 2b178b7f..48b602fc 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp @@ -240,7 +240,7 @@ namespace void PrintHeaderConstructor() const { - LINEF("{0}(Zone* zone, IZoneInputStream* stream);", LoaderClassName(m_env.m_asset)) + LINEF("{0}(Zone& zone, IZoneInputStream* stream);", LoaderClassName(m_env.m_asset)) } void PrintVariableInitialization(const DataDefinition* def) const @@ -255,7 +255,7 @@ namespace void PrintConstructorMethod() { - LINEF("{0}::{0}(Zone* zone, IZoneInputStream* stream)", LoaderClassName(m_env.m_asset)) + LINEF("{0}::{0}(Zone& zone, IZoneInputStream* stream)", LoaderClassName(m_env.m_asset)) m_intendation++; LINE_STARTF(": AssetLoader({0}::EnumEntry, zone, stream)", m_env.m_asset->m_asset_name) @@ -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.GetMemory()->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/ZoneCodeGeneratorLib/Generating/Templates/ZoneMarkTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneMarkTemplate.cpp index 8fb90d66..e16302dc 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneMarkTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneMarkTemplate.cpp @@ -215,7 +215,7 @@ namespace void PrintHeaderConstructor() const { - LINEF("{0}(Zone* zone);", MarkerClassName(m_env.m_asset)) + LINEF("{0}(Zone& zone);", MarkerClassName(m_env.m_asset)) } void PrintHeaderMainMarkMethodDeclaration(const StructureInformation* info) const @@ -235,7 +235,7 @@ namespace void PrintConstructorMethod() { - LINEF("{0}::{0}(Zone* zone)", MarkerClassName(m_env.m_asset)) + LINEF("{0}::{0}(Zone& zone)", MarkerClassName(m_env.m_asset)) m_intendation++; LINEF(": AssetMarker({0}::EnumEntry, zone)", m_env.m_asset->m_asset_name) diff --git a/src/ZoneLoading/Game/IW3/ContentLoaderIW3.cpp b/src/ZoneLoading/Game/IW3/ContentLoaderIW3.cpp index e78039c9..2b6663ca 100644 --- a/src/ZoneLoading/Game/IW3/ContentLoaderIW3.cpp +++ b/src/ZoneLoading/Game/IW3/ContentLoaderIW3.cpp @@ -32,8 +32,9 @@ using namespace IW3; -ContentLoader::ContentLoader() - : varXAsset(nullptr), +ContentLoader::ContentLoader(Zone& zone) + : ContentLoaderBase(zone), + varXAsset(nullptr), varScriptStringList(nullptr) { } @@ -54,12 +55,12 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart) LoadXStringArray(true, varScriptStringList->count); if (varScriptStringList->strings && varScriptStringList->count > 0) - m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast(varScriptStringList->count)); + m_zone.m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast(varScriptStringList->count)); } m_stream->PopBlock(); - assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1); + assert(m_zone.m_script_strings.Count() <= SCR_STRING_MAX + 1); } void ContentLoader::LoadXAsset(const bool atStreamStart) const @@ -133,9 +134,8 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count } } -void ContentLoader::Load(Zone* zone, IZoneInputStream* stream) +void ContentLoader::Load(IZoneInputStream* stream) { - m_zone = zone; m_stream = stream; m_stream->PushBlock(XFILE_BLOCK_VIRTUAL); diff --git a/src/ZoneLoading/Game/IW3/ContentLoaderIW3.h b/src/ZoneLoading/Game/IW3/ContentLoaderIW3.h index 1d0c0d30..7e34a008 100644 --- a/src/ZoneLoading/Game/IW3/ContentLoaderIW3.h +++ b/src/ZoneLoading/Game/IW3/ContentLoaderIW3.h @@ -1,4 +1,5 @@ #pragma once + #include "Game/IW3/IW3.h" #include "Loading/ContentLoaderBase.h" #include "Loading/IContentLoadingEntryPoint.h" @@ -7,17 +8,18 @@ namespace IW3 { class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint { - XAsset* varXAsset; - ScriptStringList* varScriptStringList; + public: + explicit ContentLoader(Zone& zone); + void Load(IZoneInputStream* stream) override; + + private: void LoadScriptStringList(bool atStreamStart); void LoadXAsset(bool atStreamStart) const; void LoadXAssetArray(bool atStreamStart, size_t count); - public: - ContentLoader(); - - void Load(Zone* zone, IZoneInputStream* stream) override; + XAsset* varXAsset; + ScriptStringList* varScriptStringList; }; } // namespace IW3 diff --git a/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.cpp b/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.cpp index b3befd5c..294ec7f6 100644 --- a/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.cpp +++ b/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.cpp @@ -5,7 +5,7 @@ using namespace IW3; -Actions_GfxImage::Actions_GfxImage(Zone* zone) +Actions_GfxImage::Actions_GfxImage(Zone& zone) : AssetLoadingActions(zone) { } @@ -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.GetMemory()->AllocRaw(loadDefSize)); memcpy(image->texture.loadDef, loadDef, loadDefSize); } diff --git a/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.h b/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.h index fc2c9617..6b48483c 100644 --- a/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.h +++ b/src/ZoneLoading/Game/IW3/XAssets/gfximage/gfximage_actions.h @@ -8,7 +8,7 @@ namespace IW3 class Actions_GfxImage final : public AssetLoadingActions { public: - explicit Actions_GfxImage(Zone* zone); + explicit Actions_GfxImage(Zone& zone); void OnImageLoaded(GfxImage* image) const; void LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const; diff --git a/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.cpp b/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.cpp index 8c58ca9b..26169d25 100644 --- a/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.cpp +++ b/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.cpp @@ -4,7 +4,7 @@ using namespace IW3; -Actions_LoadedSound::Actions_LoadedSound(Zone* zone) +Actions_LoadedSound::Actions_LoadedSound(Zone& zone) : AssetLoadingActions(zone) { } @@ -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.GetMemory()->Alloc(sound->info.data_len); memcpy(sound->data, tempData, sound->info.data_len); } else diff --git a/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.h b/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.h index 6df942e7..7787400f 100644 --- a/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.h +++ b/src/ZoneLoading/Game/IW3/XAssets/loadedsound/loadedsound_actions.h @@ -8,7 +8,7 @@ namespace IW3 class Actions_LoadedSound final : public AssetLoadingActions { public: - explicit Actions_LoadedSound(Zone* zone); + explicit Actions_LoadedSound(Zone& zone); void SetSoundData(MssSound* sound) const; }; diff --git a/src/ZoneLoading/Game/IW3/ZoneLoaderFactoryIW3.cpp b/src/ZoneLoading/Game/IW3/ZoneLoaderFactoryIW3.cpp index 1bfedf58..dc8c583c 100644 --- a/src/ZoneLoading/Game/IW3/ZoneLoaderFactoryIW3.cpp +++ b/src/ZoneLoading/Game/IW3/ZoneLoaderFactoryIW3.cpp @@ -85,8 +85,8 @@ std::unique_ptr ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& zoneLoader->AddLoadingStep(std::make_unique()); // Start of the zone content - zoneLoader->AddLoadingStep( - std::make_unique(std::make_unique(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); + zoneLoader->AddLoadingStep(std::make_unique( + std::make_unique(*zonePtr), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); return zoneLoader; } diff --git a/src/ZoneLoading/Game/IW4/ContentLoaderIW4.cpp b/src/ZoneLoading/Game/IW4/ContentLoaderIW4.cpp index 6ae4f493..07c26bb6 100644 --- a/src/ZoneLoading/Game/IW4/ContentLoaderIW4.cpp +++ b/src/ZoneLoading/Game/IW4/ContentLoaderIW4.cpp @@ -42,8 +42,9 @@ using namespace IW4; -ContentLoader::ContentLoader() - : varXAsset(nullptr), +ContentLoader::ContentLoader(Zone& zone) + : ContentLoaderBase(zone), + varXAsset(nullptr), varScriptStringList(nullptr) { } @@ -64,12 +65,12 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart) LoadXStringArray(true, varScriptStringList->count); if (varScriptStringList->strings && varScriptStringList->count > 0) - m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast(varScriptStringList->count)); + m_zone.m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast(varScriptStringList->count)); } m_stream->PopBlock(); - assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1); + assert(m_zone.m_script_strings.Count() <= SCR_STRING_MAX + 1); } void ContentLoader::LoadXAsset(const bool atStreamStart) const @@ -153,9 +154,8 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count } } -void ContentLoader::Load(Zone* zone, IZoneInputStream* stream) +void ContentLoader::Load(IZoneInputStream* stream) { - m_zone = zone; m_stream = stream; m_stream->PushBlock(XFILE_BLOCK_VIRTUAL); diff --git a/src/ZoneLoading/Game/IW4/ContentLoaderIW4.h b/src/ZoneLoading/Game/IW4/ContentLoaderIW4.h index 8a3fd944..9d0987b3 100644 --- a/src/ZoneLoading/Game/IW4/ContentLoaderIW4.h +++ b/src/ZoneLoading/Game/IW4/ContentLoaderIW4.h @@ -9,9 +9,9 @@ namespace IW4 class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint { public: - ContentLoader(); + explicit ContentLoader(Zone& zone); - void Load(Zone* zone, IZoneInputStream* stream) override; + void Load(IZoneInputStream* stream) override; private: void LoadScriptStringList(bool atStreamStart); diff --git a/src/ZoneLoading/Game/IW4/XAssets/gfximage/gfximage_actions.cpp b/src/ZoneLoading/Game/IW4/XAssets/gfximage/gfximage_actions.cpp index 9c208c2f..de0519f2 100644 --- a/src/ZoneLoading/Game/IW4/XAssets/gfximage/gfximage_actions.cpp +++ b/src/ZoneLoading/Game/IW4/XAssets/gfximage/gfximage_actions.cpp @@ -5,7 +5,7 @@ using namespace IW4; -Actions_GfxImage::Actions_GfxImage(Zone* zone) +Actions_GfxImage::Actions_GfxImage(Zone& zone) : AssetLoadingActions(zone) { } @@ -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.GetMemory()->AllocRaw(loadDefSize)); memcpy(image->texture.loadDef, loadDef, loadDefSize); } diff --git a/src/ZoneLoading/Game/IW4/XAssets/gfximage/gfximage_actions.h b/src/ZoneLoading/Game/IW4/XAssets/gfximage/gfximage_actions.h index 5dc03af6..dda325d7 100644 --- a/src/ZoneLoading/Game/IW4/XAssets/gfximage/gfximage_actions.h +++ b/src/ZoneLoading/Game/IW4/XAssets/gfximage/gfximage_actions.h @@ -8,7 +8,7 @@ namespace IW4 class Actions_GfxImage final : public AssetLoadingActions { public: - explicit Actions_GfxImage(Zone* zone); + explicit Actions_GfxImage(Zone& zone); void OnImageLoaded(GfxImage* image) const; void LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const; diff --git a/src/ZoneLoading/Game/IW4/XAssets/loadedsound/loadedsound_actions.cpp b/src/ZoneLoading/Game/IW4/XAssets/loadedsound/loadedsound_actions.cpp index 4f4b579f..5b6549ed 100644 --- a/src/ZoneLoading/Game/IW4/XAssets/loadedsound/loadedsound_actions.cpp +++ b/src/ZoneLoading/Game/IW4/XAssets/loadedsound/loadedsound_actions.cpp @@ -4,7 +4,7 @@ using namespace IW4; -Actions_LoadedSound::Actions_LoadedSound(Zone* zone) +Actions_LoadedSound::Actions_LoadedSound(Zone& zone) : AssetLoadingActions(zone) { } @@ -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.GetMemory()->Alloc(sound->info.data_len); memcpy(sound->data, tempData, sound->info.data_len); } else diff --git a/src/ZoneLoading/Game/IW4/XAssets/loadedsound/loadedsound_actions.h b/src/ZoneLoading/Game/IW4/XAssets/loadedsound/loadedsound_actions.h index 7b04a24a..c13591b5 100644 --- a/src/ZoneLoading/Game/IW4/XAssets/loadedsound/loadedsound_actions.h +++ b/src/ZoneLoading/Game/IW4/XAssets/loadedsound/loadedsound_actions.h @@ -8,7 +8,7 @@ namespace IW4 class Actions_LoadedSound final : public AssetLoadingActions { public: - explicit Actions_LoadedSound(Zone* zone); + explicit Actions_LoadedSound(Zone& zone); void SetSoundData(MssSound* sound) const; }; diff --git a/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.cpp b/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.cpp index 887dc3ae..2966bfa1 100644 --- a/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.cpp +++ b/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.cpp @@ -4,7 +4,7 @@ using namespace IW4; -Actions_XModel::Actions_XModel(Zone* zone) +Actions_XModel::Actions_XModel(Zone& zone) : AssetLoadingActions(zone) { } @@ -13,7 +13,7 @@ void Actions_XModel::SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSur { if (modelSurfs) { - lodInfo->modelSurfs = m_zone->GetMemory()->Alloc(); + lodInfo->modelSurfs = m_zone.GetMemory()->Alloc(); memcpy(lodInfo->modelSurfs, modelSurfs, sizeof(XModelSurfs)); } } diff --git a/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.h b/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.h index 8f98d377..8a192307 100644 --- a/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.h +++ b/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.h @@ -8,7 +8,7 @@ namespace IW4 class Actions_XModel final : public AssetLoadingActions { public: - explicit Actions_XModel(Zone* zone); + explicit Actions_XModel(Zone& zone); void SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSurfs) const; }; diff --git a/src/ZoneLoading/Game/IW4/ZoneLoaderFactoryIW4.cpp b/src/ZoneLoading/Game/IW4/ZoneLoaderFactoryIW4.cpp index f7347570..04621db5 100644 --- a/src/ZoneLoading/Game/IW4/ZoneLoaderFactoryIW4.cpp +++ b/src/ZoneLoading/Game/IW4/ZoneLoaderFactoryIW4.cpp @@ -207,8 +207,8 @@ std::unique_ptr ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& zoneLoader->AddLoadingStep(std::make_unique()); // Start of the zone content - zoneLoader->AddLoadingStep( - std::make_unique(std::make_unique(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); + zoneLoader->AddLoadingStep(std::make_unique( + std::make_unique(*zonePtr), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); return zoneLoader; } diff --git a/src/ZoneLoading/Game/IW5/ContentLoaderIW5.cpp b/src/ZoneLoading/Game/IW5/ContentLoaderIW5.cpp index 101d259b..31dee1e2 100644 --- a/src/ZoneLoading/Game/IW5/ContentLoaderIW5.cpp +++ b/src/ZoneLoading/Game/IW5/ContentLoaderIW5.cpp @@ -47,8 +47,9 @@ using namespace IW5; -ContentLoader::ContentLoader() - : varXAsset(nullptr), +ContentLoader::ContentLoader(Zone& zone) + : ContentLoaderBase(zone), + varXAsset(nullptr), varScriptStringList(nullptr) { } @@ -69,12 +70,12 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart) LoadXStringArray(true, varScriptStringList->count); if (varScriptStringList->strings && varScriptStringList->count > 0) - m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast(varScriptStringList->count)); + m_zone.m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast(varScriptStringList->count)); } m_stream->PopBlock(); - assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1); + assert(m_zone.m_script_strings.Count() <= SCR_STRING_MAX + 1); } void ContentLoader::LoadXAsset(const bool atStreamStart) const @@ -162,9 +163,8 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count } } -void ContentLoader::Load(Zone* zone, IZoneInputStream* stream) +void ContentLoader::Load(IZoneInputStream* stream) { - m_zone = zone; m_stream = stream; m_stream->PushBlock(XFILE_BLOCK_VIRTUAL); diff --git a/src/ZoneLoading/Game/IW5/ContentLoaderIW5.h b/src/ZoneLoading/Game/IW5/ContentLoaderIW5.h index 115f2c91..33aaad83 100644 --- a/src/ZoneLoading/Game/IW5/ContentLoaderIW5.h +++ b/src/ZoneLoading/Game/IW5/ContentLoaderIW5.h @@ -1,4 +1,5 @@ #pragma once + #include "Game/IW5/IW5.h" #include "Loading/ContentLoaderBase.h" #include "Loading/IContentLoadingEntryPoint.h" @@ -7,17 +8,18 @@ namespace IW5 { class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint { - XAsset* varXAsset; - ScriptStringList* varScriptStringList; + public: + explicit ContentLoader(Zone& zone); + void Load(IZoneInputStream* stream) override; + + private: void LoadScriptStringList(bool atStreamStart); void LoadXAsset(bool atStreamStart) const; void LoadXAssetArray(bool atStreamStart, size_t count); - public: - ContentLoader(); - - void Load(Zone* zone, IZoneInputStream* stream) override; + XAsset* varXAsset; + ScriptStringList* varScriptStringList; }; } // namespace IW5 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 0ce5583b..a75b267c 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 @@ -5,13 +5,13 @@ using namespace IW5; -Actions_clipMap_t::Actions_clipMap_t(Zone* zone) +Actions_clipMap_t::Actions_clipMap_t(Zone& zone) : AssetLoadingActions(zone) { } void Actions_clipMap_t::ReallocClipInfo(const ClipInfo* clipInfo, clipMap_t* clipMap) const { - clipMap->pInfo = m_zone->GetMemory()->Alloc(); + clipMap->pInfo = m_zone.GetMemory()->Alloc(); memcpy(clipMap->pInfo, clipInfo, sizeof(ClipInfo)); } diff --git a/src/ZoneLoading/Game/IW5/XAssets/clipmap_t/clipmap_t_actions.h b/src/ZoneLoading/Game/IW5/XAssets/clipmap_t/clipmap_t_actions.h index 062ca06f..d7f50b97 100644 --- a/src/ZoneLoading/Game/IW5/XAssets/clipmap_t/clipmap_t_actions.h +++ b/src/ZoneLoading/Game/IW5/XAssets/clipmap_t/clipmap_t_actions.h @@ -8,7 +8,7 @@ namespace IW5 class Actions_clipMap_t final : public AssetLoadingActions { public: - explicit Actions_clipMap_t(Zone* zone); + explicit Actions_clipMap_t(Zone& zone); void ReallocClipInfo(const ClipInfo* clipInfo, clipMap_t* clipMap) const; }; diff --git a/src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.cpp b/src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.cpp index cb5f7a75..5675ee3c 100644 --- a/src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.cpp +++ b/src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.cpp @@ -5,7 +5,7 @@ using namespace IW5; -Actions_GfxImage::Actions_GfxImage(Zone* zone) +Actions_GfxImage::Actions_GfxImage(Zone& zone) : AssetLoadingActions(zone) { } @@ -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.GetMemory()->AllocRaw(loadDefSize)); memcpy(image->texture.loadDef, loadDef, loadDefSize); } diff --git a/src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.h b/src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.h index 7ea60d7d..944089fd 100644 --- a/src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.h +++ b/src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.h @@ -8,7 +8,7 @@ namespace IW5 class Actions_GfxImage final : public AssetLoadingActions { public: - explicit Actions_GfxImage(Zone* zone); + explicit Actions_GfxImage(Zone& zone); void OnImageLoaded(GfxImage* image) const; void LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const; diff --git a/src/ZoneLoading/Game/IW5/XAssets/loadedsound/loadedsound_actions.cpp b/src/ZoneLoading/Game/IW5/XAssets/loadedsound/loadedsound_actions.cpp index 6c4f27aa..a462e4e5 100644 --- a/src/ZoneLoading/Game/IW5/XAssets/loadedsound/loadedsound_actions.cpp +++ b/src/ZoneLoading/Game/IW5/XAssets/loadedsound/loadedsound_actions.cpp @@ -4,7 +4,7 @@ using namespace IW5; -Actions_LoadedSound::Actions_LoadedSound(Zone* zone) +Actions_LoadedSound::Actions_LoadedSound(Zone& zone) : AssetLoadingActions(zone) { } @@ -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.GetMemory()->Alloc(sound->info.data_len); memcpy(sound->data, tempData, sound->info.data_len); } else diff --git a/src/ZoneLoading/Game/IW5/XAssets/loadedsound/loadedsound_actions.h b/src/ZoneLoading/Game/IW5/XAssets/loadedsound/loadedsound_actions.h index 4e0de4d2..649c7b5f 100644 --- a/src/ZoneLoading/Game/IW5/XAssets/loadedsound/loadedsound_actions.h +++ b/src/ZoneLoading/Game/IW5/XAssets/loadedsound/loadedsound_actions.h @@ -8,7 +8,7 @@ namespace IW5 class Actions_LoadedSound final : public AssetLoadingActions { public: - explicit Actions_LoadedSound(Zone* zone); + explicit Actions_LoadedSound(Zone& zone); void SetSoundData(MssSound* sound) const; }; diff --git a/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp b/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp index 5739c607..b54a996f 100644 --- a/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp +++ b/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp @@ -4,7 +4,7 @@ using namespace IW5; -Actions_XModel::Actions_XModel(Zone* zone) +Actions_XModel::Actions_XModel(Zone& zone) : AssetLoadingActions(zone) { } @@ -13,7 +13,7 @@ void Actions_XModel::SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSur { if (modelSurfs) { - lodInfo->modelSurfs = m_zone->GetMemory()->Alloc(); + lodInfo->modelSurfs = m_zone.GetMemory()->Alloc(); memcpy(lodInfo->modelSurfs, modelSurfs, sizeof(XModelSurfs)); } } diff --git a/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.h b/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.h index 3176c8f9..0117de3e 100644 --- a/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.h +++ b/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.h @@ -8,7 +8,7 @@ namespace IW5 class Actions_XModel final : public AssetLoadingActions { public: - explicit Actions_XModel(Zone* zone); + explicit Actions_XModel(Zone& zone); void SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSurfs) const; }; diff --git a/src/ZoneLoading/Game/IW5/ZoneLoaderFactoryIW5.cpp b/src/ZoneLoading/Game/IW5/ZoneLoaderFactoryIW5.cpp index b35b4274..a2fe4cf3 100644 --- a/src/ZoneLoading/Game/IW5/ZoneLoaderFactoryIW5.cpp +++ b/src/ZoneLoading/Game/IW5/ZoneLoaderFactoryIW5.cpp @@ -184,8 +184,8 @@ std::unique_ptr ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& zoneLoader->AddLoadingStep(std::make_unique()); // Start of the zone content - zoneLoader->AddLoadingStep( - std::make_unique(std::make_unique(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); + zoneLoader->AddLoadingStep(std::make_unique( + std::make_unique(*zonePtr), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); return zoneLoader; } diff --git a/src/ZoneLoading/Game/T5/ContentLoaderT5.cpp b/src/ZoneLoading/Game/T5/ContentLoaderT5.cpp index 327cdf93..284f44c5 100644 --- a/src/ZoneLoading/Game/T5/ContentLoaderT5.cpp +++ b/src/ZoneLoading/Game/T5/ContentLoaderT5.cpp @@ -39,8 +39,9 @@ using namespace T5; -ContentLoader::ContentLoader() - : varXAsset(nullptr), +ContentLoader::ContentLoader(Zone& zone) + : ContentLoaderBase(zone), + varXAsset(nullptr), varScriptStringList(nullptr) { } @@ -61,12 +62,12 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart) LoadXStringArray(true, varScriptStringList->count); if (varScriptStringList->strings && varScriptStringList->count > 0) - m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast(varScriptStringList->count)); + m_zone.m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast(varScriptStringList->count)); } m_stream->PopBlock(); - assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1); + assert(m_zone.m_script_strings.Count() <= SCR_STRING_MAX + 1); } void ContentLoader::LoadXAsset(const bool atStreamStart) const @@ -146,9 +147,8 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count } } -void ContentLoader::Load(Zone* zone, IZoneInputStream* stream) +void ContentLoader::Load(IZoneInputStream* stream) { - m_zone = zone; m_stream = stream; m_stream->PushBlock(XFILE_BLOCK_VIRTUAL); diff --git a/src/ZoneLoading/Game/T5/ContentLoaderT5.h b/src/ZoneLoading/Game/T5/ContentLoaderT5.h index e924514b..e3d2c705 100644 --- a/src/ZoneLoading/Game/T5/ContentLoaderT5.h +++ b/src/ZoneLoading/Game/T5/ContentLoaderT5.h @@ -1,4 +1,5 @@ #pragma once + #include "Game/T5/T5.h" #include "Loading/ContentLoaderBase.h" #include "Loading/IContentLoadingEntryPoint.h" @@ -7,17 +8,18 @@ namespace T5 { class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint { - XAsset* varXAsset; - ScriptStringList* varScriptStringList; + public: + explicit ContentLoader(Zone& zone); + void Load(IZoneInputStream* stream) override; + + private: void LoadScriptStringList(bool atStreamStart); void LoadXAsset(bool atStreamStart) const; void LoadXAssetArray(bool atStreamStart, size_t count); - public: - ContentLoader(); - - void Load(Zone* zone, IZoneInputStream* stream) override; + XAsset* varXAsset; + ScriptStringList* varScriptStringList; }; } // namespace T5 diff --git a/src/ZoneLoading/Game/T5/XAssets/gfximage/gfximage_actions.cpp b/src/ZoneLoading/Game/T5/XAssets/gfximage/gfximage_actions.cpp index f25439f9..32ef5280 100644 --- a/src/ZoneLoading/Game/T5/XAssets/gfximage/gfximage_actions.cpp +++ b/src/ZoneLoading/Game/T5/XAssets/gfximage/gfximage_actions.cpp @@ -5,7 +5,7 @@ using namespace T5; -Actions_GfxImage::Actions_GfxImage(Zone* zone) +Actions_GfxImage::Actions_GfxImage(Zone& zone) : AssetLoadingActions(zone) { } @@ -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.GetMemory()->AllocRaw(loadDefSize)); memcpy(image->texture.loadDef, loadDef, loadDefSize); } diff --git a/src/ZoneLoading/Game/T5/XAssets/gfximage/gfximage_actions.h b/src/ZoneLoading/Game/T5/XAssets/gfximage/gfximage_actions.h index bc98aefe..9648cee2 100644 --- a/src/ZoneLoading/Game/T5/XAssets/gfximage/gfximage_actions.h +++ b/src/ZoneLoading/Game/T5/XAssets/gfximage/gfximage_actions.h @@ -8,7 +8,7 @@ namespace T5 class Actions_GfxImage final : public AssetLoadingActions { public: - explicit Actions_GfxImage(Zone* zone); + explicit Actions_GfxImage(Zone& zone); void OnImageLoaded(GfxImage* image) const; void LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const; diff --git a/src/ZoneLoading/Game/T5/ZoneLoaderFactoryT5.cpp b/src/ZoneLoading/Game/T5/ZoneLoaderFactoryT5.cpp index d1fa61fd..348b1e6f 100644 --- a/src/ZoneLoading/Game/T5/ZoneLoaderFactoryT5.cpp +++ b/src/ZoneLoading/Game/T5/ZoneLoaderFactoryT5.cpp @@ -85,8 +85,8 @@ std::unique_ptr ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& zoneLoader->AddLoadingStep(std::make_unique()); // Start of the zone content - zoneLoader->AddLoadingStep( - std::make_unique(std::make_unique(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); + zoneLoader->AddLoadingStep(std::make_unique( + std::make_unique(*zonePtr), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); return zoneLoader; } diff --git a/src/ZoneLoading/Game/T6/ContentLoaderT6.cpp b/src/ZoneLoading/Game/T6/ContentLoaderT6.cpp index 2b54ebc1..b00a4fba 100644 --- a/src/ZoneLoading/Game/T6/ContentLoaderT6.cpp +++ b/src/ZoneLoading/Game/T6/ContentLoaderT6.cpp @@ -55,8 +55,9 @@ using namespace T6; -ContentLoader::ContentLoader() - : varXAsset(nullptr), +ContentLoader::ContentLoader(Zone& zone) + : ContentLoaderBase(zone), + varXAsset(nullptr), varScriptStringList(nullptr) { } @@ -77,12 +78,12 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart) LoadXStringArray(true, varScriptStringList->count); if (varScriptStringList->strings && varScriptStringList->count > 0) - m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast(varScriptStringList->count)); + m_zone.m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast(varScriptStringList->count)); } m_stream->PopBlock(); - assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1); + assert(m_zone.m_script_strings.Count() <= SCR_STRING_MAX + 1); } void ContentLoader::LoadXAsset(const bool atStreamStart) const @@ -175,9 +176,8 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count } } -void ContentLoader::Load(Zone* zone, IZoneInputStream* stream) +void ContentLoader::Load(IZoneInputStream* stream) { - m_zone = zone; m_stream = stream; m_stream->PushBlock(XFILE_BLOCK_VIRTUAL); diff --git a/src/ZoneLoading/Game/T6/ContentLoaderT6.h b/src/ZoneLoading/Game/T6/ContentLoaderT6.h index fc88dc59..81511835 100644 --- a/src/ZoneLoading/Game/T6/ContentLoaderT6.h +++ b/src/ZoneLoading/Game/T6/ContentLoaderT6.h @@ -1,4 +1,5 @@ #pragma once + #include "Game/T6/T6.h" #include "Loading/ContentLoaderBase.h" #include "Loading/IContentLoadingEntryPoint.h" @@ -7,17 +8,18 @@ namespace T6 { class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint { - XAsset* varXAsset; - ScriptStringList* varScriptStringList; + public: + explicit ContentLoader(Zone& zone); + void Load(IZoneInputStream* stream) override; + + private: void LoadScriptStringList(bool atStreamStart); void LoadXAsset(bool atStreamStart) const; void LoadXAssetArray(bool atStreamStart, size_t count); - public: - ContentLoader(); - - void Load(Zone* zone, IZoneInputStream* stream) override; + XAsset* varXAsset; + ScriptStringList* varScriptStringList; }; } // namespace T6 diff --git a/src/ZoneLoading/Game/T6/XAssets/gfximage/gfximage_actions.cpp b/src/ZoneLoading/Game/T6/XAssets/gfximage/gfximage_actions.cpp index 532b515d..96144dab 100644 --- a/src/ZoneLoading/Game/T6/XAssets/gfximage/gfximage_actions.cpp +++ b/src/ZoneLoading/Game/T6/XAssets/gfximage/gfximage_actions.cpp @@ -5,7 +5,7 @@ using namespace T6; -Actions_GfxImage::Actions_GfxImage(Zone* zone) +Actions_GfxImage::Actions_GfxImage(Zone& zone) : AssetLoadingActions(zone) { } @@ -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.GetMemory()->AllocRaw(loadDefSize)); memcpy(image->texture.loadDef, loadDef, loadDefSize); } diff --git a/src/ZoneLoading/Game/T6/XAssets/gfximage/gfximage_actions.h b/src/ZoneLoading/Game/T6/XAssets/gfximage/gfximage_actions.h index d938ff6f..41f7b188 100644 --- a/src/ZoneLoading/Game/T6/XAssets/gfximage/gfximage_actions.h +++ b/src/ZoneLoading/Game/T6/XAssets/gfximage/gfximage_actions.h @@ -8,7 +8,7 @@ namespace T6 class Actions_GfxImage final : public AssetLoadingActions { public: - explicit Actions_GfxImage(Zone* zone); + explicit Actions_GfxImage(Zone& zone); void OnImageLoaded(GfxImage* image) const; void LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const; diff --git a/src/ZoneLoading/Game/T6/ZoneLoaderFactoryT6.cpp b/src/ZoneLoading/Game/T6/ZoneLoaderFactoryT6.cpp index 09642fd6..7cb8146d 100644 --- a/src/ZoneLoading/Game/T6/ZoneLoaderFactoryT6.cpp +++ b/src/ZoneLoading/Game/T6/ZoneLoaderFactoryT6.cpp @@ -203,8 +203,8 @@ std::unique_ptr ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& zoneLoader->AddLoadingStep(std::make_unique()); // Start of the zone content - zoneLoader->AddLoadingStep( - std::make_unique(std::make_unique(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); + zoneLoader->AddLoadingStep(std::make_unique( + std::make_unique(*zonePtr), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); if (isSecure) { diff --git a/src/ZoneLoading/Loading/AssetLoader.cpp b/src/ZoneLoading/Loading/AssetLoader.cpp index 868aae62..6637e1b9 100644 --- a/src/ZoneLoading/Loading/AssetLoader.cpp +++ b/src/ZoneLoading/Loading/AssetLoader.cpp @@ -3,10 +3,10 @@ #include #include -AssetLoader::AssetLoader(const asset_type_t assetType, Zone* zone, IZoneInputStream* stream) +AssetLoader::AssetLoader(const asset_type_t assetType, Zone& zone, IZoneInputStream* stream) : ContentLoaderBase(zone, stream), - m_asset_type(assetType), - varScriptString(nullptr) + varScriptString(nullptr), + m_asset_type(assetType) { } @@ -16,11 +16,11 @@ XAssetInfoGeneric* AssetLoader::LinkAsset(std::string name, std::vector scriptStrings, std::vector indirectAssetReferences) const { - return m_zone->m_pools->AddAsset( + return m_zone.m_pools->AddAsset( m_asset_type, std::move(name), asset, std::move(dependencies), std::move(scriptStrings), std::move(indirectAssetReferences)); } XAssetInfoGeneric* AssetLoader::GetAssetInfo(const std::string& name) const { - return m_zone->m_pools->GetAsset(m_asset_type, name); + return m_zone.m_pools->GetAsset(m_asset_type, name); } diff --git a/src/ZoneLoading/Loading/AssetLoader.h b/src/ZoneLoading/Loading/AssetLoader.h index dd9e2c04..feb904ea 100644 --- a/src/ZoneLoading/Loading/AssetLoader.h +++ b/src/ZoneLoading/Loading/AssetLoader.h @@ -4,17 +4,12 @@ #include "Pool/XAssetInfo.h" #include "Zone/ZoneTypes.h" -#include #include class AssetLoader : public ContentLoaderBase { - asset_type_t m_asset_type; - protected: - scr_string_t* varScriptString; - - AssetLoader(asset_type_t assetType, Zone* zone, IZoneInputStream* stream); + AssetLoader(asset_type_t assetType, Zone& zone, IZoneInputStream* stream); XAssetInfoGeneric* LinkAsset(std::string name, void* asset, @@ -22,5 +17,10 @@ protected: std::vector scriptStrings, std::vector indirectAssetReferences) const; - _NODISCARD XAssetInfoGeneric* GetAssetInfo(const std::string& name) const; + [[nodiscard]] XAssetInfoGeneric* GetAssetInfo(const std::string& name) const; + + scr_string_t* varScriptString; + +private: + asset_type_t m_asset_type; }; diff --git a/src/ZoneLoading/Loading/AssetLoadingActions.cpp b/src/ZoneLoading/Loading/AssetLoadingActions.cpp index 2908a982..f1ff127e 100644 --- a/src/ZoneLoading/Loading/AssetLoadingActions.cpp +++ b/src/ZoneLoading/Loading/AssetLoadingActions.cpp @@ -1,6 +1,6 @@ #include "AssetLoadingActions.h" -AssetLoadingActions::AssetLoadingActions(Zone* zone) +AssetLoadingActions::AssetLoadingActions(Zone& zone) + : m_zone(zone) { - m_zone = zone; } diff --git a/src/ZoneLoading/Loading/AssetLoadingActions.h b/src/ZoneLoading/Loading/AssetLoadingActions.h index 37e7a781..6e2ccb62 100644 --- a/src/ZoneLoading/Loading/AssetLoadingActions.h +++ b/src/ZoneLoading/Loading/AssetLoadingActions.h @@ -4,9 +4,9 @@ class AssetLoadingActions { -protected: - Zone* m_zone; - public: - explicit AssetLoadingActions(Zone* zone); + explicit AssetLoadingActions(Zone& zone); + +protected: + Zone& m_zone; }; diff --git a/src/ZoneLoading/Loading/AssetMarker.cpp b/src/ZoneLoading/Loading/AssetMarker.cpp index 2761fed3..c215c7cf 100644 --- a/src/ZoneLoading/Loading/AssetMarker.cpp +++ b/src/ZoneLoading/Loading/AssetMarker.cpp @@ -3,9 +3,9 @@ #include #include -AssetMarker::AssetMarker(const asset_type_t assetType, Zone* zone) - : m_asset_type(assetType), - m_zone(zone) +AssetMarker::AssetMarker(const asset_type_t assetType, Zone& zone) + : m_zone(zone), + m_asset_type(assetType) { } @@ -23,9 +23,9 @@ void AssetMarker::AddDependency(XAssetInfoGeneric* assetInfo) void AssetMarker::Mark_ScriptString(const scr_string_t scrString) { - assert(scrString < m_zone->m_script_strings.Count()); + assert(scrString < m_zone.m_script_strings.Count()); - if (scrString >= m_zone->m_script_strings.Count()) + if (scrString >= m_zone.m_script_strings.Count()) return; m_used_script_strings.emplace(scrString); @@ -57,7 +57,7 @@ void AssetMarker::MarkArray_IndirectAssetRef(const asset_type_t type, const char XAssetInfoGeneric* AssetMarker::GetAssetInfoByName(const std::string& name) const { - return m_zone->m_pools->GetAsset(m_asset_type, name); + return m_zone.m_pools->GetAsset(m_asset_type, name); } std::vector AssetMarker::GetDependencies() const diff --git a/src/ZoneLoading/Loading/AssetMarker.h b/src/ZoneLoading/Loading/AssetMarker.h index bb24c1b1..3507db4b 100644 --- a/src/ZoneLoading/Loading/AssetMarker.h +++ b/src/ZoneLoading/Loading/AssetMarker.h @@ -2,21 +2,19 @@ #include "ContentLoaderBase.h" #include "Pool/XAssetInfo.h" -#include "Utils/ClassUtils.h" #include "Zone/ZoneTypes.h" #include class AssetMarker { - asset_type_t m_asset_type; - - std::unordered_set m_dependencies; - std::unordered_set m_used_script_strings; - std::unordered_set m_indirect_asset_references; +public: + [[nodiscard]] std::vector GetDependencies() const; + [[nodiscard]] std::vector GetUsedScriptStrings() const; + [[nodiscard]] std::vector GetIndirectAssetReferences() const; protected: - AssetMarker(asset_type_t assetType, Zone* zone); + AssetMarker(asset_type_t assetType, Zone& zone); void AddDependency(XAssetInfoGeneric* assetInfo); @@ -26,12 +24,14 @@ protected: void Mark_IndirectAssetRef(asset_type_t type, const char* assetRefName); void MarkArray_IndirectAssetRef(asset_type_t type, const char** assetRefNames, size_t count); - _NODISCARD XAssetInfoGeneric* GetAssetInfoByName(const std::string& name) const; + [[nodiscard]] XAssetInfoGeneric* GetAssetInfoByName(const std::string& name) const; - Zone* m_zone; + Zone& m_zone; -public: - _NODISCARD std::vector GetDependencies() const; - _NODISCARD std::vector GetUsedScriptStrings() const; - _NODISCARD std::vector GetIndirectAssetReferences() const; +private: + asset_type_t m_asset_type; + + std::unordered_set m_dependencies; + std::unordered_set m_used_script_strings; + std::unordered_set m_indirect_asset_references; }; diff --git a/src/ZoneLoading/Loading/ContentLoaderBase.cpp b/src/ZoneLoading/Loading/ContentLoaderBase.cpp index 8ac12b96..2fc499d3 100644 --- a/src/ZoneLoading/Loading/ContentLoaderBase.cpp +++ b/src/ZoneLoading/Loading/ContentLoaderBase.cpp @@ -2,19 +2,18 @@ #include -const void* ContentLoaderBase::PTR_FOLLOWING = reinterpret_cast(-1); -const void* ContentLoaderBase::PTR_INSERT = reinterpret_cast(-2); - -ContentLoaderBase::ContentLoaderBase() +ContentLoaderBase::ContentLoaderBase(Zone& zone) : varXString(nullptr), - m_zone(nullptr), + m_zone(zone), + m_memory(*zone.GetMemory()), m_stream(nullptr) { } -ContentLoaderBase::ContentLoaderBase(Zone* zone, IZoneInputStream* stream) +ContentLoaderBase::ContentLoaderBase(Zone& zone, IZoneInputStream* stream) : varXString(nullptr), m_zone(zone), + m_memory(*zone.GetMemory()), m_stream(stream) { } diff --git a/src/ZoneLoading/Loading/ContentLoaderBase.h b/src/ZoneLoading/Loading/ContentLoaderBase.h index eba6aac2..515859a8 100644 --- a/src/ZoneLoading/Loading/ContentLoaderBase.h +++ b/src/ZoneLoading/Loading/ContentLoaderBase.h @@ -6,20 +6,22 @@ class ContentLoaderBase { protected: - static const void* PTR_FOLLOWING; - static const void* PTR_INSERT; + static constexpr auto PTR_FOLLOWING = reinterpret_cast(-1); + static constexpr auto PTR_INSERT = reinterpret_cast(-2); - const char** varXString; +public: + virtual ~ContentLoaderBase() = default; - Zone* m_zone; - IZoneInputStream* m_stream; - - ContentLoaderBase(); - ContentLoaderBase(Zone* zone, IZoneInputStream* stream); +protected: + explicit ContentLoaderBase(Zone& zone); + ContentLoaderBase(Zone& zone, IZoneInputStream* stream); void LoadXString(bool atStreamStart) const; void LoadXStringArray(bool atStreamStart, size_t count); -public: - virtual ~ContentLoaderBase() = default; + const char** varXString; + + Zone& m_zone; + MemoryManager& m_memory; + IZoneInputStream* m_stream; }; diff --git a/src/ZoneLoading/Loading/IContentLoadingEntryPoint.h b/src/ZoneLoading/Loading/IContentLoadingEntryPoint.h index 3ffda768..4b8dfb58 100644 --- a/src/ZoneLoading/Loading/IContentLoadingEntryPoint.h +++ b/src/ZoneLoading/Loading/IContentLoadingEntryPoint.h @@ -1,12 +1,16 @@ #pragma once #include "Zone/Stream/IZoneInputStream.h" -#include "Zone/Zone.h" class IContentLoadingEntryPoint { public: + IContentLoadingEntryPoint() = default; virtual ~IContentLoadingEntryPoint() = default; + IContentLoadingEntryPoint(const IContentLoadingEntryPoint& other) = default; + IContentLoadingEntryPoint(IContentLoadingEntryPoint&& other) noexcept = default; + IContentLoadingEntryPoint& operator=(const IContentLoadingEntryPoint& other) = default; + IContentLoadingEntryPoint& operator=(IContentLoadingEntryPoint&& other) noexcept = default; - virtual void Load(Zone* zone, IZoneInputStream* stream) = 0; + virtual void Load(IZoneInputStream* stream) = 0; }; diff --git a/src/ZoneLoading/Loading/Steps/StepLoadZoneContent.cpp b/src/ZoneLoading/Loading/Steps/StepLoadZoneContent.cpp index fa4e1c67..7dbdb015 100644 --- a/src/ZoneLoading/Loading/Steps/StepLoadZoneContent.cpp +++ b/src/ZoneLoading/Loading/Steps/StepLoadZoneContent.cpp @@ -19,7 +19,7 @@ void StepLoadZoneContent::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* st { auto* inputStream = new XBlockInputStream(zoneLoader->m_blocks, stream, m_offset_block_bit_count, m_insert_block); - m_content_loader->Load(m_zone, inputStream); + m_content_loader->Load(inputStream); delete inputStream; }