ZoneLoading: Properly link assets as dependencies instead of only saving the name of the dependency

This commit is contained in:
Jan 2020-02-18 13:16:39 +01:00
parent 246d74992c
commit 992e9cea30
16 changed files with 159 additions and 61 deletions

View File

@ -130,7 +130,7 @@ void ObjLoaderT6::LoadReferencedContainersForZone(ISearchPath* searchPath, Zone*
{
for(auto* keyValuePairsEntry : *assetPoolT6->m_key_value_pairs)
{
auto* keyValuePairs = keyValuePairsEntry->m_asset;
auto* keyValuePairs = keyValuePairsEntry->Asset();
for(int variableIndex = 0; variableIndex < keyValuePairs->numVariables; variableIndex++)
{
T6::KeyValuePair* variable = &keyValuePairs->keyValuePairs[variableIndex];
@ -217,7 +217,7 @@ void ObjLoaderT6::LoadImageData(ISearchPath* searchPath, Zone* zone)
{
for (auto* imageEntry : *assetPoolT6->m_image)
{
auto* image = imageEntry->m_asset;
auto* image = imageEntry->Asset();
if(image->loadedSize > 0)
{

View File

@ -19,13 +19,15 @@ public:
{
for(auto assetInfo : *pool)
{
T* asset = assetInfo->Asset();
if(assetInfo->m_name[0] == ','
|| !ShouldDump(assetInfo->m_asset))
|| !ShouldDump(asset))
{
continue;
}
std::string assetFilePath = utils::Path::Combine(basePath, GetFileNameForAsset(zone, assetInfo->m_asset));
std::string assetFilePath = utils::Path::Combine(basePath, GetFileNameForAsset(zone, asset));
FileAPI::DirectoryCreate(utils::Path::GetDirectory(assetFilePath));
@ -33,7 +35,7 @@ public:
if(file.IsOpen())
{
DumpAsset(zone, assetInfo->m_asset, &file);
DumpAsset(zone, asset, &file);
file.Close();
}

View File

@ -61,7 +61,7 @@ std::string AssetDumperLocalizeEntry::GetNameOfLanguage(GameLanguage language)
void AssetDumperLocalizeEntry::DumpPool(Zone* zone, AssetPool<LocalizeEntry>* pool, const std::string& basePath)
{
if (pool->m_asset_lookup.size() == 0)
if (pool->m_asset_lookup.empty())
return;
const std::string language = GetNameOfLanguage(zone->m_language);
@ -84,7 +84,7 @@ void AssetDumperLocalizeEntry::DumpPool(Zone* zone, AssetPool<LocalizeEntry>* po
for(auto localizeEntry : *pool)
{
stringFileDumper.WriteLocalizeEntry(localizeEntry->m_asset->name, localizeEntry->m_asset->value);
stringFileDumper.WriteLocalizeEntry(localizeEntry->m_name, localizeEntry->Asset()->value);
}
stringFileDumper.Finalize();

View File

@ -90,7 +90,7 @@ $endif$
LoadPointerArrayMethod_Asset(context, type, structure) ::= <<
$LoaderClassName(structure)$ loader(m_script_string_provider, m_zone, m_stream);
loader.Load($TypePtrVarName(type)$);
AddDependency(loader.Load($TypePtrVarName(type)$));
>>
LoadPointerArrayMethod_PointerCheck(context, type, structure, reusable) ::= <<

View File

@ -39,7 +39,7 @@ $endif$
LoadSinglePointerAsset(context, structure, member, reference) ::= <<
$LoaderClassName(member.StructureType)$ loader(m_script_string_provider, m_zone, m_stream);
loader.Load(&$TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$);
AddDependency(loader.Load(&$TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$));
>>
LoadSinglePointer_Reuse(context, structure, member, reference) ::= <<

View File

@ -21,7 +21,7 @@ HeaderLoadMethodDeclaration(structure) ::= "void Load_$structure.Type.Name$(bool
HeaderGetNameMethodDeclaration(asset) ::= "static std::string GetAssetName($asset.Type.FullName$* pAsset);"
HeaderAssetLoadMethodDeclaration(asset) ::= "void LoadAsset_$asset.Type.Name$($asset.Type.FullName$** pAsset);"
HeaderMainLoadMethodDeclaration(asset) ::= "void Load($asset.Type.FullName$** pAsset);"
HeaderMainLoadMethodDeclaration(asset) ::= "XAssetInfo<$asset.Type.FullName$>* Load($asset.Type.FullName$** pAsset);"
VariableDeclaration(type) ::= <<
$type.FullName$* var$SafeTypeName(type)$;
@ -54,6 +54,7 @@ namespace $context.Game$
{
class $LoaderClassName(context.Asset)$ final : public AssetLoader
{
XAssetInfo<$context.Asset.Type.FullName$>* m_asset_info;
$if(context.HasActions)$
Actions_$context.Asset.Type.Name$ m_actions;
$endif$
@ -287,6 +288,7 @@ $LoaderClassName(context.Asset)$::$LoaderClassName(context.Asset)$(IZoneScriptSt
: AssetLoader($context.Asset.AssetEnumEntry.Name$, scriptStringProvider, zone, stream)$\\$
$if(context.HasActions)$, m_actions(zone)$endif$
{
m_asset_info = nullptr;
$VariableInitialization(context.Asset.Type)$
$PointerVariableInitialization(context.Asset.Type)$
@ -301,17 +303,25 @@ LoadAssetMethod(context, structure) ::= <<
void $LoaderClassName(context.Asset)$::LoadAsset_$structure.Type.Name$($structure.Type.FullName$** pAsset)
{
assert(pAsset != nullptr);
*pAsset = static_cast<$structure.Type.FullName$*>(LinkAsset(GetAssetName(*pAsset), *pAsset));
m_asset_info = reinterpret_cast<XAssetInfo<$structure.Type.FullName$>*>(LinkAsset(GetAssetName(*pAsset), *pAsset));
*pAsset = m_asset_info->Asset();
}
>>
MainLoadMethod(context) ::= <<
void $LoaderClassName(context.Asset)$::Load($context.Asset.Type.FullName$** pAsset)
XAssetInfo<$context.Asset.Type.FullName$>* $LoaderClassName(context.Asset)$::Load($context.Asset.Type.FullName$** pAsset)
{
assert(pAsset != nullptr);
m_asset_info = nullptr;
$TypePtrVarName(context.Asset.Type)$ = pAsset;
LoadPtr_$context.Asset.Type.Name$(false);
if(m_asset_info == nullptr && *pAsset != nullptr)
m_asset_info = reinterpret_cast<XAssetInfo<$context.Asset.Type.FullName$>*>(GetAssetInfo(GetAssetName(*pAsset)));
return m_asset_info;
}
>>

View File

@ -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
}
}

View File

@ -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;
};

View File

@ -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)
{

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);
}
};

View File

@ -1,9 +0,0 @@
#pragma once
#include <string>
class XAssetDependency
{
public:
int m_type;
std::string m_name;
};

View File

@ -10,22 +10,18 @@ AssetLoader::AssetLoader(const asset_type_t assetType, IZoneScriptStringProvider
varScriptString = nullptr;
}
void AssetLoader::AddDependency(const asset_type_t type, std::string& name)
void AssetLoader::AddDependency(XAssetInfoGeneric* assetInfo)
{
for(auto& existingDependency : m_dependencies)
if (assetInfo == nullptr)
return;
const auto existingEntry = std::find(m_dependencies.begin(), m_dependencies.end(), assetInfo);
if(existingEntry != m_dependencies.end())
{
if(existingDependency.m_type == type
&& existingDependency.m_name == name)
{
return;
}
return;
}
XAssetDependency dependency;
dependency.m_type = type;
dependency.m_name = name;
m_dependencies.push_back(dependency);
m_dependencies.push_back(assetInfo);
}
scr_string_t AssetLoader::UseScriptString(const scr_string_t scrString)
@ -63,7 +59,12 @@ void AssetLoader::LoadScriptStringArray(const bool atStreamStart, const size_t c
}
}
void* AssetLoader::LinkAsset(std::string name, void* asset)
XAssetInfoGeneric* AssetLoader::LinkAsset(std::string name, void* asset)
{
return m_zone->GetPools()->AddAsset(m_asset_type, std::move(name), asset, m_used_script_strings, m_dependencies);
}
return m_zone->GetPools()->AddAsset(m_asset_type, std::move(name), asset, m_used_script_strings, m_dependencies);;
}
XAssetInfoGeneric* AssetLoader::GetAssetInfo(std::string name) const
{
return m_zone->GetPools()->GetAsset(m_asset_type, std::move(name));
}

View File

@ -1,7 +1,7 @@
#pragma once
#include "Pool/XAssetInfo.h"
#include "ContentLoader.h"
#include "IZoneScriptStringProvider.h"
#include "Zone/XAssetDependency.h"
class AssetLoader : public ContentLoader
{
@ -9,7 +9,7 @@ class AssetLoader : public ContentLoader
std::vector<std::string> m_used_script_strings;
std::vector<XAssetDependency> m_dependencies;
std::vector<XAssetInfoGeneric*> m_dependencies;
protected:
IZoneScriptStringProvider* m_script_string_provider;
@ -18,10 +18,12 @@ protected:
AssetLoader(asset_type_t assetType, IZoneScriptStringProvider* scriptStringProvider, Zone* zone, IZoneInputStream* stream);
void AddDependency(asset_type_t type, std::string& name);
void AddDependency(XAssetInfoGeneric* assetInfo);
scr_string_t UseScriptString(scr_string_t scrString);
void LoadScriptStringArray(bool atStreamStart, size_t count);
void* LinkAsset(std::string name, void* asset);
XAssetInfoGeneric* LinkAsset(std::string name, void* asset);
XAssetInfoGeneric* GetAssetInfo(std::string name) const;
};