chore: always use dynamic asset pools and remove static implementation

This commit is contained in:
Jan 2025-01-21 20:42:13 +01:00
parent 74f84cbf83
commit b4194eff28
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
20 changed files with 420 additions and 963 deletions

View File

@ -1,123 +1,57 @@
#include "GameAssetPoolIW3.h"
#include "Pool/AssetPoolDynamic.h"
#include "Pool/AssetPoolStatic.h"
#include <cassert>
#include <type_traits>
using namespace IW3;
const char* GameAssetPoolIW3::ASSET_TYPE_NAMES[]{
namespace
{
constexpr const char* ASSET_TYPE_NAMES[]{
"xmodelpieces", "physpreset", "xanim", "xmodel", "material", "techniqueset", "image", "sound", "soundcurve", "loadedsound",
"clipmap", "clipmap", "comworld", "gameworldsp", "gameworldmp", "mapents", "gfxworld", "lightdef", "uimap", "font",
"menulist", "menu", "localize", "weapon", "snddriverglobals", "fx", "impactfx", "aitype", "mptype", "character",
"xmodelalias", "rawfile", "stringtable",
};
};
}
GameAssetPoolIW3::GameAssetPoolIW3(Zone* zone, const int priority)
GameAssetPoolIW3::GameAssetPoolIW3(Zone* zone, const zone_priority_t priority)
: ZoneAssetPools(zone),
m_priority(priority)
{
static_assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
}
void GameAssetPoolIW3::InitPoolStatic(const asset_type_t type, const size_t capacity)
{
#define CASE_INIT_POOL_STATIC(assetType, poolName) \
case assetType: \
{ \
if ((poolName) == nullptr && capacity > 0) \
{ \
(poolName) = std::make_unique<AssetPoolStatic<decltype(poolName)::element_type::type>>(capacity, m_priority, (assetType)); \
} \
break; \
}
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
switch (type)
{
CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSPRESET, m_phys_preset)
CASE_INIT_POOL_STATIC(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
CASE_INIT_POOL_STATIC(ASSET_TYPE_XMODEL, m_xmodel)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MATERIAL, m_material)
CASE_INIT_POOL_STATIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
CASE_INIT_POOL_STATIC(ASSET_TYPE_IMAGE, m_image)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND, m_sound)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND_CURVE, m_sound_curve)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LOADED_SOUND, m_loaded_sound)
CASE_INIT_POOL_STATIC(ASSET_TYPE_CLIPMAP, m_clip_map)
CASE_INIT_POOL_STATIC(ASSET_TYPE_CLIPMAP_PVS, m_clip_map)
CASE_INIT_POOL_STATIC(ASSET_TYPE_COMWORLD, m_com_world)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MAP_ENTS, m_map_ents)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GFXWORLD, m_gfx_world)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FONT, m_font)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MENULIST, m_menu_list)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MENU, m_menu_def)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
CASE_INIT_POOL_STATIC(ASSET_TYPE_WEAPON, m_weapon)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FX, m_fx)
CASE_INIT_POOL_STATIC(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
CASE_INIT_POOL_STATIC(ASSET_TYPE_RAWFILE, m_raw_file)
CASE_INIT_POOL_STATIC(ASSET_TYPE_STRINGTABLE, m_string_table)
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);
default:
assert(type >= 0 && type < ASSET_TYPE_COUNT);
break;
}
#undef CASE_INIT_POOL_STATIC
}
void GameAssetPoolIW3::InitPoolDynamic(const asset_type_t type)
{
#define CASE_INIT_POOL_DYNAMIC(assetType, poolName) \
case assetType: \
{ \
if ((poolName) == nullptr) \
{ \
(poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority, (assetType)); \
} \
break; \
}
switch (type)
{
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSPRESET, m_phys_preset)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XMODEL, m_xmodel)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MATERIAL, m_material)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_IMAGE, m_image)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND, m_sound)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND_CURVE, m_sound_curve)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LOADED_SOUND, m_loaded_sound)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_CLIPMAP, m_clip_map)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_CLIPMAP_PVS, m_clip_map)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_COMWORLD, m_com_world)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MAP_ENTS, m_map_ents)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GFXWORLD, m_gfx_world)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FONT, m_font)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MENULIST, m_menu_list)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MENU, m_menu_def)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_WEAPON, m_weapon)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FX, m_fx)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_RAWFILE, m_raw_file)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_STRINGTABLE, m_string_table)
default:
assert(type >= 0 && type < ASSET_TYPE_COUNT);
break;
}
#undef CASE_INIT_POOL_STATIC
#undef INIT_POOL
}
XAssetInfoGeneric* GameAssetPoolIW3::AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
@ -125,7 +59,7 @@ XAssetInfoGeneric* GameAssetPoolIW3::AddAssetToPool(std::unique_ptr<XAssetInfoGe
#define CASE_ADD_TO_POOL(assetType, poolName) \
case assetType: \
{ \
assert((poolName) != nullptr); \
assert(poolName); \
return (poolName)->AddAsset(std::unique_ptr<XAssetInfo<decltype(poolName)::element_type::type>>( \
static_cast<XAssetInfo<decltype(poolName)::element_type::type>*>(xAssetInfo.release()))); \
}
@ -174,7 +108,7 @@ XAssetInfoGeneric* GameAssetPoolIW3::GetAsset(const asset_type_t type, const std
#define CASE_GET_ASSET(assetType, poolName) \
case assetType: \
{ \
if ((poolName) != nullptr) \
if (poolName) \
return (poolName)->GetAsset(std::move(name)); \
break; \
}

View File

@ -9,13 +9,6 @@
class GameAssetPoolIW3 final : public ZoneAssetPools
{
int m_priority;
static const char* ASSET_TYPE_NAMES[];
protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
public:
std::unique_ptr<AssetPool<IW3::PhysPreset>> m_phys_preset;
std::unique_ptr<AssetPool<IW3::XAnimParts>> m_xanim_parts;
@ -46,17 +39,20 @@ public:
std::unique_ptr<AssetPool<IW3::RawFile>> m_raw_file;
std::unique_ptr<AssetPool<IW3::StringTable>> m_string_table;
GameAssetPoolIW3(Zone* zone, int priority);
GameAssetPoolIW3(Zone* zone, zone_priority_t priority);
~GameAssetPoolIW3() override = default;
void InitPoolStatic(asset_type_t type, size_t capacity) override;
void InitPoolDynamic(asset_type_t type) override;
_NODISCARD XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
static std::optional<const char*> AssetTypeNameByType(asset_type_t assetType);
_NODISCARD std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
static asset_type_t AssetTypeCount();
_NODISCARD asset_type_t GetAssetTypeCount() const override;
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
private:
zone_priority_t m_priority;
};

View File

@ -1,144 +1,69 @@
#include "GameAssetPoolIW4.h"
#include "Pool/AssetPoolDynamic.h"
#include "Pool/AssetPoolStatic.h"
#include <cassert>
#include <type_traits>
using namespace IW4;
const char* GameAssetPoolIW4::ASSET_TYPE_NAMES[]{
"physpreset", "physcollmap", "xanim", "xmodelsurfs", "xmodel", "material", "pixelshader", "vertexshader", "vertexdecl", "techniqueset",
"image", "sound", "soundcurve", "loadedsound", "clipmap", "clipmap", "comworld", "gameworldsp", "gameworldmp", "mapents",
"fxworld", "gfxworld", "lightdef", "uimap", "font", "menulist", "menu", "localize", "weapon", "snddriverglobals",
"fx", "impactfx", "aitype", "mptype", "character", "xmodelalias", "rawfile", "stringtable", "leaderboard", "structureddatadef",
namespace
{
constexpr const char* ASSET_TYPE_NAMES[]{
"physpreset", "physcollmap", "xanim", "xmodelsurfs", "xmodel", "material", "pixelshader", "vertexshader",
"vertexdecl", "techniqueset", "image", "sound", "soundcurve", "loadedsound", "clipmap", "clipmap",
"comworld", "gameworldsp", "gameworldmp", "mapents", "fxworld", "gfxworld", "lightdef", "uimap",
"font", "menulist", "menu", "localize", "weapon", "snddriverglobals", "fx", "impactfx",
"aitype", "mptype", "character", "xmodelalias", "rawfile", "stringtable", "leaderboard", "structureddatadef",
"tracer", "vehicle", "addonmapents",
};
};
}
GameAssetPoolIW4::GameAssetPoolIW4(Zone* zone, const int priority)
GameAssetPoolIW4::GameAssetPoolIW4(Zone* zone, const zone_priority_t priority)
: ZoneAssetPools(zone),
m_priority(priority)
{
assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
}
static_assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
void GameAssetPoolIW4::InitPoolStatic(const asset_type_t type, const size_t capacity)
{
#define CASE_INIT_POOL_STATIC(assetType, poolName) \
case assetType: \
{ \
if ((poolName) == nullptr && capacity > 0) \
{ \
(poolName) = std::make_unique<AssetPoolStatic<decltype(poolName)::element_type::type>>(capacity, m_priority, (assetType)); \
} \
break; \
}
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
switch (type)
{
CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSPRESET, m_phys_preset)
CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSCOLLMAP, m_phys_collmap)
CASE_INIT_POOL_STATIC(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
CASE_INIT_POOL_STATIC(ASSET_TYPE_XMODEL, m_xmodel)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MATERIAL, m_material)
CASE_INIT_POOL_STATIC(ASSET_TYPE_PIXELSHADER, m_material_pixel_shader)
CASE_INIT_POOL_STATIC(ASSET_TYPE_VERTEXSHADER, m_material_vertex_shader)
CASE_INIT_POOL_STATIC(ASSET_TYPE_VERTEXDECL, m_material_vertex_decl)
CASE_INIT_POOL_STATIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
CASE_INIT_POOL_STATIC(ASSET_TYPE_IMAGE, m_image)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND, m_sound)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND_CURVE, m_sound_curve)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LOADED_SOUND, m_loaded_sound)
CASE_INIT_POOL_STATIC(ASSET_TYPE_CLIPMAP_SP, m_clip_map)
CASE_INIT_POOL_STATIC(ASSET_TYPE_CLIPMAP_MP, m_clip_map)
CASE_INIT_POOL_STATIC(ASSET_TYPE_COMWORLD, m_com_world)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MAP_ENTS, m_map_ents)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FXWORLD, m_fx_world)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GFXWORLD, m_gfx_world)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FONT, m_font)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MENULIST, m_menu_list)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MENU, m_menu_def)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
CASE_INIT_POOL_STATIC(ASSET_TYPE_WEAPON, m_weapon)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FX, m_fx)
CASE_INIT_POOL_STATIC(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
CASE_INIT_POOL_STATIC(ASSET_TYPE_RAWFILE, m_raw_file)
CASE_INIT_POOL_STATIC(ASSET_TYPE_STRINGTABLE, m_string_table)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LEADERBOARD, m_leaderboard)
CASE_INIT_POOL_STATIC(ASSET_TYPE_STRUCTURED_DATA_DEF, m_structed_data_def_set)
CASE_INIT_POOL_STATIC(ASSET_TYPE_TRACER, m_tracer)
CASE_INIT_POOL_STATIC(ASSET_TYPE_VEHICLE, m_vehicle)
CASE_INIT_POOL_STATIC(ASSET_TYPE_ADDON_MAP_ENTS, m_addon_map_ents)
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);
default:
assert(type >= 0 && type < ASSET_TYPE_COUNT);
break;
}
#undef CASE_INIT_POOL_STATIC
}
void GameAssetPoolIW4::InitPoolDynamic(const asset_type_t type)
{
#define CASE_INIT_POOL_DYNAMIC(assetType, poolName) \
case assetType: \
{ \
if ((poolName) == nullptr) \
{ \
(poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority, (assetType)); \
} \
break; \
}
switch (type)
{
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSPRESET, m_phys_preset)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSCOLLMAP, m_phys_collmap)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XMODEL, m_xmodel)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MATERIAL, m_material)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PIXELSHADER, m_material_pixel_shader)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_VERTEXSHADER, m_material_vertex_shader)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_VERTEXDECL, m_material_vertex_decl)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_IMAGE, m_image)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND, m_sound)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND_CURVE, m_sound_curve)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LOADED_SOUND, m_loaded_sound)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_CLIPMAP_SP, m_clip_map)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_CLIPMAP_MP, m_clip_map)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_COMWORLD, m_com_world)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MAP_ENTS, m_map_ents)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FXWORLD, m_fx_world)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GFXWORLD, m_gfx_world)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FONT, m_font)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MENULIST, m_menu_list)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MENU, m_menu_def)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_WEAPON, m_weapon)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FX, m_fx)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_RAWFILE, m_raw_file)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_STRINGTABLE, m_string_table)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LEADERBOARD, m_leaderboard)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_STRUCTURED_DATA_DEF, m_structed_data_def_set)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_TRACER, m_tracer)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_VEHICLE, m_vehicle)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_ADDON_MAP_ENTS, m_addon_map_ents)
default:
assert(type >= 0 && type < ASSET_TYPE_COUNT);
break;
}
#undef CASE_INIT_POOL_DYNAMIC
#undef INIT_POOL
}
XAssetInfoGeneric* GameAssetPoolIW4::AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
@ -146,7 +71,7 @@ XAssetInfoGeneric* GameAssetPoolIW4::AddAssetToPool(std::unique_ptr<XAssetInfoGe
#define CASE_ADD_TO_POOL(assetType, poolName) \
case assetType: \
{ \
assert((poolName) != nullptr); \
assert(poolName); \
return (poolName)->AddAsset(std::unique_ptr<XAssetInfo<decltype(poolName)::element_type::type>>( \
static_cast<XAssetInfo<decltype(poolName)::element_type::type>*>(xAssetInfo.release()))); \
}
@ -205,7 +130,7 @@ XAssetInfoGeneric* GameAssetPoolIW4::GetAsset(const asset_type_t type, const std
#define CASE_GET_ASSET(assetType, poolName) \
case assetType: \
{ \
if ((poolName) != nullptr) \
if (poolName) \
return (poolName)->GetAsset(name); \
break; \
}

View File

@ -3,20 +3,11 @@
#include "Game/IW4/IW4.h"
#include "Pool/AssetPool.h"
#include "Pool/ZoneAssetPools.h"
#include "Utils/ClassUtils.h"
#include <memory>
class GameAssetPoolIW4 final : public ZoneAssetPools
{
int m_priority;
static constexpr const char* ASSET_TYPE_INVALID = "invalid_asset_type";
static const char* ASSET_TYPE_NAMES[];
protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
public:
std::unique_ptr<AssetPool<IW4::PhysPreset>> m_phys_preset;
std::unique_ptr<AssetPool<IW4::PhysCollmap>> m_phys_collmap;
@ -54,17 +45,20 @@ public:
std::unique_ptr<AssetPool<IW4::VehicleDef>> m_vehicle;
std::unique_ptr<AssetPool<IW4::AddonMapEnts>> m_addon_map_ents;
GameAssetPoolIW4(Zone* zone, int priority);
GameAssetPoolIW4(Zone* zone, zone_priority_t priority);
~GameAssetPoolIW4() override = default;
void InitPoolStatic(asset_type_t type, size_t capacity) override;
void InitPoolDynamic(asset_type_t type) override;
_NODISCARD XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
static std::optional<const char*> AssetTypeNameByType(asset_type_t assetType);
_NODISCARD std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
static asset_type_t AssetTypeCount();
_NODISCARD asset_type_t GetAssetTypeCount() const override;
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
private:
zone_priority_t m_priority;
};

View File

@ -1,14 +1,15 @@
#include "GameAssetPoolIW5.h"
#include "Pool/AssetPoolDynamic.h"
#include "Pool/AssetPoolStatic.h"
#include <cassert>
#include <type_traits>
using namespace IW5;
const char* GameAssetPoolIW5::ASSET_TYPE_NAMES[]{
namespace
{
constexpr const char* ASSET_TYPE_NAMES[]{
"physpreset",
"physcollmap",
"xanim",
@ -55,139 +56,59 @@ const char* GameAssetPoolIW5::ASSET_TYPE_NAMES[]{
"tracer",
"vehicle",
"addonmapents",
};
};
}
GameAssetPoolIW5::GameAssetPoolIW5(Zone* zone, const int priority)
GameAssetPoolIW5::GameAssetPoolIW5(Zone* zone, const zone_priority_t priority)
: ZoneAssetPools(zone),
m_priority(priority)
{
assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
}
static_assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
void GameAssetPoolIW5::InitPoolStatic(const asset_type_t type, const size_t capacity)
{
#define CASE_INIT_POOL_STATIC(assetType, poolName) \
case assetType: \
{ \
if ((poolName) == nullptr && capacity > 0) \
{ \
(poolName) = std::make_unique<AssetPoolStatic<decltype(poolName)::element_type::type>>(capacity, m_priority, (assetType)); \
} \
break; \
}
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
switch (type)
{
CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSPRESET, m_phys_preset)
CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSCOLLMAP, m_phys_collmap)
CASE_INIT_POOL_STATIC(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
CASE_INIT_POOL_STATIC(ASSET_TYPE_XMODEL_SURFS, m_xmodel_surfs)
CASE_INIT_POOL_STATIC(ASSET_TYPE_XMODEL, m_xmodel)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MATERIAL, m_material)
CASE_INIT_POOL_STATIC(ASSET_TYPE_PIXELSHADER, m_material_pixel_shader)
CASE_INIT_POOL_STATIC(ASSET_TYPE_VERTEXSHADER, m_material_vertex_shader)
CASE_INIT_POOL_STATIC(ASSET_TYPE_VERTEXDECL, m_material_vertex_decl)
CASE_INIT_POOL_STATIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
CASE_INIT_POOL_STATIC(ASSET_TYPE_IMAGE, m_image)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND, m_sound)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND_CURVE, m_sound_curve)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LOADED_SOUND, m_loaded_sound)
CASE_INIT_POOL_STATIC(ASSET_TYPE_CLIPMAP, m_clip_map)
CASE_INIT_POOL_STATIC(ASSET_TYPE_COMWORLD, m_com_world)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GLASSWORLD, m_glass_world)
CASE_INIT_POOL_STATIC(ASSET_TYPE_PATHDATA, m_path_data)
CASE_INIT_POOL_STATIC(ASSET_TYPE_VEHICLE_TRACK, m_vehicle_track)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MAP_ENTS, m_map_ents)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FXWORLD, m_fx_world)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GFXWORLD, m_gfx_world)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FONT, m_font)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MENULIST, m_menu_list)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MENU, m_menu_def)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
CASE_INIT_POOL_STATIC(ASSET_TYPE_ATTACHMENT, m_attachment)
CASE_INIT_POOL_STATIC(ASSET_TYPE_WEAPON, m_weapon)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FX, m_fx)
CASE_INIT_POOL_STATIC(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SURFACE_FX, m_surface_fx_table)
CASE_INIT_POOL_STATIC(ASSET_TYPE_RAWFILE, m_raw_file)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SCRIPTFILE, m_script_file)
CASE_INIT_POOL_STATIC(ASSET_TYPE_STRINGTABLE, m_string_table)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LEADERBOARD, m_leaderboard)
CASE_INIT_POOL_STATIC(ASSET_TYPE_STRUCTURED_DATA_DEF, m_structed_data_def_set)
CASE_INIT_POOL_STATIC(ASSET_TYPE_TRACER, m_tracer)
CASE_INIT_POOL_STATIC(ASSET_TYPE_VEHICLE, m_vehicle)
CASE_INIT_POOL_STATIC(ASSET_TYPE_ADDON_MAP_ENTS, m_addon_map_ents)
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);
default:
assert(type >= 0 && type < ASSET_TYPE_COUNT);
break;
}
#undef CASE_INIT_POOL_STATIC
}
void GameAssetPoolIW5::InitPoolDynamic(const asset_type_t type)
{
#define CASE_INIT_POOL_DYNAMIC(assetType, poolName) \
case assetType: \
{ \
if ((poolName) == nullptr) \
{ \
(poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority, (assetType)); \
} \
break; \
}
switch (type)
{
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSPRESET, m_phys_preset)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSCOLLMAP, m_phys_collmap)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XMODEL_SURFS, m_xmodel_surfs)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XMODEL, m_xmodel)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MATERIAL, m_material)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PIXELSHADER, m_material_pixel_shader)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_VERTEXSHADER, m_material_vertex_shader)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_VERTEXDECL, m_material_vertex_decl)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_IMAGE, m_image)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND, m_sound)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND_CURVE, m_sound_curve)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LOADED_SOUND, m_loaded_sound)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_CLIPMAP, m_clip_map)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_COMWORLD, m_com_world)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GLASSWORLD, m_glass_world)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PATHDATA, m_path_data)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_VEHICLE_TRACK, m_vehicle_track)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MAP_ENTS, m_map_ents)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FXWORLD, m_fx_world)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GFXWORLD, m_gfx_world)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FONT, m_font)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MENULIST, m_menu_list)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MENU, m_menu_def)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_ATTACHMENT, m_attachment)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_WEAPON, m_weapon)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FX, m_fx)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SURFACE_FX, m_surface_fx_table)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_RAWFILE, m_raw_file)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SCRIPTFILE, m_script_file)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_STRINGTABLE, m_string_table)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LEADERBOARD, m_leaderboard)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_STRUCTURED_DATA_DEF, m_structed_data_def_set)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_TRACER, m_tracer)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_VEHICLE, m_vehicle)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_ADDON_MAP_ENTS, m_addon_map_ents)
default:
assert(type >= 0 && type < ASSET_TYPE_COUNT);
break;
}
#undef CASE_INIT_POOL_DYNAMIC
#undef INIT_POOL
}
XAssetInfoGeneric* GameAssetPoolIW5::AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
@ -195,7 +116,7 @@ XAssetInfoGeneric* GameAssetPoolIW5::AddAssetToPool(std::unique_ptr<XAssetInfoGe
#define CASE_ADD_TO_POOL(assetType, poolName) \
case assetType: \
{ \
assert((poolName) != nullptr); \
assert(poolName); \
return (poolName)->AddAsset(std::unique_ptr<XAssetInfo<decltype(poolName)::element_type::type>>( \
static_cast<XAssetInfo<decltype(poolName)::element_type::type>*>(xAssetInfo.release()))); \
}
@ -258,8 +179,8 @@ XAssetInfoGeneric* GameAssetPoolIW5::GetAsset(const asset_type_t type, const std
#define CASE_GET_ASSET(assetType, poolName) \
case assetType: \
{ \
if ((poolName) != nullptr) \
return (poolName)->GetAsset(std::move(name)); \
if (poolName) \
return (poolName)->GetAsset(name); \
break; \
}

View File

@ -8,14 +8,6 @@
class GameAssetPoolIW5 final : public ZoneAssetPools
{
int m_priority;
static constexpr const char* ASSET_TYPE_INVALID = "invalid_asset_type";
static const char* ASSET_TYPE_NAMES[];
protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
public:
std::unique_ptr<AssetPool<IW5::PhysPreset>> m_phys_preset;
std::unique_ptr<AssetPool<IW5::PhysCollmap>> m_phys_collmap;
@ -58,17 +50,20 @@ public:
std::unique_ptr<AssetPool<IW5::VehicleDef>> m_vehicle;
std::unique_ptr<AssetPool<IW5::AddonMapEnts>> m_addon_map_ents;
GameAssetPoolIW5(Zone* zone, int priority);
GameAssetPoolIW5(Zone* zone, zone_priority_t priority);
~GameAssetPoolIW5() override = default;
void InitPoolStatic(asset_type_t type, size_t capacity) override;
void InitPoolDynamic(asset_type_t type) override;
_NODISCARD XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
static std::optional<const char*> AssetTypeNameByType(asset_type_t assetType);
_NODISCARD std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
static asset_type_t AssetTypeCount();
_NODISCARD asset_type_t GetAssetTypeCount() const override;
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
private:
zone_priority_t m_priority;
};

View File

@ -1,14 +1,15 @@
#include "GameAssetPoolT5.h"
#include "Pool/AssetPoolDynamic.h"
#include "Pool/AssetPoolStatic.h"
#include <cassert>
#include <type_traits>
using namespace T5;
const char* GameAssetPoolT5::ASSET_TYPE_NAMES[]{
namespace
{
constexpr const char* ASSET_TYPE_NAMES[]{
"xmodelpieces", "physpreset", "physconstraints", "destructibledef", "xanim", "xmodel", "material",
"techniqueset", "image", "soundbank", "soundpatch", "clipmap", "clipmap", "comworld",
"gameworldsp", "gameworldmp", "mapents", "gfxworld", "gfxlightdef", "uimap", "font",
@ -16,125 +17,51 @@ const char* GameAssetPoolT5::ASSET_TYPE_NAMES[]{
"fx", "fximpacttable", "aitype", "mptype", "mpbody", "mphead", "character",
"xmodelalias", "rawfile", "stringtable", "packindex", "xglobals", "ddl", "glasses",
"emblemset",
};
};
}
GameAssetPoolT5::GameAssetPoolT5(Zone* zone, const int priority)
GameAssetPoolT5::GameAssetPoolT5(Zone* zone, const zone_priority_t priority)
: ZoneAssetPools(zone),
m_priority(priority)
{
assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
}
static_assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
void GameAssetPoolT5::InitPoolStatic(const asset_type_t type, const size_t capacity)
{
#define CASE_INIT_POOL_STATIC(assetType, poolName) \
case assetType: \
{ \
if ((poolName) == nullptr && capacity > 0) \
{ \
(poolName) = std::make_unique<AssetPoolStatic<decltype(poolName)::element_type::type>>(capacity, m_priority, (assetType)); \
} \
break; \
}
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
switch (type)
{
CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSPRESET, m_phys_preset)
CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints)
CASE_INIT_POOL_STATIC(ASSET_TYPE_DESTRUCTIBLEDEF, m_destructible_def)
CASE_INIT_POOL_STATIC(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
CASE_INIT_POOL_STATIC(ASSET_TYPE_XMODEL, m_xmodel)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MATERIAL, m_material)
CASE_INIT_POOL_STATIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
CASE_INIT_POOL_STATIC(ASSET_TYPE_IMAGE, m_image)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND, m_sound_bank)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND_PATCH, m_sound_patch)
CASE_INIT_POOL_STATIC(ASSET_TYPE_CLIPMAP, m_clip_map)
CASE_INIT_POOL_STATIC(ASSET_TYPE_CLIPMAP_PVS, m_clip_map)
CASE_INIT_POOL_STATIC(ASSET_TYPE_COMWORLD, m_com_world)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MAP_ENTS, m_map_ents)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GFXWORLD, m_gfx_world)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FONT, m_font)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MENULIST, m_menu_list)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MENU, m_menu_def)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
CASE_INIT_POOL_STATIC(ASSET_TYPE_WEAPON, m_weapon)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SNDDRIVER_GLOBALS, m_snd_driver_globals)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FX, m_fx)
CASE_INIT_POOL_STATIC(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
CASE_INIT_POOL_STATIC(ASSET_TYPE_RAWFILE, m_raw_file)
CASE_INIT_POOL_STATIC(ASSET_TYPE_STRINGTABLE, m_string_table)
CASE_INIT_POOL_STATIC(ASSET_TYPE_PACK_INDEX, m_pack_index)
CASE_INIT_POOL_STATIC(ASSET_TYPE_XGLOBALS, m_xglobals)
CASE_INIT_POOL_STATIC(ASSET_TYPE_DDL, m_ddl)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GLASSES, m_glasses)
CASE_INIT_POOL_STATIC(ASSET_TYPE_EMBLEMSET, m_emblem_set)
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);
default:
assert(type >= 0 && type < ASSET_TYPE_COUNT);
break;
}
#undef CASE_INIT_POOL_STATIC
}
void GameAssetPoolT5::InitPoolDynamic(const asset_type_t type)
{
#define CASE_INIT_POOL_DYNAMIC(assetType, poolName) \
case assetType: \
{ \
if ((poolName) == nullptr) \
{ \
(poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority, (assetType)); \
} \
break; \
}
switch (type)
{
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSPRESET, m_phys_preset)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_DESTRUCTIBLEDEF, m_destructible_def)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XMODEL, m_xmodel)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MATERIAL, m_material)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_IMAGE, m_image)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND, m_sound_bank)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND_PATCH, m_sound_patch)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_CLIPMAP, m_clip_map)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_CLIPMAP_PVS, m_clip_map)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_COMWORLD, m_com_world)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MAP_ENTS, m_map_ents)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GFXWORLD, m_gfx_world)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FONT, m_font)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MENULIST, m_menu_list)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MENU, m_menu_def)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_WEAPON, m_weapon)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SNDDRIVER_GLOBALS, m_snd_driver_globals)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FX, m_fx)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_RAWFILE, m_raw_file)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_STRINGTABLE, m_string_table)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PACK_INDEX, m_pack_index)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XGLOBALS, m_xglobals)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_DDL, m_ddl)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GLASSES, m_glasses)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_EMBLEMSET, m_emblem_set)
default:
assert(type >= 0 && type < ASSET_TYPE_COUNT);
break;
}
#undef CASE_INIT_POOL_DYNAMIC
#undef INIT_POOL
}
XAssetInfoGeneric* GameAssetPoolT5::AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
@ -142,7 +69,7 @@ XAssetInfoGeneric* GameAssetPoolT5::AddAssetToPool(std::unique_ptr<XAssetInfoGen
#define CASE_ADD_TO_POOL(assetType, poolName) \
case assetType: \
{ \
assert((poolName) != nullptr); \
assert(poolName); \
return (poolName)->AddAsset(std::unique_ptr<XAssetInfo<decltype(poolName)::element_type::type>>( \
static_cast<XAssetInfo<decltype(poolName)::element_type::type>*>(xAssetInfo.release()))); \
}
@ -198,8 +125,8 @@ XAssetInfoGeneric* GameAssetPoolT5::GetAsset(const asset_type_t type, const std:
#define CASE_GET_ASSET(assetType, poolName) \
case assetType: \
{ \
if ((poolName) != nullptr) \
return (poolName)->GetAsset(std::move(name)); \
if (poolName) \
return (poolName)->GetAsset(name); \
break; \
}

View File

@ -8,14 +8,6 @@
class GameAssetPoolT5 final : public ZoneAssetPools
{
int m_priority;
static constexpr const char* ASSET_TYPE_INVALID = "invalid_asset_type";
static const char* ASSET_TYPE_NAMES[];
protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
public:
std::unique_ptr<AssetPool<T5::PhysPreset>> m_phys_preset;
std::unique_ptr<AssetPool<T5::PhysConstraints>> m_phys_constraints;
@ -50,17 +42,20 @@ public:
std::unique_ptr<AssetPool<T5::Glasses>> m_glasses;
std::unique_ptr<AssetPool<T5::EmblemSet>> m_emblem_set;
GameAssetPoolT5(Zone* zone, int priority);
GameAssetPoolT5(Zone* zone, zone_priority_t priority);
~GameAssetPoolT5() override = default;
void InitPoolStatic(asset_type_t type, size_t capacity) override;
void InitPoolDynamic(asset_type_t type) override;
_NODISCARD XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
static std::optional<const char*> AssetTypeNameByType(asset_type_t assetType);
_NODISCARD std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
static asset_type_t AssetTypeCount();
_NODISCARD asset_type_t GetAssetTypeCount() const override;
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
private:
zone_priority_t m_priority;
};

View File

@ -1,14 +1,15 @@
#include "GameAssetPoolT6.h"
#include "Pool/AssetPoolDynamic.h"
#include "Pool/AssetPoolStatic.h"
#include <cassert>
#include <type_traits>
using namespace T6;
const char* GameAssetPoolT6::ASSET_TYPE_NAMES[]{
namespace
{
constexpr const char* ASSET_TYPE_NAMES[]{
"xmodelpieces",
"physpreset",
"physconstraints",
@ -69,157 +70,67 @@ const char* GameAssetPoolT6::ASSET_TYPE_NAMES[]{
"footsteptable",
"footstepfxtable",
"zbarrier",
};
};
} // namespace
GameAssetPoolT6::GameAssetPoolT6(Zone* zone, const int priority)
GameAssetPoolT6::GameAssetPoolT6(Zone* zone, const zone_priority_t priority)
: ZoneAssetPools(zone),
m_priority(priority)
{
assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
}
static_assert(std::extent_v<decltype(ASSET_TYPE_NAMES)> == ASSET_TYPE_COUNT);
void GameAssetPoolT6::InitPoolStatic(const asset_type_t type, const size_t capacity)
{
#define CASE_INIT_POOL_STATIC(assetType, poolName) \
case assetType: \
{ \
if ((poolName) == nullptr && capacity > 0) \
{ \
(poolName) = std::make_unique<AssetPoolStatic<decltype(poolName)::element_type::type>>(capacity, m_priority, (assetType)); \
} \
break; \
}
#define INIT_POOL(poolName) (poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority)
switch (type)
{
CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSPRESET, m_phys_preset)
CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints)
CASE_INIT_POOL_STATIC(ASSET_TYPE_DESTRUCTIBLEDEF, m_destructible_def)
CASE_INIT_POOL_STATIC(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
CASE_INIT_POOL_STATIC(ASSET_TYPE_XMODEL, m_xmodel)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MATERIAL, m_material)
CASE_INIT_POOL_STATIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
CASE_INIT_POOL_STATIC(ASSET_TYPE_IMAGE, m_image)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND, m_sound_bank)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND_PATCH, m_sound_patch)
CASE_INIT_POOL_STATIC(ASSET_TYPE_CLIPMAP, m_clip_map)
CASE_INIT_POOL_STATIC(ASSET_TYPE_CLIPMAP_PVS, m_clip_map)
CASE_INIT_POOL_STATIC(ASSET_TYPE_COMWORLD, m_com_world)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MAP_ENTS, m_map_ents)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GFXWORLD, m_gfx_world)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FONT, m_font)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FONTICON, m_font_icon)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MENULIST, m_menu_list)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MENU, m_menu_def)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
CASE_INIT_POOL_STATIC(ASSET_TYPE_WEAPON, m_weapon)
CASE_INIT_POOL_STATIC(ASSET_TYPE_ATTACHMENT, m_attachment)
CASE_INIT_POOL_STATIC(ASSET_TYPE_ATTACHMENT_UNIQUE, m_attachment_unique)
CASE_INIT_POOL_STATIC(ASSET_TYPE_WEAPON_CAMO, m_camo)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SNDDRIVER_GLOBALS, m_snd_driver_globals)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FX, m_fx)
CASE_INIT_POOL_STATIC(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
CASE_INIT_POOL_STATIC(ASSET_TYPE_RAWFILE, m_raw_file)
CASE_INIT_POOL_STATIC(ASSET_TYPE_STRINGTABLE, m_string_table)
CASE_INIT_POOL_STATIC(ASSET_TYPE_LEADERBOARD, m_leaderboard)
CASE_INIT_POOL_STATIC(ASSET_TYPE_XGLOBALS, m_xglobals)
CASE_INIT_POOL_STATIC(ASSET_TYPE_DDL, m_ddl)
CASE_INIT_POOL_STATIC(ASSET_TYPE_GLASSES, m_glasses)
CASE_INIT_POOL_STATIC(ASSET_TYPE_EMBLEMSET, m_emblem_set)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SCRIPTPARSETREE, m_script)
CASE_INIT_POOL_STATIC(ASSET_TYPE_KEYVALUEPAIRS, m_key_value_pairs)
CASE_INIT_POOL_STATIC(ASSET_TYPE_VEHICLEDEF, m_vehicle)
CASE_INIT_POOL_STATIC(ASSET_TYPE_MEMORYBLOCK, m_memory_block)
CASE_INIT_POOL_STATIC(ASSET_TYPE_ADDON_MAP_ENTS, m_addon_map_ents)
CASE_INIT_POOL_STATIC(ASSET_TYPE_TRACER, m_tracer)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SKINNEDVERTS, m_skinned_verts)
CASE_INIT_POOL_STATIC(ASSET_TYPE_QDB, m_qdb)
CASE_INIT_POOL_STATIC(ASSET_TYPE_SLUG, m_slug)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FOOTSTEP_TABLE, m_footstep_table)
CASE_INIT_POOL_STATIC(ASSET_TYPE_FOOTSTEPFX_TABLE, m_footstep_fx_table)
CASE_INIT_POOL_STATIC(ASSET_TYPE_ZBARRIER, m_zbarrier)
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);
default:
assert(type >= 0 && type < ASSET_TYPE_COUNT);
break;
}
#undef CASE_INIT_POOL_STATIC
}
void GameAssetPoolT6::InitPoolDynamic(const asset_type_t type)
{
#define CASE_INIT_POOL_DYNAMIC(assetType, poolName) \
case assetType: \
{ \
if ((poolName) == nullptr) \
{ \
(poolName) = std::make_unique<AssetPoolDynamic<decltype(poolName)::element_type::type>>(m_priority, (assetType)); \
} \
break; \
}
switch (type)
{
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSPRESET, m_phys_preset)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_DESTRUCTIBLEDEF, m_destructible_def)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XANIMPARTS, m_xanim_parts)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XMODEL, m_xmodel)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MATERIAL, m_material)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_IMAGE, m_image)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND, m_sound_bank)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND_PATCH, m_sound_patch)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_CLIPMAP, m_clip_map)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_CLIPMAP_PVS, m_clip_map)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_COMWORLD, m_com_world)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MAP_ENTS, m_map_ents)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GFXWORLD, m_gfx_world)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FONT, m_font)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FONTICON, m_font_icon)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MENULIST, m_menu_list)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MENU, m_menu_def)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LOCALIZE_ENTRY, m_localize)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_WEAPON, m_weapon)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_ATTACHMENT, m_attachment)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_ATTACHMENT_UNIQUE, m_attachment_unique)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_WEAPON_CAMO, m_camo)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SNDDRIVER_GLOBALS, m_snd_driver_globals)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FX, m_fx)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_IMPACT_FX, m_fx_impact_table)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_RAWFILE, m_raw_file)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_STRINGTABLE, m_string_table)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LEADERBOARD, m_leaderboard)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_XGLOBALS, m_xglobals)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_DDL, m_ddl)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_GLASSES, m_glasses)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_EMBLEMSET, m_emblem_set)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SCRIPTPARSETREE, m_script)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_KEYVALUEPAIRS, m_key_value_pairs)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_VEHICLEDEF, m_vehicle)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_MEMORYBLOCK, m_memory_block)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_ADDON_MAP_ENTS, m_addon_map_ents)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_TRACER, m_tracer)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SKINNEDVERTS, m_skinned_verts)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_QDB, m_qdb)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SLUG, m_slug)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FOOTSTEP_TABLE, m_footstep_table)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_FOOTSTEPFX_TABLE, m_footstep_fx_table)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_ZBARRIER, m_zbarrier)
default:
assert(type >= 0 && type < ASSET_TYPE_COUNT);
break;
}
#undef CASE_INIT_POOL_DYNAMIC
#undef INIT_POOL
}
XAssetInfoGeneric* GameAssetPoolT6::AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
@ -227,7 +138,7 @@ XAssetInfoGeneric* GameAssetPoolT6::AddAssetToPool(std::unique_ptr<XAssetInfoGen
#define CASE_ADD_TO_POOL(assetType, poolName) \
case assetType: \
{ \
assert((poolName) != nullptr); \
assert(poolName); \
return (poolName)->AddAsset(std::unique_ptr<XAssetInfo<decltype(poolName)::element_type::type>>( \
static_cast<XAssetInfo<decltype(poolName)::element_type::type>*>(xAssetInfo.release()))); \
}
@ -299,7 +210,7 @@ XAssetInfoGeneric* GameAssetPoolT6::GetAsset(const asset_type_t type, const std:
#define CASE_GET_ASSET(assetType, poolName) \
case assetType: \
{ \
if ((poolName) != nullptr) \
if (poolName) \
return (poolName)->GetAsset(name); \
break; \
}

View File

@ -8,14 +8,6 @@
class GameAssetPoolT6 final : public ZoneAssetPools
{
int m_priority;
static constexpr const char* ASSET_TYPE_INVALID = "invalid_asset_type";
static const char* ASSET_TYPE_NAMES[];
protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
public:
std::unique_ptr<AssetPool<T6::PhysPreset>> m_phys_preset;
std::unique_ptr<AssetPool<T6::PhysConstraints>> m_phys_constraints;
@ -66,17 +58,20 @@ public:
std::unique_ptr<AssetPool<T6::FootstepFXTableDef>> m_footstep_fx_table;
std::unique_ptr<AssetPool<T6::ZBarrierDef>> m_zbarrier;
GameAssetPoolT6(Zone* zone, int priority);
GameAssetPoolT6(Zone* zone, zone_priority_t priority);
~GameAssetPoolT6() override = default;
void InitPoolStatic(asset_type_t type, size_t capacity) override;
void InitPoolDynamic(asset_type_t type) override;
_NODISCARD XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
[[nodiscard]] XAssetInfoGeneric* GetAsset(asset_type_t type, const std::string& name) const override;
static std::optional<const char*> AssetTypeNameByType(asset_type_t assetType);
_NODISCARD std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
static asset_type_t AssetTypeCount();
_NODISCARD asset_type_t GetAssetTypeCount() const override;
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
protected:
XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
private:
zone_priority_t m_priority;
};

View File

@ -4,20 +4,18 @@
#include "GlobalAssetPool.h"
#include "XAssetInfo.h"
#include <cstring>
#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;
asset_type_t m_type;
public:
AssetPoolDynamic(const int priority, const asset_type_t type)
explicit AssetPoolDynamic(const zone_priority_t priority)
{
GlobalAssetPool<T>::LinkAssetPool(this, priority);
m_type = type;
}
AssetPoolDynamic(AssetPoolDynamic<T>&) = delete;

View File

@ -1,104 +0,0 @@
#pragma once
#include "AssetPool.h"
#include "GlobalAssetPool.h"
#include "XAssetInfo.h"
#include <cstring>
#include <stdexcept>
template<typename T> class AssetPoolStatic final : public AssetPool<T>
{
using AssetPool<T>::m_asset_lookup;
struct AssetPoolEntry
{
XAssetInfo<T>* m_info;
union
{
T m_entry;
AssetPoolEntry* m_next;
};
};
AssetPoolEntry* m_free;
AssetPoolEntry* m_pool;
XAssetInfo<T>* m_info_pool;
size_t m_capacity;
asset_type_t m_type;
public:
AssetPoolStatic(const size_t capacity, const int priority, const asset_type_t type)
{
m_capacity = capacity;
m_type = type;
if (m_capacity > 0)
{
m_pool = new AssetPoolEntry[m_capacity];
m_info_pool = new XAssetInfo<T>[m_capacity];
for (size_t i = 0; i < m_capacity - 1; i++)
{
m_pool[i].m_info = &m_info_pool[i];
m_pool[i].m_next = &m_pool[i + 1];
}
m_pool[m_capacity - 1].m_info = &m_info_pool[m_capacity - 1];
m_pool[m_capacity - 1].m_next = nullptr;
m_free = m_pool;
GlobalAssetPool<T>::LinkAssetPool(this, priority);
}
else
{
m_pool = nullptr;
m_free = nullptr;
m_info_pool = nullptr;
}
}
AssetPoolStatic(AssetPoolStatic<T>&) = delete;
AssetPoolStatic(AssetPoolStatic<T>&&) = delete;
AssetPoolStatic<T>& operator=(AssetPoolStatic<T>&) = delete;
AssetPoolStatic<T>& operator=(AssetPoolStatic<T>&&) = default;
~AssetPoolStatic() override
{
if (m_capacity > 0)
GlobalAssetPool<T>::UnlinkAssetPool(this);
delete[] m_pool;
m_pool = nullptr;
delete[] m_info_pool;
m_info_pool = nullptr;
m_free = nullptr;
m_capacity = 0;
}
XAssetInfo<T>* AddAsset(std::unique_ptr<XAssetInfo<T>> xAssetInfo) override
{
if (m_free == nullptr)
throw std::runtime_error("Could not add asset to static asset pool: capacity exhausted.");
const auto normalizedName = XAssetInfo<T>::NormalizeAssetName(xAssetInfo->m_name);
AssetPoolEntry* poolSlot = m_free;
m_free = m_free->m_next;
const T* pAsset = xAssetInfo->Asset();
xAssetInfo->m_ptr = static_cast<void*>(&poolSlot->m_entry);
memcpy(&poolSlot->m_entry, pAsset, sizeof(T));
*poolSlot->m_info = std::move(*xAssetInfo);
m_asset_lookup[normalizedName] = poolSlot->m_info;
GlobalAssetPool<T>::LinkAsset(this, normalizedName, poolSlot->m_info);
return poolSlot->m_info;
}
};

View File

@ -1,6 +1,7 @@
#pragma once
#include "AssetPool.h"
#include "Zone/ZoneTypes.h"
#include <algorithm>
#include <cassert>
@ -14,7 +15,7 @@ template<typename T> class GlobalAssetPool
struct LinkedAssetPool
{
AssetPool<T>* m_asset_pool;
int m_priority;
zone_priority_t m_priority;
};
struct GameAssetPoolEntry
@ -92,7 +93,7 @@ template<typename T> class GlobalAssetPool
}
public:
static void LinkAssetPool(AssetPool<T>* assetPool, const int priority)
static void LinkAssetPool(AssetPool<T>* assetPool, const zone_priority_t priority)
{
auto newLink = std::make_unique<LinkedAssetPool>();
newLink->m_asset_pool = assetPool;

View File

@ -16,12 +16,6 @@ class XAssetInfoGeneric;
class ZoneAssetPools
{
protected:
Zone* m_zone;
std::vector<XAssetInfoGeneric*> m_assets_in_order;
virtual XAssetInfoGeneric* AddAssetToPool(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) = 0;
public:
using iterator = std::vector<XAssetInfoGeneric*>::const_iterator;
@ -45,13 +39,16 @@ public:
_NODISCARD virtual asset_type_t GetAssetTypeCount() const = 0;
_NODISCARD virtual std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const = 0;
virtual void InitPoolStatic(asset_type_t type, size_t capacity) = 0;
virtual void InitPoolDynamic(asset_type_t type) = 0;
_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;
};

View File

@ -9,9 +9,6 @@ Zone::Zone(std::string name, const zone_priority_t priority, IGame* game)
m_game(game),
m_pools(ZoneAssetPools::CreateForGame(game->GetId(), this, priority))
{
const auto assetTypeCount = m_pools->GetAssetTypeCount();
for (auto i = 0; i < assetTypeCount; i++)
m_pools->InitPoolDynamic(i);
}
Zone::~Zone()

View File

@ -126,11 +126,6 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
if (atStreamStart)
m_stream->Load<XAsset>(varXAsset, count);
for (asset_type_t assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
{
m_zone->m_pools->InitPoolDynamic(assetType);
}
for (size_t index = 0; index < count; index++)
{
LoadXAsset(false);

View File

@ -146,11 +146,6 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
if (atStreamStart)
m_stream->Load<XAsset>(varXAsset, count);
for (asset_type_t assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
{
m_zone->m_pools->InitPoolDynamic(assetType);
}
for (size_t index = 0; index < count; index++)
{
LoadXAsset(false);

View File

@ -155,11 +155,6 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
if (atStreamStart)
m_stream->Load<XAsset>(varXAsset, count);
for (asset_type_t assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
{
m_zone->m_pools->InitPoolDynamic(assetType);
}
for (size_t index = 0; index < count; index++)
{
LoadXAsset(false);

View File

@ -139,11 +139,6 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
if (atStreamStart)
m_stream->Load<XAsset>(varXAsset, count);
for (asset_type_t assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
{
m_zone->m_pools->InitPoolDynamic(assetType);
}
for (size_t index = 0; index < count; index++)
{
LoadXAsset(false);

View File

@ -168,11 +168,6 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
if (atStreamStart)
m_stream->Load<XAsset>(varXAsset, count);
for (asset_type_t assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
{
m_zone->m_pools->InitPoolDynamic(assetType);
}
for (size_t index = 0; index < count; index++)
{
LoadXAsset(false);