2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-02-10 17:43:03 +00:00

refactor: introduce subasset loading

This commit is contained in:
Jan Laupetin
2026-02-05 16:25:00 +00:00
parent 1be411b371
commit aa47ffa629
255 changed files with 1668 additions and 3132 deletions

View File

@@ -1,7 +1,6 @@
#include "Game/T6/KeyValuePairs/KeyValuePairsCompilerT6.h"
#include "Game/T6/CommonT6.h"
#include "Game/T6/GameAssetPoolT6.h"
#include "KeyValuePairs/KeyValuePairsCreator.h"
#include "Utils/TestMemoryManager.h"
@@ -73,7 +72,7 @@ namespace test::game::t6::keyvaluepairs
sut->FinalizeZone(testContext.m_context);
REQUIRE(testContext.m_memory.GetAllocationCount() == 0u);
REQUIRE(testContext.m_zone.m_pools->GetTotalAssetCount() == 0u);
REQUIRE(testContext.m_zone.m_pools.GetTotalAssetCount() == 0u);
}
TEST_CASE("KeyValuePairsCompilerT6: Creates KeyValuePairs asset with identical name to the zone", "[keyvaluepairs][t6]")
@@ -86,9 +85,9 @@ namespace test::game::t6::keyvaluepairs
sut->FinalizeZone(testContext.m_context);
REQUIRE(testContext.m_memory.GetAllocationCount() > 0u);
REQUIRE(testContext.m_zone.m_pools->GetTotalAssetCount() == 1u);
REQUIRE(testContext.m_zone.m_pools.GetTotalAssetCount() == 1u);
XAssetInfo<KeyValuePairs>* assetInfo = *dynamic_cast<GameAssetPoolT6*>(testContext.m_zone.m_pools.get())->m_key_value_pairs->begin();
XAssetInfo<KeyValuePairs>* assetInfo = *testContext.m_zone.m_pools.PoolAssets<AssetKeyValuePairs>().begin();
REQUIRE(assetInfo);
REQUIRE(assetInfo->m_name == "test");
@@ -112,9 +111,9 @@ namespace test::game::t6::keyvaluepairs
sut->FinalizeZone(testContext.m_context);
REQUIRE(testContext.m_memory.GetAllocationCount() > 0u);
REQUIRE(testContext.m_zone.m_pools->GetTotalAssetCount() == 1u);
REQUIRE(testContext.m_zone.m_pools.GetTotalAssetCount() == 1u);
XAssetInfo<KeyValuePairs>* assetInfo = *dynamic_cast<GameAssetPoolT6*>(testContext.m_zone.m_pools.get())->m_key_value_pairs->begin();
XAssetInfo<KeyValuePairs>* assetInfo = *testContext.m_zone.m_pools.PoolAssets<AssetKeyValuePairs>().begin();
REQUIRE(assetInfo);
REQUIRE(assetInfo->m_name == "test");

View File

@@ -1,7 +1,6 @@
#include "Game/IW3/StringTable/AssetLoaderStringTableIW3.h"
#include "Game/IW3/GameIW3.h"
#include "Pool/ZoneAssetPools.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"

View File

@@ -65,7 +65,7 @@ namespace test::game::iw4::menu::parsing::it
menuDef_t* GetMenuAsset(const std::string& menuName)
{
const auto addedAsset = m_zone.m_pools->GetAsset(ASSET_TYPE_MENU, menuName);
const auto addedAsset = m_zone.m_pools.GetAsset(ASSET_TYPE_MENU, menuName);
REQUIRE(addedAsset);
REQUIRE(addedAsset->m_type == ASSET_TYPE_MENU);

View File

@@ -4,7 +4,6 @@
#include "Game/IW3/CommonIW3.h"
#include "Game/IW3/GameIW3.h"
#include "NormalizedJson.h"
#include "Pool/AssetPoolDynamic.h"
#include "SearchPath/MockOutputPath.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
@@ -35,7 +34,7 @@ namespace
return techset;
}
void GivenMaterial(const std::string& name, AssetPool<Material>& pool, MemoryManager& memory)
void GivenMaterial(const std::string& name, Zone& zone, MemoryManager& memory)
{
auto* material = memory.Alloc<Material>();
material->info.name = memory.Dup(name.c_str());
@@ -310,7 +309,7 @@ namespace
stateBits6.loadBits.structured.stencilBackZFail = 0;
stateBits6.loadBits.structured.stencilBackFunc = 0;
pool.AddAsset(std::make_unique<XAssetInfo<Material>>(ASSET_TYPE_MATERIAL, name, material));
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<Material>>(ASSET_TYPE_MATERIAL, name, material));
}
TEST_CASE("DumperMaterial(IW3): Can dump material", "[iw3][material][assetdumper]")
@@ -558,11 +557,9 @@ namespace
MockOutputPath mockOutput;
AssetDumpingContext context(zone, "", mockOutput, mockObjPath, std::nullopt);
AssetPoolDynamic<Material> materialPool(0);
GivenMaterial("wc/ch_plasterwall_long", zone, memory);
GivenMaterial("wc/ch_plasterwall_long", materialPool, memory);
material::JsonDumperIW3 dumper(materialPool);
material::JsonDumperIW3 dumper;
dumper.Dump(context);
const auto* file = mockOutput.GetMockedFile("materials/wc/ch_plasterwall_long.json");

View File

@@ -4,7 +4,6 @@
#include "Game/IW4/CommonIW4.h"
#include "Game/IW4/GameIW4.h"
#include "NormalizedJson.h"
#include "Pool/AssetPoolDynamic.h"
#include "SearchPath/MockOutputPath.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
@@ -35,7 +34,7 @@ namespace
return techset;
}
void GivenMaterial(const std::string& name, AssetPool<Material>& pool, MemoryManager& memory)
void GivenMaterial(const std::string& name, Zone& zone, MemoryManager& memory)
{
auto* material = memory.Alloc<Material>();
material->info.name = memory.Dup(name.c_str());
@@ -288,7 +287,7 @@ namespace
stateBits5.loadBits.structured.stencilBackZFail = 0;
stateBits5.loadBits.structured.stencilBackFunc = 0;
pool.AddAsset(std::make_unique<XAssetInfo<Material>>(ASSET_TYPE_MATERIAL, name, material));
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<Material>>(ASSET_TYPE_MATERIAL, name, material));
}
TEST_CASE("DumperMaterial(IW4): Can dump material", "[iw4][material][assetdumper]")
@@ -539,11 +538,9 @@ namespace
MockOutputPath mockOutput;
AssetDumpingContext context(zone, "", mockOutput, mockObjPath, std::nullopt);
AssetPoolDynamic<Material> materialPool(0);
GivenMaterial("mc/ch_rubble01", zone, memory);
GivenMaterial("mc/ch_rubble01", materialPool, memory);
material::JsonDumperIW4 dumper(materialPool);
material::JsonDumperIW4 dumper;
dumper.Dump(context);
const auto* file = mockOutput.GetMockedFile("materials/mc/ch_rubble01.json");

View File

@@ -4,7 +4,6 @@
#include "Game/IW5/CommonIW5.h"
#include "Game/IW5/GameIW5.h"
#include "NormalizedJson.h"
#include "Pool/AssetPoolDynamic.h"
#include "SearchPath/MockOutputPath.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
@@ -35,7 +34,7 @@ namespace
return techset;
}
void GivenMaterial(const std::string& name, AssetPool<Material>& pool, MemoryManager& memory)
void GivenMaterial(const std::string& name, Zone& zone, MemoryManager& memory)
{
auto* material = memory.Alloc<Material>();
material->info.name = memory.Dup(name.c_str());
@@ -317,7 +316,7 @@ namespace
stateBits6.loadBits.structured.stencilBackZFail = 0;
stateBits6.loadBits.structured.stencilBackFunc = 0;
pool.AddAsset(std::make_unique<XAssetInfo<Material>>(ASSET_TYPE_MATERIAL, name, material));
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<Material>>(ASSET_TYPE_MATERIAL, name, material));
}
TEST_CASE("DumperMaterial(IW5): Can dump material", "[iw5][material][assetdumper]")
@@ -592,11 +591,9 @@ namespace
MockOutputPath mockOutput;
AssetDumpingContext context(zone, "", mockOutput, mockObjPath, std::nullopt);
AssetPoolDynamic<Material> materialPool(0);
GivenMaterial("wc/me_metal_rust_02", zone, memory);
GivenMaterial("wc/me_metal_rust_02", materialPool, memory);
material::JsonDumperIW5 dumper(materialPool);
material::JsonDumperIW5 dumper;
dumper.Dump(context);
const auto* file = mockOutput.GetMockedFile("materials/wc/me_metal_rust_02.json");

View File

@@ -4,7 +4,6 @@
#include "Game/T5/CommonT5.h"
#include "Game/T5/GameT5.h"
#include "NormalizedJson.h"
#include "Pool/AssetPoolDynamic.h"
#include "SearchPath/MockOutputPath.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
@@ -35,7 +34,7 @@ namespace
return techset;
}
void GivenMaterial(const std::string& name, AssetPool<Material>& pool, MemoryManager& memory)
void GivenMaterial(const std::string& name, Zone& zone, MemoryManager& memory)
{
auto* material = memory.Alloc<Material>();
material->info.name = memory.Dup(name.c_str());
@@ -289,7 +288,7 @@ namespace
stateBits5.loadBits.structured.stencilBackZFail = 0;
stateBits5.loadBits.structured.stencilBackFunc = 0;
pool.AddAsset(std::make_unique<XAssetInfo<Material>>(ASSET_TYPE_MATERIAL, name, material));
zone.m_pools.AddAsset<AssetMaterial>(std::make_unique<XAssetInfo<Material>>(ASSET_TYPE_MATERIAL, name, material));
}
TEST_CASE("DumperMaterial(T5): Can dump material", "[t5][material][assetdumper]")
@@ -621,11 +620,9 @@ namespace
MockOutputPath mockOutput;
AssetDumpingContext context(zone, "", mockOutput, mockObjPath, std::nullopt);
AssetPoolDynamic<Material> materialPool(0);
GivenMaterial("mc/ch_rubble01", zone, memory);
GivenMaterial("mc/ch_rubble01", materialPool, memory);
material::JsonDumperT5 dumper(materialPool);
material::JsonDumperT5 dumper;
dumper.Dump(context);
const auto* file = mockOutput.GetMockedFile("materials/mc/ch_rubble01.json");

View File

@@ -4,7 +4,6 @@
#include "Game/T6/CommonT6.h"
#include "Game/T6/GameT6.h"
#include "NormalizedJson.h"
#include "Pool/AssetPoolDynamic.h"
#include "SearchPath/MockOutputPath.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
@@ -27,7 +26,7 @@ namespace
return material;
}
void GivenFontIcon(const std::string& name, AssetPool<FontIcon>& pool, MemoryManager& memory)
void GivenFontIcon(const std::string& name, Zone& zone, MemoryManager& memory)
{
auto* fontIcon = memory.Alloc<FontIcon>();
fontIcon->name = memory.Dup(name.c_str());
@@ -86,7 +85,7 @@ namespace
alias5.aliasHash = Common::Com_HashString("BUTTON_MOVESTICK");
alias5.buttonHash = entry2.fontIconName.hash;
pool.AddAsset(std::make_unique<XAssetInfo<FontIcon>>(ASSET_TYPE_FONTICON, name, fontIcon));
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<FontIcon>>(ASSET_TYPE_FONTICON, name, fontIcon));
}
TEST_CASE("DumperFontIconJson(T6): Can dump font icon", "[t6][font-icon][assetdumper]")
@@ -148,10 +147,9 @@ namespace
MockOutputPath mockOutput;
AssetDumpingContext context(zone, "", mockOutput, mockObjPath, std::nullopt);
AssetPoolDynamic<FontIcon> fontIconPool(0);
GivenFontIcon("fonticon/test.csv", fontIconPool, memory);
GivenFontIcon("fonticon/test.csv", zone, memory);
font_icon::JsonDumperT6 dumper(fontIconPool);
font_icon::JsonDumperT6 dumper;
dumper.Dump(context);
const auto* file = mockOutput.GetMockedFile("fonticon/test.json");

View File

@@ -4,7 +4,6 @@
#include "Game/T6/CommonT6.h"
#include "Game/T6/GameT6.h"
#include "NormalizedJson.h"
#include "Pool/AssetPoolDynamic.h"
#include "SearchPath/MockOutputPath.h"
#include "SearchPath/MockSearchPath.h"
#include "Utils/MemoryManager.h"
@@ -35,7 +34,7 @@ namespace
return techset;
}
void GivenMaterial(const std::string& name, AssetPool<Material>& pool, MemoryManager& memory)
void GivenMaterial(const std::string& name, Zone& zone, MemoryManager& memory)
{
auto* material = memory.Alloc<Material>();
material->info.name = memory.Dup(name.c_str());
@@ -254,7 +253,7 @@ namespace
material->thermalMaterial = nullptr;
pool.AddAsset(std::make_unique<XAssetInfo<Material>>(ASSET_TYPE_MATERIAL, name, material));
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<Material>>(ASSET_TYPE_MATERIAL, name, material));
}
TEST_CASE("DumperMaterial(T6): Can dump material", "[t6][material][assetdumper]")
@@ -469,10 +468,9 @@ namespace
MockOutputPath mockOutput;
AssetDumpingContext context(zone, "", mockOutput, mockObjPath, std::nullopt);
AssetPoolDynamic<Material> materialPool(0);
GivenMaterial("wpc/metal_ac_duct", materialPool, memory);
GivenMaterial("wpc/metal_ac_duct", zone, memory);
material::JsonDumperT6 dumper(materialPool);
material::JsonDumperT6 dumper;
dumper.Dump(context);
const auto* file = mockOutput.GetMockedFile("materials/wpc/metal_ac_duct.json");

View File

@@ -1,4 +1,4 @@
#include "Game/IW3/GameAssetPoolIW3.h"
#include "Game/IW3/IW3.h"
#include "Linker.h"
#include "OatTestPaths.h"
#include "SystemTestsPaths.h"
@@ -51,12 +51,11 @@ namespace
REQUIRE(maybeZone);
auto zone = std::move(*maybeZone);
auto pools = dynamic_cast<GameAssetPoolIW3*>(zone->m_pools.get());
REQUIRE(zone->m_game_id == GameId::IW3);
REQUIRE(zone->m_platform == GamePlatform::PC);
REQUIRE(zone->m_name == "SimpleZoneIW3");
REQUIRE(pools->GetTotalAssetCount() == 1);
REQUIRE(pools->m_raw_file->GetAsset("SimpleZone.txt"));
REQUIRE(zone->m_pools.GetTotalAssetCount() == 1);
REQUIRE(zone->m_pools.GetAsset<IW3::AssetRawFile>("SimpleZone.txt"));
}
} // namespace

View File

@@ -1,4 +1,4 @@
#include "Game/IW4/GameAssetPoolIW4.h"
#include "Game/IW4/IW4.h"
#include "Linker.h"
#include "OatTestPaths.h"
#include "SystemTestsPaths.h"
@@ -51,12 +51,11 @@ namespace
REQUIRE(maybeZone);
auto zone = std::move(*maybeZone);
auto pools = dynamic_cast<GameAssetPoolIW4*>(zone->m_pools.get());
REQUIRE(zone->m_game_id == GameId::IW4);
REQUIRE(zone->m_platform == GamePlatform::PC);
REQUIRE(zone->m_name == "SimpleZoneIW4");
REQUIRE(pools->GetTotalAssetCount() == 1);
REQUIRE(pools->m_raw_file->GetAsset("SimpleZone.txt"));
REQUIRE(zone->m_pools.GetTotalAssetCount() == 1);
REQUIRE(zone->m_pools.GetAsset<IW4::AssetRawFile>("SimpleZone.txt"));
}
} // namespace

View File

@@ -1,4 +1,5 @@
#include "Game/IW5/GameAssetPoolIW5.h"
#include "Game/IW5/IW5.h"
#include "Linker.h"
#include "OatTestPaths.h"
#include "SystemTestsPaths.h"
@@ -51,12 +52,11 @@ namespace
REQUIRE(maybeZone);
auto zone = std::move(*maybeZone);
auto pools = dynamic_cast<GameAssetPoolIW5*>(zone->m_pools.get());
REQUIRE(zone->m_game_id == GameId::IW5);
REQUIRE(zone->m_platform == GamePlatform::PC);
REQUIRE(zone->m_name == "SimpleZoneIW5");
REQUIRE(pools->GetTotalAssetCount() == 1);
REQUIRE(pools->m_raw_file->GetAsset("SimpleZone.txt"));
REQUIRE(zone->m_pools.GetTotalAssetCount() == 1);
REQUIRE(zone->m_pools.GetAsset<IW5::AssetRawFile>("SimpleZone.txt"));
}
} // namespace

View File

@@ -1,4 +1,4 @@
#include "Game/T5/GameAssetPoolT5.h"
#include "Game/T5/T5.h"
#include "Linker.h"
#include "OatTestPaths.h"
#include "SystemTestsPaths.h"
@@ -51,12 +51,11 @@ namespace
REQUIRE(maybeZone);
auto zone = std::move(*maybeZone);
auto pools = dynamic_cast<GameAssetPoolT5*>(zone->m_pools.get());
REQUIRE(zone->m_game_id == GameId::T5);
REQUIRE(zone->m_platform == GamePlatform::PC);
REQUIRE(zone->m_name == "SimpleZoneT5");
REQUIRE(pools->GetTotalAssetCount() == 1);
REQUIRE(pools->m_raw_file->GetAsset("SimpleZone.txt"));
REQUIRE(zone->m_pools.GetTotalAssetCount() == 1);
REQUIRE(zone->m_pools.GetAsset<T5::AssetRawFile>("SimpleZone.txt"));
}
} // namespace

View File

@@ -9,7 +9,7 @@ In this case:
(actual asset, not a reference) techniqueset `trivial_floatz_2992w610`
*/
#include "Game/T6/GameAssetPoolT6.h"
#include "Game/T6/T6.h"
#include "Linker.h"
#include "OatTestPaths.h"
#include "SystemTestsPaths.h"
@@ -100,15 +100,14 @@ namespace
REQUIRE(maybeZone);
auto zone = std::move(*maybeZone);
auto pools = dynamic_cast<GameAssetPoolT6*>(zone->m_pools.get());
REQUIRE(zone->m_game_id == GameId::T6);
REQUIRE(zone->m_platform == GamePlatform::PC);
REQUIRE(zone->m_name == "CombinedZoneT6");
REQUIRE(pools->GetTotalAssetCount() == 2);
REQUIRE(pools->m_technique_set->GetAsset("trivial_floatz_2992w610"));
REQUIRE(zone->m_pools.GetTotalAssetCount() == 2);
REQUIRE(zone->m_pools.GetAsset<T6::AssetTechniqueSet>("trivial_floatz_2992w610"));
const auto* material = pools->m_material->GetAsset("test");
const auto* material = zone->m_pools.GetAsset<T6::AssetMaterial>("test");
REQUIRE(material);
REQUIRE(material->Asset()->techniqueSet);
REQUIRE(material->Asset()->techniqueSet->name == "trivial_floatz_2992w610"s);

View File

@@ -9,7 +9,7 @@ In this case:
(actual asset, not a reference) techniqueset `trivial_floatz_2992w610`
*/
#include "Game/T6/GameAssetPoolT6.h"
#include "Game/T6/T6.h"
#include "Linker.h"
#include "OatTestPaths.h"
#include "SystemTestsPaths.h"
@@ -103,16 +103,15 @@ namespace
REQUIRE(maybeZone);
auto zone = std::move(*maybeZone);
auto pools = dynamic_cast<GameAssetPoolT6*>(zone->m_pools.get());
REQUIRE(zone->m_game_id == GameId::T6);
REQUIRE(zone->m_platform == GamePlatform::PC);
REQUIRE(zone->m_name == "TestZone");
REQUIRE(pools->GetTotalAssetCount() == 3);
REQUIRE(pools->m_material->GetAsset("Suzanne2"));
REQUIRE(pools->m_technique_set->GetAsset(",trivial_floatz_2992w610"));
REQUIRE(zone->m_pools.GetTotalAssetCount() == 3);
REQUIRE(zone->m_pools.GetAsset<T6::AssetMaterial>("Suzanne2"));
REQUIRE(zone->m_pools.GetAsset<T6::AssetTechniqueSet>(",trivial_floatz_2992w610"));
const auto* xmodel = pools->m_xmodel->GetAsset("Suzanne2");
const auto* xmodel = zone->m_pools.GetAsset<T6::AssetXModel>("Suzanne2");
REQUIRE(xmodel);
REQUIRE(xmodel->Asset()->boneNames);
REQUIRE(xmodel->Asset()->numRootBones == 1);

View File

@@ -1,4 +1,4 @@
#include "Game/T6/GameAssetPoolT6.h"
#include "Game/T6/T6.h"
#include "Linker.h"
#include "OatTestPaths.h"
#include "SystemTestsPaths.h"
@@ -51,12 +51,11 @@ namespace
REQUIRE(maybeZone);
auto zone = std::move(*maybeZone);
auto pools = dynamic_cast<GameAssetPoolT6*>(zone->m_pools.get());
REQUIRE(zone->m_game_id == GameId::T6);
REQUIRE(zone->m_platform == GamePlatform::PC);
REQUIRE(zone->m_name == "SimpleZoneT6");
REQUIRE(pools->GetTotalAssetCount() == 1);
REQUIRE(pools->m_raw_file->GetAsset("SimpleZone.txt"));
REQUIRE(zone->m_pools.GetTotalAssetCount() == 1);
REQUIRE(zone->m_pools.GetAsset<T6::AssetRawFile>("SimpleZone.txt"));
}
} // namespace

View File

@@ -1,4 +1,4 @@
#include "Game/T6/GameAssetPoolT6.h"
#include "Game/T6/T6.h"
#include "OatTestPaths.h"
#include "Utils/Logging/Log.h"
#include "Utils/StringUtils.h"
@@ -47,8 +47,8 @@ namespace
auto rebuiltZone = std::move(*maybeRebuiltZone);
const auto& pools = *zone->m_pools;
const auto& rebuiltPools = *rebuiltZone->m_pools;
const auto& pools = zone->m_pools;
const auto& rebuiltPools = rebuiltZone->m_pools;
const auto totalAssetCount = pools.GetTotalAssetCount();
REQUIRE(totalAssetCount == rebuiltPools.GetTotalAssetCount());