2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-12-27 20:41:49 +00:00

chore: move asset marker to ZoneCommon

This commit is contained in:
Jan Laupetin
2025-12-15 22:52:34 +00:00
parent e14f37f493
commit c73b2ed838
6 changed files with 29 additions and 7 deletions

View File

@@ -1,102 +0,0 @@
#include "AssetMarker.h"
#include <algorithm>
#include <cassert>
AssetMarker::AssetMarker(const asset_type_t assetType, Zone& zone)
: m_zone(zone),
m_asset_type(assetType)
{
}
void AssetMarker::AddDependency(XAssetInfoGeneric* assetInfo)
{
if (assetInfo == nullptr)
return;
const auto existingEntry = m_dependencies.find(assetInfo);
if (existingEntry != m_dependencies.end())
return;
m_dependencies.emplace(assetInfo);
}
void AssetMarker::Mark_ScriptString(const scr_string_t scrString)
{
assert(scrString < m_zone.m_script_strings.Count());
if (scrString >= m_zone.m_script_strings.Count())
return;
m_used_script_strings.emplace(scrString);
}
void AssetMarker::MarkArray_ScriptString(const scr_string_t* scrStringArray, const size_t count)
{
assert(scrStringArray != nullptr);
for (size_t index = 0; index < count; index++)
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(const std::string& name) const
{
return m_zone.m_pools->GetAsset(m_asset_type, name);
}
std::vector<XAssetInfoGeneric*> AssetMarker::GetDependencies() const
{
std::vector<XAssetInfoGeneric*> dependencies;
if (!m_dependencies.empty())
{
dependencies.reserve(m_dependencies.size());
for (auto dependency : m_dependencies)
dependencies.push_back(dependency);
}
return dependencies;
}
std::vector<scr_string_t> AssetMarker::GetUsedScriptStrings() const
{
std::vector<scr_string_t> usedScriptStrings;
if (!m_used_script_strings.empty())
{
usedScriptStrings.reserve(m_used_script_strings.size());
for (auto scrString : m_used_script_strings)
usedScriptStrings.push_back(scrString);
std::ranges::sort(usedScriptStrings);
}
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

@@ -1,37 +0,0 @@
#pragma once
#include "ContentLoaderBase.h"
#include "Pool/XAssetInfo.h"
#include "Zone/ZoneTypes.h"
#include <unordered_set>
class AssetMarker
{
public:
[[nodiscard]] std::vector<XAssetInfoGeneric*> GetDependencies() const;
[[nodiscard]] std::vector<scr_string_t> GetUsedScriptStrings() const;
[[nodiscard]] std::vector<IndirectAssetReference> GetIndirectAssetReferences() const;
protected:
AssetMarker(asset_type_t assetType, Zone& zone);
void AddDependency(XAssetInfoGeneric* assetInfo);
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(const std::string& name) const;
Zone& m_zone;
private:
asset_type_t m_asset_type;
std::unordered_set<XAssetInfoGeneric*> m_dependencies;
std::unordered_set<scr_string_t> m_used_script_strings;
std::unordered_set<IndirectAssetReference> m_indirect_asset_references;
};