From 992e9cea30a33b91a8bc751220ac77564b25152d Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 18 Feb 2020 13:16:39 +0100 Subject: [PATCH] ZoneLoading: Properly link assets as dependencies instead of only saving the name of the dependency --- src/ObjLoading/Game/T6/ObjLoaderT6.cpp | 4 +- src/ObjWriting/Dumping/AbstractAssetDumper.h | 8 +- .../AssetDumpers/AssetDumperLocalizeEntry.cpp | 4 +- .../Templates/Loading/ArrayPointer.stg | 2 +- .../Templates/Loading/SinglePointer.stg | 2 +- .../Generating/Templates/ZoneLoad.stg | 16 +++- src/ZoneCommon/Game/T6/GameAssetPoolT6.cpp | 82 +++++++++++++++++-- src/ZoneCommon/Game/T6/GameAssetPoolT6.h | 5 +- src/ZoneCommon/Pool/AssetPool.h | 2 +- src/ZoneCommon/Pool/AssetPoolDynamic.h | 11 ++- src/ZoneCommon/Pool/AssetPoolStatic.h | 9 +- src/ZoneCommon/Pool/IZoneAssetPools.h | 5 +- src/ZoneCommon/Pool/XAssetInfo.h | 20 +++-- src/ZoneCommon/Zone/XAssetDependency.h | 9 -- src/ZoneLoading/Loading/AssetLoader.cpp | 31 +++---- src/ZoneLoading/Loading/AssetLoader.h | 10 ++- 16 files changed, 159 insertions(+), 61 deletions(-) delete mode 100644 src/ZoneCommon/Zone/XAssetDependency.h diff --git a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp index 3d63ec77..db824692 100644 --- a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp +++ b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp @@ -130,7 +130,7 @@ void ObjLoaderT6::LoadReferencedContainersForZone(ISearchPath* searchPath, Zone* { for(auto* keyValuePairsEntry : *assetPoolT6->m_key_value_pairs) { - auto* keyValuePairs = keyValuePairsEntry->m_asset; + auto* keyValuePairs = keyValuePairsEntry->Asset(); for(int variableIndex = 0; variableIndex < keyValuePairs->numVariables; variableIndex++) { T6::KeyValuePair* variable = &keyValuePairs->keyValuePairs[variableIndex]; @@ -217,7 +217,7 @@ void ObjLoaderT6::LoadImageData(ISearchPath* searchPath, Zone* zone) { for (auto* imageEntry : *assetPoolT6->m_image) { - auto* image = imageEntry->m_asset; + auto* image = imageEntry->Asset(); if(image->loadedSize > 0) { diff --git a/src/ObjWriting/Dumping/AbstractAssetDumper.h b/src/ObjWriting/Dumping/AbstractAssetDumper.h index 6d71a237..8a70eaa2 100644 --- a/src/ObjWriting/Dumping/AbstractAssetDumper.h +++ b/src/ObjWriting/Dumping/AbstractAssetDumper.h @@ -19,13 +19,15 @@ public: { for(auto assetInfo : *pool) { + T* asset = assetInfo->Asset(); + if(assetInfo->m_name[0] == ',' - || !ShouldDump(assetInfo->m_asset)) + || !ShouldDump(asset)) { continue; } - std::string assetFilePath = utils::Path::Combine(basePath, GetFileNameForAsset(zone, assetInfo->m_asset)); + std::string assetFilePath = utils::Path::Combine(basePath, GetFileNameForAsset(zone, asset)); FileAPI::DirectoryCreate(utils::Path::GetDirectory(assetFilePath)); @@ -33,7 +35,7 @@ public: if(file.IsOpen()) { - DumpAsset(zone, assetInfo->m_asset, &file); + DumpAsset(zone, asset, &file); file.Close(); } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperLocalizeEntry.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperLocalizeEntry.cpp index f0b6bf3f..353bef5f 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperLocalizeEntry.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperLocalizeEntry.cpp @@ -61,7 +61,7 @@ std::string AssetDumperLocalizeEntry::GetNameOfLanguage(GameLanguage language) void AssetDumperLocalizeEntry::DumpPool(Zone* zone, AssetPool* pool, const std::string& basePath) { - if (pool->m_asset_lookup.size() == 0) + if (pool->m_asset_lookup.empty()) return; const std::string language = GetNameOfLanguage(zone->m_language); @@ -84,7 +84,7 @@ void AssetDumperLocalizeEntry::DumpPool(Zone* zone, AssetPool* po for(auto localizeEntry : *pool) { - stringFileDumper.WriteLocalizeEntry(localizeEntry->m_asset->name, localizeEntry->m_asset->value); + stringFileDumper.WriteLocalizeEntry(localizeEntry->m_name, localizeEntry->Asset()->value); } stringFileDumper.Finalize(); diff --git a/src/ZoneCodeGenerator/Generating/Templates/Loading/ArrayPointer.stg b/src/ZoneCodeGenerator/Generating/Templates/Loading/ArrayPointer.stg index 6a04218c..12df0b3c 100644 --- a/src/ZoneCodeGenerator/Generating/Templates/Loading/ArrayPointer.stg +++ b/src/ZoneCodeGenerator/Generating/Templates/Loading/ArrayPointer.stg @@ -90,7 +90,7 @@ $endif$ LoadPointerArrayMethod_Asset(context, type, structure) ::= << $LoaderClassName(structure)$ loader(m_script_string_provider, m_zone, m_stream); -loader.Load($TypePtrVarName(type)$); +AddDependency(loader.Load($TypePtrVarName(type)$)); >> LoadPointerArrayMethod_PointerCheck(context, type, structure, reusable) ::= << diff --git a/src/ZoneCodeGenerator/Generating/Templates/Loading/SinglePointer.stg b/src/ZoneCodeGenerator/Generating/Templates/Loading/SinglePointer.stg index 9111bbcf..e17e9aa1 100644 --- a/src/ZoneCodeGenerator/Generating/Templates/Loading/SinglePointer.stg +++ b/src/ZoneCodeGenerator/Generating/Templates/Loading/SinglePointer.stg @@ -39,7 +39,7 @@ $endif$ LoadSinglePointerAsset(context, structure, member, reference) ::= << $LoaderClassName(member.StructureType)$ loader(m_script_string_provider, m_zone, m_stream); -loader.Load(&$TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$); +AddDependency(loader.Load(&$TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$)); >> LoadSinglePointer_Reuse(context, structure, member, reference) ::= << diff --git a/src/ZoneCodeGenerator/Generating/Templates/ZoneLoad.stg b/src/ZoneCodeGenerator/Generating/Templates/ZoneLoad.stg index 85c5feba..882ae735 100644 --- a/src/ZoneCodeGenerator/Generating/Templates/ZoneLoad.stg +++ b/src/ZoneCodeGenerator/Generating/Templates/ZoneLoad.stg @@ -21,7 +21,7 @@ HeaderLoadMethodDeclaration(structure) ::= "void Load_$structure.Type.Name$(bool HeaderGetNameMethodDeclaration(asset) ::= "static std::string GetAssetName($asset.Type.FullName$* pAsset);" HeaderAssetLoadMethodDeclaration(asset) ::= "void LoadAsset_$asset.Type.Name$($asset.Type.FullName$** pAsset);" -HeaderMainLoadMethodDeclaration(asset) ::= "void Load($asset.Type.FullName$** pAsset);" +HeaderMainLoadMethodDeclaration(asset) ::= "XAssetInfo<$asset.Type.FullName$>* Load($asset.Type.FullName$** pAsset);" VariableDeclaration(type) ::= << $type.FullName$* var$SafeTypeName(type)$; @@ -54,6 +54,7 @@ namespace $context.Game$ { class $LoaderClassName(context.Asset)$ final : public AssetLoader { + XAssetInfo<$context.Asset.Type.FullName$>* m_asset_info; $if(context.HasActions)$ Actions_$context.Asset.Type.Name$ m_actions; $endif$ @@ -287,6 +288,7 @@ $LoaderClassName(context.Asset)$::$LoaderClassName(context.Asset)$(IZoneScriptSt : AssetLoader($context.Asset.AssetEnumEntry.Name$, scriptStringProvider, zone, stream)$\\$ $if(context.HasActions)$, m_actions(zone)$endif$ { + m_asset_info = nullptr; $VariableInitialization(context.Asset.Type)$ $PointerVariableInitialization(context.Asset.Type)$ @@ -301,17 +303,25 @@ LoadAssetMethod(context, structure) ::= << void $LoaderClassName(context.Asset)$::LoadAsset_$structure.Type.Name$($structure.Type.FullName$** pAsset) { assert(pAsset != nullptr); - *pAsset = static_cast<$structure.Type.FullName$*>(LinkAsset(GetAssetName(*pAsset), *pAsset)); + m_asset_info = reinterpret_cast*>(LinkAsset(GetAssetName(*pAsset), *pAsset)); + *pAsset = m_asset_info->Asset(); } >> MainLoadMethod(context) ::= << -void $LoaderClassName(context.Asset)$::Load($context.Asset.Type.FullName$** pAsset) +XAssetInfo<$context.Asset.Type.FullName$>* $LoaderClassName(context.Asset)$::Load($context.Asset.Type.FullName$** pAsset) { assert(pAsset != nullptr); + m_asset_info = nullptr; + $TypePtrVarName(context.Asset.Type)$ = pAsset; LoadPtr_$context.Asset.Type.Name$(false); + + if(m_asset_info == nullptr && *pAsset != nullptr) + m_asset_info = reinterpret_cast*>(GetAssetInfo(GetAssetName(*pAsset))); + + return m_asset_info; } >> diff --git a/src/ZoneCommon/Game/T6/GameAssetPoolT6.cpp b/src/ZoneCommon/Game/T6/GameAssetPoolT6.cpp index 1247c0ca..d6f84f9a 100644 --- a/src/ZoneCommon/Game/T6/GameAssetPoolT6.cpp +++ b/src/ZoneCommon/Game/T6/GameAssetPoolT6.cpp @@ -123,7 +123,7 @@ void GameAssetPoolT6::InitPoolStatic(const asset_type_t type, const size_t capac { \ if((poolName) == nullptr && capacity > 0) \ { \ - (poolName) = new AssetPoolStatic(capacity, m_priority); \ + (poolName) = new AssetPoolStatic(capacity, m_priority, (assetType)); \ } \ break; \ } @@ -195,7 +195,7 @@ void GameAssetPoolT6::InitPoolDynamic(const asset_type_t type) { \ if((poolName) == nullptr) \ { \ - (poolName) = new AssetPoolDynamic(m_priority); \ + (poolName) = new AssetPoolDynamic(m_priority, (assetType)); \ } \ break; \ } @@ -260,7 +260,7 @@ void GameAssetPoolT6::InitPoolDynamic(const asset_type_t type) #undef CASE_INIT_POOL_STATIC } -void* GameAssetPoolT6::AddAsset(asset_type_t type, std::string name, void* asset, std::vector& scriptStrings, std::vector& dependencies) +XAssetInfoGeneric* GameAssetPoolT6::AddAsset(asset_type_t type, std::string name, void* asset, std::vector& scriptStrings, std::vector& dependencies) { XAsset xAsset{}; @@ -271,7 +271,7 @@ void* GameAssetPoolT6::AddAsset(asset_type_t type, std::string name, void* asset case assetType: \ { \ assert((poolName) != nullptr); \ - return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, scriptStrings, dependencies)->m_asset; \ + return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, scriptStrings, dependencies); \ } switch(xAsset.type) @@ -336,6 +336,78 @@ void* GameAssetPoolT6::AddAsset(asset_type_t type, std::string name, void* asset #undef CASE_ADD_TO_POOL } +XAssetInfoGeneric* GameAssetPoolT6::GetAsset(const asset_type_t type, std::string name) +{ +#define CASE_GET_ASSET(assetType, poolName) \ + case assetType: \ + { \ + if((poolName) != nullptr) \ + return (poolName)->GetAsset(std::move(name)); \ + break; \ + } + + switch (type) + { + CASE_GET_ASSET(ASSET_TYPE_PHYSPRESET, m_phys_preset); + CASE_GET_ASSET(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints); + CASE_GET_ASSET(ASSET_TYPE_DESTRUCTIBLEDEF, m_destructible_def); + CASE_GET_ASSET(ASSET_TYPE_XANIMPARTS, m_xanim_parts); + CASE_GET_ASSET(ASSET_TYPE_XMODEL, m_xmodel); + CASE_GET_ASSET(ASSET_TYPE_MATERIAL, m_material); + CASE_GET_ASSET(ASSET_TYPE_TECHNIQUE_SET, m_technique_set); + CASE_GET_ASSET(ASSET_TYPE_IMAGE, m_image); + CASE_GET_ASSET(ASSET_TYPE_SOUND, m_sound_bank); + CASE_GET_ASSET(ASSET_TYPE_SOUND_PATCH, m_sound_patch); + CASE_GET_ASSET(ASSET_TYPE_CLIPMAP, m_clip_map); + CASE_GET_ASSET(ASSET_TYPE_CLIPMAP_PVS, m_clip_map); + CASE_GET_ASSET(ASSET_TYPE_COMWORLD, m_com_world); + CASE_GET_ASSET(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp); + CASE_GET_ASSET(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp); + CASE_GET_ASSET(ASSET_TYPE_MAP_ENTS, m_map_ents); + CASE_GET_ASSET(ASSET_TYPE_GFXWORLD, m_gfx_world); + CASE_GET_ASSET(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def); + CASE_GET_ASSET(ASSET_TYPE_FONT, m_font); + CASE_GET_ASSET(ASSET_TYPE_FONTICON, m_font_icon); + CASE_GET_ASSET(ASSET_TYPE_MENULIST, m_menu_list); + CASE_GET_ASSET(ASSET_TYPE_MENU, m_menu_def); + CASE_GET_ASSET(ASSET_TYPE_LOCALIZE_ENTRY, m_localize); + CASE_GET_ASSET(ASSET_TYPE_WEAPON, m_weapon); + CASE_GET_ASSET(ASSET_TYPE_ATTACHMENT, m_attachment); + CASE_GET_ASSET(ASSET_TYPE_ATTACHMENT_UNIQUE, m_attachment_unique); + CASE_GET_ASSET(ASSET_TYPE_WEAPON_CAMO, m_camo); + CASE_GET_ASSET(ASSET_TYPE_SNDDRIVER_GLOBALS, m_snd_driver_globals); + CASE_GET_ASSET(ASSET_TYPE_FX, m_fx); + CASE_GET_ASSET(ASSET_TYPE_IMPACT_FX, m_fx_impact_table); + CASE_GET_ASSET(ASSET_TYPE_RAWFILE, m_raw_file); + CASE_GET_ASSET(ASSET_TYPE_STRINGTABLE, m_string_table); + CASE_GET_ASSET(ASSET_TYPE_LEADERBOARD, m_leaderboard); + CASE_GET_ASSET(ASSET_TYPE_XGLOBALS, m_xglobals); + CASE_GET_ASSET(ASSET_TYPE_DDL, m_ddl); + CASE_GET_ASSET(ASSET_TYPE_GLASSES, m_glasses); + CASE_GET_ASSET(ASSET_TYPE_EMBLEMSET, m_emblem_set); + CASE_GET_ASSET(ASSET_TYPE_SCRIPTPARSETREE, m_script); + CASE_GET_ASSET(ASSET_TYPE_KEYVALUEPAIRS, m_key_value_pairs); + CASE_GET_ASSET(ASSET_TYPE_VEHICLEDEF, m_vehicle); + CASE_GET_ASSET(ASSET_TYPE_MEMORYBLOCK, m_memory_block); + CASE_GET_ASSET(ASSET_TYPE_ADDON_MAP_ENTS, m_addon_map_ents); + CASE_GET_ASSET(ASSET_TYPE_TRACER, m_tracer); + CASE_GET_ASSET(ASSET_TYPE_SKINNEDVERTS, m_skinned_verts); + CASE_GET_ASSET(ASSET_TYPE_QDB, m_qdb); + CASE_GET_ASSET(ASSET_TYPE_SLUG, m_slug); + CASE_GET_ASSET(ASSET_TYPE_FOOTSTEP_TABLE, m_footstep_table); + CASE_GET_ASSET(ASSET_TYPE_FOOTSTEPFX_TABLE, m_footstep_fx_table); + CASE_GET_ASSET(ASSET_TYPE_ZBARRIER, m_zbarrier); + + default: + assert(false); + break; + } + + return nullptr; + +#undef CASE_GET_ASSET +} + ZoneContent GameAssetPoolT6::GetContent() const { ZoneContent content{}; @@ -403,4 +475,4 @@ ZoneContent GameAssetPoolT6::GetContent() const return content; #undef POOL_ADD_TO_CONTENT -} \ No newline at end of file +} diff --git a/src/ZoneCommon/Game/T6/GameAssetPoolT6.h b/src/ZoneCommon/Game/T6/GameAssetPoolT6.h index eb09e24e..5e11207b 100644 --- a/src/ZoneCommon/Game/T6/GameAssetPoolT6.h +++ b/src/ZoneCommon/Game/T6/GameAssetPoolT6.h @@ -1,7 +1,7 @@ #pragma once -#include "Pool/AssetPool.h" #include "Pool/IZoneAssetPools.h" +#include "Pool/AssetPool.h" #include "T6.h" class GameAssetPoolT6 final : public IZoneAssetPools @@ -64,7 +64,8 @@ public: void InitPoolStatic(asset_type_t type, size_t capacity) override; void InitPoolDynamic(asset_type_t type) override; - void* AddAsset(asset_type_t type, std::string name, void* asset, std::vector& scriptStrings, std::vector& dependencies) override; + XAssetInfoGeneric* AddAsset(asset_type_t type, std::string name, void* asset, std::vector& scriptStrings, std::vector& dependencies) override; + XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) override; ZoneContent GetContent() const override; }; diff --git a/src/ZoneCommon/Pool/AssetPool.h b/src/ZoneCommon/Pool/AssetPool.h index f654ffcd..4abec139 100644 --- a/src/ZoneCommon/Pool/AssetPool.h +++ b/src/ZoneCommon/Pool/AssetPool.h @@ -43,7 +43,7 @@ public: virtual ~AssetPool() = default; - virtual XAssetInfo* AddAsset(std::string name, T* asset, std::vector& scriptStrings, std::vector& dependencies) = 0; + virtual XAssetInfo* AddAsset(std::string name, T* asset, std::vector& scriptStrings, std::vector& dependencies) = 0; XAssetInfo* GetAsset(const std::string& name) { diff --git a/src/ZoneCommon/Pool/AssetPoolDynamic.h b/src/ZoneCommon/Pool/AssetPoolDynamic.h index 2189d45c..186a205b 100644 --- a/src/ZoneCommon/Pool/AssetPoolDynamic.h +++ b/src/ZoneCommon/Pool/AssetPoolDynamic.h @@ -12,11 +12,13 @@ class AssetPoolDynamic final : public AssetPool using AssetPool::m_asset_lookup; std::vector*> m_assets; + asset_type_t m_type; public: - explicit AssetPoolDynamic(const int priority) + AssetPoolDynamic(const int priority, const asset_type_t type) { GlobalAssetPool::LinkAssetPool(this, priority); + m_type = type; } AssetPoolDynamic(AssetPoolDynamic&) = delete; @@ -30,7 +32,7 @@ public: for(auto* entry : m_assets) { - delete entry->m_asset; + delete entry->m_ptr; delete entry; } @@ -38,16 +40,17 @@ public: m_asset_lookup.clear(); } - XAssetInfo* AddAsset(std::string name, T* asset, std::vector& scriptStrings, std::vector& dependencies) override + XAssetInfo* AddAsset(std::string name, T* asset, std::vector& scriptStrings, std::vector& dependencies) override { auto* newInfo = new XAssetInfo(); + newInfo->m_type = m_type; newInfo->m_name = std::move(name); newInfo->m_script_strings = std::move(scriptStrings); newInfo->m_dependencies = std::move(dependencies); T* newAsset = new T(); memcpy(newAsset, asset, sizeof(T)); - newInfo->m_asset = newAsset; + newInfo->m_ptr = newAsset; m_assets.push_back(newInfo); m_asset_lookup[newInfo->m_name] = newInfo; diff --git a/src/ZoneCommon/Pool/AssetPoolStatic.h b/src/ZoneCommon/Pool/AssetPoolStatic.h index 5432d174..45d3ae5f 100644 --- a/src/ZoneCommon/Pool/AssetPoolStatic.h +++ b/src/ZoneCommon/Pool/AssetPoolStatic.h @@ -2,6 +2,7 @@ #include "GlobalAssetPool.h" #include "AssetPool.h" +#include "XAssetInfo.h" #include @@ -25,9 +26,10 @@ class AssetPoolStatic final : public AssetPool AssetPoolEntry* m_pool; XAssetInfo* m_info_pool; size_t m_capacity; + asset_type_t m_type; public: - AssetPoolStatic(const size_t capacity, const int priority) + AssetPoolStatic(const size_t capacity, const int priority, asset_type_t type) { m_capacity = capacity; @@ -78,7 +80,7 @@ public: m_capacity = 0; } - XAssetInfo* AddAsset(std::string name, T* asset, std::vector& scriptStrings, std::vector& dependencies) override + XAssetInfo* AddAsset(std::string name, T* asset, std::vector& scriptStrings, std::vector& dependencies) override { if(m_free == nullptr) { @@ -90,8 +92,9 @@ public: memcpy(&poolSlot->m_entry, asset, sizeof(T)); + poolSlot->m_info->m_type = m_type; poolSlot->m_info->m_name = std::move(name); - poolSlot->m_info->m_asset = &poolSlot->m_entry; + poolSlot->m_info->m_ptr = &poolSlot->m_entry; poolSlot->m_info->m_script_strings = std::move(scriptStrings); poolSlot->m_info->m_dependencies = std::move(dependencies); diff --git a/src/ZoneCommon/Pool/IZoneAssetPools.h b/src/ZoneCommon/Pool/IZoneAssetPools.h index 01be4b31..72d31abd 100644 --- a/src/ZoneCommon/Pool/IZoneAssetPools.h +++ b/src/ZoneCommon/Pool/IZoneAssetPools.h @@ -3,13 +3,16 @@ #include "XAssetInfo.h" #include "Zone/ZoneTypes.h" #include "Zone/ZoneContent.h" +#include +#include class IZoneAssetPools { public: virtual ~IZoneAssetPools() = default; - virtual void* AddAsset(asset_type_t type, std::string name, void* asset, std::vector& scriptStrings, std::vector& dependencies) = 0; + virtual XAssetInfoGeneric* AddAsset(asset_type_t type, std::string name, void* asset, std::vector& scriptStrings, std::vector& dependencies) = 0; + virtual XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) = 0; virtual void InitPoolStatic(asset_type_t type, size_t capacity) = 0; virtual void InitPoolDynamic(asset_type_t type) = 0; virtual ZoneContent GetContent() const = 0; diff --git a/src/ZoneCommon/Pool/XAssetInfo.h b/src/ZoneCommon/Pool/XAssetInfo.h index 9e84e5a6..1d06593d 100644 --- a/src/ZoneCommon/Pool/XAssetInfo.h +++ b/src/ZoneCommon/Pool/XAssetInfo.h @@ -1,13 +1,23 @@ #pragma once #include -#include "Zone/XAssetDependency.h" +#include -template -class XAssetInfo +class XAssetInfoGeneric { public: + int m_type = -1; std::string m_name; - T* m_asset; std::vector m_script_strings; - std::vector m_dependencies; + std::vector m_dependencies; + void* m_ptr; +}; + +template +class XAssetInfo : public XAssetInfoGeneric +{ +public: + T* Asset() + { + return static_cast(m_ptr); + } }; diff --git a/src/ZoneCommon/Zone/XAssetDependency.h b/src/ZoneCommon/Zone/XAssetDependency.h deleted file mode 100644 index 3f7a6cf9..00000000 --- a/src/ZoneCommon/Zone/XAssetDependency.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -class XAssetDependency -{ -public: - int m_type; - std::string m_name; -}; \ No newline at end of file diff --git a/src/ZoneLoading/Loading/AssetLoader.cpp b/src/ZoneLoading/Loading/AssetLoader.cpp index 650351db..4c19608c 100644 --- a/src/ZoneLoading/Loading/AssetLoader.cpp +++ b/src/ZoneLoading/Loading/AssetLoader.cpp @@ -10,22 +10,18 @@ AssetLoader::AssetLoader(const asset_type_t assetType, IZoneScriptStringProvider varScriptString = nullptr; } -void AssetLoader::AddDependency(const asset_type_t type, std::string& name) +void AssetLoader::AddDependency(XAssetInfoGeneric* assetInfo) { - for(auto& existingDependency : m_dependencies) + if (assetInfo == nullptr) + return; + + const auto existingEntry = std::find(m_dependencies.begin(), m_dependencies.end(), assetInfo); + if(existingEntry != m_dependencies.end()) { - if(existingDependency.m_type == type - && existingDependency.m_name == name) - { - return; - } + return; } - XAssetDependency dependency; - dependency.m_type = type; - dependency.m_name = name; - - m_dependencies.push_back(dependency); + m_dependencies.push_back(assetInfo); } scr_string_t AssetLoader::UseScriptString(const scr_string_t scrString) @@ -63,7 +59,12 @@ void AssetLoader::LoadScriptStringArray(const bool atStreamStart, const size_t c } } -void* AssetLoader::LinkAsset(std::string name, void* asset) +XAssetInfoGeneric* AssetLoader::LinkAsset(std::string name, void* asset) { - return m_zone->GetPools()->AddAsset(m_asset_type, std::move(name), asset, m_used_script_strings, m_dependencies); -} \ No newline at end of file + return m_zone->GetPools()->AddAsset(m_asset_type, std::move(name), asset, m_used_script_strings, m_dependencies);; +} + +XAssetInfoGeneric* AssetLoader::GetAssetInfo(std::string name) const +{ + return m_zone->GetPools()->GetAsset(m_asset_type, std::move(name)); +} diff --git a/src/ZoneLoading/Loading/AssetLoader.h b/src/ZoneLoading/Loading/AssetLoader.h index c2ef9933..300bb12f 100644 --- a/src/ZoneLoading/Loading/AssetLoader.h +++ b/src/ZoneLoading/Loading/AssetLoader.h @@ -1,7 +1,7 @@ #pragma once +#include "Pool/XAssetInfo.h" #include "ContentLoader.h" #include "IZoneScriptStringProvider.h" -#include "Zone/XAssetDependency.h" class AssetLoader : public ContentLoader { @@ -9,7 +9,7 @@ class AssetLoader : public ContentLoader std::vector m_used_script_strings; - std::vector m_dependencies; + std::vector m_dependencies; protected: IZoneScriptStringProvider* m_script_string_provider; @@ -18,10 +18,12 @@ protected: AssetLoader(asset_type_t assetType, IZoneScriptStringProvider* scriptStringProvider, Zone* zone, IZoneInputStream* stream); - void AddDependency(asset_type_t type, std::string& name); + void AddDependency(XAssetInfoGeneric* assetInfo); scr_string_t UseScriptString(scr_string_t scrString); void LoadScriptStringArray(bool atStreamStart, size_t count); - void* LinkAsset(std::string name, void* asset); + XAssetInfoGeneric* LinkAsset(std::string name, void* asset); + + XAssetInfoGeneric* GetAssetInfo(std::string name) const; };