feat: recognize indirect asset refs when marking assets

This commit is contained in:
Jan
2024-02-07 00:53:52 +01:00
parent 2dd4eaf54f
commit fef815e708
14 changed files with 175 additions and 10 deletions

View File

@ -10,12 +10,14 @@ AssetLoader::AssetLoader(const asset_type_t assetType, Zone* zone, IZoneInputStr
{
}
XAssetInfoGeneric*
AssetLoader::LinkAsset(std::string name, void* asset, std::vector<scr_string_t> scriptStrings, std::vector<XAssetInfoGeneric*> dependencies) const
XAssetInfoGeneric* AssetLoader::LinkAsset(std::string name,
void* asset,
std::vector<XAssetInfoGeneric*> dependencies,
std::vector<scr_string_t> scriptStrings,
std::vector<IndirectAssetReference> indirectAssetReferences) const
{
// TODO: Add indirect asset references here
return m_zone->m_pools->AddAsset(
m_asset_type, std::move(name), asset, std::move(dependencies), std::move(scriptStrings), std::vector<IndirectAssetReference>());
m_asset_type, std::move(name), asset, std::move(dependencies), std::move(scriptStrings), std::move(indirectAssetReferences));
}
XAssetInfoGeneric* AssetLoader::GetAssetInfo(std::string name) const

View File

@ -16,7 +16,11 @@ protected:
AssetLoader(asset_type_t assetType, Zone* zone, IZoneInputStream* stream);
XAssetInfoGeneric* LinkAsset(std::string name, void* asset, std::vector<scr_string_t> scriptStrings, std::vector<XAssetInfoGeneric*> dependencies) const;
XAssetInfoGeneric* LinkAsset(std::string name,
void* asset,
std::vector<XAssetInfoGeneric*> dependencies,
std::vector<scr_string_t> scriptStrings,
std::vector<IndirectAssetReference> indirectAssetReferences) const;
_NODISCARD XAssetInfoGeneric* GetAssetInfo(std::string name) const;
};

View File

@ -39,6 +39,22 @@ void AssetMarker::MarkArray_ScriptString(const scr_string_t* scrStringArray, con
Mark_ScriptString(scrStringArray[index]);
}
void AssetMarker::Mark_IndirectAssetRef(asset_type_t type, const char* assetRefName)
{
if (!assetRefName || !assetRefName[0])
return;
m_indirect_asset_references.emplace(type, assetRefName);
}
void AssetMarker::MarkArray_IndirectAssetRef(const asset_type_t type, const char** assetRefNames, const size_t count)
{
assert(assetRefNames != nullptr);
for (size_t index = 0; index < count; index++)
Mark_IndirectAssetRef(type, assetRefNames[index]);
}
XAssetInfoGeneric* AssetMarker::GetAssetInfoByName(std::string name) const
{
return m_zone->m_pools->GetAsset(m_asset_type, std::move(name));
@ -71,3 +87,16 @@ std::vector<scr_string_t> AssetMarker::GetUsedScriptStrings() const
return usedScriptStrings;
}
std::vector<IndirectAssetReference> AssetMarker::GetIndirectAssetReferences() const
{
std::vector<IndirectAssetReference> assetReferences;
if (!m_indirect_asset_references.empty())
{
assetReferences.reserve(m_indirect_asset_references.size());
for (const auto& assetReference : m_indirect_asset_references)
assetReferences.emplace_back(assetReference);
}
return assetReferences;
}

View File

@ -13,6 +13,7 @@ class AssetMarker
std::unordered_set<XAssetInfoGeneric*> m_dependencies;
std::unordered_set<scr_string_t> m_used_script_strings;
std::unordered_set<IndirectAssetReference> m_indirect_asset_references;
protected:
AssetMarker(asset_type_t assetType, Zone* zone);
@ -22,6 +23,9 @@ protected:
void Mark_ScriptString(scr_string_t scrString);
void MarkArray_ScriptString(const scr_string_t* scrStringArray, size_t count);
void Mark_IndirectAssetRef(asset_type_t type, const char* assetRefName);
void MarkArray_IndirectAssetRef(asset_type_t type, const char** assetRefNames, size_t count);
_NODISCARD XAssetInfoGeneric* GetAssetInfoByName(std::string name) const;
Zone* m_zone;
@ -29,4 +33,5 @@ protected:
public:
_NODISCARD std::vector<XAssetInfoGeneric*> GetDependencies() const;
_NODISCARD std::vector<scr_string_t> GetUsedScriptStrings() const;
_NODISCARD std::vector<IndirectAssetReference> GetIndirectAssetReferences() const;
};