mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-01-24 08:53:04 +00:00
chore: implement base skeleton for architecture independent zone loading
This commit is contained in:
@@ -5,14 +5,6 @@
|
||||
const void* ContentLoaderBase::PTR_FOLLOWING = reinterpret_cast<void*>(-1);
|
||||
const void* ContentLoaderBase::PTR_INSERT = reinterpret_cast<void*>(-2);
|
||||
|
||||
ContentLoaderBase::ContentLoaderBase(Zone& zone)
|
||||
: varXString(nullptr),
|
||||
m_zone(zone),
|
||||
m_memory(zone.Memory()),
|
||||
m_stream(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
ContentLoaderBase::ContentLoaderBase(Zone& zone, ZoneInputStream& stream)
|
||||
: varXString(nullptr),
|
||||
m_zone(zone),
|
||||
@@ -37,7 +29,7 @@ void ContentLoaderBase::LoadXString(const bool atStreamStart) const
|
||||
}
|
||||
else
|
||||
{
|
||||
*varXString = m_stream->ConvertOffsetToPointer<const char>(*varXString);
|
||||
*varXString = m_stream->ConvertOffsetToPointerNative<const char>(*varXString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ public:
|
||||
ContentLoaderBase& operator=(ContentLoaderBase&& other) noexcept = delete;
|
||||
|
||||
protected:
|
||||
explicit ContentLoaderBase(Zone& zone);
|
||||
ContentLoaderBase(Zone& zone, ZoneInputStream& stream);
|
||||
|
||||
void LoadXString(bool atStreamStart) const;
|
||||
@@ -27,5 +26,5 @@ protected:
|
||||
|
||||
Zone& m_zone;
|
||||
MemoryManager& m_memory;
|
||||
ZoneInputStream* m_stream;
|
||||
ZoneInputStream* m_stream; // TODO: Change this to reference
|
||||
};
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Stream/ZoneInputStream.h"
|
||||
|
||||
class IContentLoadingEntryPoint
|
||||
{
|
||||
public:
|
||||
@@ -12,5 +10,5 @@ public:
|
||||
IContentLoadingEntryPoint& operator=(const IContentLoadingEntryPoint& other) = default;
|
||||
IContentLoadingEntryPoint& operator=(IContentLoadingEntryPoint&& other) noexcept = default;
|
||||
|
||||
virtual void Load(ZoneInputStream& stream) = 0;
|
||||
virtual void Load() = 0;
|
||||
};
|
||||
|
||||
@@ -7,8 +7,12 @@ namespace
|
||||
class StepLoadZoneContent final : public ILoadingStep
|
||||
{
|
||||
public:
|
||||
StepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, const int offsetBlockBitCount, const block_t insertBlock)
|
||||
: m_content_loader(std::move(entryPoint)),
|
||||
StepLoadZoneContent(std::function<std::unique_ptr<IContentLoadingEntryPoint>(ZoneInputStream&)> entryPointFactory,
|
||||
const unsigned pointerBitCount,
|
||||
const unsigned offsetBlockBitCount,
|
||||
const block_t insertBlock)
|
||||
: m_entry_point_factory(std::move(entryPointFactory)),
|
||||
m_pointer_bit_count(pointerBitCount),
|
||||
m_offset_block_bit_count(offsetBlockBitCount),
|
||||
m_insert_block(insertBlock)
|
||||
{
|
||||
@@ -16,23 +20,29 @@ namespace
|
||||
|
||||
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
|
||||
{
|
||||
const auto inputStream = ZoneInputStream::Create(zoneLoader.m_blocks, stream, m_offset_block_bit_count, m_insert_block);
|
||||
const auto inputStream = ZoneInputStream::Create(m_pointer_bit_count, m_offset_block_bit_count, zoneLoader.m_blocks, m_insert_block, stream);
|
||||
|
||||
m_content_loader->Load(*inputStream);
|
||||
const auto entryPoint = m_entry_point_factory(*inputStream);
|
||||
assert(entryPoint);
|
||||
|
||||
entryPoint->Load();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<IContentLoadingEntryPoint> m_content_loader;
|
||||
int m_offset_block_bit_count;
|
||||
std::function<std::unique_ptr<IContentLoadingEntryPoint>(ZoneInputStream&)> m_entry_point_factory;
|
||||
unsigned m_pointer_bit_count;
|
||||
unsigned m_offset_block_bit_count;
|
||||
block_t m_insert_block;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace step
|
||||
{
|
||||
std::unique_ptr<ILoadingStep>
|
||||
CreateStepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, const int offsetBlockBitCount, const block_t insertBlock)
|
||||
std::unique_ptr<ILoadingStep> CreateStepLoadZoneContent(std::function<std::unique_ptr<IContentLoadingEntryPoint>(ZoneInputStream&)> entryPointFactory,
|
||||
const unsigned pointerBitCount,
|
||||
const unsigned offsetBlockBitCount,
|
||||
const block_t insertBlock)
|
||||
{
|
||||
return std::make_unique<StepLoadZoneContent>(std::move(entryPoint), offsetBlockBitCount, insertBlock);
|
||||
return std::make_unique<StepLoadZoneContent>(std::move(entryPointFactory), pointerBitCount, offsetBlockBitCount, insertBlock);
|
||||
}
|
||||
} // namespace step
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
|
||||
#include "Loading/IContentLoadingEntryPoint.h"
|
||||
#include "Loading/ILoadingStep.h"
|
||||
#include "Zone/Stream/ZoneInputStream.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace step
|
||||
{
|
||||
std::unique_ptr<ILoadingStep>
|
||||
CreateStepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, int offsetBlockBitCount, block_t insertBlock);
|
||||
std::unique_ptr<ILoadingStep> CreateStepLoadZoneContent(std::function<std::unique_ptr<IContentLoadingEntryPoint>(ZoneInputStream&)> entryPointFactory,
|
||||
unsigned pointerBitCount,
|
||||
unsigned offsetBlockBitCount,
|
||||
block_t insertBlock);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user