mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-03-15 17:33:03 +00:00
refactor: introduce subasset loading
This commit is contained in:
@@ -1,140 +0,0 @@
|
||||
#include "GameAssetPoolIW3.h"
|
||||
|
||||
#include "Pool/AssetPoolDynamic.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
GameAssetPoolIW3::GameAssetPoolIW3(Zone* zone, const zone_priority_t priority)
|
||||
: ZoneAssetPools(zone),
|
||||
m_priority(priority)
|
||||
{
|
||||
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
|
||||
|
||||
INIT_POOL(m_phys_preset);
|
||||
INIT_POOL(m_xanim_parts);
|
||||
INIT_POOL(m_xmodel);
|
||||
INIT_POOL(m_material);
|
||||
INIT_POOL(m_technique_set);
|
||||
INIT_POOL(m_image);
|
||||
INIT_POOL(m_sound);
|
||||
INIT_POOL(m_sound_curve);
|
||||
INIT_POOL(m_loaded_sound);
|
||||
INIT_POOL(m_clip_map);
|
||||
INIT_POOL(m_com_world);
|
||||
INIT_POOL(m_game_world_sp);
|
||||
INIT_POOL(m_game_world_mp);
|
||||
INIT_POOL(m_map_ents);
|
||||
INIT_POOL(m_gfx_world);
|
||||
INIT_POOL(m_gfx_light_def);
|
||||
INIT_POOL(m_font);
|
||||
INIT_POOL(m_menu_list);
|
||||
INIT_POOL(m_menu_def);
|
||||
INIT_POOL(m_localize);
|
||||
INIT_POOL(m_weapon);
|
||||
INIT_POOL(m_fx);
|
||||
INIT_POOL(m_fx_impact_table);
|
||||
INIT_POOL(m_raw_file);
|
||||
INIT_POOL(m_string_table);
|
||||
|
||||
#undef INIT_POOL
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameAssetPoolIW3::AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
|
||||
{
|
||||
#define CASE_ADD_TO_POOL(assetType, poolName) \
|
||||
case assetType: \
|
||||
{ \
|
||||
assert(poolName); \
|
||||
return (poolName)->AddAsset(std::unique_ptr<XAssetInfo<decltype(poolName)::element_type::type>>( \
|
||||
static_cast<XAssetInfo<decltype(poolName)::element_type::type>*>(xAssetInfo.release()))); \
|
||||
}
|
||||
|
||||
switch (static_cast<XAssetType>(xAssetInfo->m_type))
|
||||
{
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_PHYSPRESET, m_phys_preset)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_XMODEL, m_xmodel)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MATERIAL, m_material)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_IMAGE, m_image)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SOUND, m_sound)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SOUND_CURVE, m_sound_curve)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LOADED_SOUND, m_loaded_sound)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_CLIPMAP, m_clip_map)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_CLIPMAP_PVS, m_clip_map)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_COMWORLD, m_com_world)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MAP_ENTS, m_map_ents)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GFXWORLD, m_gfx_world)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FONT, m_font)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MENULIST, m_menu_list)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MENU, m_menu_def)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_WEAPON, m_weapon)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FX, m_fx)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_RAWFILE, m_raw_file)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_STRINGTABLE, m_string_table)
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
#undef CASE_ADD_TO_POOL
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameAssetPoolIW3::GetAsset(const asset_type_t type, const std::string& name) const
|
||||
{
|
||||
#define CASE_GET_ASSET(assetType, poolName) \
|
||||
case assetType: \
|
||||
{ \
|
||||
if (poolName) \
|
||||
return (poolName)->GetAsset(std::move(name)); \
|
||||
break; \
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
CASE_GET_ASSET(ASSET_TYPE_PHYSPRESET, m_phys_preset)
|
||||
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)
|
||||
CASE_GET_ASSET(ASSET_TYPE_SOUND_CURVE, m_sound_curve)
|
||||
CASE_GET_ASSET(ASSET_TYPE_LOADED_SOUND, m_loaded_sound)
|
||||
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_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_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)
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
#undef CASE_GET_ASSET
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Pool/AssetPool.h"
|
||||
#include "Pool/ZoneAssetPools.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class GameAssetPoolIW3 final : public ZoneAssetPools
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<AssetPool<IW3::PhysPreset>> m_phys_preset;
|
||||
std::unique_ptr<AssetPool<IW3::XAnimParts>> m_xanim_parts;
|
||||
std::unique_ptr<AssetPool<IW3::XModel>> m_xmodel;
|
||||
std::unique_ptr<AssetPool<IW3::Material>> m_material;
|
||||
std::unique_ptr<AssetPool<IW3::MaterialTechniqueSet>> m_technique_set;
|
||||
std::unique_ptr<AssetPool<IW3::GfxImage>> m_image;
|
||||
std::unique_ptr<AssetPool<IW3::snd_alias_list_t>> m_sound;
|
||||
std::unique_ptr<AssetPool<IW3::SndCurve>> m_sound_curve;
|
||||
std::unique_ptr<AssetPool<IW3::LoadedSound>> m_loaded_sound;
|
||||
std::unique_ptr<AssetPool<IW3::clipMap_t>> m_clip_map;
|
||||
std::unique_ptr<AssetPool<IW3::ComWorld>> m_com_world;
|
||||
std::unique_ptr<AssetPool<IW3::GameWorldSp>> m_game_world_sp;
|
||||
std::unique_ptr<AssetPool<IW3::GameWorldMp>> m_game_world_mp;
|
||||
std::unique_ptr<AssetPool<IW3::MapEnts>> m_map_ents;
|
||||
std::unique_ptr<AssetPool<IW3::GfxWorld>> m_gfx_world;
|
||||
std::unique_ptr<AssetPool<IW3::GfxLightDef>> m_gfx_light_def;
|
||||
std::unique_ptr<AssetPool<IW3::Font_s>> m_font;
|
||||
std::unique_ptr<AssetPool<IW3::MenuList>> m_menu_list;
|
||||
std::unique_ptr<AssetPool<IW3::menuDef_t>> m_menu_def;
|
||||
std::unique_ptr<AssetPool<IW3::LocalizeEntry>> m_localize;
|
||||
std::unique_ptr<AssetPool<IW3::WeaponDef>> m_weapon;
|
||||
std::unique_ptr<AssetPool<IW3::FxEffectDef>> m_fx;
|
||||
std::unique_ptr<AssetPool<IW3::FxImpactTable>> m_fx_impact_table;
|
||||
std::unique_ptr<AssetPool<IW3::RawFile>> m_raw_file;
|
||||
std::unique_ptr<AssetPool<IW3::StringTable>> m_string_table;
|
||||
|
||||
GameAssetPoolIW3(Zone* zone, zone_priority_t priority);
|
||||
~GameAssetPoolIW3() override = default;
|
||||
|
||||
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
|
||||
|
||||
protected:
|
||||
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
|
||||
|
||||
private:
|
||||
zone_priority_t m_priority;
|
||||
};
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "ZoneDefWriterIW3.h"
|
||||
|
||||
#include "Game/IW3/GameAssetPoolIW3.h"
|
||||
|
||||
#include <cassert>
|
||||
#include "Game/IW3/IW3.h"
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
@@ -11,17 +9,13 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
|
||||
{
|
||||
const auto* game = IGame::GetGameById(zone.m_game_id);
|
||||
const auto* pools = dynamic_cast<GameAssetPoolIW3*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
auto localizePoolAssets = zone.m_pools.PoolAssets<AssetLocalize>();
|
||||
if (localizePoolAssets.begin() != localizePoolAssets.end())
|
||||
stream.WriteEntry(*game->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
for (const auto& asset : zone.m_pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
#include "GameAssetPoolIW4.h"
|
||||
|
||||
#include "Pool/AssetPoolDynamic.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
GameAssetPoolIW4::GameAssetPoolIW4(Zone* zone, const zone_priority_t priority)
|
||||
: ZoneAssetPools(zone),
|
||||
m_priority(priority)
|
||||
{
|
||||
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
|
||||
|
||||
INIT_POOL(m_phys_preset);
|
||||
INIT_POOL(m_phys_collmap);
|
||||
INIT_POOL(m_xanim_parts);
|
||||
INIT_POOL(m_xmodel);
|
||||
INIT_POOL(m_material);
|
||||
INIT_POOL(m_material_pixel_shader);
|
||||
INIT_POOL(m_material_vertex_shader);
|
||||
INIT_POOL(m_material_vertex_decl);
|
||||
INIT_POOL(m_technique_set);
|
||||
INIT_POOL(m_image);
|
||||
INIT_POOL(m_sound);
|
||||
INIT_POOL(m_sound_curve);
|
||||
INIT_POOL(m_loaded_sound);
|
||||
INIT_POOL(m_clip_map);
|
||||
INIT_POOL(m_com_world);
|
||||
INIT_POOL(m_game_world_sp);
|
||||
INIT_POOL(m_game_world_mp);
|
||||
INIT_POOL(m_map_ents);
|
||||
INIT_POOL(m_fx_world);
|
||||
INIT_POOL(m_gfx_world);
|
||||
INIT_POOL(m_gfx_light_def);
|
||||
INIT_POOL(m_font);
|
||||
INIT_POOL(m_menu_list);
|
||||
INIT_POOL(m_menu_def);
|
||||
INIT_POOL(m_localize);
|
||||
INIT_POOL(m_weapon);
|
||||
INIT_POOL(m_fx);
|
||||
INIT_POOL(m_fx_impact_table);
|
||||
INIT_POOL(m_raw_file);
|
||||
INIT_POOL(m_string_table);
|
||||
INIT_POOL(m_leaderboard);
|
||||
INIT_POOL(m_structed_data_def_set);
|
||||
INIT_POOL(m_tracer);
|
||||
INIT_POOL(m_vehicle);
|
||||
INIT_POOL(m_addon_map_ents);
|
||||
|
||||
#undef INIT_POOL
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameAssetPoolIW4::AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
|
||||
{
|
||||
#define CASE_ADD_TO_POOL(assetType, poolName) \
|
||||
case assetType: \
|
||||
{ \
|
||||
assert(poolName); \
|
||||
return (poolName)->AddAsset(std::unique_ptr<XAssetInfo<decltype(poolName)::element_type::type>>( \
|
||||
static_cast<XAssetInfo<decltype(poolName)::element_type::type>*>(xAssetInfo.release()))); \
|
||||
}
|
||||
|
||||
switch (static_cast<XAssetType>(xAssetInfo->m_type))
|
||||
{
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_PHYSPRESET, m_phys_preset)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_PHYSCOLLMAP, m_phys_collmap)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_XMODEL, m_xmodel)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MATERIAL, m_material)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_PIXELSHADER, m_material_pixel_shader)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_VERTEXSHADER, m_material_vertex_shader)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_VERTEXDECL, m_material_vertex_decl)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_IMAGE, m_image)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SOUND, m_sound)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SOUND_CURVE, m_sound_curve)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LOADED_SOUND, m_loaded_sound)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_CLIPMAP_SP, m_clip_map)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_CLIPMAP_MP, m_clip_map)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_COMWORLD, m_com_world)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MAP_ENTS, m_map_ents)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FXWORLD, m_fx_world)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GFXWORLD, m_gfx_world)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FONT, m_font)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MENULIST, m_menu_list)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MENU, m_menu_def)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_WEAPON, m_weapon)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FX, m_fx)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_RAWFILE, m_raw_file)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_STRINGTABLE, m_string_table)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LEADERBOARD, m_leaderboard)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_STRUCTURED_DATA_DEF, m_structed_data_def_set)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_TRACER, m_tracer)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_VEHICLE, m_vehicle)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_ADDON_MAP_ENTS, m_addon_map_ents)
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
#undef CASE_ADD_TO_POOL
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameAssetPoolIW4::GetAsset(const asset_type_t type, const std::string& name) const
|
||||
{
|
||||
#define CASE_GET_ASSET(assetType, poolName) \
|
||||
case assetType: \
|
||||
{ \
|
||||
if (poolName) \
|
||||
return (poolName)->GetAsset(name); \
|
||||
break; \
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
CASE_GET_ASSET(ASSET_TYPE_PHYSPRESET, m_phys_preset)
|
||||
CASE_GET_ASSET(ASSET_TYPE_PHYSCOLLMAP, m_phys_collmap)
|
||||
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_PIXELSHADER, m_material_pixel_shader)
|
||||
CASE_GET_ASSET(ASSET_TYPE_VERTEXSHADER, m_material_vertex_shader)
|
||||
CASE_GET_ASSET(ASSET_TYPE_VERTEXDECL, m_material_vertex_decl)
|
||||
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)
|
||||
CASE_GET_ASSET(ASSET_TYPE_SOUND_CURVE, m_sound_curve)
|
||||
CASE_GET_ASSET(ASSET_TYPE_LOADED_SOUND, m_loaded_sound)
|
||||
CASE_GET_ASSET(ASSET_TYPE_CLIPMAP_SP, m_clip_map)
|
||||
CASE_GET_ASSET(ASSET_TYPE_CLIPMAP_MP, 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_FXWORLD, m_fx_world)
|
||||
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_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_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_STRUCTURED_DATA_DEF, m_structed_data_def_set)
|
||||
CASE_GET_ASSET(ASSET_TYPE_TRACER, m_tracer)
|
||||
CASE_GET_ASSET(ASSET_TYPE_VEHICLE, m_vehicle)
|
||||
CASE_GET_ASSET(ASSET_TYPE_ADDON_MAP_ENTS, m_addon_map_ents)
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
#undef CASE_GET_ASSET
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Pool/AssetPool.h"
|
||||
#include "Pool/ZoneAssetPools.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class GameAssetPoolIW4 final : public ZoneAssetPools
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<AssetPool<IW4::PhysPreset>> m_phys_preset;
|
||||
std::unique_ptr<AssetPool<IW4::PhysCollmap>> m_phys_collmap;
|
||||
std::unique_ptr<AssetPool<IW4::XAnimParts>> m_xanim_parts;
|
||||
std::unique_ptr<AssetPool<IW4::XModel>> m_xmodel;
|
||||
std::unique_ptr<AssetPool<IW4::Material>> m_material;
|
||||
std::unique_ptr<AssetPool<IW4::MaterialPixelShader>> m_material_pixel_shader;
|
||||
std::unique_ptr<AssetPool<IW4::MaterialVertexShader>> m_material_vertex_shader;
|
||||
std::unique_ptr<AssetPool<IW4::MaterialVertexDeclaration>> m_material_vertex_decl;
|
||||
std::unique_ptr<AssetPool<IW4::MaterialTechniqueSet>> m_technique_set;
|
||||
std::unique_ptr<AssetPool<IW4::GfxImage>> m_image;
|
||||
std::unique_ptr<AssetPool<IW4::snd_alias_list_t>> m_sound;
|
||||
std::unique_ptr<AssetPool<IW4::SndCurve>> m_sound_curve;
|
||||
std::unique_ptr<AssetPool<IW4::LoadedSound>> m_loaded_sound;
|
||||
std::unique_ptr<AssetPool<IW4::clipMap_t>> m_clip_map;
|
||||
std::unique_ptr<AssetPool<IW4::ComWorld>> m_com_world;
|
||||
std::unique_ptr<AssetPool<IW4::GameWorldSp>> m_game_world_sp;
|
||||
std::unique_ptr<AssetPool<IW4::GameWorldMp>> m_game_world_mp;
|
||||
std::unique_ptr<AssetPool<IW4::MapEnts>> m_map_ents;
|
||||
std::unique_ptr<AssetPool<IW4::FxWorld>> m_fx_world;
|
||||
std::unique_ptr<AssetPool<IW4::GfxWorld>> m_gfx_world;
|
||||
std::unique_ptr<AssetPool<IW4::GfxLightDef>> m_gfx_light_def;
|
||||
std::unique_ptr<AssetPool<IW4::Font_s>> m_font;
|
||||
std::unique_ptr<AssetPool<IW4::MenuList>> m_menu_list;
|
||||
std::unique_ptr<AssetPool<IW4::menuDef_t>> m_menu_def;
|
||||
std::unique_ptr<AssetPool<IW4::LocalizeEntry>> m_localize;
|
||||
std::unique_ptr<AssetPool<IW4::WeaponCompleteDef>> m_weapon;
|
||||
std::unique_ptr<AssetPool<IW4::FxEffectDef>> m_fx;
|
||||
std::unique_ptr<AssetPool<IW4::FxImpactTable>> m_fx_impact_table;
|
||||
std::unique_ptr<AssetPool<IW4::RawFile>> m_raw_file;
|
||||
std::unique_ptr<AssetPool<IW4::StringTable>> m_string_table;
|
||||
std::unique_ptr<AssetPool<IW4::LeaderboardDef>> m_leaderboard;
|
||||
std::unique_ptr<AssetPool<IW4::StructuredDataDefSet>> m_structed_data_def_set;
|
||||
std::unique_ptr<AssetPool<IW4::TracerDef>> m_tracer;
|
||||
std::unique_ptr<AssetPool<IW4::VehicleDef>> m_vehicle;
|
||||
std::unique_ptr<AssetPool<IW4::AddonMapEnts>> m_addon_map_ents;
|
||||
|
||||
GameAssetPoolIW4(Zone* zone, zone_priority_t priority);
|
||||
~GameAssetPoolIW4() override = default;
|
||||
|
||||
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
|
||||
|
||||
protected:
|
||||
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
|
||||
|
||||
private:
|
||||
zone_priority_t m_priority;
|
||||
};
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "ZoneDefWriterIW4.h"
|
||||
|
||||
#include "Game/IW4/GameAssetPoolIW4.h"
|
||||
|
||||
#include <cassert>
|
||||
#include "Game/IW4/IW4.h"
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
@@ -11,17 +9,13 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
|
||||
{
|
||||
const auto* game = IGame::GetGameById(zone.m_game_id);
|
||||
const auto* pools = dynamic_cast<GameAssetPoolIW4*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
auto localizePoolAssets = zone.m_pools.PoolAssets<AssetLocalize>();
|
||||
if (localizePoolAssets.begin() != localizePoolAssets.end())
|
||||
stream.WriteEntry(*game->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
for (const auto& asset : zone.m_pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
#include "GameAssetPoolIW5.h"
|
||||
|
||||
#include "Pool/AssetPoolDynamic.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
GameAssetPoolIW5::GameAssetPoolIW5(Zone* zone, const zone_priority_t priority)
|
||||
: ZoneAssetPools(zone),
|
||||
m_priority(priority)
|
||||
{
|
||||
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
|
||||
|
||||
INIT_POOL(m_phys_preset);
|
||||
INIT_POOL(m_phys_collmap);
|
||||
INIT_POOL(m_xanim_parts);
|
||||
INIT_POOL(m_xmodel_surfs);
|
||||
INIT_POOL(m_xmodel);
|
||||
INIT_POOL(m_material);
|
||||
INIT_POOL(m_material_pixel_shader);
|
||||
INIT_POOL(m_material_vertex_shader);
|
||||
INIT_POOL(m_material_vertex_decl);
|
||||
INIT_POOL(m_technique_set);
|
||||
INIT_POOL(m_image);
|
||||
INIT_POOL(m_sound);
|
||||
INIT_POOL(m_sound_curve);
|
||||
INIT_POOL(m_loaded_sound);
|
||||
INIT_POOL(m_clip_map);
|
||||
INIT_POOL(m_com_world);
|
||||
INIT_POOL(m_glass_world);
|
||||
INIT_POOL(m_path_data);
|
||||
INIT_POOL(m_vehicle_track);
|
||||
INIT_POOL(m_map_ents);
|
||||
INIT_POOL(m_fx_world);
|
||||
INIT_POOL(m_gfx_world);
|
||||
INIT_POOL(m_gfx_light_def);
|
||||
INIT_POOL(m_font);
|
||||
INIT_POOL(m_menu_list);
|
||||
INIT_POOL(m_menu_def);
|
||||
INIT_POOL(m_localize);
|
||||
INIT_POOL(m_attachment);
|
||||
INIT_POOL(m_weapon);
|
||||
INIT_POOL(m_fx);
|
||||
INIT_POOL(m_fx_impact_table);
|
||||
INIT_POOL(m_surface_fx_table);
|
||||
INIT_POOL(m_raw_file);
|
||||
INIT_POOL(m_script_file);
|
||||
INIT_POOL(m_string_table);
|
||||
INIT_POOL(m_leaderboard);
|
||||
INIT_POOL(m_structed_data_def_set);
|
||||
INIT_POOL(m_tracer);
|
||||
INIT_POOL(m_vehicle);
|
||||
INIT_POOL(m_addon_map_ents);
|
||||
|
||||
#undef INIT_POOL
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameAssetPoolIW5::AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
|
||||
{
|
||||
#define CASE_ADD_TO_POOL(assetType, poolName) \
|
||||
case assetType: \
|
||||
{ \
|
||||
assert(poolName); \
|
||||
return (poolName)->AddAsset(std::unique_ptr<XAssetInfo<decltype(poolName)::element_type::type>>( \
|
||||
static_cast<XAssetInfo<decltype(poolName)::element_type::type>*>(xAssetInfo.release()))); \
|
||||
}
|
||||
|
||||
switch (static_cast<XAssetType>(xAssetInfo->m_type))
|
||||
{
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_PHYSPRESET, m_phys_preset)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_PHYSCOLLMAP, m_phys_collmap)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_XMODEL_SURFS, m_xmodel_surfs)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_XMODEL, m_xmodel)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MATERIAL, m_material)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_PIXELSHADER, m_material_pixel_shader)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_VERTEXSHADER, m_material_vertex_shader)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_VERTEXDECL, m_material_vertex_decl)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_IMAGE, m_image)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SOUND, m_sound)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SOUND_CURVE, m_sound_curve)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LOADED_SOUND, m_loaded_sound)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_CLIPMAP, m_clip_map)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_COMWORLD, m_com_world)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GLASSWORLD, m_glass_world)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_PATHDATA, m_path_data)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_VEHICLE_TRACK, m_vehicle_track)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MAP_ENTS, m_map_ents)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FXWORLD, m_fx_world)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GFXWORLD, m_gfx_world)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FONT, m_font)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MENULIST, m_menu_list)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MENU, m_menu_def)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_ATTACHMENT, m_attachment)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_WEAPON, m_weapon)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FX, m_fx)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SURFACE_FX, m_surface_fx_table)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_RAWFILE, m_raw_file)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SCRIPTFILE, m_script_file)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_STRINGTABLE, m_string_table)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LEADERBOARD, m_leaderboard)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_STRUCTURED_DATA_DEF, m_structed_data_def_set)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_TRACER, m_tracer)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_VEHICLE, m_vehicle)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_ADDON_MAP_ENTS, m_addon_map_ents)
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
#undef CASE_ADD_TO_POOL
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameAssetPoolIW5::GetAsset(const asset_type_t type, const std::string& name) const
|
||||
{
|
||||
#define CASE_GET_ASSET(assetType, poolName) \
|
||||
case assetType: \
|
||||
{ \
|
||||
if (poolName) \
|
||||
return (poolName)->GetAsset(name); \
|
||||
break; \
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
CASE_GET_ASSET(ASSET_TYPE_PHYSPRESET, m_phys_preset)
|
||||
CASE_GET_ASSET(ASSET_TYPE_PHYSCOLLMAP, m_phys_collmap)
|
||||
CASE_GET_ASSET(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
|
||||
CASE_GET_ASSET(ASSET_TYPE_XMODEL_SURFS, m_xmodel_surfs)
|
||||
CASE_GET_ASSET(ASSET_TYPE_XMODEL, m_xmodel)
|
||||
CASE_GET_ASSET(ASSET_TYPE_MATERIAL, m_material)
|
||||
CASE_GET_ASSET(ASSET_TYPE_PIXELSHADER, m_material_pixel_shader)
|
||||
CASE_GET_ASSET(ASSET_TYPE_VERTEXSHADER, m_material_vertex_shader)
|
||||
CASE_GET_ASSET(ASSET_TYPE_VERTEXDECL, m_material_vertex_decl)
|
||||
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)
|
||||
CASE_GET_ASSET(ASSET_TYPE_SOUND_CURVE, m_sound_curve)
|
||||
CASE_GET_ASSET(ASSET_TYPE_LOADED_SOUND, m_loaded_sound)
|
||||
CASE_GET_ASSET(ASSET_TYPE_CLIPMAP, m_clip_map)
|
||||
CASE_GET_ASSET(ASSET_TYPE_COMWORLD, m_com_world)
|
||||
CASE_GET_ASSET(ASSET_TYPE_GLASSWORLD, m_glass_world)
|
||||
CASE_GET_ASSET(ASSET_TYPE_PATHDATA, m_path_data)
|
||||
CASE_GET_ASSET(ASSET_TYPE_VEHICLE_TRACK, m_vehicle_track)
|
||||
CASE_GET_ASSET(ASSET_TYPE_MAP_ENTS, m_map_ents)
|
||||
CASE_GET_ASSET(ASSET_TYPE_FXWORLD, m_fx_world)
|
||||
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_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_ATTACHMENT, m_attachment)
|
||||
CASE_GET_ASSET(ASSET_TYPE_WEAPON, m_weapon)
|
||||
CASE_GET_ASSET(ASSET_TYPE_FX, m_fx)
|
||||
CASE_GET_ASSET(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
|
||||
CASE_GET_ASSET(ASSET_TYPE_SURFACE_FX, m_surface_fx_table)
|
||||
CASE_GET_ASSET(ASSET_TYPE_RAWFILE, m_raw_file)
|
||||
CASE_GET_ASSET(ASSET_TYPE_SCRIPTFILE, m_script_file)
|
||||
CASE_GET_ASSET(ASSET_TYPE_STRINGTABLE, m_string_table)
|
||||
CASE_GET_ASSET(ASSET_TYPE_LEADERBOARD, m_leaderboard)
|
||||
CASE_GET_ASSET(ASSET_TYPE_STRUCTURED_DATA_DEF, m_structed_data_def_set)
|
||||
CASE_GET_ASSET(ASSET_TYPE_TRACER, m_tracer)
|
||||
CASE_GET_ASSET(ASSET_TYPE_VEHICLE, m_vehicle)
|
||||
CASE_GET_ASSET(ASSET_TYPE_ADDON_MAP_ENTS, m_addon_map_ents)
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
#undef CASE_GET_ASSET
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Pool/AssetPool.h"
|
||||
#include "Pool/ZoneAssetPools.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class GameAssetPoolIW5 final : public ZoneAssetPools
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<AssetPool<IW5::PhysPreset>> m_phys_preset;
|
||||
std::unique_ptr<AssetPool<IW5::PhysCollmap>> m_phys_collmap;
|
||||
std::unique_ptr<AssetPool<IW5::XAnimParts>> m_xanim_parts;
|
||||
std::unique_ptr<AssetPool<IW5::XModelSurfs>> m_xmodel_surfs;
|
||||
std::unique_ptr<AssetPool<IW5::XModel>> m_xmodel;
|
||||
std::unique_ptr<AssetPool<IW5::Material>> m_material;
|
||||
std::unique_ptr<AssetPool<IW5::MaterialPixelShader>> m_material_pixel_shader;
|
||||
std::unique_ptr<AssetPool<IW5::MaterialVertexShader>> m_material_vertex_shader;
|
||||
std::unique_ptr<AssetPool<IW5::MaterialVertexDeclaration>> m_material_vertex_decl;
|
||||
std::unique_ptr<AssetPool<IW5::MaterialTechniqueSet>> m_technique_set;
|
||||
std::unique_ptr<AssetPool<IW5::GfxImage>> m_image;
|
||||
std::unique_ptr<AssetPool<IW5::snd_alias_list_t>> m_sound;
|
||||
std::unique_ptr<AssetPool<IW5::SndCurve>> m_sound_curve;
|
||||
std::unique_ptr<AssetPool<IW5::LoadedSound>> m_loaded_sound;
|
||||
std::unique_ptr<AssetPool<IW5::clipMap_t>> m_clip_map;
|
||||
std::unique_ptr<AssetPool<IW5::ComWorld>> m_com_world;
|
||||
std::unique_ptr<AssetPool<IW5::GlassWorld>> m_glass_world;
|
||||
std::unique_ptr<AssetPool<IW5::PathData>> m_path_data;
|
||||
std::unique_ptr<AssetPool<IW5::VehicleTrack>> m_vehicle_track;
|
||||
std::unique_ptr<AssetPool<IW5::MapEnts>> m_map_ents;
|
||||
std::unique_ptr<AssetPool<IW5::FxWorld>> m_fx_world;
|
||||
std::unique_ptr<AssetPool<IW5::GfxWorld>> m_gfx_world;
|
||||
std::unique_ptr<AssetPool<IW5::GfxLightDef>> m_gfx_light_def;
|
||||
std::unique_ptr<AssetPool<IW5::Font_s>> m_font;
|
||||
std::unique_ptr<AssetPool<IW5::MenuList>> m_menu_list;
|
||||
std::unique_ptr<AssetPool<IW5::menuDef_t>> m_menu_def;
|
||||
std::unique_ptr<AssetPool<IW5::LocalizeEntry>> m_localize;
|
||||
std::unique_ptr<AssetPool<IW5::WeaponAttachment>> m_attachment;
|
||||
std::unique_ptr<AssetPool<IW5::WeaponCompleteDef>> m_weapon;
|
||||
std::unique_ptr<AssetPool<IW5::FxEffectDef>> m_fx;
|
||||
std::unique_ptr<AssetPool<IW5::FxImpactTable>> m_fx_impact_table;
|
||||
std::unique_ptr<AssetPool<IW5::SurfaceFxTable>> m_surface_fx_table;
|
||||
std::unique_ptr<AssetPool<IW5::RawFile>> m_raw_file;
|
||||
std::unique_ptr<AssetPool<IW5::ScriptFile>> m_script_file;
|
||||
std::unique_ptr<AssetPool<IW5::StringTable>> m_string_table;
|
||||
std::unique_ptr<AssetPool<IW5::LeaderboardDef>> m_leaderboard;
|
||||
std::unique_ptr<AssetPool<IW5::StructuredDataDefSet>> m_structed_data_def_set;
|
||||
std::unique_ptr<AssetPool<IW5::TracerDef>> m_tracer;
|
||||
std::unique_ptr<AssetPool<IW5::VehicleDef>> m_vehicle;
|
||||
std::unique_ptr<AssetPool<IW5::AddonMapEnts>> m_addon_map_ents;
|
||||
|
||||
GameAssetPoolIW5(Zone* zone, zone_priority_t priority);
|
||||
~GameAssetPoolIW5() override = default;
|
||||
|
||||
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
|
||||
|
||||
protected:
|
||||
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
|
||||
|
||||
private:
|
||||
zone_priority_t m_priority;
|
||||
};
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "ZoneDefWriterIW5.h"
|
||||
|
||||
#include "Game/IW5/GameAssetPoolIW5.h"
|
||||
|
||||
#include <cassert>
|
||||
#include "Game/IW5/AssetMarkerIW5.h"
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
@@ -11,17 +9,13 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
|
||||
{
|
||||
const auto* game = IGame::GetGameById(zone.m_game_id);
|
||||
const auto* pools = dynamic_cast<GameAssetPoolIW5*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
auto localizePoolAssets = zone.m_pools.PoolAssets<AssetLocalize>();
|
||||
if (localizePoolAssets.begin() != localizePoolAssets.end())
|
||||
stream.WriteEntry(*game->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
for (const auto& asset : zone.m_pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
#include "GameAssetPoolT5.h"
|
||||
|
||||
#include "Pool/AssetPoolDynamic.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace T5;
|
||||
|
||||
GameAssetPoolT5::GameAssetPoolT5(Zone* zone, const zone_priority_t priority)
|
||||
: ZoneAssetPools(zone),
|
||||
m_priority(priority)
|
||||
{
|
||||
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
|
||||
|
||||
INIT_POOL(m_phys_preset);
|
||||
INIT_POOL(m_phys_constraints);
|
||||
INIT_POOL(m_destructible_def);
|
||||
INIT_POOL(m_xanim_parts);
|
||||
INIT_POOL(m_xmodel);
|
||||
INIT_POOL(m_material);
|
||||
INIT_POOL(m_technique_set);
|
||||
INIT_POOL(m_image);
|
||||
INIT_POOL(m_sound_bank);
|
||||
INIT_POOL(m_sound_patch);
|
||||
INIT_POOL(m_clip_map);
|
||||
INIT_POOL(m_com_world);
|
||||
INIT_POOL(m_game_world_sp);
|
||||
INIT_POOL(m_game_world_mp);
|
||||
INIT_POOL(m_map_ents);
|
||||
INIT_POOL(m_gfx_world);
|
||||
INIT_POOL(m_gfx_light_def);
|
||||
INIT_POOL(m_font);
|
||||
INIT_POOL(m_menu_list);
|
||||
INIT_POOL(m_menu_def);
|
||||
INIT_POOL(m_localize);
|
||||
INIT_POOL(m_weapon);
|
||||
INIT_POOL(m_snd_driver_globals);
|
||||
INIT_POOL(m_fx);
|
||||
INIT_POOL(m_fx_impact_table);
|
||||
INIT_POOL(m_raw_file);
|
||||
INIT_POOL(m_string_table);
|
||||
INIT_POOL(m_pack_index);
|
||||
INIT_POOL(m_xglobals);
|
||||
INIT_POOL(m_ddl);
|
||||
INIT_POOL(m_glasses);
|
||||
INIT_POOL(m_emblem_set);
|
||||
|
||||
#undef INIT_POOL
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameAssetPoolT5::AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
|
||||
{
|
||||
#define CASE_ADD_TO_POOL(assetType, poolName) \
|
||||
case assetType: \
|
||||
{ \
|
||||
assert(poolName); \
|
||||
return (poolName)->AddAsset(std::unique_ptr<XAssetInfo<decltype(poolName)::element_type::type>>( \
|
||||
static_cast<XAssetInfo<decltype(poolName)::element_type::type>*>(xAssetInfo.release()))); \
|
||||
}
|
||||
|
||||
switch (static_cast<XAssetType>(xAssetInfo->m_type))
|
||||
{
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_PHYSPRESET, m_phys_preset)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_DESTRUCTIBLEDEF, m_destructible_def)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_XMODEL, m_xmodel)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MATERIAL, m_material)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_IMAGE, m_image)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SOUND, m_sound_bank)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SOUND_PATCH, m_sound_patch)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_CLIPMAP, m_clip_map)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_CLIPMAP_PVS, m_clip_map)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_COMWORLD, m_com_world)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MAP_ENTS, m_map_ents)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GFXWORLD, m_gfx_world)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FONT, m_font)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MENULIST, m_menu_list)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MENU, m_menu_def)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_WEAPON, m_weapon)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SNDDRIVER_GLOBALS, m_snd_driver_globals)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FX, m_fx)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_RAWFILE, m_raw_file)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_STRINGTABLE, m_string_table)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_PACK_INDEX, m_pack_index)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_XGLOBALS, m_xglobals)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_DDL, m_ddl)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GLASSES, m_glasses)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_EMBLEMSET, m_emblem_set)
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
#undef CASE_ADD_TO_POOL
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameAssetPoolT5::GetAsset(const asset_type_t type, const std::string& name) const
|
||||
{
|
||||
#define CASE_GET_ASSET(assetType, poolName) \
|
||||
case assetType: \
|
||||
{ \
|
||||
if (poolName) \
|
||||
return (poolName)->GetAsset(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_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_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_PACK_INDEX, m_pack_index)
|
||||
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)
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
#undef CASE_GET_ASSET
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/T5/T5.h"
|
||||
#include "Pool/AssetPool.h"
|
||||
#include "Pool/ZoneAssetPools.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class GameAssetPoolT5 final : public ZoneAssetPools
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<AssetPool<T5::PhysPreset>> m_phys_preset;
|
||||
std::unique_ptr<AssetPool<T5::PhysConstraints>> m_phys_constraints;
|
||||
std::unique_ptr<AssetPool<T5::DestructibleDef>> m_destructible_def;
|
||||
std::unique_ptr<AssetPool<T5::XAnimParts>> m_xanim_parts;
|
||||
std::unique_ptr<AssetPool<T5::XModel>> m_xmodel;
|
||||
std::unique_ptr<AssetPool<T5::Material>> m_material;
|
||||
std::unique_ptr<AssetPool<T5::MaterialTechniqueSet>> m_technique_set;
|
||||
std::unique_ptr<AssetPool<T5::GfxImage>> m_image;
|
||||
std::unique_ptr<AssetPool<T5::SndBank>> m_sound_bank;
|
||||
std::unique_ptr<AssetPool<T5::SndPatch>> m_sound_patch;
|
||||
std::unique_ptr<AssetPool<T5::clipMap_t>> m_clip_map;
|
||||
std::unique_ptr<AssetPool<T5::ComWorld>> m_com_world;
|
||||
std::unique_ptr<AssetPool<T5::GameWorldSp>> m_game_world_sp;
|
||||
std::unique_ptr<AssetPool<T5::GameWorldMp>> m_game_world_mp;
|
||||
std::unique_ptr<AssetPool<T5::MapEnts>> m_map_ents;
|
||||
std::unique_ptr<AssetPool<T5::GfxWorld>> m_gfx_world;
|
||||
std::unique_ptr<AssetPool<T5::GfxLightDef>> m_gfx_light_def;
|
||||
std::unique_ptr<AssetPool<T5::Font_s>> m_font;
|
||||
std::unique_ptr<AssetPool<T5::MenuList>> m_menu_list;
|
||||
std::unique_ptr<AssetPool<T5::menuDef_t>> m_menu_def;
|
||||
std::unique_ptr<AssetPool<T5::LocalizeEntry>> m_localize;
|
||||
std::unique_ptr<AssetPool<T5::WeaponVariantDef>> m_weapon;
|
||||
std::unique_ptr<AssetPool<T5::SndDriverGlobals>> m_snd_driver_globals;
|
||||
std::unique_ptr<AssetPool<T5::FxEffectDef>> m_fx;
|
||||
std::unique_ptr<AssetPool<T5::FxImpactTable>> m_fx_impact_table;
|
||||
std::unique_ptr<AssetPool<T5::RawFile>> m_raw_file;
|
||||
std::unique_ptr<AssetPool<T5::StringTable>> m_string_table;
|
||||
std::unique_ptr<AssetPool<T5::PackIndex>> m_pack_index;
|
||||
std::unique_ptr<AssetPool<T5::XGlobals>> m_xglobals;
|
||||
std::unique_ptr<AssetPool<T5::ddlRoot_t>> m_ddl;
|
||||
std::unique_ptr<AssetPool<T5::Glasses>> m_glasses;
|
||||
std::unique_ptr<AssetPool<T5::EmblemSet>> m_emblem_set;
|
||||
|
||||
GameAssetPoolT5(Zone* zone, zone_priority_t priority);
|
||||
~GameAssetPoolT5() override = default;
|
||||
|
||||
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
|
||||
|
||||
protected:
|
||||
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
|
||||
|
||||
private:
|
||||
zone_priority_t m_priority;
|
||||
};
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "ZoneDefWriterT5.h"
|
||||
|
||||
#include "Game/T5/GameAssetPoolT5.h"
|
||||
|
||||
#include <cassert>
|
||||
#include "Game/T5/AssetMarkerT5.h"
|
||||
|
||||
using namespace T5;
|
||||
|
||||
@@ -11,17 +9,13 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
|
||||
{
|
||||
const auto* game = IGame::GetGameById(zone.m_game_id);
|
||||
const auto* pools = dynamic_cast<GameAssetPoolT5*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
auto localizePoolAssets = zone.m_pools.PoolAssets<AssetLocalize>();
|
||||
if (localizePoolAssets.begin() != localizePoolAssets.end())
|
||||
stream.WriteEntry(*game->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
for (const auto& asset : zone.m_pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
|
||||
@@ -1,209 +0,0 @@
|
||||
#include "GameAssetPoolT6.h"
|
||||
|
||||
#include "Pool/AssetPoolDynamic.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
GameAssetPoolT6::GameAssetPoolT6(Zone* zone, const zone_priority_t priority)
|
||||
: ZoneAssetPools(zone),
|
||||
m_priority(priority)
|
||||
{
|
||||
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
|
||||
|
||||
INIT_POOL(m_phys_preset);
|
||||
INIT_POOL(m_phys_constraints);
|
||||
INIT_POOL(m_destructible_def);
|
||||
INIT_POOL(m_xanim_parts);
|
||||
INIT_POOL(m_xmodel);
|
||||
INIT_POOL(m_material);
|
||||
INIT_POOL(m_technique_set);
|
||||
INIT_POOL(m_image);
|
||||
INIT_POOL(m_sound_bank);
|
||||
INIT_POOL(m_sound_patch);
|
||||
INIT_POOL(m_clip_map);
|
||||
INIT_POOL(m_com_world);
|
||||
INIT_POOL(m_game_world_sp);
|
||||
INIT_POOL(m_game_world_mp);
|
||||
INIT_POOL(m_map_ents);
|
||||
INIT_POOL(m_gfx_world);
|
||||
INIT_POOL(m_gfx_light_def);
|
||||
INIT_POOL(m_font);
|
||||
INIT_POOL(m_font_icon);
|
||||
INIT_POOL(m_menu_list);
|
||||
INIT_POOL(m_menu_def);
|
||||
INIT_POOL(m_localize);
|
||||
INIT_POOL(m_weapon);
|
||||
INIT_POOL(m_attachment);
|
||||
INIT_POOL(m_attachment_unique);
|
||||
INIT_POOL(m_camo);
|
||||
INIT_POOL(m_snd_driver_globals);
|
||||
INIT_POOL(m_fx);
|
||||
INIT_POOL(m_fx_impact_table);
|
||||
INIT_POOL(m_raw_file);
|
||||
INIT_POOL(m_string_table);
|
||||
INIT_POOL(m_leaderboard);
|
||||
INIT_POOL(m_xglobals);
|
||||
INIT_POOL(m_ddl);
|
||||
INIT_POOL(m_glasses);
|
||||
INIT_POOL(m_emblem_set);
|
||||
INIT_POOL(m_script);
|
||||
INIT_POOL(m_key_value_pairs);
|
||||
INIT_POOL(m_vehicle);
|
||||
INIT_POOL(m_memory_block);
|
||||
INIT_POOL(m_addon_map_ents);
|
||||
INIT_POOL(m_tracer);
|
||||
INIT_POOL(m_skinned_verts);
|
||||
INIT_POOL(m_qdb);
|
||||
INIT_POOL(m_slug);
|
||||
INIT_POOL(m_footstep_table);
|
||||
INIT_POOL(m_footstep_fx_table);
|
||||
INIT_POOL(m_zbarrier);
|
||||
|
||||
#undef INIT_POOL
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameAssetPoolT6::AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
|
||||
{
|
||||
#define CASE_ADD_TO_POOL(assetType, poolName) \
|
||||
case assetType: \
|
||||
{ \
|
||||
assert(poolName); \
|
||||
return (poolName)->AddAsset(std::unique_ptr<XAssetInfo<decltype(poolName)::element_type::type>>( \
|
||||
static_cast<XAssetInfo<decltype(poolName)::element_type::type>*>(xAssetInfo.release()))); \
|
||||
}
|
||||
|
||||
switch (static_cast<XAssetType>(xAssetInfo->m_type))
|
||||
{
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_PHYSPRESET, m_phys_preset)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_DESTRUCTIBLEDEF, m_destructible_def)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_XMODEL, m_xmodel)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MATERIAL, m_material)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_IMAGE, m_image)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SOUND, m_sound_bank)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SOUND_PATCH, m_sound_patch)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_CLIPMAP, m_clip_map)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_CLIPMAP_PVS, m_clip_map)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_COMWORLD, m_com_world)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MAP_ENTS, m_map_ents)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GFXWORLD, m_gfx_world)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FONT, m_font)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FONTICON, m_font_icon)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MENULIST, m_menu_list)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MENU, m_menu_def)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_WEAPON, m_weapon)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_ATTACHMENT, m_attachment)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_ATTACHMENT_UNIQUE, m_attachment_unique)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_WEAPON_CAMO, m_camo)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SNDDRIVER_GLOBALS, m_snd_driver_globals)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FX, m_fx)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_RAWFILE, m_raw_file)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_STRINGTABLE, m_string_table)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_LEADERBOARD, m_leaderboard)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_XGLOBALS, m_xglobals)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_DDL, m_ddl)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_GLASSES, m_glasses)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_EMBLEMSET, m_emblem_set)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SCRIPTPARSETREE, m_script)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_KEYVALUEPAIRS, m_key_value_pairs)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_VEHICLEDEF, m_vehicle)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_MEMORYBLOCK, m_memory_block)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_ADDON_MAP_ENTS, m_addon_map_ents)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_TRACER, m_tracer)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SKINNEDVERTS, m_skinned_verts)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_QDB, m_qdb)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_SLUG, m_slug)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FOOTSTEP_TABLE, m_footstep_table)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_FOOTSTEPFX_TABLE, m_footstep_fx_table)
|
||||
CASE_ADD_TO_POOL(ASSET_TYPE_ZBARRIER, m_zbarrier)
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
#undef CASE_ADD_TO_POOL
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameAssetPoolT6::GetAsset(const asset_type_t type, const std::string& name) const
|
||||
{
|
||||
#define CASE_GET_ASSET(assetType, poolName) \
|
||||
case assetType: \
|
||||
{ \
|
||||
if (poolName) \
|
||||
return (poolName)->GetAsset(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
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Pool/AssetPool.h"
|
||||
#include "Pool/ZoneAssetPools.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class GameAssetPoolT6 final : public ZoneAssetPools
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<AssetPool<T6::PhysPreset>> m_phys_preset;
|
||||
std::unique_ptr<AssetPool<T6::PhysConstraints>> m_phys_constraints;
|
||||
std::unique_ptr<AssetPool<T6::DestructibleDef>> m_destructible_def;
|
||||
std::unique_ptr<AssetPool<T6::XAnimParts>> m_xanim_parts;
|
||||
std::unique_ptr<AssetPool<T6::XModel>> m_xmodel;
|
||||
std::unique_ptr<AssetPool<T6::Material>> m_material;
|
||||
std::unique_ptr<AssetPool<T6::MaterialTechniqueSet>> m_technique_set;
|
||||
std::unique_ptr<AssetPool<T6::GfxImage>> m_image;
|
||||
std::unique_ptr<AssetPool<T6::SndBank>> m_sound_bank;
|
||||
std::unique_ptr<AssetPool<T6::SndPatch>> m_sound_patch;
|
||||
std::unique_ptr<AssetPool<T6::clipMap_t>> m_clip_map;
|
||||
std::unique_ptr<AssetPool<T6::ComWorld>> m_com_world;
|
||||
std::unique_ptr<AssetPool<T6::GameWorldSp>> m_game_world_sp;
|
||||
std::unique_ptr<AssetPool<T6::GameWorldMp>> m_game_world_mp;
|
||||
std::unique_ptr<AssetPool<T6::MapEnts>> m_map_ents;
|
||||
std::unique_ptr<AssetPool<T6::GfxWorld>> m_gfx_world;
|
||||
std::unique_ptr<AssetPool<T6::GfxLightDef>> m_gfx_light_def;
|
||||
std::unique_ptr<AssetPool<T6::Font_s>> m_font;
|
||||
std::unique_ptr<AssetPool<T6::FontIcon>> m_font_icon;
|
||||
std::unique_ptr<AssetPool<T6::MenuList>> m_menu_list;
|
||||
std::unique_ptr<AssetPool<T6::menuDef_t>> m_menu_def;
|
||||
std::unique_ptr<AssetPool<T6::LocalizeEntry>> m_localize;
|
||||
std::unique_ptr<AssetPool<T6::WeaponVariantDef>> m_weapon;
|
||||
std::unique_ptr<AssetPool<T6::WeaponAttachment>> m_attachment;
|
||||
std::unique_ptr<AssetPool<T6::WeaponAttachmentUnique>> m_attachment_unique;
|
||||
std::unique_ptr<AssetPool<T6::WeaponCamo>> m_camo;
|
||||
std::unique_ptr<AssetPool<T6::SndDriverGlobals>> m_snd_driver_globals;
|
||||
std::unique_ptr<AssetPool<T6::FxEffectDef>> m_fx;
|
||||
std::unique_ptr<AssetPool<T6::FxImpactTable>> m_fx_impact_table;
|
||||
std::unique_ptr<AssetPool<T6::RawFile>> m_raw_file;
|
||||
std::unique_ptr<AssetPool<T6::StringTable>> m_string_table;
|
||||
std::unique_ptr<AssetPool<T6::LeaderboardDef>> m_leaderboard;
|
||||
std::unique_ptr<AssetPool<T6::XGlobals>> m_xglobals;
|
||||
std::unique_ptr<AssetPool<T6::ddlRoot_t>> m_ddl;
|
||||
std::unique_ptr<AssetPool<T6::Glasses>> m_glasses;
|
||||
std::unique_ptr<AssetPool<T6::EmblemSet>> m_emblem_set;
|
||||
std::unique_ptr<AssetPool<T6::ScriptParseTree>> m_script;
|
||||
std::unique_ptr<AssetPool<T6::KeyValuePairs>> m_key_value_pairs;
|
||||
std::unique_ptr<AssetPool<T6::VehicleDef>> m_vehicle;
|
||||
std::unique_ptr<AssetPool<T6::MemoryBlock>> m_memory_block;
|
||||
std::unique_ptr<AssetPool<T6::AddonMapEnts>> m_addon_map_ents;
|
||||
std::unique_ptr<AssetPool<T6::TracerDef>> m_tracer;
|
||||
std::unique_ptr<AssetPool<T6::SkinnedVertsDef>> m_skinned_verts;
|
||||
std::unique_ptr<AssetPool<T6::Qdb>> m_qdb;
|
||||
std::unique_ptr<AssetPool<T6::Slug>> m_slug;
|
||||
std::unique_ptr<AssetPool<T6::FootstepTableDef>> m_footstep_table;
|
||||
std::unique_ptr<AssetPool<T6::FootstepFXTableDef>> m_footstep_fx_table;
|
||||
std::unique_ptr<AssetPool<T6::ZBarrierDef>> m_zbarrier;
|
||||
|
||||
GameAssetPoolT6(Zone* zone, zone_priority_t priority);
|
||||
~GameAssetPoolT6() override = default;
|
||||
|
||||
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
|
||||
|
||||
protected:
|
||||
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
|
||||
|
||||
private:
|
||||
zone_priority_t m_priority;
|
||||
};
|
||||
@@ -1,9 +1,7 @@
|
||||
#include "ZoneDefWriterT6.h"
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/GameAssetPoolT6.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
@@ -15,12 +13,12 @@ namespace
|
||||
{
|
||||
public:
|
||||
std::string m_key;
|
||||
int m_hash;
|
||||
unsigned m_hash;
|
||||
|
||||
explicit KeyValuePairKnownKey(std::string key)
|
||||
{
|
||||
m_key = std::move(key);
|
||||
m_hash = Common::Com_HashKey(m_key.c_str(), 64);
|
||||
m_hash = static_cast<unsigned>(Common::Com_HashKey(m_key.c_str(), 64));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -31,7 +29,7 @@ namespace
|
||||
KeyValuePairKnownKey("initial_materials"),
|
||||
};
|
||||
|
||||
void WriteKeyValuePair(ZoneDefinitionOutputStream& stream, const KeyValuePair& kvp)
|
||||
void WriteKeyValuePair(const ZoneDefinitionOutputStream& stream, const KeyValuePair& kvp)
|
||||
{
|
||||
for (const auto& knownKey : KEY_VALUE_PAIR_KNOWN_KEYS)
|
||||
{
|
||||
@@ -50,10 +48,10 @@ namespace
|
||||
|
||||
void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone& zone) const
|
||||
{
|
||||
const auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(zone.m_pools.get());
|
||||
if (assetPoolT6 && !assetPoolT6->m_key_value_pairs->m_asset_lookup.empty())
|
||||
auto kvpPoolAssets = zone.m_pools.PoolAssets<AssetKeyValuePairs>();
|
||||
if (kvpPoolAssets.begin() != kvpPoolAssets.end())
|
||||
{
|
||||
for (const auto* kvpAsset : *assetPoolT6->m_key_value_pairs)
|
||||
for (const auto* kvpAsset : kvpPoolAssets)
|
||||
{
|
||||
const auto* keyValuePairs = kvpAsset->Asset();
|
||||
for (auto varIndex = 0u; varIndex < keyValuePairs->numVariables; varIndex++)
|
||||
@@ -67,17 +65,13 @@ void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
|
||||
{
|
||||
const auto* game = IGame::GetGameById(zone.m_game_id);
|
||||
const auto* pools = dynamic_cast<GameAssetPoolT6*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
auto localizePoolAssets = zone.m_pools.PoolAssets<AssetLocalize>();
|
||||
if (localizePoolAssets.begin() != localizePoolAssets.end())
|
||||
stream.WriteEntry(*game->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
for (const auto& asset : zone.m_pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
|
||||
@@ -11,13 +11,11 @@ class BaseAssetMarker
|
||||
protected:
|
||||
explicit BaseAssetMarker(AssetVisitor& visitor);
|
||||
|
||||
template<typename AssetType> void Mark_Dependency(std::add_lvalue_reference_t<std::add_pointer_t<typename AssetType::Type>> asset)
|
||||
template<AssetDefinition Asset_t> void Mark_Dependency(std::add_lvalue_reference_t<std::add_pointer_t<typename Asset_t::Type>> asset)
|
||||
{
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
const auto result = m_visitor.Visit_Dependency(AssetType::EnumEntry, AssetName<AssetType>(*asset));
|
||||
const auto result = m_visitor.Visit_Dependency(Asset_t::EnumEntry, AssetName<Asset_t>(*asset));
|
||||
if (result.has_value())
|
||||
asset = static_cast<std::add_pointer_t<typename AssetType::Type>>((*result)->m_ptr);
|
||||
asset = static_cast<std::add_pointer_t<typename Asset_t::Type>>((*result)->m_ptr);
|
||||
}
|
||||
|
||||
void Mark_ScriptString(scr_string_t& scriptString) const;
|
||||
@@ -29,9 +27,8 @@ protected:
|
||||
AssetVisitor& m_visitor;
|
||||
};
|
||||
|
||||
template<typename AssetType> struct AssetMarkerWrapper
|
||||
template<AssetDefinition> struct AssetMarkerWrapper
|
||||
{
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
// using WrapperClass = WrapperClass;
|
||||
};
|
||||
|
||||
@@ -40,6 +37,5 @@ template<typename AssetType> using AssetMarker = AssetMarkerWrapper<AssetType>::
|
||||
#define DEFINE_MARKER_CLASS_FOR_ASSET(asset, markerClass) \
|
||||
template<> struct AssetMarkerWrapper<asset> \
|
||||
{ \
|
||||
static_assert(std::is_base_of_v<IAssetBase, asset>); \
|
||||
using WrapperClass = markerClass; \
|
||||
};
|
||||
|
||||
193
src/ZoneCommon/Pool/AssetPool.cpp
Normal file
193
src/ZoneCommon/Pool/AssetPool.cpp
Normal file
@@ -0,0 +1,193 @@
|
||||
#include "AssetPool.h"
|
||||
|
||||
#include "GlobalAssetPool.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <format>
|
||||
|
||||
AssetPool::Iterator::Iterator(std::unordered_map<std::string, XAssetInfoGeneric*>::iterator i)
|
||||
: m_iterator(std::move(i))
|
||||
{
|
||||
}
|
||||
|
||||
bool AssetPool::Iterator::operator!=(const Iterator& rhs) const
|
||||
{
|
||||
return m_iterator != rhs.m_iterator;
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetPool::Iterator::operator*() const
|
||||
{
|
||||
return m_iterator.operator*().second;
|
||||
}
|
||||
|
||||
void AssetPool::Iterator::operator++()
|
||||
{
|
||||
++m_iterator;
|
||||
}
|
||||
|
||||
AssetPool::CIterator::CIterator(std::unordered_map<std::string, XAssetInfoGeneric*>::const_iterator i)
|
||||
: m_iterator(std::move(i))
|
||||
{
|
||||
}
|
||||
|
||||
bool AssetPool::CIterator::operator!=(const CIterator& rhs) const
|
||||
{
|
||||
return m_iterator != rhs.m_iterator;
|
||||
}
|
||||
|
||||
const XAssetInfoGeneric* AssetPool::CIterator::operator*() const
|
||||
{
|
||||
return m_iterator.operator*().second;
|
||||
}
|
||||
|
||||
void AssetPool::CIterator::operator++()
|
||||
{
|
||||
++m_iterator;
|
||||
}
|
||||
|
||||
//
|
||||
// AssetPool
|
||||
//
|
||||
|
||||
XAssetInfoGeneric* AssetPool::AddAsset(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
|
||||
{
|
||||
const auto normalizedName = XAssetInfoGeneric::NormalizeAssetName(xAssetInfo->m_name);
|
||||
|
||||
auto* pAssetInfo = xAssetInfo.get();
|
||||
m_asset_lookup[normalizedName] = pAssetInfo;
|
||||
m_assets.emplace_back(std::move(xAssetInfo));
|
||||
|
||||
return pAssetInfo;
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetPool::GetAsset(const std::string& name)
|
||||
{
|
||||
const auto normalizedName = XAssetInfoGeneric::NormalizeAssetName(name);
|
||||
|
||||
const auto foundAsset = m_asset_lookup.find(normalizedName);
|
||||
if (foundAsset == m_asset_lookup.end())
|
||||
return nullptr;
|
||||
|
||||
return foundAsset->second;
|
||||
}
|
||||
|
||||
size_t AssetPool::size() const
|
||||
{
|
||||
return m_asset_lookup.size();
|
||||
}
|
||||
|
||||
bool AssetPool::empty() const
|
||||
{
|
||||
return m_asset_lookup.empty();
|
||||
}
|
||||
|
||||
AssetPool::Iterator AssetPool::begin()
|
||||
{
|
||||
return Iterator(m_asset_lookup.begin());
|
||||
}
|
||||
|
||||
AssetPool::Iterator AssetPool::end()
|
||||
{
|
||||
return Iterator(m_asset_lookup.end());
|
||||
}
|
||||
|
||||
AssetPool::CIterator AssetPool::begin() const
|
||||
{
|
||||
return CIterator(m_asset_lookup.cbegin());
|
||||
}
|
||||
|
||||
AssetPool::CIterator AssetPool::end() const
|
||||
{
|
||||
return CIterator(m_asset_lookup.cend());
|
||||
}
|
||||
|
||||
//
|
||||
// ZoneAssetPools
|
||||
//
|
||||
|
||||
ZoneAssetPools::ZoneAssetPools(Zone& zone, const zone_priority_t priority)
|
||||
: m_zone(zone)
|
||||
{
|
||||
const auto assetTypeCount = IGame::GetGameById(zone.m_game_id)->GetAssetTypeCount();
|
||||
const auto* gameGlobalAssetPools = GameGlobalAssetPools::GetGlobalPoolsForGame(zone.m_game_id);
|
||||
|
||||
m_asset_pools.resize(assetTypeCount);
|
||||
for (asset_type_t assetType = 0; assetType < assetTypeCount; assetType++)
|
||||
{
|
||||
m_asset_pools[assetType] = std::make_unique<AssetPool>();
|
||||
gameGlobalAssetPools->LinkAssetPool(assetType, m_asset_pools[assetType].get(), priority);
|
||||
}
|
||||
}
|
||||
|
||||
ZoneAssetPools::~ZoneAssetPools()
|
||||
{
|
||||
const auto assetTypeCount = IGame::GetGameById(m_zone.m_game_id)->GetAssetTypeCount();
|
||||
const auto* gameGlobalAssetPools = GameGlobalAssetPools::GetGlobalPoolsForGame(m_zone.m_game_id);
|
||||
|
||||
assert(assetTypeCount == m_asset_pools.size());
|
||||
for (asset_type_t assetType = 0; assetType < assetTypeCount; assetType++)
|
||||
{
|
||||
assert(m_asset_pools[assetType]);
|
||||
gameGlobalAssetPools->UnlinkAssetPool(assetType, m_asset_pools[assetType].get());
|
||||
}
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* ZoneAssetPools::AddAsset(const asset_type_t type,
|
||||
std::string name,
|
||||
void* asset,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> usedScriptStrings,
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences)
|
||||
{
|
||||
return AddAsset(std::make_unique<XAssetInfoGeneric>(
|
||||
type, std::move(name), asset, std::move(dependencies), std::move(usedScriptStrings), std::move(indirectAssetReferences), &m_zone));
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* ZoneAssetPools::AddAsset(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
|
||||
{
|
||||
const auto type = xAssetInfo->m_type;
|
||||
assert(m_asset_pools.size() > type);
|
||||
|
||||
auto* assetInfo = m_asset_pools[type]->AddAsset(std::move(xAssetInfo));
|
||||
|
||||
const auto normalizedName = XAssetInfoGeneric::NormalizeAssetName(assetInfo->m_name);
|
||||
GameGlobalAssetPools::GetGlobalPoolsForGame(m_zone.m_game_id)->LinkAsset(type, m_asset_pools[type].get(), normalizedName, assetInfo);
|
||||
|
||||
assert(assetInfo);
|
||||
m_assets_in_order.emplace_back(assetInfo);
|
||||
|
||||
return assetInfo;
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* ZoneAssetPools::GetAsset(const asset_type_t type, const std::string& name) const
|
||||
{
|
||||
assert(m_asset_pools.size() > type);
|
||||
|
||||
return m_asset_pools[type]->GetAsset(name);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
ZoneAssetPools::all_iterator ZoneAssetPools::begin() const
|
||||
{
|
||||
return m_assets_in_order.begin();
|
||||
}
|
||||
|
||||
ZoneAssetPools::all_iterator ZoneAssetPools::end() const
|
||||
{
|
||||
return m_assets_in_order.end();
|
||||
}
|
||||
@@ -1,109 +1,183 @@
|
||||
#pragma once
|
||||
|
||||
#include "XAssetInfo.h"
|
||||
#include "Zone/Zone.h"
|
||||
#include "Game/IAsset.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class Zone;
|
||||
template<typename T> class XAssetInfo;
|
||||
class XAssetInfoGeneric;
|
||||
class IndirectAssetReference;
|
||||
|
||||
template<typename T> class AssetPool
|
||||
class AssetPool
|
||||
{
|
||||
public:
|
||||
using type = T;
|
||||
|
||||
std::map<std::string, XAssetInfo<T>*> m_asset_lookup;
|
||||
|
||||
class Iterator
|
||||
{
|
||||
typename std::map<std::string, XAssetInfo<T>*>::iterator m_iterator;
|
||||
|
||||
public:
|
||||
explicit Iterator(typename std::map<std::string, XAssetInfo<T>*>::iterator i)
|
||||
{
|
||||
m_iterator = i;
|
||||
}
|
||||
explicit Iterator(std::unordered_map<std::string, XAssetInfoGeneric*>::iterator i);
|
||||
|
||||
bool operator!=(Iterator rhs)
|
||||
{
|
||||
return m_iterator != rhs.m_iterator;
|
||||
}
|
||||
bool operator!=(const Iterator& rhs) const;
|
||||
XAssetInfoGeneric* operator*() const;
|
||||
void operator++();
|
||||
|
||||
XAssetInfo<T>* operator*()
|
||||
{
|
||||
return m_iterator.operator*().second;
|
||||
}
|
||||
|
||||
void operator++()
|
||||
{
|
||||
++m_iterator;
|
||||
}
|
||||
private:
|
||||
std::unordered_map<std::string, XAssetInfoGeneric*>::iterator m_iterator;
|
||||
};
|
||||
|
||||
class CIterator
|
||||
{
|
||||
typename std::map<std::string, XAssetInfo<T>*>::const_iterator m_iterator;
|
||||
|
||||
public:
|
||||
explicit CIterator(typename std::map<std::string, XAssetInfo<T>*>::const_iterator i)
|
||||
{
|
||||
m_iterator = i;
|
||||
}
|
||||
explicit CIterator(std::unordered_map<std::string, XAssetInfoGeneric*>::const_iterator i);
|
||||
|
||||
bool operator!=(CIterator rhs)
|
||||
{
|
||||
return m_iterator != rhs.m_iterator;
|
||||
}
|
||||
bool operator!=(const CIterator& rhs) const;
|
||||
const XAssetInfoGeneric* operator*() const;
|
||||
void operator++();
|
||||
|
||||
const XAssetInfo<T>* operator*()
|
||||
{
|
||||
return m_iterator.operator*().second;
|
||||
}
|
||||
|
||||
void operator++()
|
||||
{
|
||||
++m_iterator;
|
||||
}
|
||||
private:
|
||||
std::unordered_map<std::string, XAssetInfoGeneric*>::const_iterator m_iterator;
|
||||
};
|
||||
|
||||
AssetPool()
|
||||
{
|
||||
m_asset_lookup = std::map<std::string, XAssetInfo<T>*>();
|
||||
}
|
||||
AssetPool() = default;
|
||||
~AssetPool() = default;
|
||||
|
||||
virtual ~AssetPool() = default;
|
||||
AssetPool(AssetPool&) = delete;
|
||||
AssetPool(AssetPool&&) = delete;
|
||||
AssetPool& operator=(AssetPool&) = delete;
|
||||
AssetPool& operator=(AssetPool&&) = delete;
|
||||
|
||||
virtual XAssetInfo<T>* AddAsset(std::unique_ptr<XAssetInfo<T>> xAssetInfo) = 0;
|
||||
XAssetInfoGeneric* AddAsset(std::unique_ptr<XAssetInfoGeneric> xAssetInfo);
|
||||
XAssetInfoGeneric* GetAsset(const std::string& name);
|
||||
|
||||
XAssetInfo<T>* GetAsset(const std::string& name)
|
||||
{
|
||||
const auto normalizedName = XAssetInfo<T>::NormalizeAssetName(name);
|
||||
auto foundAsset = m_asset_lookup.find(normalizedName);
|
||||
[[nodiscard]] size_t size() const;
|
||||
[[nodiscard]] bool empty() const;
|
||||
|
||||
if (foundAsset == m_asset_lookup.end())
|
||||
return nullptr;
|
||||
[[nodiscard]] Iterator begin();
|
||||
[[nodiscard]] Iterator end();
|
||||
|
||||
return foundAsset->second;
|
||||
}
|
||||
[[nodiscard]] CIterator begin() const;
|
||||
[[nodiscard]] CIterator end() const;
|
||||
|
||||
Iterator begin()
|
||||
{
|
||||
return Iterator(m_asset_lookup.begin());
|
||||
}
|
||||
|
||||
Iterator end()
|
||||
{
|
||||
return Iterator(m_asset_lookup.end());
|
||||
}
|
||||
|
||||
CIterator begin() const
|
||||
{
|
||||
return CIterator(m_asset_lookup.cbegin());
|
||||
}
|
||||
|
||||
CIterator end() const
|
||||
{
|
||||
return CIterator(m_asset_lookup.cend());
|
||||
}
|
||||
private:
|
||||
std::unordered_map<std::string, XAssetInfoGeneric*> m_asset_lookup;
|
||||
std::vector<std::unique_ptr<XAssetInfoGeneric>> m_assets;
|
||||
};
|
||||
|
||||
template<AssetDefinition Asset_t> class AssetPoolIterator
|
||||
{
|
||||
public:
|
||||
explicit AssetPoolIterator(AssetPool::Iterator i)
|
||||
: m_iterator(std::move(i))
|
||||
{
|
||||
}
|
||||
|
||||
bool operator!=(const AssetPoolIterator& rhs) const
|
||||
{
|
||||
return m_iterator != rhs.m_iterator;
|
||||
}
|
||||
|
||||
XAssetInfo<typename Asset_t::Type>* operator*() const
|
||||
{
|
||||
return reinterpret_cast<XAssetInfo<typename Asset_t::Type>*>(*m_iterator);
|
||||
}
|
||||
|
||||
void operator++()
|
||||
{
|
||||
++m_iterator;
|
||||
}
|
||||
|
||||
private:
|
||||
AssetPool::Iterator m_iterator;
|
||||
};
|
||||
|
||||
template<AssetDefinition Asset_t> class AssetPoolIterators
|
||||
{
|
||||
public:
|
||||
explicit AssetPoolIterators(AssetPool& assetPool)
|
||||
: m_asset_pool(assetPool)
|
||||
{
|
||||
}
|
||||
|
||||
AssetPoolIterator<Asset_t> begin()
|
||||
{
|
||||
return AssetPoolIterator<Asset_t>(m_asset_pool.begin());
|
||||
}
|
||||
|
||||
AssetPoolIterator<Asset_t> end()
|
||||
{
|
||||
return AssetPoolIterator<Asset_t>(m_asset_pool.end());
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t size() const
|
||||
{
|
||||
return m_asset_pool.size();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool empty() const
|
||||
{
|
||||
return m_asset_pool.empty();
|
||||
}
|
||||
|
||||
private:
|
||||
AssetPool& m_asset_pool;
|
||||
};
|
||||
|
||||
class ZoneAssetPools
|
||||
{
|
||||
public:
|
||||
using all_iterator = std::vector<XAssetInfoGeneric*>::const_iterator;
|
||||
|
||||
ZoneAssetPools(Zone& zone, zone_priority_t priority);
|
||||
~ZoneAssetPools();
|
||||
ZoneAssetPools(const ZoneAssetPools& other) = delete;
|
||||
ZoneAssetPools(ZoneAssetPools&& other) noexcept = delete;
|
||||
ZoneAssetPools& operator=(const ZoneAssetPools& other) = delete;
|
||||
ZoneAssetPools& operator=(ZoneAssetPools&& other) noexcept = delete;
|
||||
|
||||
XAssetInfoGeneric* AddAsset(std::unique_ptr<XAssetInfoGeneric> xAssetInfo);
|
||||
XAssetInfoGeneric* AddAsset(asset_type_t type,
|
||||
std::string name,
|
||||
void* asset,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> usedScriptStrings,
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences);
|
||||
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const;
|
||||
[[nodiscard]] XAssetInfoGeneric* GetAssetOrAssetReference(asset_type_t type, const std::string& name) const;
|
||||
|
||||
template<AssetDefinition Asset_t> XAssetInfo<typename Asset_t::Type>* AddAsset(std::unique_ptr<XAssetInfo<typename Asset_t::Type>> xAssetInfo)
|
||||
{
|
||||
return reinterpret_cast<XAssetInfo<typename Asset_t::Type>*>(AddAsset(std::unique_ptr<XAssetInfoGeneric>(xAssetInfo.release())));
|
||||
}
|
||||
|
||||
template<AssetDefinition Asset_t> [[nodiscard]] XAssetInfo<typename Asset_t::Type>* GetAsset(const std::string& name) const
|
||||
{
|
||||
return reinterpret_cast<XAssetInfo<typename Asset_t::Type>*>(GetAsset(Asset_t::EnumEntry, name));
|
||||
}
|
||||
|
||||
template<AssetDefinition Asset_t> [[nodiscard]] XAssetInfo<typename Asset_t::Type>* GetAssetOrAssetReference(const std::string& name) const
|
||||
{
|
||||
return reinterpret_cast<XAssetInfo<typename Asset_t::Type>*>(GetAssetOrAssetReference(Asset_t::EnumEntry, name));
|
||||
}
|
||||
|
||||
template<AssetDefinition Asset_t> [[nodiscard]] AssetPoolIterators<Asset_t> PoolAssets() const
|
||||
{
|
||||
return AssetPoolIterators<Asset_t>(*m_asset_pools[Asset_t::EnumEntry]);
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t GetTotalAssetCount() const;
|
||||
|
||||
[[nodiscard]] all_iterator begin() const;
|
||||
[[nodiscard]] all_iterator end() const;
|
||||
|
||||
private:
|
||||
Zone& m_zone;
|
||||
std::vector<std::unique_ptr<AssetPool>> m_asset_pools;
|
||||
std::vector<XAssetInfoGeneric*> m_assets_in_order;
|
||||
};
|
||||
|
||||
#include "XAssetInfo.h"
|
||||
#include "Zone/Zone.h"
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetPool.h"
|
||||
#include "GlobalAssetPool.h"
|
||||
#include "XAssetInfo.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
template<typename T> class AssetPoolDynamic final : public AssetPool<T>
|
||||
{
|
||||
using AssetPool<T>::m_asset_lookup;
|
||||
|
||||
std::vector<std::unique_ptr<XAssetInfo<T>>> m_assets;
|
||||
|
||||
public:
|
||||
explicit AssetPoolDynamic(const zone_priority_t priority)
|
||||
{
|
||||
GlobalAssetPool<T>::LinkAssetPool(this, priority);
|
||||
}
|
||||
|
||||
AssetPoolDynamic(AssetPoolDynamic<T>&) = delete;
|
||||
AssetPoolDynamic(AssetPoolDynamic<T>&&) = delete;
|
||||
AssetPoolDynamic<T>& operator=(AssetPoolDynamic<T>&) = delete;
|
||||
AssetPoolDynamic<T>& operator=(AssetPoolDynamic<T>&&) = default;
|
||||
|
||||
~AssetPoolDynamic() override
|
||||
{
|
||||
GlobalAssetPool<T>::UnlinkAssetPool(this);
|
||||
|
||||
m_assets.clear();
|
||||
m_asset_lookup.clear();
|
||||
}
|
||||
|
||||
XAssetInfo<T>* AddAsset(std::unique_ptr<XAssetInfo<T>> xAssetInfo) override
|
||||
{
|
||||
const auto normalizedName = XAssetInfo<T>::NormalizeAssetName(xAssetInfo->m_name);
|
||||
|
||||
auto* pAssetInfo = xAssetInfo.get();
|
||||
m_asset_lookup[normalizedName] = pAssetInfo;
|
||||
m_assets.emplace_back(std::move(xAssetInfo));
|
||||
|
||||
GlobalAssetPool<T>::LinkAsset(this, normalizedName, pAssetInfo);
|
||||
|
||||
return pAssetInfo;
|
||||
}
|
||||
};
|
||||
212
src/ZoneCommon/Pool/GlobalAssetPool.cpp
Normal file
212
src/ZoneCommon/Pool/GlobalAssetPool.cpp
Normal file
@@ -0,0 +1,212 @@
|
||||
#include "GlobalAssetPool.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
void GlobalAssetPool::LinkAssetPool(AssetPool* assetPool, const zone_priority_t priority)
|
||||
{
|
||||
auto newLink = std::make_unique<LinkedAssetPool>();
|
||||
newLink->m_asset_pool = assetPool;
|
||||
newLink->m_priority = priority;
|
||||
|
||||
auto* newLinkPtr = newLink.get();
|
||||
m_linked_asset_pools.emplace_back(std::move(newLink));
|
||||
SortLinkedAssetPools();
|
||||
|
||||
for (auto* asset : *assetPool)
|
||||
{
|
||||
const auto normalizedAssetName = XAssetInfoGeneric::NormalizeAssetName(asset->m_name);
|
||||
LinkAsset(newLinkPtr, normalizedAssetName, asset);
|
||||
}
|
||||
}
|
||||
|
||||
void GlobalAssetPool::LinkAsset(const AssetPool* assetPool, const std::string& normalizedAssetName, XAssetInfoGeneric* asset)
|
||||
{
|
||||
LinkedAssetPool* link = nullptr;
|
||||
|
||||
for (const auto& existingLink : m_linked_asset_pools)
|
||||
{
|
||||
if (existingLink->m_asset_pool == assetPool)
|
||||
{
|
||||
link = existingLink.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(link != nullptr);
|
||||
if (link == nullptr)
|
||||
return;
|
||||
|
||||
LinkAsset(link, normalizedAssetName, asset);
|
||||
}
|
||||
|
||||
void GlobalAssetPool::UnlinkAssetPool(const AssetPool* assetPool)
|
||||
{
|
||||
auto iLinkEntry = m_linked_asset_pools.begin();
|
||||
|
||||
for (; iLinkEntry != m_linked_asset_pools.end(); ++iLinkEntry)
|
||||
{
|
||||
const auto* linkEntry = iLinkEntry->get();
|
||||
if (linkEntry->m_asset_pool == assetPool)
|
||||
break;
|
||||
}
|
||||
|
||||
assert(iLinkEntry != m_linked_asset_pools.end());
|
||||
if (iLinkEntry == m_linked_asset_pools.end())
|
||||
return;
|
||||
|
||||
const auto assetPoolToUnlink = std::move(*iLinkEntry);
|
||||
m_linked_asset_pools.erase(iLinkEntry);
|
||||
|
||||
for (auto iAssetEntry = m_assets.begin(); iAssetEntry != m_assets.end();)
|
||||
{
|
||||
auto& assetEntry = *iAssetEntry;
|
||||
|
||||
if (assetEntry.second.m_asset_pool != assetPoolToUnlink.get())
|
||||
{
|
||||
++iAssetEntry;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (assetEntry.second.m_duplicate && ReplaceAssetPoolEntry(assetEntry.second))
|
||||
{
|
||||
++iAssetEntry;
|
||||
continue;
|
||||
}
|
||||
|
||||
iAssetEntry = m_assets.erase(iAssetEntry);
|
||||
}
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GlobalAssetPool::GetAsset(const std::string& name)
|
||||
{
|
||||
const auto normalizedName = XAssetInfoGeneric::NormalizeAssetName(name);
|
||||
const auto foundEntry = m_assets.find(normalizedName);
|
||||
if (foundEntry == m_assets.end())
|
||||
return nullptr;
|
||||
|
||||
return foundEntry->second.m_asset;
|
||||
}
|
||||
|
||||
void GlobalAssetPool::SortLinkedAssetPools()
|
||||
{
|
||||
std::ranges::sort(m_linked_asset_pools,
|
||||
[](const std::unique_ptr<LinkedAssetPool>& a, const std::unique_ptr<LinkedAssetPool>& b) -> bool
|
||||
{
|
||||
return a->m_priority < b->m_priority;
|
||||
});
|
||||
}
|
||||
|
||||
bool GlobalAssetPool::ReplaceAssetPoolEntry(GameAssetPoolEntry& assetEntry) const
|
||||
{
|
||||
int occurrences = 0;
|
||||
|
||||
for (const auto& linkedAssetPool : m_linked_asset_pools)
|
||||
{
|
||||
auto* foundAsset = linkedAssetPool->m_asset_pool->GetAsset(assetEntry.m_asset->m_name);
|
||||
|
||||
if (foundAsset != nullptr)
|
||||
{
|
||||
if (++occurrences == 1)
|
||||
{
|
||||
assetEntry.m_asset = foundAsset;
|
||||
assetEntry.m_duplicate = false;
|
||||
assetEntry.m_asset_pool = linkedAssetPool.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
assetEntry.m_duplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return occurrences > 0;
|
||||
}
|
||||
|
||||
void GlobalAssetPool::LinkAsset(LinkedAssetPool* link, const std::string& normalizedAssetName, XAssetInfoGeneric* asset)
|
||||
{
|
||||
const auto existingAsset = m_assets.find(normalizedAssetName);
|
||||
|
||||
if (existingAsset == m_assets.end())
|
||||
{
|
||||
const GameAssetPoolEntry entry{
|
||||
.m_asset = asset,
|
||||
.m_asset_pool = link,
|
||||
.m_duplicate = false,
|
||||
};
|
||||
|
||||
m_assets[normalizedAssetName] = entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto& existingEntry = existingAsset->second;
|
||||
|
||||
existingEntry.m_duplicate = true;
|
||||
|
||||
if (existingEntry.m_asset_pool->m_priority < link->m_priority)
|
||||
{
|
||||
existingEntry.m_asset_pool = link;
|
||||
existingEntry.m_asset = asset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameGlobalAssetPools::GameGlobalAssetPools(const GameId gameId)
|
||||
{
|
||||
const auto assetTypeCount = IGame::GetGameById(gameId)->GetAssetTypeCount();
|
||||
m_global_asset_pools.resize(assetTypeCount);
|
||||
|
||||
for (auto assetType = 0u; assetType < assetTypeCount; assetType++)
|
||||
{
|
||||
m_global_asset_pools[assetType] = std::make_unique<GlobalAssetPool>();
|
||||
}
|
||||
}
|
||||
|
||||
void GameGlobalAssetPools::LinkAssetPool(const asset_type_t assetType, AssetPool* assetPool, const zone_priority_t priority) const
|
||||
{
|
||||
assert(assetType < m_global_asset_pools.size());
|
||||
|
||||
m_global_asset_pools[assetType]->LinkAssetPool(assetPool, priority);
|
||||
}
|
||||
|
||||
void GameGlobalAssetPools::LinkAsset(const asset_type_t assetType,
|
||||
const AssetPool* assetPool,
|
||||
const std::string& normalizedAssetName,
|
||||
XAssetInfoGeneric* asset) const
|
||||
{
|
||||
assert(assetType < m_global_asset_pools.size());
|
||||
|
||||
m_global_asset_pools[assetType]->LinkAsset(assetPool, normalizedAssetName, asset);
|
||||
}
|
||||
|
||||
void GameGlobalAssetPools::UnlinkAssetPool(const asset_type_t assetType, const AssetPool* assetPool) const
|
||||
{
|
||||
assert(assetType < m_global_asset_pools.size());
|
||||
|
||||
m_global_asset_pools[assetType]->UnlinkAssetPool(assetPool);
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameGlobalAssetPools::GetAsset(const asset_type_t assetType, const std::string& name) const
|
||||
{
|
||||
assert(assetType < m_global_asset_pools.size());
|
||||
|
||||
return m_global_asset_pools[assetType]->GetAsset(name);
|
||||
}
|
||||
|
||||
GameGlobalAssetPools* GameGlobalAssetPools::GetGlobalPoolsForGame(GameId gameId)
|
||||
{
|
||||
static GameGlobalAssetPools* globalAssetPools[static_cast<unsigned>(GameId::COUNT)]{
|
||||
new GameGlobalAssetPools(GameId::IW3),
|
||||
new GameGlobalAssetPools(GameId::IW4),
|
||||
new GameGlobalAssetPools(GameId::IW5),
|
||||
new GameGlobalAssetPools(GameId::T5),
|
||||
new GameGlobalAssetPools(GameId::T6),
|
||||
};
|
||||
|
||||
assert(static_cast<unsigned>(gameId) < static_cast<unsigned>(GameId::COUNT));
|
||||
auto* result = globalAssetPools[static_cast<unsigned>(gameId)];
|
||||
assert(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -3,188 +3,60 @@
|
||||
#include "AssetPool.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
template<typename T> class GlobalAssetPool
|
||||
struct LinkedAssetPool
|
||||
{
|
||||
struct LinkedAssetPool
|
||||
{
|
||||
AssetPool<T>* m_asset_pool;
|
||||
zone_priority_t m_priority;
|
||||
};
|
||||
|
||||
struct GameAssetPoolEntry
|
||||
{
|
||||
XAssetInfo<T>* m_asset;
|
||||
bool m_duplicate;
|
||||
LinkedAssetPool* m_asset_pool;
|
||||
};
|
||||
|
||||
static std::vector<std::unique_ptr<LinkedAssetPool>> m_linked_asset_pools;
|
||||
static std::unordered_map<std::string, GameAssetPoolEntry> m_assets;
|
||||
|
||||
static void SortLinkedAssetPools()
|
||||
{
|
||||
std::sort(m_linked_asset_pools.begin(),
|
||||
m_linked_asset_pools.end(),
|
||||
[](const std::unique_ptr<LinkedAssetPool>& a, const std::unique_ptr<LinkedAssetPool>& b) -> bool
|
||||
{
|
||||
return a->m_priority < b->m_priority;
|
||||
});
|
||||
}
|
||||
|
||||
static bool ReplaceAssetPoolEntry(GameAssetPoolEntry& assetEntry)
|
||||
{
|
||||
int occurrences = 0;
|
||||
|
||||
for (const auto& linkedAssetPool : m_linked_asset_pools)
|
||||
{
|
||||
XAssetInfo<T>* foundAsset = linkedAssetPool->m_asset_pool->GetAsset(assetEntry.m_asset->m_name);
|
||||
|
||||
if (foundAsset != nullptr)
|
||||
{
|
||||
if (++occurrences == 1)
|
||||
{
|
||||
assetEntry.m_asset = foundAsset;
|
||||
assetEntry.m_duplicate = false;
|
||||
assetEntry.m_asset_pool = linkedAssetPool.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
assetEntry.m_duplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return occurrences > 0;
|
||||
}
|
||||
|
||||
static void LinkAsset(LinkedAssetPool* link, const std::string& normalizedAssetName, XAssetInfo<T>* asset)
|
||||
{
|
||||
auto existingAsset = m_assets.find(normalizedAssetName);
|
||||
|
||||
if (existingAsset == m_assets.end())
|
||||
{
|
||||
GameAssetPoolEntry entry{};
|
||||
entry.m_asset = asset;
|
||||
entry.m_asset_pool = link;
|
||||
entry.m_duplicate = false;
|
||||
|
||||
m_assets[normalizedAssetName] = entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto& existingEntry = existingAsset->second;
|
||||
|
||||
existingEntry.m_duplicate = true;
|
||||
|
||||
if (existingEntry.m_asset_pool->m_priority < link->m_priority)
|
||||
{
|
||||
existingEntry.m_asset_pool = link;
|
||||
existingEntry.m_asset = asset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
static void LinkAssetPool(AssetPool<T>* assetPool, const zone_priority_t priority)
|
||||
{
|
||||
auto newLink = std::make_unique<LinkedAssetPool>();
|
||||
newLink->m_asset_pool = assetPool;
|
||||
newLink->m_priority = priority;
|
||||
|
||||
auto* newLinkPtr = newLink.get();
|
||||
m_linked_asset_pools.emplace_back(std::move(newLink));
|
||||
SortLinkedAssetPools();
|
||||
|
||||
for (auto asset : *assetPool)
|
||||
{
|
||||
const auto normalizedAssetName = XAssetInfo<T>::NormalizeAssetName(asset->m_name);
|
||||
LinkAsset(newLinkPtr, normalizedAssetName, asset);
|
||||
}
|
||||
}
|
||||
|
||||
static void LinkAsset(AssetPool<T>* assetPool, const std::string& normalizedAssetName, XAssetInfo<T>* asset)
|
||||
{
|
||||
LinkedAssetPool* link = nullptr;
|
||||
|
||||
for (const auto& existingLink : m_linked_asset_pools)
|
||||
{
|
||||
if (existingLink->m_asset_pool == assetPool)
|
||||
{
|
||||
link = existingLink.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(link != nullptr);
|
||||
if (link == nullptr)
|
||||
return;
|
||||
|
||||
LinkAsset(link, normalizedAssetName, asset);
|
||||
}
|
||||
|
||||
static void UnlinkAssetPool(AssetPool<T>* assetPool)
|
||||
{
|
||||
auto iLinkEntry = m_linked_asset_pools.begin();
|
||||
|
||||
for (; iLinkEntry != m_linked_asset_pools.end(); ++iLinkEntry)
|
||||
{
|
||||
LinkedAssetPool* linkEntry = iLinkEntry->get();
|
||||
if (linkEntry->m_asset_pool == assetPool)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(iLinkEntry != m_linked_asset_pools.end());
|
||||
if (iLinkEntry == m_linked_asset_pools.end())
|
||||
return;
|
||||
|
||||
auto assetPoolToUnlink = std::move(*iLinkEntry);
|
||||
m_linked_asset_pools.erase(iLinkEntry);
|
||||
|
||||
for (auto iAssetEntry = m_assets.begin(); iAssetEntry != m_assets.end();)
|
||||
{
|
||||
auto& assetEntry = *iAssetEntry;
|
||||
|
||||
if (assetEntry.second.m_asset_pool != assetPoolToUnlink.get())
|
||||
{
|
||||
++iAssetEntry;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (assetEntry.second.m_duplicate && ReplaceAssetPoolEntry(assetEntry.second))
|
||||
{
|
||||
++iAssetEntry;
|
||||
continue;
|
||||
}
|
||||
|
||||
iAssetEntry = m_assets.erase(iAssetEntry);
|
||||
}
|
||||
}
|
||||
|
||||
static XAssetInfo<T>* GetAssetByName(const std::string& name)
|
||||
{
|
||||
const auto normalizedName = XAssetInfo<T>::NormalizeAssetName(name);
|
||||
const auto foundEntry = m_assets.find(normalizedName);
|
||||
if (foundEntry == m_assets.end())
|
||||
return nullptr;
|
||||
|
||||
return foundEntry->second.m_asset;
|
||||
}
|
||||
AssetPool* m_asset_pool;
|
||||
zone_priority_t m_priority;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
std::vector<std::unique_ptr<typename GlobalAssetPool<T>::LinkedAssetPool>> GlobalAssetPool<T>::m_linked_asset_pools =
|
||||
std::vector<std::unique_ptr<LinkedAssetPool>>();
|
||||
struct GameAssetPoolEntry
|
||||
{
|
||||
XAssetInfoGeneric* m_asset;
|
||||
LinkedAssetPool* m_asset_pool;
|
||||
bool m_duplicate;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
std::unordered_map<std::string, typename GlobalAssetPool<T>::GameAssetPoolEntry> GlobalAssetPool<T>::m_assets =
|
||||
std::unordered_map<std::string, GameAssetPoolEntry>();
|
||||
class GlobalAssetPool
|
||||
{
|
||||
public:
|
||||
void LinkAssetPool(AssetPool* assetPool, zone_priority_t priority);
|
||||
void LinkAsset(const AssetPool* assetPool, const std::string& normalizedAssetName, XAssetInfoGeneric* asset);
|
||||
void UnlinkAssetPool(const AssetPool* assetPool);
|
||||
|
||||
XAssetInfoGeneric* GetAsset(const std::string& name);
|
||||
|
||||
private:
|
||||
void SortLinkedAssetPools();
|
||||
bool ReplaceAssetPoolEntry(GameAssetPoolEntry& assetEntry) const;
|
||||
void LinkAsset(LinkedAssetPool* link, const std::string& normalizedAssetName, XAssetInfoGeneric* asset);
|
||||
|
||||
std::vector<std::unique_ptr<LinkedAssetPool>> m_linked_asset_pools;
|
||||
std::unordered_map<std::string, GameAssetPoolEntry> m_assets;
|
||||
};
|
||||
|
||||
class GameGlobalAssetPools
|
||||
{
|
||||
public:
|
||||
explicit GameGlobalAssetPools(GameId gameId);
|
||||
|
||||
void LinkAssetPool(asset_type_t assetType, AssetPool* assetPool, zone_priority_t priority) const;
|
||||
void LinkAsset(asset_type_t assetType, const AssetPool* assetPool, const std::string& normalizedAssetName, XAssetInfoGeneric* asset) const;
|
||||
void UnlinkAssetPool(asset_type_t assetType, const AssetPool* assetPool) const;
|
||||
|
||||
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t assetType, const std::string& name) const;
|
||||
|
||||
template<AssetDefinition Asset_t> [[nodiscard]] XAssetInfo<typename Asset_t::Type>* GetAsset(const std::string& name) const
|
||||
{
|
||||
return reinterpret_cast<XAssetInfo<typename Asset_t::Type>*>(GetAsset(Asset_t::EnumEntry, name));
|
||||
}
|
||||
|
||||
static GameGlobalAssetPools* GetGlobalPoolsForGame(GameId gameId);
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<GlobalAssetPool>> m_global_asset_pools;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Zone.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
#include "ZoneAssetPools.h"
|
||||
|
||||
#include "Game/IW3/GameAssetPoolIW3.h"
|
||||
#include "Game/IW4/GameAssetPoolIW4.h"
|
||||
#include "Game/IW5/GameAssetPoolIW5.h"
|
||||
#include "Game/T5/GameAssetPoolT5.h"
|
||||
#include "Game/T6/GameAssetPoolT6.h"
|
||||
#include "Game/T6/ZoneConstantsT6.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <format>
|
||||
|
||||
ZoneAssetPools::ZoneAssetPools(Zone* zone)
|
||||
: m_zone(zone)
|
||||
{
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* ZoneAssetPools::AddAsset(const asset_type_t type,
|
||||
std::string name,
|
||||
void* asset,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> usedScriptStrings,
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences)
|
||||
{
|
||||
return AddAsset(std::make_unique<XAssetInfoGeneric>(
|
||||
type, std::move(name), asset, std::move(dependencies), std::move(usedScriptStrings), std::move(indirectAssetReferences), m_zone));
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* ZoneAssetPools::AddAsset(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
|
||||
{
|
||||
auto* assetInfo = AddAssetToPool(std::move(xAssetInfo));
|
||||
if (assetInfo)
|
||||
m_assets_in_order.push_back(assetInfo);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
ZoneAssetPools::iterator ZoneAssetPools::begin() const
|
||||
{
|
||||
return m_assets_in_order.begin();
|
||||
}
|
||||
|
||||
ZoneAssetPools::iterator ZoneAssetPools::end() const
|
||||
{
|
||||
return m_assets_in_order.end();
|
||||
}
|
||||
|
||||
std::unique_ptr<ZoneAssetPools> ZoneAssetPools::CreateForGame(const GameId game, Zone* zone, const zone_priority_t priority)
|
||||
{
|
||||
switch (game)
|
||||
{
|
||||
case GameId::IW3:
|
||||
return std::make_unique<GameAssetPoolIW3>(zone, priority);
|
||||
case GameId::IW4:
|
||||
return std::make_unique<GameAssetPoolIW4>(zone, priority);
|
||||
case GameId::IW5:
|
||||
return std::make_unique<GameAssetPoolIW5>(zone, priority);
|
||||
case GameId::T5:
|
||||
return std::make_unique<GameAssetPoolT5>(zone, priority);
|
||||
case GameId::T6:
|
||||
return std::make_unique<GameAssetPoolT6>(zone, priority);
|
||||
default:
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "XAssetInfo.h"
|
||||
#include "Zone/Zone.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Zone;
|
||||
class IndirectAssetReference;
|
||||
class XAssetInfoGeneric;
|
||||
|
||||
class ZoneAssetPools
|
||||
{
|
||||
public:
|
||||
using iterator = std::vector<XAssetInfoGeneric*>::const_iterator;
|
||||
|
||||
explicit ZoneAssetPools(Zone* zone);
|
||||
virtual ~ZoneAssetPools() = default;
|
||||
ZoneAssetPools(const ZoneAssetPools& other) = delete;
|
||||
ZoneAssetPools(ZoneAssetPools&& other) noexcept = default;
|
||||
ZoneAssetPools& operator=(const ZoneAssetPools& other) = delete;
|
||||
ZoneAssetPools& operator=(ZoneAssetPools&& other) noexcept = default;
|
||||
|
||||
XAssetInfoGeneric* AddAsset(std::unique_ptr<XAssetInfoGeneric> xAssetInfo);
|
||||
XAssetInfoGeneric* AddAsset(asset_type_t type,
|
||||
std::string name,
|
||||
void* asset,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> usedScriptStrings,
|
||||
std::vector<IndirectAssetReference> 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]] size_t GetTotalAssetCount() const;
|
||||
|
||||
[[nodiscard]] iterator begin() const;
|
||||
[[nodiscard]] iterator end() const;
|
||||
|
||||
static std::unique_ptr<ZoneAssetPools> CreateForGame(GameId game, Zone* zone, zone_priority_t priority);
|
||||
|
||||
protected:
|
||||
virtual XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) = 0;
|
||||
|
||||
Zone* m_zone;
|
||||
std::vector<XAssetInfoGeneric*> m_assets_in_order;
|
||||
};
|
||||
@@ -8,7 +8,7 @@ Zone::Zone(std::string name, const zone_priority_t priority, const GameId gameId
|
||||
m_language(GameLanguage::LANGUAGE_NONE),
|
||||
m_game_id(gameId),
|
||||
m_platform(platform),
|
||||
m_pools(ZoneAssetPools::CreateForGame(gameId, this, priority)),
|
||||
m_pools(*this, priority),
|
||||
m_memory(std::make_unique<ZoneMemory>()),
|
||||
m_registered(false)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "Game/GameLanguage.h"
|
||||
#include "Game/IGame.h"
|
||||
#include "Pool/ZoneAssetPools.h"
|
||||
#include "Pool/AssetPool.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
#include "ZoneMemory.h"
|
||||
#include "ZoneScriptStrings.h"
|
||||
@@ -10,17 +10,15 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class ZoneAssetPools;
|
||||
|
||||
class Zone
|
||||
{
|
||||
public:
|
||||
Zone(std::string name, zone_priority_t priority, GameId gameId, GamePlatform platform);
|
||||
~Zone();
|
||||
Zone(const Zone& other) = delete;
|
||||
Zone(Zone&& other) noexcept = default;
|
||||
Zone(Zone&& other) noexcept = delete;
|
||||
Zone& operator=(const Zone& other) = delete;
|
||||
Zone& operator=(Zone&& other) noexcept = default;
|
||||
Zone& operator=(Zone&& other) noexcept = delete;
|
||||
|
||||
void Register();
|
||||
|
||||
@@ -32,7 +30,7 @@ public:
|
||||
GameId m_game_id;
|
||||
GamePlatform m_platform;
|
||||
ZoneScriptStrings m_script_strings;
|
||||
std::unique_ptr<ZoneAssetPools> m_pools;
|
||||
ZoneAssetPools m_pools;
|
||||
|
||||
private:
|
||||
std::unique_ptr<ZoneMemory> m_memory;
|
||||
|
||||
Reference in New Issue
Block a user