mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-16 01:15:40 +00:00
wip
This commit is contained in:
parent
2132716e34
commit
f90725fd27
@ -369,7 +369,8 @@ namespace
|
|||||||
{
|
{
|
||||||
if (reusable)
|
if (reusable)
|
||||||
{
|
{
|
||||||
LINEF("if (*{0} == PTR_FOLLOWING)", MakeTypePtrVarName(def))
|
LINEF("const auto zonePtrType = GetZonePointerType(*{0});", MakeTypePtrVarName(def))
|
||||||
|
LINEF("if (zonePtrType == ZonePointerType::FOLLOWING)", MakeTypePtrVarName(def))
|
||||||
LINE("{")
|
LINE("{")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
|
|
||||||
@ -805,7 +806,7 @@ namespace
|
|||||||
{
|
{
|
||||||
LINE("")
|
LINE("")
|
||||||
LINEF("{0}** toInsert = nullptr;", member->m_member->m_type_declaration->m_type->GetFullName())
|
LINEF("{0}** toInsert = nullptr;", member->m_member->m_type_declaration->m_type->GetFullName())
|
||||||
LINE("if (ptr == PTR_INSERT)")
|
LINE("if (zonePtrType == ZonePointerType::INSERT)")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
LINEF("toInsert = m_stream.InsertPointerNative<{0}>();", member->m_member->m_type_declaration->m_type->GetFullName())
|
LINEF("toInsert = m_stream.InsertPointerNative<{0}>();", member->m_member->m_type_declaration->m_type->GetFullName())
|
||||||
m_intendation--;
|
m_intendation--;
|
||||||
@ -850,10 +851,12 @@ namespace
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LINEF("const auto zonePtrType = GetZonePointerType({0});", MakeMemberAccess(info, member, modifier))
|
||||||
|
|
||||||
const MemberComputations computations(member);
|
const MemberComputations computations(member);
|
||||||
if (computations.IsInTempBlock())
|
if (computations.IsInTempBlock())
|
||||||
{
|
{
|
||||||
LINEF("if ({0} == PTR_FOLLOWING || {0} == PTR_INSERT)", MakeMemberAccess(info, member, modifier))
|
LINE("if (zonePtrType == ZonePointerType::FOLLOWING || zonePtrType == ZonePointerType::INSERT)")
|
||||||
LINE("{")
|
LINE("{")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
|
|
||||||
@ -872,7 +875,7 @@ namespace
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LINEF("if ({0} == PTR_FOLLOWING)", MakeMemberAccess(info, member, modifier))
|
LINE("if (zonePtrType == ZonePointerType::FOLLOWING)")
|
||||||
LINE("{")
|
LINE("{")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
|
|
||||||
@ -1213,13 +1216,14 @@ namespace
|
|||||||
LINE("{")
|
LINE("{")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
|
|
||||||
|
LINEF("const auto zonePtrType = GetZonePointerType(*{0});", MakeTypePtrVarName(info->m_definition))
|
||||||
if (inTemp)
|
if (inTemp)
|
||||||
{
|
{
|
||||||
LINEF("if (*{0} == PTR_FOLLOWING || *{0} == PTR_INSERT)", MakeTypePtrVarName(info->m_definition))
|
LINEF("if (zonePtrType == ZonePointerType::FOLLOWING || zonePtrType == ZonePointerType::INSERT)", MakeTypePtrVarName(info->m_definition))
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LINEF("if (*{0} == PTR_FOLLOWING)", MakeTypePtrVarName(info->m_definition))
|
LINEF("if (zonePtrType == ZonePointerType::FOLLOWING)", MakeTypePtrVarName(info->m_definition))
|
||||||
}
|
}
|
||||||
LINE("{")
|
LINE("{")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
@ -1237,7 +1241,7 @@ namespace
|
|||||||
{
|
{
|
||||||
LINE("")
|
LINE("")
|
||||||
LINEF("{0}** toInsert = nullptr;", info->m_definition->GetFullName())
|
LINEF("{0}** toInsert = nullptr;", info->m_definition->GetFullName())
|
||||||
LINE("if (ptr == PTR_INSERT)")
|
LINE("if (zonePtrType == ZonePointerType::INSERT)")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
LINEF("toInsert = m_stream.InsertPointerNative<{0}>();", info->m_definition->GetFullName())
|
LINEF("toInsert = m_stream.InsertPointerNative<{0}>();", info->m_definition->GetFullName())
|
||||||
m_intendation--;
|
m_intendation--;
|
||||||
|
@ -48,7 +48,7 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
|
|
||||||
if (varScriptStringList->strings != nullptr)
|
if (varScriptStringList->strings != nullptr)
|
||||||
{
|
{
|
||||||
assert(varScriptStringList->strings == PTR_FOLLOWING);
|
assert(GetZonePointerType(varScriptStringList->strings) == ZonePointerType::FOLLOWING);
|
||||||
|
|
||||||
varScriptStringList->strings = m_stream.Alloc<const char*>(alignof(const char*));
|
varScriptStringList->strings = m_stream.Alloc<const char*>(alignof(const char*));
|
||||||
varXString = varScriptStringList->strings;
|
varXString = varScriptStringList->strings;
|
||||||
@ -146,7 +146,7 @@ void ContentLoader::Load()
|
|||||||
|
|
||||||
if (assetList.assets != nullptr)
|
if (assetList.assets != nullptr)
|
||||||
{
|
{
|
||||||
assert(assetList.assets == PTR_FOLLOWING);
|
assert(GetZonePointerType(assetList.assets) == ZonePointerType::FOLLOWING);
|
||||||
|
|
||||||
assetList.assets = m_stream.Alloc<XAsset>(alignof(XAsset));
|
assetList.assets = m_stream.Alloc<XAsset>(alignof(XAsset));
|
||||||
varXAsset = assetList.assets;
|
varXAsset = assetList.assets;
|
||||||
|
@ -71,7 +71,7 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
|
|
||||||
if (varScriptStringList->strings != nullptr)
|
if (varScriptStringList->strings != nullptr)
|
||||||
{
|
{
|
||||||
assert(varScriptStringList->strings == PTR_FOLLOWING);
|
assert(GetZonePointerType(varScriptStringList->strings) == ZonePointerType::FOLLOWING);
|
||||||
|
|
||||||
varScriptStringList->strings = m_stream.Alloc<const char*>(4);
|
varScriptStringList->strings = m_stream.Alloc<const char*>(4);
|
||||||
varXString = varScriptStringList->strings;
|
varXString = varScriptStringList->strings;
|
||||||
@ -179,7 +179,7 @@ void ContentLoader::Load()
|
|||||||
|
|
||||||
if (assetList.assets != nullptr)
|
if (assetList.assets != nullptr)
|
||||||
{
|
{
|
||||||
assert(assetList.assets == PTR_FOLLOWING);
|
assert(GetZonePointerType(assetList.assets) == ZonePointerType::FOLLOWING);
|
||||||
|
|
||||||
assetList.assets = m_stream.Alloc<XAsset>(alignof(XAsset));
|
assetList.assets = m_stream.Alloc<XAsset>(alignof(XAsset));
|
||||||
varXAsset = assetList.assets;
|
varXAsset = assetList.assets;
|
||||||
|
@ -63,7 +63,7 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
|
|
||||||
if (varScriptStringList->strings != nullptr)
|
if (varScriptStringList->strings != nullptr)
|
||||||
{
|
{
|
||||||
assert(varScriptStringList->strings == PTR_FOLLOWING);
|
assert(GetZonePointerType(varScriptStringList->strings) == ZonePointerType::FOLLOWING);
|
||||||
|
|
||||||
varScriptStringList->strings = m_stream.Alloc<const char*>(alignof(const char*));
|
varScriptStringList->strings = m_stream.Alloc<const char*>(alignof(const char*));
|
||||||
varXString = varScriptStringList->strings;
|
varXString = varScriptStringList->strings;
|
||||||
@ -175,7 +175,7 @@ void ContentLoader::Load()
|
|||||||
|
|
||||||
if (assetList.assets != nullptr)
|
if (assetList.assets != nullptr)
|
||||||
{
|
{
|
||||||
assert(assetList.assets == PTR_FOLLOWING);
|
assert(GetZonePointerType(assetList.assets) == ZonePointerType::FOLLOWING);
|
||||||
|
|
||||||
assetList.assets = m_stream.Alloc<XAsset>(alignof(XAsset));
|
assetList.assets = m_stream.Alloc<XAsset>(alignof(XAsset));
|
||||||
varXAsset = assetList.assets;
|
varXAsset = assetList.assets;
|
||||||
|
@ -55,7 +55,7 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
|
|
||||||
if (varScriptStringList->strings != nullptr)
|
if (varScriptStringList->strings != nullptr)
|
||||||
{
|
{
|
||||||
assert(varScriptStringList->strings == PTR_FOLLOWING);
|
assert(GetZonePointerType(varScriptStringList->strings) == ZonePointerType::FOLLOWING);
|
||||||
|
|
||||||
varScriptStringList->strings = m_stream.Alloc<const char*>(alignof(const char*));
|
varScriptStringList->strings = m_stream.Alloc<const char*>(alignof(const char*));
|
||||||
varXString = varScriptStringList->strings;
|
varXString = varScriptStringList->strings;
|
||||||
@ -159,7 +159,7 @@ void ContentLoader::Load()
|
|||||||
|
|
||||||
if (assetList.assets != nullptr)
|
if (assetList.assets != nullptr)
|
||||||
{
|
{
|
||||||
assert(assetList.assets == PTR_FOLLOWING);
|
assert(GetZonePointerType(assetList.assets) == ZonePointerType::FOLLOWING);
|
||||||
|
|
||||||
assetList.assets = m_stream.Alloc<XAsset>(alignof(XAsset));
|
assetList.assets = m_stream.Alloc<XAsset>(alignof(XAsset));
|
||||||
varXAsset = assetList.assets;
|
varXAsset = assetList.assets;
|
||||||
|
@ -71,7 +71,7 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
|
|
||||||
if (varScriptStringList->strings != nullptr)
|
if (varScriptStringList->strings != nullptr)
|
||||||
{
|
{
|
||||||
assert(varScriptStringList->strings == PTR_FOLLOWING);
|
assert(GetZonePointerType(varScriptStringList->strings) == ZonePointerType::FOLLOWING);
|
||||||
|
|
||||||
varScriptStringList->strings = m_stream.Alloc<const char*>(alignof(const char*));
|
varScriptStringList->strings = m_stream.Alloc<const char*>(alignof(const char*));
|
||||||
varXString = varScriptStringList->strings;
|
varXString = varScriptStringList->strings;
|
||||||
@ -188,7 +188,7 @@ void ContentLoader::Load()
|
|||||||
|
|
||||||
if (assetList.depends != nullptr)
|
if (assetList.depends != nullptr)
|
||||||
{
|
{
|
||||||
assert(assetList.depends == PTR_FOLLOWING);
|
assert(GetZonePointerType(assetList.depends) == ZonePointerType::FOLLOWING);
|
||||||
|
|
||||||
assetList.depends = m_stream.Alloc<const char*>(alignof(const char*));
|
assetList.depends = m_stream.Alloc<const char*>(alignof(const char*));
|
||||||
varXString = assetList.depends;
|
varXString = assetList.depends;
|
||||||
@ -197,7 +197,7 @@ void ContentLoader::Load()
|
|||||||
|
|
||||||
if (assetList.assets != nullptr)
|
if (assetList.assets != nullptr)
|
||||||
{
|
{
|
||||||
assert(assetList.assets == PTR_FOLLOWING);
|
assert(GetZonePointerType(assetList.assets) == ZonePointerType::FOLLOWING);
|
||||||
|
|
||||||
assetList.assets = m_stream.Alloc<XAsset>(alignof(XAsset));
|
assetList.assets = m_stream.Alloc<XAsset>(alignof(XAsset));
|
||||||
varXAsset = assetList.assets;
|
varXAsset = assetList.assets;
|
||||||
|
@ -1,15 +1,22 @@
|
|||||||
#include "ContentLoaderBase.h"
|
#include "ContentLoaderBase.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cstdint>
|
||||||
const void* ContentLoaderBase::PTR_FOLLOWING = reinterpret_cast<void*>(-1);
|
#include <limits>
|
||||||
const void* ContentLoaderBase::PTR_INSERT = reinterpret_cast<void*>(-2);
|
|
||||||
|
|
||||||
ContentLoaderBase::ContentLoaderBase(Zone& zone, ZoneInputStream& stream)
|
ContentLoaderBase::ContentLoaderBase(Zone& zone, ZoneInputStream& stream)
|
||||||
: varXString(nullptr),
|
: varXString(nullptr),
|
||||||
m_zone(zone),
|
m_zone(zone),
|
||||||
m_memory(zone.Memory()),
|
m_memory(zone.Memory()),
|
||||||
m_stream(stream)
|
m_stream(stream),
|
||||||
|
|
||||||
|
// -1
|
||||||
|
m_zone_ptr_following(
|
||||||
|
reinterpret_cast<const void*>(std::numeric_limits<std::uintptr_t>::max() >> ((sizeof(std::uintptr_t) * 8u) - stream.GetPointerBitCount()))),
|
||||||
|
|
||||||
|
// -2
|
||||||
|
m_zone_ptr_insert(
|
||||||
|
reinterpret_cast<const void*>((std::numeric_limits<std::uintptr_t>::max() >> ((sizeof(std::uintptr_t) * 8u) - stream.GetPointerBitCount())) - 1u))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,9 +29,9 @@ void ContentLoaderBase::LoadXString(const bool atStreamStart) const
|
|||||||
|
|
||||||
if (*varXString != nullptr)
|
if (*varXString != nullptr)
|
||||||
{
|
{
|
||||||
if (*varXString == PTR_FOLLOWING)
|
if (GetZonePointerType(varXString) == ZonePointerType::FOLLOWING)
|
||||||
{
|
{
|
||||||
*varXString = m_stream.Alloc<const char>(alignof(const char));
|
*varXString = m_stream.Alloc<const char>(1);
|
||||||
m_stream.LoadNullTerminated(const_cast<char*>(*varXString));
|
m_stream.LoadNullTerminated(const_cast<char*>(*varXString));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -39,7 +46,10 @@ void ContentLoaderBase::LoadXStringArray(const bool atStreamStart, const size_t
|
|||||||
assert(varXString != nullptr);
|
assert(varXString != nullptr);
|
||||||
|
|
||||||
if (atStreamStart)
|
if (atStreamStart)
|
||||||
|
{
|
||||||
|
m_stream.LoadWithFill(4u * count);
|
||||||
m_stream.Load<const char*>(varXString, count);
|
m_stream.Load<const char*>(varXString, count);
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t index = 0; index < count; index++)
|
for (size_t index = 0; index < count; index++)
|
||||||
{
|
{
|
||||||
@ -47,3 +57,13 @@ void ContentLoaderBase::LoadXStringArray(const bool atStreamStart, const size_t
|
|||||||
varXString++;
|
varXString++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZonePointerType ContentLoaderBase::GetZonePointerType(const void* zonePtr) const
|
||||||
|
{
|
||||||
|
if (zonePtr == m_zone_ptr_following)
|
||||||
|
return ZonePointerType::FOLLOWING;
|
||||||
|
if (zonePtr == m_zone_ptr_insert)
|
||||||
|
return ZonePointerType::INSERT;
|
||||||
|
|
||||||
|
return ZonePointerType::OFFSET;
|
||||||
|
}
|
||||||
|
@ -3,12 +3,17 @@
|
|||||||
#include "Zone/Stream/ZoneInputStream.h"
|
#include "Zone/Stream/ZoneInputStream.h"
|
||||||
#include "Zone/Zone.h"
|
#include "Zone/Zone.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
enum class ZonePointerType : std::uint8_t
|
||||||
|
{
|
||||||
|
FOLLOWING,
|
||||||
|
INSERT,
|
||||||
|
OFFSET
|
||||||
|
};
|
||||||
|
|
||||||
class ContentLoaderBase
|
class ContentLoaderBase
|
||||||
{
|
{
|
||||||
protected:
|
|
||||||
static const void* PTR_FOLLOWING;
|
|
||||||
static const void* PTR_INSERT;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~ContentLoaderBase() = default;
|
virtual ~ContentLoaderBase() = default;
|
||||||
ContentLoaderBase(const ContentLoaderBase& other) = default;
|
ContentLoaderBase(const ContentLoaderBase& other) = default;
|
||||||
@ -22,9 +27,20 @@ protected:
|
|||||||
void LoadXString(bool atStreamStart) const;
|
void LoadXString(bool atStreamStart) const;
|
||||||
void LoadXStringArray(bool atStreamStart, size_t count);
|
void LoadXStringArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
|
[[nodiscard]] ZonePointerType GetZonePointerType(const void* zonePtr) const;
|
||||||
|
|
||||||
|
template<typename T> [[nodiscard]] ZonePointerType GetZonePointerType(T* zonePtr) const
|
||||||
|
{
|
||||||
|
return GetZonePointerType(reinterpret_cast<const void*>(zonePtr));
|
||||||
|
}
|
||||||
|
|
||||||
const char** varXString;
|
const char** varXString;
|
||||||
|
|
||||||
Zone& m_zone;
|
Zone& m_zone;
|
||||||
MemoryManager& m_memory;
|
MemoryManager& m_memory;
|
||||||
ZoneInputStream& m_stream;
|
ZoneInputStream& m_stream;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const void* m_zone_ptr_following;
|
||||||
|
const void* m_zone_ptr_insert;
|
||||||
};
|
};
|
||||||
|
@ -45,6 +45,11 @@ namespace
|
|||||||
m_insert_block = blocks[insertBlock];
|
m_insert_block = blocks[insertBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] unsigned GetPointerBitCount() const override
|
||||||
|
{
|
||||||
|
return m_pointer_byte_count * 8u;
|
||||||
|
}
|
||||||
|
|
||||||
void PushBlock(const block_t block) override
|
void PushBlock(const block_t block) override
|
||||||
{
|
{
|
||||||
assert(block < static_cast<block_t>(m_blocks.size()));
|
assert(block < static_cast<block_t>(m_blocks.size()));
|
||||||
|
@ -47,6 +47,11 @@ private:
|
|||||||
class ZoneInputStream : public IZoneStream
|
class ZoneInputStream : public IZoneStream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* \brief Returns the configured bits that make up a pointer.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] virtual unsigned GetPointerBitCount() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Retrieves the new read position in the current block by aligning the position with the specified value and then returning the current read
|
* \brief Retrieves the new read position in the current block by aligning the position with the specified value and then returning the current read
|
||||||
* position in the block.
|
* position in the block.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user