mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
ZoneCodeGenerator: Change ContentLoader to use vars for fastfile pointer transfer and change ZoneInputStream API to be able to specify load location to better reflect the way the games do it.
This commit is contained in:
parent
3839b22f71
commit
b7ab2a1aa6
@ -57,122 +57,129 @@ using namespace T6;
|
|||||||
|
|
||||||
ContentLoaderT6::ContentLoaderT6()
|
ContentLoaderT6::ContentLoaderT6()
|
||||||
{
|
{
|
||||||
|
varXAsset = nullptr;
|
||||||
|
varScriptStringList = nullptr;
|
||||||
|
|
||||||
// Script String 0 is always empty string
|
// Script String 0 is always empty string
|
||||||
m_script_strings.emplace_back("");
|
m_script_strings.emplace_back("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoaderT6::LoadScriptStringList(ScriptStringList* scriptStringList)
|
void ContentLoaderT6::LoadScriptStringList(const bool atStreamStart)
|
||||||
{
|
{
|
||||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
if(scriptStringList->strings != nullptr)
|
if (atStreamStart)
|
||||||
|
m_stream->Load<ScriptStringList>(varScriptStringList);
|
||||||
|
|
||||||
|
if(varScriptStringList->strings != nullptr)
|
||||||
{
|
{
|
||||||
assert(scriptStringList->strings == PTR_FOLLOWING);
|
assert(varScriptStringList->strings == PTR_FOLLOWING);
|
||||||
|
|
||||||
scriptStringList->strings = m_stream->Alloc<const char*>();
|
varScriptStringList->strings = m_stream->Alloc<const char*>(alignof(const char));
|
||||||
LoadXStringArray(scriptStringList->strings, scriptStringList->count, true);
|
varXString = varScriptStringList->strings;
|
||||||
|
LoadXStringArray(true, varScriptStringList->count);
|
||||||
|
|
||||||
for(int i = 0; i < scriptStringList->count; i++)
|
for(int i = 0; i < varScriptStringList->count; i++)
|
||||||
{
|
{
|
||||||
m_script_strings.emplace_back(scriptStringList->strings[i]);
|
m_script_strings.emplace_back(varScriptStringList->strings[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_stream->PopBlock();
|
m_stream->PopBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoaderT6::LoadXAsset(XAsset* pXAsset, const bool atStreamStart)
|
void ContentLoaderT6::LoadXAsset(const bool atStreamStart)
|
||||||
{
|
{
|
||||||
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
||||||
case type_index: \
|
case type_index: \
|
||||||
{ \
|
{ \
|
||||||
Loader_##typeName loader(this, m_zone, m_stream); \
|
Loader_##typeName loader(this, m_zone, m_stream); \
|
||||||
loader.LoadPtr_##typeName(&pXAsset->header.headerEntry); \
|
loader.Load(&varXAsset->header.headerEntry); \
|
||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(pXAsset != nullptr);
|
assert(varXAsset != nullptr);
|
||||||
|
|
||||||
if(atStreamStart)
|
if(atStreamStart)
|
||||||
m_stream->Load<XAsset>();
|
m_stream->Load<XAsset>(varXAsset);
|
||||||
|
|
||||||
switch(pXAsset->type)
|
switch(varXAsset->type)
|
||||||
{
|
{
|
||||||
LOAD_ASSET(ASSET_TYPE_PHYSPRESET, PhysPreset, physPreset);
|
// LOAD_ASSET(ASSET_TYPE_PHYSPRESET, PhysPreset, physPreset);
|
||||||
LOAD_ASSET(ASSET_TYPE_PHYSCONSTRAINTS, PhysConstraints, physConstraints);
|
// LOAD_ASSET(ASSET_TYPE_PHYSCONSTRAINTS, PhysConstraints, physConstraints);
|
||||||
LOAD_ASSET(ASSET_TYPE_DESTRUCTIBLEDEF, DestructibleDef, destructibleDef);
|
// LOAD_ASSET(ASSET_TYPE_DESTRUCTIBLEDEF, DestructibleDef, destructibleDef);
|
||||||
LOAD_ASSET(ASSET_TYPE_XANIMPARTS, XAnimParts, parts);
|
// LOAD_ASSET(ASSET_TYPE_XANIMPARTS, XAnimParts, parts);
|
||||||
LOAD_ASSET(ASSET_TYPE_XMODEL, XModel, model);
|
// LOAD_ASSET(ASSET_TYPE_XMODEL, XModel, model);
|
||||||
LOAD_ASSET(ASSET_TYPE_MATERIAL, Material, material);
|
// LOAD_ASSET(ASSET_TYPE_MATERIAL, Material, material);
|
||||||
LOAD_ASSET(ASSET_TYPE_TECHNIQUE_SET, MaterialTechniqueSet, techniqueSet);
|
// LOAD_ASSET(ASSET_TYPE_TECHNIQUE_SET, MaterialTechniqueSet, techniqueSet);
|
||||||
LOAD_ASSET(ASSET_TYPE_IMAGE, GfxImage, image);
|
// LOAD_ASSET(ASSET_TYPE_IMAGE, GfxImage, image);
|
||||||
LOAD_ASSET(ASSET_TYPE_SOUND, SndBank, sound);
|
// LOAD_ASSET(ASSET_TYPE_SOUND, SndBank, sound);
|
||||||
LOAD_ASSET(ASSET_TYPE_SOUND_PATCH, SndPatch, soundPatch);
|
// LOAD_ASSET(ASSET_TYPE_SOUND_PATCH, SndPatch, soundPatch);
|
||||||
LOAD_ASSET(ASSET_TYPE_CLIPMAP, clipMap_t, clipMap);
|
// LOAD_ASSET(ASSET_TYPE_CLIPMAP, clipMap_t, clipMap);
|
||||||
LOAD_ASSET(ASSET_TYPE_CLIPMAP_PVS, clipMap_t, clipMap);
|
// LOAD_ASSET(ASSET_TYPE_CLIPMAP_PVS, clipMap_t, clipMap);
|
||||||
LOAD_ASSET(ASSET_TYPE_COMWORLD, ComWorld, comWorld);
|
// LOAD_ASSET(ASSET_TYPE_COMWORLD, ComWorld, comWorld);
|
||||||
LOAD_ASSET(ASSET_TYPE_GAMEWORLD_SP, GameWorldSp, gameWorldSp);
|
// LOAD_ASSET(ASSET_TYPE_GAMEWORLD_SP, GameWorldSp, gameWorldSp);
|
||||||
LOAD_ASSET(ASSET_TYPE_GAMEWORLD_MP, GameWorldMp, gameWorldMp);
|
// LOAD_ASSET(ASSET_TYPE_GAMEWORLD_MP, GameWorldMp, gameWorldMp);
|
||||||
LOAD_ASSET(ASSET_TYPE_MAP_ENTS, MapEnts, mapEnts);
|
// LOAD_ASSET(ASSET_TYPE_MAP_ENTS, MapEnts, mapEnts);
|
||||||
LOAD_ASSET(ASSET_TYPE_GFXWORLD, GfxWorld, gfxWorld);
|
// LOAD_ASSET(ASSET_TYPE_GFXWORLD, GfxWorld, gfxWorld);
|
||||||
LOAD_ASSET(ASSET_TYPE_LIGHT_DEF, GfxLightDef, lightDef);
|
// LOAD_ASSET(ASSET_TYPE_LIGHT_DEF, GfxLightDef, lightDef);
|
||||||
LOAD_ASSET(ASSET_TYPE_FONT, Font_s, font);
|
// LOAD_ASSET(ASSET_TYPE_FONT, Font_s, font);
|
||||||
LOAD_ASSET(ASSET_TYPE_FONTICON, FontIcon, fontIcon);
|
// LOAD_ASSET(ASSET_TYPE_FONTICON, FontIcon, fontIcon);
|
||||||
LOAD_ASSET(ASSET_TYPE_MENULIST, MenuList, menuList);
|
// LOAD_ASSET(ASSET_TYPE_MENULIST, MenuList, menuList);
|
||||||
LOAD_ASSET(ASSET_TYPE_MENU, menuDef_t, menu);
|
// LOAD_ASSET(ASSET_TYPE_MENU, menuDef_t, menu);
|
||||||
LOAD_ASSET(ASSET_TYPE_LOCALIZE_ENTRY, LocalizeEntry, localize);
|
// LOAD_ASSET(ASSET_TYPE_LOCALIZE_ENTRY, LocalizeEntry, localize);
|
||||||
LOAD_ASSET(ASSET_TYPE_WEAPON, WeaponVariantDef, weapon);
|
// LOAD_ASSET(ASSET_TYPE_WEAPON, WeaponVariantDef, weapon);
|
||||||
LOAD_ASSET(ASSET_TYPE_ATTACHMENT, WeaponAttachment, attachment);
|
// LOAD_ASSET(ASSET_TYPE_ATTACHMENT, WeaponAttachment, attachment);
|
||||||
LOAD_ASSET(ASSET_TYPE_ATTACHMENT_UNIQUE, WeaponAttachmentUnique, attachmentUnique);
|
// LOAD_ASSET(ASSET_TYPE_ATTACHMENT_UNIQUE, WeaponAttachmentUnique, attachmentUnique);
|
||||||
LOAD_ASSET(ASSET_TYPE_WEAPON_CAMO, WeaponCamo, weaponCamo);
|
// LOAD_ASSET(ASSET_TYPE_WEAPON_CAMO, WeaponCamo, weaponCamo);
|
||||||
LOAD_ASSET(ASSET_TYPE_SNDDRIVER_GLOBALS, SndDriverGlobals, sndDriverGlobals);
|
// LOAD_ASSET(ASSET_TYPE_SNDDRIVER_GLOBALS, SndDriverGlobals, sndDriverGlobals);
|
||||||
LOAD_ASSET(ASSET_TYPE_FX, FxEffectDef, fx);
|
// LOAD_ASSET(ASSET_TYPE_FX, FxEffectDef, fx);
|
||||||
LOAD_ASSET(ASSET_TYPE_IMPACT_FX, FxImpactTable, impactFx);
|
// LOAD_ASSET(ASSET_TYPE_IMPACT_FX, FxImpactTable, impactFx);
|
||||||
LOAD_ASSET(ASSET_TYPE_RAWFILE, RawFile, rawfile);
|
LOAD_ASSET(ASSET_TYPE_RAWFILE, RawFile, rawfile);
|
||||||
LOAD_ASSET(ASSET_TYPE_STRINGTABLE, StringTable, stringTable);
|
LOAD_ASSET(ASSET_TYPE_STRINGTABLE, StringTable, stringTable);
|
||||||
LOAD_ASSET(ASSET_TYPE_LEADERBOARD, LeaderboardDef, leaderboardDef);
|
// LOAD_ASSET(ASSET_TYPE_LEADERBOARD, LeaderboardDef, leaderboardDef);
|
||||||
LOAD_ASSET(ASSET_TYPE_XGLOBALS, XGlobals, xGlobals);
|
// LOAD_ASSET(ASSET_TYPE_XGLOBALS, XGlobals, xGlobals);
|
||||||
LOAD_ASSET(ASSET_TYPE_DDL, ddlRoot_t, ddlRoot);
|
// LOAD_ASSET(ASSET_TYPE_DDL, ddlRoot_t, ddlRoot);
|
||||||
LOAD_ASSET(ASSET_TYPE_GLASSES, Glasses, glasses);
|
// LOAD_ASSET(ASSET_TYPE_GLASSES, Glasses, glasses);
|
||||||
LOAD_ASSET(ASSET_TYPE_EMBLEMSET, EmblemSet, emblemSet);
|
// LOAD_ASSET(ASSET_TYPE_EMBLEMSET, EmblemSet, emblemSet);
|
||||||
LOAD_ASSET(ASSET_TYPE_SCRIPTPARSETREE, ScriptParseTree, scriptParseTree);
|
LOAD_ASSET(ASSET_TYPE_SCRIPTPARSETREE, ScriptParseTree, scriptParseTree);
|
||||||
LOAD_ASSET(ASSET_TYPE_KEYVALUEPAIRS, KeyValuePairs, keyValuePairs);
|
// LOAD_ASSET(ASSET_TYPE_KEYVALUEPAIRS, KeyValuePairs, keyValuePairs);
|
||||||
LOAD_ASSET(ASSET_TYPE_VEHICLEDEF, VehicleDef, vehicleDef);
|
// LOAD_ASSET(ASSET_TYPE_VEHICLEDEF, VehicleDef, vehicleDef);
|
||||||
LOAD_ASSET(ASSET_TYPE_MEMORYBLOCK, MemoryBlock, memoryBlock);
|
// LOAD_ASSET(ASSET_TYPE_MEMORYBLOCK, MemoryBlock, memoryBlock);
|
||||||
LOAD_ASSET(ASSET_TYPE_ADDON_MAP_ENTS, AddonMapEnts, addonMapEnts);
|
// LOAD_ASSET(ASSET_TYPE_ADDON_MAP_ENTS, AddonMapEnts, addonMapEnts);
|
||||||
LOAD_ASSET(ASSET_TYPE_TRACER, TracerDef, tracerDef);
|
// LOAD_ASSET(ASSET_TYPE_TRACER, TracerDef, tracerDef);
|
||||||
LOAD_ASSET(ASSET_TYPE_SKINNEDVERTS, SkinnedVertsDef, skinnedVertsDef);
|
// LOAD_ASSET(ASSET_TYPE_SKINNEDVERTS, SkinnedVertsDef, skinnedVertsDef);
|
||||||
LOAD_ASSET(ASSET_TYPE_QDB, Qdb, qdb);
|
// LOAD_ASSET(ASSET_TYPE_QDB, Qdb, qdb);
|
||||||
LOAD_ASSET(ASSET_TYPE_SLUG, Slug, slug);
|
// LOAD_ASSET(ASSET_TYPE_SLUG, Slug, slug);
|
||||||
LOAD_ASSET(ASSET_TYPE_FOOTSTEP_TABLE, FootstepTableDef, footstepTableDef);
|
// LOAD_ASSET(ASSET_TYPE_FOOTSTEP_TABLE, FootstepTableDef, footstepTableDef);
|
||||||
LOAD_ASSET(ASSET_TYPE_FOOTSTEPFX_TABLE, FootstepFXTableDef, footstepFXTableDef);
|
// LOAD_ASSET(ASSET_TYPE_FOOTSTEPFX_TABLE, FootstepFXTableDef, footstepFXTableDef);
|
||||||
LOAD_ASSET(ASSET_TYPE_ZBARRIER, ZBarrierDef, zbarrierDef);
|
// LOAD_ASSET(ASSET_TYPE_ZBARRIER, ZBarrierDef, zbarrierDef);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
throw UnsupportedAssetTypeException(pXAsset->type);
|
throw UnsupportedAssetTypeException(varXAsset->type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef LOAD_ASSET
|
#undef LOAD_ASSET
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoaderT6::LoadXAssetArray(XAsset* pArray, const size_t count, const bool atStreamStart)
|
void ContentLoaderT6::LoadXAssetArray(const bool atStreamStart, const size_t count)
|
||||||
{
|
{
|
||||||
assert(pArray != nullptr);
|
assert(varXAsset != nullptr);
|
||||||
|
|
||||||
if(atStreamStart)
|
if(atStreamStart)
|
||||||
m_stream->Load<XAsset>(count);
|
m_stream->Load<XAsset>(varXAsset, count);
|
||||||
|
|
||||||
size_t assetCounts[ASSET_TYPE_COUNT]{0};
|
size_t assetCounts[ASSET_TYPE_COUNT]{0};
|
||||||
|
|
||||||
for(size_t index = 0; index < count; index++)
|
for(size_t index = 0; index < count; index++)
|
||||||
{
|
{
|
||||||
assert(pArray[index].type >= 0 && pArray[index].type < ASSET_TYPE_COUNT);
|
assert(varXAsset[index].type >= 0 && varXAsset[index].type < ASSET_TYPE_COUNT);
|
||||||
|
|
||||||
if(pArray[index].type >= 0 && pArray[index].type < ASSET_TYPE_COUNT)
|
if(varXAsset[index].type >= 0 && varXAsset[index].type < ASSET_TYPE_COUNT)
|
||||||
{
|
{
|
||||||
assetCounts[pArray[index].type]++;
|
assetCounts[varXAsset[index].type]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +194,8 @@ void ContentLoaderT6::LoadXAssetArray(XAsset* pArray, const size_t count, const
|
|||||||
|
|
||||||
for(size_t index = 0; index < count; index++)
|
for(size_t index = 0; index < count; index++)
|
||||||
{
|
{
|
||||||
LoadXAsset(&pArray[index], false);
|
LoadXAsset(false);
|
||||||
|
varXAsset++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,25 +206,28 @@ void ContentLoaderT6::Load(Zone* zone, IZoneInputStream* stream)
|
|||||||
|
|
||||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
auto* assetList = m_stream->Alloc<XAssetList>();
|
auto* assetList = m_stream->Alloc<XAssetList>(alignof(XAssetList));
|
||||||
m_stream->Load<XAssetList>();
|
m_stream->Load<XAssetList>(assetList);
|
||||||
|
|
||||||
LoadScriptStringList(&assetList->stringList);
|
varScriptStringList = &assetList->stringList;
|
||||||
|
LoadScriptStringList(false);
|
||||||
|
|
||||||
if(assetList->depends != nullptr)
|
if(assetList->depends != nullptr)
|
||||||
{
|
{
|
||||||
assert(assetList->depends == PTR_FOLLOWING);
|
assert(assetList->depends == PTR_FOLLOWING);
|
||||||
|
|
||||||
assetList->depends = m_stream->Alloc<const char*>();
|
assetList->depends = m_stream->Alloc<const char*>(alignof(const char));
|
||||||
LoadXStringArray(assetList->depends, assetList->dependCount, true);
|
varXString = assetList->depends;
|
||||||
|
LoadXStringArray(true, assetList->dependCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(assetList->assets != nullptr)
|
if(assetList->assets != nullptr)
|
||||||
{
|
{
|
||||||
assert(assetList->assets == PTR_FOLLOWING);
|
assert(assetList->assets == PTR_FOLLOWING);
|
||||||
|
|
||||||
assetList->assets = m_stream->Alloc<XAsset>();
|
assetList->assets = m_stream->Alloc<XAsset>(alignof(XAsset));
|
||||||
LoadXAssetArray(assetList->assets, assetList->assetCount, true);
|
varXAsset = assetList->assets;
|
||||||
|
LoadXAssetArray(true, assetList->assetCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_stream->PopBlock();
|
m_stream->PopBlock();
|
||||||
|
@ -7,11 +7,13 @@
|
|||||||
class ContentLoaderT6 final : public ContentLoader, public IContentLoadingEntryPoint, public IZoneScriptStringProvider
|
class ContentLoaderT6 final : public ContentLoader, public IContentLoadingEntryPoint, public IZoneScriptStringProvider
|
||||||
{
|
{
|
||||||
std::vector<std::string> m_script_strings;
|
std::vector<std::string> m_script_strings;
|
||||||
|
T6::XAsset* varXAsset;
|
||||||
|
T6::ScriptStringList* varScriptStringList;
|
||||||
|
|
||||||
void LoadScriptStringList(T6::ScriptStringList* scriptStringList);
|
void LoadScriptStringList(bool atStreamStart);
|
||||||
|
|
||||||
void LoadXAsset(T6::XAsset* pXAsset, bool atStreamStart);
|
void LoadXAsset(bool atStreamStart);
|
||||||
void LoadXAssetArray(T6::XAsset* pArray, size_t count, bool atStreamStart);
|
void LoadXAssetArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ContentLoaderT6();
|
ContentLoaderT6();
|
||||||
|
@ -6,37 +6,42 @@ const void* ContentLoader::PTR_INSERT = reinterpret_cast<void*>(-2);
|
|||||||
|
|
||||||
ContentLoader::ContentLoader()
|
ContentLoader::ContentLoader()
|
||||||
{
|
{
|
||||||
|
varXString = nullptr;
|
||||||
|
|
||||||
m_zone = nullptr;
|
m_zone = nullptr;
|
||||||
m_stream = nullptr;
|
m_stream = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::LoadXString(const char** pXString) const
|
void ContentLoader::LoadXString(const bool atStreamStart) const
|
||||||
{
|
{
|
||||||
assert(pXString != nullptr);
|
assert(varXString != nullptr);
|
||||||
|
|
||||||
if(*pXString != nullptr)
|
if (atStreamStart)
|
||||||
|
m_stream->Load<const char*>(varXString);
|
||||||
|
|
||||||
|
if(*varXString != nullptr)
|
||||||
{
|
{
|
||||||
if(*pXString == PTR_FOLLOWING)
|
if(*varXString == PTR_FOLLOWING)
|
||||||
{
|
{
|
||||||
*pXString = m_stream->Alloc<const char>();
|
*varXString = m_stream->Alloc<const char>(alignof(const char));
|
||||||
m_stream->LoadNullTerminated();
|
m_stream->LoadNullTerminated(const_cast<char*>(*varXString));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*pXString = m_stream->ConvertOffsetToPointer<const char>(*pXString);
|
*varXString = m_stream->ConvertOffsetToPointer<const char>(*varXString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::LoadXStringArray(const char** pArray, const size_t count, const bool atStreamStart) const
|
void ContentLoader::LoadXStringArray(const bool atStreamStart, const size_t count) const
|
||||||
{
|
{
|
||||||
assert(pArray != nullptr);
|
assert(varXString != nullptr);
|
||||||
|
|
||||||
if(atStreamStart)
|
if(atStreamStart)
|
||||||
m_stream->Load<const char*>(count);
|
m_stream->Load<const char*>(varXString, count);
|
||||||
|
|
||||||
for(size_t index = 0; index < count; index++)
|
for(size_t index = 0; index < count; index++)
|
||||||
{
|
{
|
||||||
LoadXString(&pArray[index]);
|
LoadXString(&varXString[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,13 +9,15 @@ protected:
|
|||||||
static const void* PTR_FOLLOWING;
|
static const void* PTR_FOLLOWING;
|
||||||
static const void* PTR_INSERT;
|
static const void* PTR_INSERT;
|
||||||
|
|
||||||
|
const char** varXString;
|
||||||
|
|
||||||
Zone* m_zone;
|
Zone* m_zone;
|
||||||
IZoneInputStream* m_stream;
|
IZoneInputStream* m_stream;
|
||||||
|
|
||||||
ContentLoader();
|
ContentLoader();
|
||||||
|
|
||||||
void LoadXString(const char** pXString) const;
|
void LoadXString(bool atStreamStart) const;
|
||||||
void LoadXStringArray(const char** pArray, size_t count, bool atStreamStart) const;
|
void LoadXStringArray(bool atStreamStart, size_t count) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~ContentLoader() = default;
|
virtual ~ContentLoader() = default;
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
#include "OutOfBlockBoundsException.h"
|
||||||
|
|
||||||
|
OutOfBlockBoundsException::OutOfBlockBoundsException(XBlock* block)
|
||||||
|
{
|
||||||
|
m_block = block;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string OutOfBlockBoundsException::DetailedMessage()
|
||||||
|
{
|
||||||
|
return "Tried to load to location out of bounds from current XBlock " + m_block->m_name + ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
char const* OutOfBlockBoundsException::what() const
|
||||||
|
{
|
||||||
|
return "Invalid Zone. Out of XBlock bounds.";
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "LoadingException.h"
|
||||||
|
#include "Zone/XBlock.h"
|
||||||
|
|
||||||
|
class OutOfBlockBoundsException final : public LoadingException
|
||||||
|
{
|
||||||
|
XBlock* m_block;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit OutOfBlockBoundsException(XBlock* block);
|
||||||
|
|
||||||
|
std::string DetailedMessage() override;
|
||||||
|
char const* what() const override;
|
||||||
|
};
|
@ -14,25 +14,19 @@ public:
|
|||||||
return static_cast<T*>(Alloc(align));
|
return static_cast<T*>(Alloc(align));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
virtual void LoadData(void* dst, size_t size) = 0;
|
||||||
T* Alloc()
|
virtual void LoadNullTerminated(void* dst) = 0;
|
||||||
{
|
|
||||||
return static_cast<T*>(Alloc(alignof(T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void LoadData(size_t size) = 0;
|
|
||||||
virtual void LoadNullTerminated() = 0;
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void Load()
|
void Load(T* dst)
|
||||||
{
|
{
|
||||||
LoadData(sizeof(T));
|
LoadData(dst, sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void Load(const uint32_t count)
|
void Load(T* dst, const uint32_t count)
|
||||||
{
|
{
|
||||||
LoadData(count * sizeof(T));
|
LoadData(const_cast<void*>(reinterpret_cast<const void*>(dst)), count * sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void** InsertPointer() = 0;
|
virtual void** InsertPointer() = 0;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "Loading/Exception/InvalidOffsetBlockOffsetException.h"
|
#include "Loading/Exception/InvalidOffsetBlockOffsetException.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include "Loading/Exception/OutOfBlockBoundsException.h"
|
||||||
|
|
||||||
XBlockInputStream::XBlockInputStream(std::vector<XBlock*>& blocks, ILoadingStream* stream, const int blockBitCount, const block_t insertBlock) : m_blocks(blocks)
|
XBlockInputStream::XBlockInputStream(std::vector<XBlock*>& blocks, ILoadingStream* stream, const int blockBitCount, const block_t insertBlock) : m_blocks(blocks)
|
||||||
{
|
{
|
||||||
@ -93,7 +94,7 @@ void* XBlockInputStream::Alloc(const int align)
|
|||||||
return &block->m_buffer[m_block_offsets[block->m_index]];
|
return &block->m_buffer[m_block_offsets[block->m_index]];
|
||||||
}
|
}
|
||||||
|
|
||||||
void XBlockInputStream::LoadData(const size_t size)
|
void XBlockInputStream::LoadData(void* dst, const size_t size)
|
||||||
{
|
{
|
||||||
assert(!m_block_stack.empty());
|
assert(!m_block_stack.empty());
|
||||||
|
|
||||||
@ -102,17 +103,25 @@ void XBlockInputStream::LoadData(const size_t size)
|
|||||||
|
|
||||||
XBlock* block = m_block_stack.top();
|
XBlock* block = m_block_stack.top();
|
||||||
|
|
||||||
if(m_block_offsets[block->m_index] + size >= block->m_buffer_size)
|
if(block->m_buffer > dst || block->m_buffer + block->m_buffer_size < dst)
|
||||||
|
{
|
||||||
|
throw OutOfBlockBoundsException(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(reinterpret_cast<uint8_t*>(dst) + size >= block->m_buffer + block->m_buffer_size)
|
||||||
{
|
{
|
||||||
throw BlockOverflowException(block);
|
throw BlockOverflowException(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_stream->Load(&block->m_buffer[m_block_offsets[block->m_index]], size);
|
// Theoretically ptr should always be at the current block offset.
|
||||||
|
assert(dst == &block->m_buffer[m_block_offsets[block->m_index]]);
|
||||||
|
|
||||||
|
m_stream->Load(dst, size);
|
||||||
|
|
||||||
m_block_offsets[block->m_index] += size;
|
m_block_offsets[block->m_index] += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XBlockInputStream::LoadNullTerminated()
|
void XBlockInputStream::LoadNullTerminated(void* dst)
|
||||||
{
|
{
|
||||||
assert(!m_block_stack.empty());
|
assert(!m_block_stack.empty());
|
||||||
|
|
||||||
@ -121,8 +130,16 @@ void XBlockInputStream::LoadNullTerminated()
|
|||||||
|
|
||||||
XBlock* block = m_block_stack.top();
|
XBlock* block = m_block_stack.top();
|
||||||
|
|
||||||
|
if (block->m_buffer > dst || block->m_buffer + block->m_buffer_size < dst)
|
||||||
|
{
|
||||||
|
throw OutOfBlockBoundsException(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theoretically ptr should always be at the current block offset.
|
||||||
|
assert(dst == &block->m_buffer[m_block_offsets[block->m_index]]);
|
||||||
|
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
size_t offset = m_block_offsets[block->m_index];
|
size_t offset = reinterpret_cast<uint8_t*>(dst) - block->m_buffer;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
m_stream->Load(&byte, 1);
|
m_stream->Load(&byte, 1);
|
||||||
|
@ -30,11 +30,12 @@ public:
|
|||||||
|
|
||||||
void* Alloc(int align) override;
|
void* Alloc(int align) override;
|
||||||
|
|
||||||
void LoadData(size_t size) override;
|
void LoadData(void* dst, size_t size) override;
|
||||||
void LoadNullTerminated() override;
|
void LoadNullTerminated(void* dst) override;
|
||||||
|
|
||||||
void** InsertPointer() override;
|
void** InsertPointer() override;
|
||||||
|
|
||||||
void* ConvertOffsetToPointer(const void* offset) override;
|
void* ConvertOffsetToPointer(const void* offset) override;
|
||||||
void* ConvertOffsetToAlias(const void* offset) override;
|
void* ConvertOffsetToAlias(const void* offset) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user