mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 23:08:05 -05:00
feat: add asset marking
This commit is contained in:
73
src/ZoneLoading/Loading/AssetMarker.cpp
Normal file
73
src/ZoneLoading/Loading/AssetMarker.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
#include "AssetMarker.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
AssetMarker::AssetMarker(const asset_type_t assetType, Zone* zone)
|
||||
: m_asset_type(assetType),
|
||||
m_zone(zone)
|
||||
{
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetMarker::GetAssetInfoByName(std::string name) const
|
||||
{
|
||||
return m_zone->m_pools->GetAsset(m_asset_type, std::move(name));
|
||||
}
|
||||
|
||||
std::vector<XAssetInfoGeneric*> AssetMarker::GetDependencies() const
|
||||
{
|
||||
std::vector<XAssetInfoGeneric*> dependencies;
|
||||
if (!m_used_script_strings.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::sort(usedScriptStrings.begin(), usedScriptStrings.end());
|
||||
}
|
||||
|
||||
return usedScriptStrings;
|
||||
}
|
32
src/ZoneLoading/Loading/AssetMarker.h
Normal file
32
src/ZoneLoading/Loading/AssetMarker.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "ContentLoaderBase.h"
|
||||
#include "Pool/XAssetInfo.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
class AssetMarker
|
||||
{
|
||||
asset_type_t m_asset_type;
|
||||
|
||||
std::unordered_set<XAssetInfoGeneric*> m_dependencies;
|
||||
std::unordered_set<scr_string_t> m_used_script_strings;
|
||||
|
||||
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);
|
||||
|
||||
_NODISCARD XAssetInfoGeneric* GetAssetInfoByName(std::string name) const;
|
||||
|
||||
Zone* m_zone;
|
||||
|
||||
public:
|
||||
_NODISCARD std::vector<XAssetInfoGeneric*> GetDependencies() const;
|
||||
_NODISCARD std::vector<scr_string_t> GetUsedScriptStrings() const;
|
||||
};
|
Reference in New Issue
Block a user