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

@ -39,8 +39,9 @@
using namespace T5;
ContentLoader::ContentLoader()
: varXAsset(nullptr),
ContentLoader::ContentLoader(Zone& zone)
: ContentLoaderBase(zone),
varXAsset(nullptr),
varScriptStringList(nullptr)
{
}
@ -61,12 +62,12 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
LoadXStringArray(true, varScriptStringList->count);
if (varScriptStringList->strings && varScriptStringList->count > 0)
m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
m_zone.m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
}
m_stream->PopBlock();
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
assert(m_zone.m_script_strings.Count() <= SCR_STRING_MAX + 1);
}
void ContentLoader::LoadXAsset(const bool atStreamStart) const
@ -146,9 +147,8 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
}
}
void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
void ContentLoader::Load(IZoneInputStream* stream)
{
m_zone = zone;
m_stream = stream;
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);

View File

@ -1,4 +1,5 @@
#pragma once
#include "Game/T5/T5.h"
#include "Loading/ContentLoaderBase.h"
#include "Loading/IContentLoadingEntryPoint.h"
@ -7,17 +8,18 @@ namespace T5
{
class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint
{
XAsset* varXAsset;
ScriptStringList* varScriptStringList;
public:
explicit ContentLoader(Zone& zone);
void Load(IZoneInputStream* stream) override;
private:
void LoadScriptStringList(bool atStreamStart);
void LoadXAsset(bool atStreamStart) const;
void LoadXAssetArray(bool atStreamStart, size_t count);
public:
ContentLoader();
void Load(Zone* zone, IZoneInputStream* stream) override;
XAsset* varXAsset;
ScriptStringList* varScriptStringList;
};
} // namespace T5

View File

@ -5,7 +5,7 @@
using namespace T5;
Actions_GfxImage::Actions_GfxImage(Zone* zone)
Actions_GfxImage::Actions_GfxImage(Zone& zone)
: AssetLoadingActions(zone)
{
}
@ -19,6 +19,6 @@ void Actions_GfxImage::LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image)
{
const size_t loadDefSize = offsetof(GfxImageLoadDef, data) + loadDef->resourceSize;
image->texture.loadDef = static_cast<GfxImageLoadDef*>(m_zone->GetMemory()->AllocRaw(loadDefSize));
image->texture.loadDef = static_cast<GfxImageLoadDef*>(m_zone.GetMemory()->AllocRaw(loadDefSize));
memcpy(image->texture.loadDef, loadDef, loadDefSize);
}

View File

@ -8,7 +8,7 @@ namespace T5
class Actions_GfxImage final : public AssetLoadingActions
{
public:
explicit Actions_GfxImage(Zone* zone);
explicit Actions_GfxImage(Zone& zone);
void OnImageLoaded(GfxImage* image) const;
void LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const;

View File

@ -85,8 +85,8 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
// Start of the zone content
zoneLoader->AddLoadingStep(
std::make_unique<StepLoadZoneContent>(std::make_unique<ContentLoader>(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneContent>(
std::make_unique<ContentLoader>(*zonePtr), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
return zoneLoader;
}