mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-13 16:28:31 -05:00
ZoneLoading: Properly link assets as dependencies instead of only saving the name of the dependency
This commit is contained in:
@ -123,7 +123,7 @@ void GameAssetPoolT6::InitPoolStatic(const asset_type_t type, const size_t capac
|
||||
{ \
|
||||
if((poolName) == nullptr && capacity > 0) \
|
||||
{ \
|
||||
(poolName) = new AssetPoolStatic<poolType>(capacity, m_priority); \
|
||||
(poolName) = new AssetPoolStatic<poolType>(capacity, m_priority, (assetType)); \
|
||||
} \
|
||||
break; \
|
||||
}
|
||||
@ -195,7 +195,7 @@ void GameAssetPoolT6::InitPoolDynamic(const asset_type_t type)
|
||||
{ \
|
||||
if((poolName) == nullptr) \
|
||||
{ \
|
||||
(poolName) = new AssetPoolDynamic<poolType>(m_priority); \
|
||||
(poolName) = new AssetPoolDynamic<poolType>(m_priority, (assetType)); \
|
||||
} \
|
||||
break; \
|
||||
}
|
||||
@ -260,7 +260,7 @@ void GameAssetPoolT6::InitPoolDynamic(const asset_type_t type)
|
||||
#undef CASE_INIT_POOL_STATIC
|
||||
}
|
||||
|
||||
void* GameAssetPoolT6::AddAsset(asset_type_t type, std::string name, void* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetDependency>& dependencies)
|
||||
XAssetInfoGeneric* GameAssetPoolT6::AddAsset(asset_type_t type, std::string name, void* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies)
|
||||
{
|
||||
XAsset xAsset{};
|
||||
|
||||
@ -271,7 +271,7 @@ void* GameAssetPoolT6::AddAsset(asset_type_t type, std::string name, void* asset
|
||||
case assetType: \
|
||||
{ \
|
||||
assert((poolName) != nullptr); \
|
||||
return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, scriptStrings, dependencies)->m_asset; \
|
||||
return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, scriptStrings, dependencies); \
|
||||
}
|
||||
|
||||
switch(xAsset.type)
|
||||
@ -336,6 +336,78 @@ void* GameAssetPoolT6::AddAsset(asset_type_t type, std::string name, void* asset
|
||||
#undef CASE_ADD_TO_POOL
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* GameAssetPoolT6::GetAsset(const asset_type_t type, std::string name)
|
||||
{
|
||||
#define CASE_GET_ASSET(assetType, poolName) \
|
||||
case assetType: \
|
||||
{ \
|
||||
if((poolName) != nullptr) \
|
||||
return (poolName)->GetAsset(std::move(name)); \
|
||||
break; \
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
CASE_GET_ASSET(ASSET_TYPE_PHYSPRESET, m_phys_preset);
|
||||
CASE_GET_ASSET(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints);
|
||||
CASE_GET_ASSET(ASSET_TYPE_DESTRUCTIBLEDEF, m_destructible_def);
|
||||
CASE_GET_ASSET(ASSET_TYPE_XANIMPARTS, m_xanim_parts);
|
||||
CASE_GET_ASSET(ASSET_TYPE_XMODEL, m_xmodel);
|
||||
CASE_GET_ASSET(ASSET_TYPE_MATERIAL, m_material);
|
||||
CASE_GET_ASSET(ASSET_TYPE_TECHNIQUE_SET, m_technique_set);
|
||||
CASE_GET_ASSET(ASSET_TYPE_IMAGE, m_image);
|
||||
CASE_GET_ASSET(ASSET_TYPE_SOUND, m_sound_bank);
|
||||
CASE_GET_ASSET(ASSET_TYPE_SOUND_PATCH, m_sound_patch);
|
||||
CASE_GET_ASSET(ASSET_TYPE_CLIPMAP, m_clip_map);
|
||||
CASE_GET_ASSET(ASSET_TYPE_CLIPMAP_PVS, m_clip_map);
|
||||
CASE_GET_ASSET(ASSET_TYPE_COMWORLD, m_com_world);
|
||||
CASE_GET_ASSET(ASSET_TYPE_GAMEWORLD_SP, m_game_world_sp);
|
||||
CASE_GET_ASSET(ASSET_TYPE_GAMEWORLD_MP, m_game_world_mp);
|
||||
CASE_GET_ASSET(ASSET_TYPE_MAP_ENTS, m_map_ents);
|
||||
CASE_GET_ASSET(ASSET_TYPE_GFXWORLD, m_gfx_world);
|
||||
CASE_GET_ASSET(ASSET_TYPE_LIGHT_DEF, m_gfx_light_def);
|
||||
CASE_GET_ASSET(ASSET_TYPE_FONT, m_font);
|
||||
CASE_GET_ASSET(ASSET_TYPE_FONTICON, m_font_icon);
|
||||
CASE_GET_ASSET(ASSET_TYPE_MENULIST, m_menu_list);
|
||||
CASE_GET_ASSET(ASSET_TYPE_MENU, m_menu_def);
|
||||
CASE_GET_ASSET(ASSET_TYPE_LOCALIZE_ENTRY, m_localize);
|
||||
CASE_GET_ASSET(ASSET_TYPE_WEAPON, m_weapon);
|
||||
CASE_GET_ASSET(ASSET_TYPE_ATTACHMENT, m_attachment);
|
||||
CASE_GET_ASSET(ASSET_TYPE_ATTACHMENT_UNIQUE, m_attachment_unique);
|
||||
CASE_GET_ASSET(ASSET_TYPE_WEAPON_CAMO, m_camo);
|
||||
CASE_GET_ASSET(ASSET_TYPE_SNDDRIVER_GLOBALS, m_snd_driver_globals);
|
||||
CASE_GET_ASSET(ASSET_TYPE_FX, m_fx);
|
||||
CASE_GET_ASSET(ASSET_TYPE_IMPACT_FX, m_fx_impact_table);
|
||||
CASE_GET_ASSET(ASSET_TYPE_RAWFILE, m_raw_file);
|
||||
CASE_GET_ASSET(ASSET_TYPE_STRINGTABLE, m_string_table);
|
||||
CASE_GET_ASSET(ASSET_TYPE_LEADERBOARD, m_leaderboard);
|
||||
CASE_GET_ASSET(ASSET_TYPE_XGLOBALS, m_xglobals);
|
||||
CASE_GET_ASSET(ASSET_TYPE_DDL, m_ddl);
|
||||
CASE_GET_ASSET(ASSET_TYPE_GLASSES, m_glasses);
|
||||
CASE_GET_ASSET(ASSET_TYPE_EMBLEMSET, m_emblem_set);
|
||||
CASE_GET_ASSET(ASSET_TYPE_SCRIPTPARSETREE, m_script);
|
||||
CASE_GET_ASSET(ASSET_TYPE_KEYVALUEPAIRS, m_key_value_pairs);
|
||||
CASE_GET_ASSET(ASSET_TYPE_VEHICLEDEF, m_vehicle);
|
||||
CASE_GET_ASSET(ASSET_TYPE_MEMORYBLOCK, m_memory_block);
|
||||
CASE_GET_ASSET(ASSET_TYPE_ADDON_MAP_ENTS, m_addon_map_ents);
|
||||
CASE_GET_ASSET(ASSET_TYPE_TRACER, m_tracer);
|
||||
CASE_GET_ASSET(ASSET_TYPE_SKINNEDVERTS, m_skinned_verts);
|
||||
CASE_GET_ASSET(ASSET_TYPE_QDB, m_qdb);
|
||||
CASE_GET_ASSET(ASSET_TYPE_SLUG, m_slug);
|
||||
CASE_GET_ASSET(ASSET_TYPE_FOOTSTEP_TABLE, m_footstep_table);
|
||||
CASE_GET_ASSET(ASSET_TYPE_FOOTSTEPFX_TABLE, m_footstep_fx_table);
|
||||
CASE_GET_ASSET(ASSET_TYPE_ZBARRIER, m_zbarrier);
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
#undef CASE_GET_ASSET
|
||||
}
|
||||
|
||||
ZoneContent GameAssetPoolT6::GetContent() const
|
||||
{
|
||||
ZoneContent content{};
|
||||
@ -403,4 +475,4 @@ ZoneContent GameAssetPoolT6::GetContent() const
|
||||
return content;
|
||||
|
||||
#undef POOL_ADD_TO_CONTENT
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Pool/AssetPool.h"
|
||||
#include "Pool/IZoneAssetPools.h"
|
||||
#include "Pool/AssetPool.h"
|
||||
#include "T6.h"
|
||||
|
||||
class GameAssetPoolT6 final : public IZoneAssetPools
|
||||
@ -64,7 +64,8 @@ public:
|
||||
void InitPoolStatic(asset_type_t type, size_t capacity) override;
|
||||
void InitPoolDynamic(asset_type_t type) override;
|
||||
|
||||
void* AddAsset(asset_type_t type, std::string name, void* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetDependency>& dependencies) override;
|
||||
XAssetInfoGeneric* AddAsset(asset_type_t type, std::string name, void* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) override;
|
||||
XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) override;
|
||||
|
||||
ZoneContent GetContent() const override;
|
||||
};
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
|
||||
virtual ~AssetPool() = default;
|
||||
|
||||
virtual XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetDependency>& dependencies) = 0;
|
||||
virtual XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) = 0;
|
||||
|
||||
XAssetInfo<T>* GetAsset(const std::string& name)
|
||||
{
|
||||
|
@ -12,11 +12,13 @@ class AssetPoolDynamic final : public AssetPool<T>
|
||||
using AssetPool<T>::m_asset_lookup;
|
||||
|
||||
std::vector<XAssetInfo<T>*> m_assets;
|
||||
asset_type_t m_type;
|
||||
|
||||
public:
|
||||
explicit AssetPoolDynamic(const int priority)
|
||||
AssetPoolDynamic(const int priority, const asset_type_t type)
|
||||
{
|
||||
GlobalAssetPool<T>::LinkAssetPool(this, priority);
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
AssetPoolDynamic(AssetPoolDynamic<T>&) = delete;
|
||||
@ -30,7 +32,7 @@ public:
|
||||
|
||||
for(auto* entry : m_assets)
|
||||
{
|
||||
delete entry->m_asset;
|
||||
delete entry->m_ptr;
|
||||
delete entry;
|
||||
}
|
||||
|
||||
@ -38,16 +40,17 @@ public:
|
||||
m_asset_lookup.clear();
|
||||
}
|
||||
|
||||
XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetDependency>& dependencies) override
|
||||
XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) override
|
||||
{
|
||||
auto* newInfo = new XAssetInfo<T>();
|
||||
newInfo->m_type = m_type;
|
||||
newInfo->m_name = std::move(name);
|
||||
newInfo->m_script_strings = std::move(scriptStrings);
|
||||
newInfo->m_dependencies = std::move(dependencies);
|
||||
|
||||
T* newAsset = new T();
|
||||
memcpy(newAsset, asset, sizeof(T));
|
||||
newInfo->m_asset = newAsset;
|
||||
newInfo->m_ptr = newAsset;
|
||||
|
||||
m_assets.push_back(newInfo);
|
||||
m_asset_lookup[newInfo->m_name] = newInfo;
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "GlobalAssetPool.h"
|
||||
#include "AssetPool.h"
|
||||
#include "XAssetInfo.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@ -25,9 +26,10 @@ class AssetPoolStatic final : public AssetPool<T>
|
||||
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)
|
||||
AssetPoolStatic(const size_t capacity, const int priority, asset_type_t type)
|
||||
{
|
||||
m_capacity = capacity;
|
||||
|
||||
@ -78,7 +80,7 @@ public:
|
||||
m_capacity = 0;
|
||||
}
|
||||
|
||||
XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetDependency>& dependencies) override
|
||||
XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) override
|
||||
{
|
||||
if(m_free == nullptr)
|
||||
{
|
||||
@ -90,8 +92,9 @@ public:
|
||||
|
||||
memcpy(&poolSlot->m_entry, asset, sizeof(T));
|
||||
|
||||
poolSlot->m_info->m_type = m_type;
|
||||
poolSlot->m_info->m_name = std::move(name);
|
||||
poolSlot->m_info->m_asset = &poolSlot->m_entry;
|
||||
poolSlot->m_info->m_ptr = &poolSlot->m_entry;
|
||||
poolSlot->m_info->m_script_strings = std::move(scriptStrings);
|
||||
poolSlot->m_info->m_dependencies = std::move(dependencies);
|
||||
|
||||
|
@ -3,13 +3,16 @@
|
||||
#include "XAssetInfo.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
#include "Zone/ZoneContent.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class IZoneAssetPools
|
||||
{
|
||||
public:
|
||||
virtual ~IZoneAssetPools() = default;
|
||||
|
||||
virtual void* AddAsset(asset_type_t type, std::string name, void* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetDependency>& dependencies) = 0;
|
||||
virtual XAssetInfoGeneric* AddAsset(asset_type_t type, std::string name, void* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) = 0;
|
||||
virtual XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) = 0;
|
||||
virtual void InitPoolStatic(asset_type_t type, size_t capacity) = 0;
|
||||
virtual void InitPoolDynamic(asset_type_t type) = 0;
|
||||
virtual ZoneContent GetContent() const = 0;
|
||||
|
@ -1,13 +1,23 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "Zone/XAssetDependency.h"
|
||||
#include <string>
|
||||
|
||||
template<typename T>
|
||||
class XAssetInfo
|
||||
class XAssetInfoGeneric
|
||||
{
|
||||
public:
|
||||
int m_type = -1;
|
||||
std::string m_name;
|
||||
T* m_asset;
|
||||
std::vector<std::string> m_script_strings;
|
||||
std::vector<XAssetDependency> m_dependencies;
|
||||
std::vector<XAssetInfoGeneric*> m_dependencies;
|
||||
void* m_ptr;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class XAssetInfo : public XAssetInfoGeneric
|
||||
{
|
||||
public:
|
||||
T* Asset()
|
||||
{
|
||||
return static_cast<T*>(m_ptr);
|
||||
}
|
||||
};
|
||||
|
@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
class XAssetDependency
|
||||
{
|
||||
public:
|
||||
int m_type;
|
||||
std::string m_name;
|
||||
};
|
Reference in New Issue
Block a user