refactor: use zone reference in AssetLoader

This commit is contained in:
Jan
2025-05-02 11:19:52 +01:00
parent 50612d117e
commit 9e940a6f53
49 changed files with 173 additions and 160 deletions

View File

@ -3,10 +3,10 @@
#include <algorithm>
#include <cassert>
AssetLoader::AssetLoader(const asset_type_t assetType, Zone* zone, IZoneInputStream* stream)
AssetLoader::AssetLoader(const asset_type_t assetType, Zone& zone, IZoneInputStream* stream)
: ContentLoaderBase(zone, stream),
m_asset_type(assetType),
varScriptString(nullptr)
varScriptString(nullptr),
m_asset_type(assetType)
{
}
@ -16,11 +16,11 @@ XAssetInfoGeneric* AssetLoader::LinkAsset(std::string name,
std::vector<scr_string_t> scriptStrings,
std::vector<IndirectAssetReference> indirectAssetReferences) const
{
return m_zone->m_pools->AddAsset(
return m_zone.m_pools->AddAsset(
m_asset_type, std::move(name), asset, std::move(dependencies), std::move(scriptStrings), std::move(indirectAssetReferences));
}
XAssetInfoGeneric* AssetLoader::GetAssetInfo(const std::string& name) const
{
return m_zone->m_pools->GetAsset(m_asset_type, name);
return m_zone.m_pools->GetAsset(m_asset_type, name);
}

View File

@ -4,17 +4,12 @@
#include "Pool/XAssetInfo.h"
#include "Zone/ZoneTypes.h"
#include <unordered_set>
#include <vector>
class AssetLoader : public ContentLoaderBase
{
asset_type_t m_asset_type;
protected:
scr_string_t* varScriptString;
AssetLoader(asset_type_t assetType, Zone* zone, IZoneInputStream* stream);
AssetLoader(asset_type_t assetType, Zone& zone, IZoneInputStream* stream);
XAssetInfoGeneric* LinkAsset(std::string name,
void* asset,
@ -22,5 +17,10 @@ protected:
std::vector<scr_string_t> scriptStrings,
std::vector<IndirectAssetReference> indirectAssetReferences) const;
_NODISCARD XAssetInfoGeneric* GetAssetInfo(const std::string& name) const;
[[nodiscard]] XAssetInfoGeneric* GetAssetInfo(const std::string& name) const;
scr_string_t* varScriptString;
private:
asset_type_t m_asset_type;
};

View File

@ -1,6 +1,6 @@
#include "AssetLoadingActions.h"
AssetLoadingActions::AssetLoadingActions(Zone* zone)
AssetLoadingActions::AssetLoadingActions(Zone& zone)
: m_zone(zone)
{
m_zone = zone;
}

View File

@ -4,9 +4,9 @@
class AssetLoadingActions
{
protected:
Zone* m_zone;
public:
explicit AssetLoadingActions(Zone* zone);
explicit AssetLoadingActions(Zone& zone);
protected:
Zone& m_zone;
};

View File

@ -3,9 +3,9 @@
#include <algorithm>
#include <cassert>
AssetMarker::AssetMarker(const asset_type_t assetType, Zone* zone)
: m_asset_type(assetType),
m_zone(zone)
AssetMarker::AssetMarker(const asset_type_t assetType, Zone& zone)
: m_zone(zone),
m_asset_type(assetType)
{
}
@ -23,9 +23,9 @@ void AssetMarker::AddDependency(XAssetInfoGeneric* assetInfo)
void AssetMarker::Mark_ScriptString(const scr_string_t scrString)
{
assert(scrString < m_zone->m_script_strings.Count());
assert(scrString < m_zone.m_script_strings.Count());
if (scrString >= m_zone->m_script_strings.Count())
if (scrString >= m_zone.m_script_strings.Count())
return;
m_used_script_strings.emplace(scrString);
@ -57,7 +57,7 @@ void AssetMarker::MarkArray_IndirectAssetRef(const asset_type_t type, const char
XAssetInfoGeneric* AssetMarker::GetAssetInfoByName(const std::string& name) const
{
return m_zone->m_pools->GetAsset(m_asset_type, name);
return m_zone.m_pools->GetAsset(m_asset_type, name);
}
std::vector<XAssetInfoGeneric*> AssetMarker::GetDependencies() const

View File

@ -2,21 +2,19 @@
#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;
std::unordered_set<IndirectAssetReference> m_indirect_asset_references;
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);
AssetMarker(asset_type_t assetType, Zone& zone);
void AddDependency(XAssetInfoGeneric* assetInfo);
@ -26,12 +24,14 @@ protected:
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;
[[nodiscard]] XAssetInfoGeneric* GetAssetInfoByName(const std::string& name) const;
Zone* m_zone;
Zone& m_zone;
public:
_NODISCARD std::vector<XAssetInfoGeneric*> GetDependencies() const;
_NODISCARD std::vector<scr_string_t> GetUsedScriptStrings() const;
_NODISCARD std::vector<IndirectAssetReference> GetIndirectAssetReferences() const;
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;
};

View File

@ -2,19 +2,18 @@
#include <cassert>
const void* ContentLoaderBase::PTR_FOLLOWING = reinterpret_cast<void*>(-1);
const void* ContentLoaderBase::PTR_INSERT = reinterpret_cast<void*>(-2);
ContentLoaderBase::ContentLoaderBase()
ContentLoaderBase::ContentLoaderBase(Zone& zone)
: varXString(nullptr),
m_zone(nullptr),
m_zone(zone),
m_memory(*zone.GetMemory()),
m_stream(nullptr)
{
}
ContentLoaderBase::ContentLoaderBase(Zone* zone, IZoneInputStream* stream)
ContentLoaderBase::ContentLoaderBase(Zone& zone, IZoneInputStream* stream)
: varXString(nullptr),
m_zone(zone),
m_memory(*zone.GetMemory()),
m_stream(stream)
{
}

View File

@ -6,20 +6,22 @@
class ContentLoaderBase
{
protected:
static const void* PTR_FOLLOWING;
static const void* PTR_INSERT;
static constexpr auto PTR_FOLLOWING = reinterpret_cast<void*>(-1);
static constexpr auto PTR_INSERT = reinterpret_cast<void*>(-2);
const char** varXString;
public:
virtual ~ContentLoaderBase() = default;
Zone* m_zone;
IZoneInputStream* m_stream;
ContentLoaderBase();
ContentLoaderBase(Zone* zone, IZoneInputStream* stream);
protected:
explicit ContentLoaderBase(Zone& zone);
ContentLoaderBase(Zone& zone, IZoneInputStream* stream);
void LoadXString(bool atStreamStart) const;
void LoadXStringArray(bool atStreamStart, size_t count);
public:
virtual ~ContentLoaderBase() = default;
const char** varXString;
Zone& m_zone;
MemoryManager& m_memory;
IZoneInputStream* m_stream;
};

View File

@ -1,12 +1,16 @@
#pragma once
#include "Zone/Stream/IZoneInputStream.h"
#include "Zone/Zone.h"
class IContentLoadingEntryPoint
{
public:
IContentLoadingEntryPoint() = default;
virtual ~IContentLoadingEntryPoint() = default;
IContentLoadingEntryPoint(const IContentLoadingEntryPoint& other) = default;
IContentLoadingEntryPoint(IContentLoadingEntryPoint&& other) noexcept = default;
IContentLoadingEntryPoint& operator=(const IContentLoadingEntryPoint& other) = default;
IContentLoadingEntryPoint& operator=(IContentLoadingEntryPoint&& other) noexcept = default;
virtual void Load(Zone* zone, IZoneInputStream* stream) = 0;
virtual void Load(IZoneInputStream* stream) = 0;
};

View File

@ -19,7 +19,7 @@ void StepLoadZoneContent::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* st
{
auto* inputStream = new XBlockInputStream(zoneLoader->m_blocks, stream, m_offset_block_bit_count, m_insert_block);
m_content_loader->Load(m_zone, inputStream);
m_content_loader->Load(inputStream);
delete inputStream;
}