From e7a9e4b528fbe8631f9a769e58eae51d6cd87453 Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 30 Mar 2024 17:19:32 +0100 Subject: [PATCH 1/2] chore: use const reference for assetName in GetAsset methods --- src/ZoneCommon/Game/IW3/GameAssetPoolIW3.cpp | 2 +- src/ZoneCommon/Game/IW3/GameAssetPoolIW3.h | 2 +- src/ZoneCommon/Game/IW4/GameAssetPoolIW4.cpp | 4 ++-- src/ZoneCommon/Game/IW4/GameAssetPoolIW4.h | 2 +- src/ZoneCommon/Game/IW5/GameAssetPoolIW5.cpp | 2 +- src/ZoneCommon/Game/IW5/GameAssetPoolIW5.h | 2 +- src/ZoneCommon/Game/T5/GameAssetPoolT5.cpp | 2 +- src/ZoneCommon/Game/T5/GameAssetPoolT5.h | 2 +- src/ZoneCommon/Game/T6/GameAssetPoolT6.cpp | 4 ++-- src/ZoneCommon/Game/T6/GameAssetPoolT6.h | 2 +- src/ZoneCommon/Pool/ZoneAssetPools.h | 2 +- src/ZoneLoading/Loading/AssetLoader.cpp | 4 ++-- src/ZoneLoading/Loading/AssetLoader.h | 2 +- src/ZoneLoading/Loading/AssetMarker.cpp | 4 ++-- src/ZoneLoading/Loading/AssetMarker.h | 2 +- 15 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/ZoneCommon/Game/IW3/GameAssetPoolIW3.cpp b/src/ZoneCommon/Game/IW3/GameAssetPoolIW3.cpp index fe986855..998e3166 100644 --- a/src/ZoneCommon/Game/IW3/GameAssetPoolIW3.cpp +++ b/src/ZoneCommon/Game/IW3/GameAssetPoolIW3.cpp @@ -169,7 +169,7 @@ XAssetInfoGeneric* GameAssetPoolIW3::AddAssetToPool(std::unique_ptrGetAsset(std::move(name)); \ + return (poolName)->GetAsset(name); \ break; \ } diff --git a/src/ZoneCommon/Game/IW4/GameAssetPoolIW4.h b/src/ZoneCommon/Game/IW4/GameAssetPoolIW4.h index 3889db03..bb0fc12c 100644 --- a/src/ZoneCommon/Game/IW4/GameAssetPoolIW4.h +++ b/src/ZoneCommon/Game/IW4/GameAssetPoolIW4.h @@ -60,7 +60,7 @@ public: void InitPoolStatic(asset_type_t type, size_t capacity) override; void InitPoolDynamic(asset_type_t type) override; - _NODISCARD XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const override; + _NODISCARD XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override; static const char* AssetTypeNameByType(asset_type_t assetType); _NODISCARD const char* GetAssetTypeName(asset_type_t assetType) const override; diff --git a/src/ZoneCommon/Game/IW5/GameAssetPoolIW5.cpp b/src/ZoneCommon/Game/IW5/GameAssetPoolIW5.cpp index d641fa54..e928fad7 100644 --- a/src/ZoneCommon/Game/IW5/GameAssetPoolIW5.cpp +++ b/src/ZoneCommon/Game/IW5/GameAssetPoolIW5.cpp @@ -253,7 +253,7 @@ XAssetInfoGeneric* GameAssetPoolIW5::AddAssetToPool(std::unique_ptrGetAsset(std::move(name)); \ + return (poolName)->GetAsset(name); \ break; \ } diff --git a/src/ZoneCommon/Game/T6/GameAssetPoolT6.h b/src/ZoneCommon/Game/T6/GameAssetPoolT6.h index 7ea69875..33ee416f 100644 --- a/src/ZoneCommon/Game/T6/GameAssetPoolT6.h +++ b/src/ZoneCommon/Game/T6/GameAssetPoolT6.h @@ -72,7 +72,7 @@ public: void InitPoolStatic(asset_type_t type, size_t capacity) override; void InitPoolDynamic(asset_type_t type) override; - _NODISCARD XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const override; + _NODISCARD XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override; static const char* AssetTypeNameByType(asset_type_t assetType); _NODISCARD const char* GetAssetTypeName(asset_type_t assetType) const override; diff --git a/src/ZoneCommon/Pool/ZoneAssetPools.h b/src/ZoneCommon/Pool/ZoneAssetPools.h index 76e6208e..5b2acaf7 100644 --- a/src/ZoneCommon/Pool/ZoneAssetPools.h +++ b/src/ZoneCommon/Pool/ZoneAssetPools.h @@ -38,7 +38,7 @@ public: std::vector dependencies, std::vector usedScriptStrings, std::vector indirectAssetReferences); - _NODISCARD virtual XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const = 0; + _NODISCARD virtual XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const = 0; _NODISCARD virtual asset_type_t GetAssetTypeCount() const = 0; _NODISCARD virtual const char* GetAssetTypeName(asset_type_t assetType) const = 0; diff --git a/src/ZoneLoading/Loading/AssetLoader.cpp b/src/ZoneLoading/Loading/AssetLoader.cpp index c61e1f2a..868aae62 100644 --- a/src/ZoneLoading/Loading/AssetLoader.cpp +++ b/src/ZoneLoading/Loading/AssetLoader.cpp @@ -20,7 +20,7 @@ XAssetInfoGeneric* AssetLoader::LinkAsset(std::string name, m_asset_type, std::move(name), asset, std::move(dependencies), std::move(scriptStrings), std::move(indirectAssetReferences)); } -XAssetInfoGeneric* AssetLoader::GetAssetInfo(std::string name) const +XAssetInfoGeneric* AssetLoader::GetAssetInfo(const std::string& name) const { - return m_zone->m_pools->GetAsset(m_asset_type, std::move(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 d4ec283e..dd9e2c04 100644 --- a/src/ZoneLoading/Loading/AssetLoader.h +++ b/src/ZoneLoading/Loading/AssetLoader.h @@ -22,5 +22,5 @@ protected: std::vector scriptStrings, std::vector indirectAssetReferences) const; - _NODISCARD XAssetInfoGeneric* GetAssetInfo(std::string name) const; + _NODISCARD XAssetInfoGeneric* GetAssetInfo(const std::string& name) const; }; diff --git a/src/ZoneLoading/Loading/AssetMarker.cpp b/src/ZoneLoading/Loading/AssetMarker.cpp index 5ea12738..2761fed3 100644 --- a/src/ZoneLoading/Loading/AssetMarker.cpp +++ b/src/ZoneLoading/Loading/AssetMarker.cpp @@ -55,9 +55,9 @@ void AssetMarker::MarkArray_IndirectAssetRef(const asset_type_t type, const char Mark_IndirectAssetRef(type, assetRefNames[index]); } -XAssetInfoGeneric* AssetMarker::GetAssetInfoByName(std::string name) const +XAssetInfoGeneric* AssetMarker::GetAssetInfoByName(const std::string& name) const { - return m_zone->m_pools->GetAsset(m_asset_type, std::move(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 92cc449d..bb24c1b1 100644 --- a/src/ZoneLoading/Loading/AssetMarker.h +++ b/src/ZoneLoading/Loading/AssetMarker.h @@ -26,7 +26,7 @@ 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(std::string name) const; + _NODISCARD XAssetInfoGeneric* GetAssetInfoByName(const std::string& name) const; Zone* m_zone; From fc18f813025c0301ef7bb4c74ffa8c11df1f481f Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 30 Mar 2024 17:44:55 +0100 Subject: [PATCH 2/2] fix: consider asset references when looking for assets of zone --- src/ObjLoading/AssetLoading/AssetLoadingManager.cpp | 6 +++--- .../Generating/Templates/ZoneWriteTemplate.cpp | 4 ++-- src/ZoneCommon/Pool/ZoneAssetPools.cpp | 13 +++++++++++++ src/ZoneCommon/Pool/ZoneAssetPools.h | 2 ++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/ObjLoading/AssetLoading/AssetLoadingManager.cpp b/src/ObjLoading/AssetLoading/AssetLoadingManager.cpp index 83a350ed..c05a7c5f 100644 --- a/src/ObjLoading/AssetLoading/AssetLoadingManager.cpp +++ b/src/ObjLoading/AssetLoading/AssetLoadingManager.cpp @@ -59,7 +59,7 @@ XAssetInfoGeneric* AssetLoadingManager::AddAsset(std::unique_ptrm_pools->GetAsset(assetType, assetName); + auto* alreadyLoadedAsset = m_context.m_zone->m_pools->GetAssetOrAssetReference(assetType, assetName); if (alreadyLoadedAsset) return alreadyLoadedAsset; @@ -147,7 +147,7 @@ XAssetInfoGeneric* AssetLoadingManager::LoadAssetDependency(const asset_type_t a XAssetInfoGeneric* AssetLoadingManager::LoadDependency(const asset_type_t assetType, const std::string& assetName) { - auto* alreadyLoadedAsset = m_context.m_zone->m_pools->GetAsset(assetType, assetName); + auto* alreadyLoadedAsset = m_context.m_zone->m_pools->GetAssetOrAssetReference(assetType, assetName); if (alreadyLoadedAsset) return alreadyLoadedAsset; @@ -171,7 +171,7 @@ XAssetInfoGeneric* AssetLoadingManager::LoadDependency(const asset_type_t assetT IndirectAssetReference AssetLoadingManager::LoadIndirectAssetReference(const asset_type_t assetType, const std::string& assetName) { - const auto* alreadyLoadedAsset = m_context.m_zone->m_pools->GetAsset(assetType, assetName); + const auto* alreadyLoadedAsset = m_context.m_zone->m_pools->GetAssetOrAssetReference(assetType, assetName); if (alreadyLoadedAsset) return IndirectAssetReference(assetType, assetName); diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp index 36d503f6..92d44eab 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp @@ -115,8 +115,8 @@ class ZoneWriteTemplate::Internal final : BaseTemplate << "* asset, Zone* zone, IZoneOutputStream* stream)") m_intendation++; - LINE_START(": AssetWriter(zone->m_pools->GetAsset(" << m_env.m_asset->m_asset_enum_entry->m_name << ", GetAssetName(asset))" - << ", zone, stream)") + LINE_START(": AssetWriter(zone->m_pools->GetAssetOrAssetReference(" << m_env.m_asset->m_asset_enum_entry->m_name << ", GetAssetName(asset))" + << ", zone, stream)") LINE_END("") m_intendation--; diff --git a/src/ZoneCommon/Pool/ZoneAssetPools.cpp b/src/ZoneCommon/Pool/ZoneAssetPools.cpp index ef13b01e..9dc79b9a 100644 --- a/src/ZoneCommon/Pool/ZoneAssetPools.cpp +++ b/src/ZoneCommon/Pool/ZoneAssetPools.cpp @@ -1,5 +1,7 @@ #include "ZoneAssetPools.h" +#include + ZoneAssetPools::ZoneAssetPools(Zone* zone) : m_zone(zone) { @@ -25,6 +27,17 @@ XAssetInfoGeneric* ZoneAssetPools::AddAsset(std::unique_ptr x return assetInfo; } +XAssetInfoGeneric* ZoneAssetPools::GetAssetOrAssetReference(const asset_type_t type, const std::string& name) const +{ + auto* result = GetAsset(type, name); + + if (result != nullptr || (!name.empty() && name[0] == ',')) + return result; + + result = GetAsset(type, std::format(",{}", name)); + return result; +} + size_t ZoneAssetPools::GetTotalAssetCount() const { return m_assets_in_order.size(); diff --git a/src/ZoneCommon/Pool/ZoneAssetPools.h b/src/ZoneCommon/Pool/ZoneAssetPools.h index 5b2acaf7..d3bf72d8 100644 --- a/src/ZoneCommon/Pool/ZoneAssetPools.h +++ b/src/ZoneCommon/Pool/ZoneAssetPools.h @@ -39,6 +39,8 @@ public: std::vector usedScriptStrings, std::vector indirectAssetReferences); _NODISCARD virtual XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const = 0; + _NODISCARD virtual XAssetInfoGeneric* GetAssetOrAssetReference(asset_type_t type, const std::string& name) const; + _NODISCARD virtual asset_type_t GetAssetTypeCount() const = 0; _NODISCARD virtual const char* GetAssetTypeName(asset_type_t assetType) const = 0;