From f0b66f0a35ed76f8b737270c8ec6def128132abf Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 19 Feb 2020 14:10:50 +0100 Subject: [PATCH] ZoneCommon: List zone content in the order it was loaded --- src/Unlinker/ContentLister/ContentPrinter.cpp | 9 +- src/Unlinker/ContentLister/ZoneDefWriter.cpp | 6 +- src/ZoneCommon/Game/IGame.h | 2 +- src/ZoneCommon/Game/T6/GameAssetPoolT6.cpp | 155 ++++++++++-------- src/ZoneCommon/Game/T6/GameAssetPoolT6.h | 10 +- src/ZoneCommon/Game/T6/GameT6.cpp | 7 + src/ZoneCommon/Game/T6/GameT6.h | 2 + src/ZoneCommon/Pool/AssetPoolStatic.h | 3 +- src/ZoneCommon/Pool/IZoneAssetPools.h | 11 +- src/ZoneCommon/Zone/ZoneContent.cpp | 13 -- src/ZoneCommon/Zone/ZoneContent.h | 21 --- 11 files changed, 123 insertions(+), 116 deletions(-) delete mode 100644 src/ZoneCommon/Zone/ZoneContent.cpp delete mode 100644 src/ZoneCommon/Zone/ZoneContent.h diff --git a/src/Unlinker/ContentLister/ContentPrinter.cpp b/src/Unlinker/ContentLister/ContentPrinter.cpp index 7025f121..04a21f08 100644 --- a/src/Unlinker/ContentLister/ContentPrinter.cpp +++ b/src/Unlinker/ContentLister/ContentPrinter.cpp @@ -7,14 +7,13 @@ ContentPrinter::ContentPrinter(Zone* zone) void ContentPrinter::PrintContent() const { - const ZoneContent content = m_zone->GetPools()->GetContent(); - - printf("Zone '%s' (%s)\n", m_zone->m_name.c_str(), content.m_game_name.c_str()); + const auto* pools = m_zone->GetPools(); + printf("Zone '%s' (%s)\n", m_zone->m_name.c_str(), m_zone->m_game->GetName().c_str()); puts("Content:"); - for(const auto& asset : content.m_assets) + for(const auto& asset : *pools) { - printf("%s, %s\n", asset.m_asset_type_name.c_str(), asset.m_asset_name.c_str()); + printf("%s, %s\n", pools->GetAssetTypeName(asset->m_type).c_str(), asset->m_name.c_str()); } puts(""); diff --git a/src/Unlinker/ContentLister/ZoneDefWriter.cpp b/src/Unlinker/ContentLister/ZoneDefWriter.cpp index 3a28e57c..586e1bc4 100644 --- a/src/Unlinker/ContentLister/ZoneDefWriter.cpp +++ b/src/Unlinker/ContentLister/ZoneDefWriter.cpp @@ -30,10 +30,10 @@ void AbstractZoneDefWriter::WriteEntry(const std::string& entryKey, const std::s void AbstractZoneDefWriter::WriteContent() const { - auto zoneContent = m_zone->GetPools()->GetContent(); + const auto* pools = m_zone->GetPools(); - for(const auto& asset : zoneContent.m_assets) + for(const auto& asset : *pools) { - WriteEntry(asset.m_asset_type_name, asset.m_asset_name); + WriteEntry(pools->GetAssetTypeName(asset->m_type), asset->m_name); } } diff --git a/src/ZoneCommon/Game/IGame.h b/src/ZoneCommon/Game/IGame.h index 67d10db3..02519c3a 100644 --- a/src/ZoneCommon/Game/IGame.h +++ b/src/ZoneCommon/Game/IGame.h @@ -1,5 +1,4 @@ #pragma once -#include "Zone/Zone.h" #include "GameLanguage.h" #include @@ -8,6 +7,7 @@ class Zone; class IGame { public: + virtual const std::string& GetName() = 0; virtual void AddZone(Zone* zone) = 0; virtual void RemoveZone(Zone* zone) = 0; virtual std::vector GetZones() = 0; diff --git a/src/ZoneCommon/Game/T6/GameAssetPoolT6.cpp b/src/ZoneCommon/Game/T6/GameAssetPoolT6.cpp index d6f84f9a..0ec3c407 100644 --- a/src/ZoneCommon/Game/T6/GameAssetPoolT6.cpp +++ b/src/ZoneCommon/Game/T6/GameAssetPoolT6.cpp @@ -5,8 +5,75 @@ using namespace T6; +const std::string GameAssetPoolT6::ASSET_TYPE_INVALID = "invalid_asset"; +const std::string GameAssetPoolT6::ASSET_TYPE_NAMES[] +{ + "xmodelpieces", + "physpreset", + "physconstraints", + "destructibledef", + "xanim", + "xmodel", + "material", + "techniqueset", + "image", + "soundbank", + "soundpatch", + "clipmap", + "clipmap", + "comworld", + "gameworldsp", + "gameworldmp", + "mapents", + "gfxworld", + "gfxlightdef", + "uimap", + "font", + "fonticon", + "menulist", + "menu", + "localize", + "weapon", + "weapondef", + "weaponvariant", + "weaponfull", + "attachment", + "attachmentunique", + "camo", + "snddriverglobals", + "fx", + "fximpacttable", + "aitype", + "mptype", + "mpbody", + "mphead", + "character", + "xmodelalias", + "rawfile", + "stringtable", + "leaderboard", + "xglobals", + "ddl", + "glasses", + "emblemset", + "script", + "keyvaluepairs", + "vehicle", + "memoryblock", + "addonmapents", + "tracer", + "skinnedverts", + "qdb", + "slug", + "footsteptable", + "footstepfxtable", + "zbarrier" +}; + GameAssetPoolT6::GameAssetPoolT6(const int priority) { + assert(_countof(ASSET_TYPE_NAMES) == ASSET_TYPE_COUNT); + m_priority = priority; m_phys_preset = nullptr; @@ -271,7 +338,12 @@ XAssetInfoGeneric* GameAssetPoolT6::AddAsset(asset_type_t type, std::string name case assetType: \ { \ assert((poolName) != nullptr); \ - return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, scriptStrings, dependencies); \ + auto* assetInfo = (poolName)->AddAsset(std::move(name), xAsset.header.headerName, scriptStrings, dependencies); \ + if(assetInfo) \ + { \ + m_assets_in_order.push_back(assetInfo); \ + } \ + return assetInfo; \ } switch(xAsset.type) @@ -336,7 +408,7 @@ XAssetInfoGeneric* GameAssetPoolT6::AddAsset(asset_type_t type, std::string name #undef CASE_ADD_TO_POOL } -XAssetInfoGeneric* GameAssetPoolT6::GetAsset(const asset_type_t type, std::string name) +XAssetInfoGeneric* GameAssetPoolT6::GetAsset(const asset_type_t type, std::string name) const { #define CASE_GET_ASSET(assetType, poolName) \ case assetType: \ @@ -408,71 +480,20 @@ XAssetInfoGeneric* GameAssetPoolT6::GetAsset(const asset_type_t type, std::strin #undef CASE_GET_ASSET } -ZoneContent GameAssetPoolT6::GetContent() const +const std::string& GameAssetPoolT6::GetAssetTypeName(const asset_type_t assetType) const { - ZoneContent content{}; + if (assetType >= 0 && assetType < static_cast(_countof(ASSET_TYPE_NAMES))) + return ASSET_TYPE_NAMES[assetType]; - content.m_game_name = "T6"; - -#define POOL_ADD_TO_CONTENT(assetTypeName, poolName) \ - if((poolName) != nullptr) \ - { \ - for(auto asset : *(poolName)) \ - { \ - content.m_assets.emplace_back((assetTypeName), asset->m_name);\ - } \ - } - - POOL_ADD_TO_CONTENT("physpreset", m_phys_preset); - POOL_ADD_TO_CONTENT("physconstraints", m_phys_constraints); - POOL_ADD_TO_CONTENT("destructibledef", m_destructible_def); - POOL_ADD_TO_CONTENT("xanim", m_xanim_parts); - POOL_ADD_TO_CONTENT("xmodel", m_xmodel); - POOL_ADD_TO_CONTENT("material", m_material); - POOL_ADD_TO_CONTENT("techniqueset", m_technique_set); - POOL_ADD_TO_CONTENT("image", m_image); - POOL_ADD_TO_CONTENT("soundbank", m_sound_bank); - POOL_ADD_TO_CONTENT("soundpatch", m_sound_patch); - POOL_ADD_TO_CONTENT("clipmap", m_clip_map); - POOL_ADD_TO_CONTENT("comworld", m_com_world); - POOL_ADD_TO_CONTENT("gameworldsp", m_game_world_sp); - POOL_ADD_TO_CONTENT("gameworldmp", m_game_world_mp); - POOL_ADD_TO_CONTENT("mapents", m_map_ents); - POOL_ADD_TO_CONTENT("gfxworld", m_gfx_world); - POOL_ADD_TO_CONTENT("gfxlightdef", m_gfx_light_def); - POOL_ADD_TO_CONTENT("font", m_font); - POOL_ADD_TO_CONTENT("fonticon", m_font_icon); - POOL_ADD_TO_CONTENT("menulist", m_menu_list); - POOL_ADD_TO_CONTENT("menudef", m_menu_def); - POOL_ADD_TO_CONTENT("localize", m_localize); - POOL_ADD_TO_CONTENT("weapon", m_weapon); - POOL_ADD_TO_CONTENT("attachment", m_attachment); - POOL_ADD_TO_CONTENT("attachmentunique", m_attachment_unique); - POOL_ADD_TO_CONTENT("camo", m_camo); - POOL_ADD_TO_CONTENT("snddriverglobals", m_snd_driver_globals); - POOL_ADD_TO_CONTENT("fx", m_fx); - POOL_ADD_TO_CONTENT("fximpacttable", m_fx_impact_table); - POOL_ADD_TO_CONTENT("rawfile", m_raw_file); - POOL_ADD_TO_CONTENT("stringtable", m_string_table); - POOL_ADD_TO_CONTENT("leaderboard", m_leaderboard); - POOL_ADD_TO_CONTENT("xglobals", m_xglobals); - POOL_ADD_TO_CONTENT("ddl", m_ddl); - POOL_ADD_TO_CONTENT("glasses", m_glasses); - POOL_ADD_TO_CONTENT("emblemset", m_emblem_set); - POOL_ADD_TO_CONTENT("script", m_script); - POOL_ADD_TO_CONTENT("keyvaluepairs", m_key_value_pairs); - POOL_ADD_TO_CONTENT("vehicle", m_vehicle); - POOL_ADD_TO_CONTENT("memoryblock", m_memory_block); - POOL_ADD_TO_CONTENT("addonmapents", m_addon_map_ents); - POOL_ADD_TO_CONTENT("tracer", m_tracer); - POOL_ADD_TO_CONTENT("skinnedverts", m_skinned_verts); - POOL_ADD_TO_CONTENT("qdb", m_qdb); - POOL_ADD_TO_CONTENT("slug", m_slug); - POOL_ADD_TO_CONTENT("footsteptable", m_footstep_table); - POOL_ADD_TO_CONTENT("footstepfxtable", m_footstep_fx_table); - POOL_ADD_TO_CONTENT("zbarrier", m_zbarrier); - - return content; - -#undef POOL_ADD_TO_CONTENT + return ASSET_TYPE_INVALID; +} + +IZoneAssetPools::iterator GameAssetPoolT6::begin() const +{ + return m_assets_in_order.begin(); +} + +IZoneAssetPools::iterator GameAssetPoolT6::end() const +{ + return m_assets_in_order.end(); } diff --git a/src/ZoneCommon/Game/T6/GameAssetPoolT6.h b/src/ZoneCommon/Game/T6/GameAssetPoolT6.h index 5e11207b..321ca0ce 100644 --- a/src/ZoneCommon/Game/T6/GameAssetPoolT6.h +++ b/src/ZoneCommon/Game/T6/GameAssetPoolT6.h @@ -7,6 +7,10 @@ class GameAssetPoolT6 final : public IZoneAssetPools { int m_priority; + std::vector m_assets_in_order; + + static const std::string ASSET_TYPE_INVALID; + static const std::string ASSET_TYPE_NAMES[]; public: AssetPool* m_phys_preset; @@ -65,7 +69,9 @@ public: void InitPoolDynamic(asset_type_t type) 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; + XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const override; + const std::string& GetAssetTypeName(asset_type_t assetType) const override; - ZoneContent GetContent() const override; + iterator begin() const override; + iterator end() const override; }; diff --git a/src/ZoneCommon/Game/T6/GameT6.cpp b/src/ZoneCommon/Game/T6/GameT6.cpp index e904efd6..ff4bb25e 100644 --- a/src/ZoneCommon/Game/T6/GameT6.cpp +++ b/src/ZoneCommon/Game/T6/GameT6.cpp @@ -5,6 +5,13 @@ using namespace T6; GameT6 g_GameT6; +const std::string GameT6::NAME = "T6"; + +const std::string& GameT6::GetName() +{ + return NAME; +} + void GameT6::AddZone(Zone* zone) { m_zones.push_back(zone); diff --git a/src/ZoneCommon/Game/T6/GameT6.h b/src/ZoneCommon/Game/T6/GameT6.h index c60ea366..b28544f5 100644 --- a/src/ZoneCommon/Game/T6/GameT6.h +++ b/src/ZoneCommon/Game/T6/GameT6.h @@ -3,9 +3,11 @@ class GameT6 : public IGame { + static const std::string NAME; std::vector m_zones; public: + const std::string& GetName() override; void AddZone(Zone* zone) override; void RemoveZone(Zone* zone) override; std::vector GetZones() override; diff --git a/src/ZoneCommon/Pool/AssetPoolStatic.h b/src/ZoneCommon/Pool/AssetPoolStatic.h index 45d3ae5f..2853c815 100644 --- a/src/ZoneCommon/Pool/AssetPoolStatic.h +++ b/src/ZoneCommon/Pool/AssetPoolStatic.h @@ -29,9 +29,10 @@ class AssetPoolStatic final : public AssetPool asset_type_t m_type; public: - AssetPoolStatic(const size_t capacity, const int priority, asset_type_t type) + AssetPoolStatic(const size_t capacity, const int priority, const asset_type_t type) { m_capacity = capacity; + m_type = type; if (m_capacity > 0) { diff --git a/src/ZoneCommon/Pool/IZoneAssetPools.h b/src/ZoneCommon/Pool/IZoneAssetPools.h index 72d31abd..455daed2 100644 --- a/src/ZoneCommon/Pool/IZoneAssetPools.h +++ b/src/ZoneCommon/Pool/IZoneAssetPools.h @@ -2,18 +2,23 @@ #include "XAssetInfo.h" #include "Zone/ZoneTypes.h" -#include "Zone/ZoneContent.h" #include #include class IZoneAssetPools { public: + using iterator = std::vector::const_iterator; + virtual ~IZoneAssetPools() = default; 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 XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const = 0; + virtual const std::string& GetAssetTypeName(asset_type_t assetType) const = 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; + + virtual iterator begin() const = 0; + virtual iterator end() const = 0; }; diff --git a/src/ZoneCommon/Zone/ZoneContent.cpp b/src/ZoneCommon/Zone/ZoneContent.cpp deleted file mode 100644 index 63eada4d..00000000 --- a/src/ZoneCommon/Zone/ZoneContent.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "ZoneContent.h" - -ZoneContent::GameAsset::GameAsset(std::string assetTypeName, std::string assetName) -{ - m_asset_type_name = std::move(assetTypeName); - m_asset_name = std::move(assetName); -} - -ZoneContent::ZoneContent() -{ - m_game_name = ""; - m_assets = std::vector(); -} \ No newline at end of file diff --git a/src/ZoneCommon/Zone/ZoneContent.h b/src/ZoneCommon/Zone/ZoneContent.h deleted file mode 100644 index b4b4d06f..00000000 --- a/src/ZoneCommon/Zone/ZoneContent.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -#include -#include - -class ZoneContent -{ -public: - class GameAsset - { - public: - GameAsset(std::string assetTypeName, std::string assetName); - - std::string m_asset_type_name; - std::string m_asset_name; - }; - - ZoneContent(); - - std::string m_game_name; - std::vector m_assets; -}; \ No newline at end of file