Major refactor of serialization system

This commit is contained in:
Aruki 2018-09-04 13:27:27 -06:00
parent 91650a2924
commit 5182f436b8
54 changed files with 1105 additions and 831 deletions

View File

@ -65,7 +65,10 @@ void CColor::Write(IOutputStream &rOutput, bool Integral /*= false*/) const
void CColor::Serialize(IArchive& rArc) void CColor::Serialize(IArchive& rArc)
{ {
rArc << SERIAL_AUTO(R) << SERIAL_AUTO(G) << SERIAL_AUTO(B) << SERIAL_AUTO(A); rArc << SerialParameter("R", R)
<< SerialParameter("G", G)
<< SerialParameter("B", B)
<< SerialParameter("A", A, SH_Optional, 1.0f);
} }
long CColor::ToLongRGBA() const long CColor::ToLongRGBA() const

View File

@ -62,7 +62,7 @@ TString GetGameShortName(EGame Game)
void Serialize(IArchive& rArc, EGame& rGame) void Serialize(IArchive& rArc, EGame& rGame)
{ {
CFourCC GameID = GetGameID(rGame); CFourCC GameID = GetGameID(rGame);
rArc.SerializePrimitive(GameID); rArc.SerializePrimitive(GameID, 0);
if (rArc.IsReader()) rGame = GetGameForID(GameID); if (rArc.IsReader()) rGame = GetGameForID(GameID);
} }
@ -83,16 +83,3 @@ ERegion GetRegionForName(const TString& rkName)
return eRegion_Unknown; return eRegion_Unknown;
} }
void Serialize(IArchive& rArc, ERegion& rRegion)
{
TString Name;
if (rArc.IsWriter())
Name = GetRegionName(rRegion);
rArc.SerializePrimitive(Name);
if (rArc.IsReader())
rRegion = GetRegionForName(Name);
}

View File

@ -38,6 +38,5 @@ enum ERegion
}; };
TString GetRegionName(ERegion Region); TString GetRegionName(ERegion Region);
ERegion GetRegionForName(const TString& rkName); ERegion GetRegionForName(const TString& rkName);
void Serialize(IArchive& rArc, ERegion& rRegion);
#endif // EGAME_H #endif // EGAME_H

View File

@ -38,7 +38,7 @@ public:
inline void ClearFlag(FlagEnum Flag) { mValue &= ~((u32) Flag); } inline void ClearFlag(FlagEnum Flag) { mValue &= ~((u32) Flag); }
inline void ClearFlag(TFlags Flags) { mValue &= ~Flags; } inline void ClearFlag(TFlags Flags) { mValue &= ~Flags; }
inline void Serialize(IArchive& rArc) { rArc.SerializeHexPrimitive(mValue); } inline void Serialize(IArchive& rArc) { rArc.SerializePrimitive(mValue, SH_HexDisplay); }
}; };
#define DECLARE_FLAGS(Enum, FlagTypeName) typedef TFlags<Enum> FlagTypeName; #define DECLARE_FLAGS(Enum, FlagTypeName) typedef TFlags<Enum> FlagTypeName;

View File

@ -53,8 +53,10 @@ bool InitLog(const TString& rkFilename)
fprintf(gpLogFile, "Opened log file at %s\n", Buffer); fprintf(gpLogFile, "Opened log file at %s\n", Buffer);
fflush(gpLogFile); fflush(gpLogFile);
#ifdef APP_FULL_NAME
// Print app name and version // Print app name and version
fprintf(gpLogFile, APP_FULL_NAME"\n"); fprintf(gpLogFile, APP_FULL_NAME"\n");
#endif
// Print any messages that were attempted before we initialized // Print any messages that were attempted before we initialized
if (!gPreInitLogs.empty()) if (!gPreInitLogs.empty())

View File

@ -20,13 +20,13 @@ public:
: IArchive() : IArchive()
, mOwnsStream(true) , mOwnsStream(true)
{ {
mArchiveFlags = AF_Binary | AF_Reader;
mpStream = new CFileInStream(rkFilename, IOUtil::eBigEndian); mpStream = new CFileInStream(rkFilename, IOUtil::eBigEndian);
if (mpStream->IsValid()) if (mpStream->IsValid())
{ {
mMagicValid = (mpStream->ReadLong() == Magic); mMagicValid = (mpStream->ReadLong() == Magic);
CSerialVersion Version(*mpStream); SerializeVersion();
SetVersion(Version);
} }
} }
@ -35,6 +35,8 @@ public:
, mMagicValid(true) , mMagicValid(true)
, mOwnsStream(false) , mOwnsStream(false)
{ {
mArchiveFlags = AF_Binary | AF_Reader;
ASSERT(pStream->IsValid()); ASSERT(pStream->IsValid());
mpStream = pStream; mpStream = pStream;
SetVersion(rkVersion); SetVersion(rkVersion);
@ -45,6 +47,7 @@ public:
, mMagicValid(true) , mMagicValid(true)
, mOwnsStream(true) , mOwnsStream(true)
{ {
mArchiveFlags = AF_Binary | AF_Reader;
mpStream = new CMemoryInStream(pData, DataSize, Endian); mpStream = new CMemoryInStream(pData, DataSize, Endian);
SetVersion(rkVersion); SetVersion(rkVersion);
} }
@ -61,34 +64,29 @@ public:
virtual bool IsWriter() const { return false; } virtual bool IsWriter() const { return false; }
virtual bool IsTextFormat() const { return false; } virtual bool IsTextFormat() const { return false; }
virtual bool ParamBegin(const char*) { return true; } virtual bool ParamBegin(const char*, u32) { return true; }
virtual void ParamEnd() { } virtual void ParamEnd() { }
virtual void SerializeContainerSize(u32& rSize, const TString&) { SerializePrimitive(rSize); } virtual bool PreSerializePointer(void*& Pointer, u32 Flags) { return ArchiveVersion() >= eArVer_Refactor ? mpStream->ReadBool() : true; }
virtual void SerializeAbstractObjectType(u32& rType) { SerializePrimitive(rType); } virtual void SerializeContainerSize(u32& rSize, const TString&, u32 Flags) { SerializePrimitive(rSize, Flags); }
virtual void SerializePrimitive(bool& rValue) { rValue = mpStream->ReadBool(); } virtual void SerializeBulkData(void* pData, u32 Size, u32 Flags) { mpStream->ReadBytes(pData, Size); }
virtual void SerializePrimitive(char& rValue) { rValue = mpStream->ReadByte(); }
virtual void SerializePrimitive(s8& rValue) { rValue = mpStream->ReadByte(); }
virtual void SerializePrimitive(u8& rValue) { rValue = mpStream->ReadByte(); }
virtual void SerializePrimitive(s16& rValue) { rValue = mpStream->ReadShort(); }
virtual void SerializePrimitive(u16& rValue) { rValue = mpStream->ReadShort(); }
virtual void SerializePrimitive(s32& rValue) { rValue = mpStream->ReadLong(); }
virtual void SerializePrimitive(u32& rValue) { rValue = mpStream->ReadLong(); }
virtual void SerializePrimitive(s64& rValue) { rValue = mpStream->ReadLongLong(); }
virtual void SerializePrimitive(u64& rValue) { rValue = mpStream->ReadLongLong(); }
virtual void SerializePrimitive(float& rValue) { rValue = mpStream->ReadFloat(); }
virtual void SerializePrimitive(double& rValue) { rValue = mpStream->ReadDouble(); }
virtual void SerializePrimitive(TString& rValue) { rValue = mpStream->ReadSizedString(); }
virtual void SerializePrimitive(TWideString& rValue) { rValue = mpStream->ReadSizedWString(); }
virtual void SerializePrimitive(CFourCC& rValue) { rValue = CFourCC(*mpStream); }
virtual void SerializePrimitive(CAssetID& rValue) { rValue = CAssetID(*mpStream, mGame); }
virtual void SerializeHexPrimitive(u8& rValue) { rValue = mpStream->ReadByte(); } virtual void SerializePrimitive(bool& rValue, u32 Flags) { rValue = mpStream->ReadBool(); }
virtual void SerializeHexPrimitive(u16& rValue) { rValue = mpStream->ReadShort(); } virtual void SerializePrimitive(char& rValue, u32 Flags) { rValue = mpStream->ReadByte(); }
virtual void SerializeHexPrimitive(u32& rValue) { rValue = mpStream->ReadLong(); } virtual void SerializePrimitive(s8& rValue, u32 Flags) { rValue = mpStream->ReadByte(); }
virtual void SerializeHexPrimitive(u64& rValue) { rValue = mpStream->ReadLongLong(); } virtual void SerializePrimitive(u8& rValue, u32 Flags) { rValue = mpStream->ReadByte(); }
virtual void SerializePrimitive(s16& rValue, u32 Flags) { rValue = mpStream->ReadShort(); }
virtual void BulkSerialize(void* pData, u32 Size) { mpStream->ReadBytes(pData, Size); } virtual void SerializePrimitive(u16& rValue, u32 Flags) { rValue = mpStream->ReadShort(); }
virtual void SerializePrimitive(s32& rValue, u32 Flags) { rValue = mpStream->ReadLong(); }
virtual void SerializePrimitive(u32& rValue, u32 Flags) { rValue = mpStream->ReadLong(); }
virtual void SerializePrimitive(s64& rValue, u32 Flags) { rValue = mpStream->ReadLongLong(); }
virtual void SerializePrimitive(u64& rValue, u32 Flags) { rValue = mpStream->ReadLongLong(); }
virtual void SerializePrimitive(float& rValue, u32 Flags) { rValue = mpStream->ReadFloat(); }
virtual void SerializePrimitive(double& rValue, u32 Flags) { rValue = mpStream->ReadDouble(); }
virtual void SerializePrimitive(TString& rValue, u32 Flags) { rValue = mpStream->ReadSizedString(); }
virtual void SerializePrimitive(TWideString& rValue, u32 Flags) { rValue = mpStream->ReadSizedWString(); }
virtual void SerializePrimitive(CFourCC& rValue, u32 Flags) { rValue = CFourCC(*mpStream); }
virtual void SerializePrimitive(CAssetID& rValue, u32 Flags) { rValue = CAssetID(*mpStream, mGame); }
}; };
#endif // CBASICBINARYREADER #endif // CBASICBINARYREADER

View File

@ -20,13 +20,14 @@ public:
, mMagic(Magic) , mMagic(Magic)
, mOwnsStream(true) , mOwnsStream(true)
{ {
mArchiveFlags = AF_Binary | AF_Writer;
mpStream = new CFileOutStream(rkFilename, IOUtil::eBigEndian); mpStream = new CFileOutStream(rkFilename, IOUtil::eBigEndian);
if (mpStream->IsValid()) if (mpStream->IsValid())
{ {
mpStream->WriteLong(0); // Magic is written after the rest of the file is successfully saved mpStream->WriteLong(0); // Magic is written after the rest of the file is successfully saved
SetVersion(skCurrentArchiveVersion, FileVersion, Game); SetVersion(skCurrentArchiveVersion, FileVersion, Game);
GetVersionInfo().Write(*mpStream); SerializeVersion();
} }
} }
@ -35,6 +36,7 @@ public:
, mOwnsStream(false) , mOwnsStream(false)
{ {
ASSERT(pStream->IsValid()); ASSERT(pStream->IsValid());
mArchiveFlags = AF_Binary | AF_Writer;
mpStream = pStream; mpStream = pStream;
SetVersion(skCurrentArchiveVersion, FileVersion, Game); SetVersion(skCurrentArchiveVersion, FileVersion, Game);
} }
@ -44,6 +46,7 @@ public:
, mOwnsStream(false) , mOwnsStream(false)
{ {
ASSERT(pStream->IsValid()); ASSERT(pStream->IsValid());
mArchiveFlags = AF_Binary | AF_Writer;
mpStream = pStream; mpStream = pStream;
SetVersion(rkVersion); SetVersion(rkVersion);
} }
@ -66,34 +69,35 @@ public:
virtual bool IsWriter() const { return true; } virtual bool IsWriter() const { return true; }
virtual bool IsTextFormat() const { return false; } virtual bool IsTextFormat() const { return false; }
virtual bool ParamBegin(const char*) { return true; } virtual bool ParamBegin(const char*, u32) { return true; }
virtual void ParamEnd() { } virtual void ParamEnd() { }
virtual bool PreSerializePointer(void*& Pointer, u32 Flags)
{
bool ValidPtr = (Pointer != nullptr);
mpStream->WriteBool(ValidPtr);
return ValidPtr;
}
virtual void SerializeContainerSize(u32& rSize, const TString&) { mpStream->WriteLong(rSize); } virtual void SerializeContainerSize(u32& rSize, const TString&) { mpStream->WriteLong(rSize); }
virtual void SerializeAbstractObjectType(u32& rType) { mpStream->WriteLong(rType); }
virtual void SerializePrimitive(bool& rValue) { mpStream->WriteBool(rValue); }
virtual void SerializePrimitive(char& rValue) { mpStream->WriteByte(rValue); }
virtual void SerializePrimitive(s8& rValue) { mpStream->WriteByte(rValue); }
virtual void SerializePrimitive(u8& rValue) { mpStream->WriteByte(rValue); }
virtual void SerializePrimitive(s16& rValue) { mpStream->WriteShort(rValue); }
virtual void SerializePrimitive(u16& rValue) { mpStream->WriteShort(rValue); }
virtual void SerializePrimitive(s32& rValue) { mpStream->WriteLong(rValue); }
virtual void SerializePrimitive(u32& rValue) { mpStream->WriteLong(rValue); }
virtual void SerializePrimitive(s64& rValue) { mpStream->WriteLongLong(rValue); }
virtual void SerializePrimitive(u64& rValue) { mpStream->WriteLongLong(rValue); }
virtual void SerializePrimitive(float& rValue) { mpStream->WriteFloat(rValue); }
virtual void SerializePrimitive(double& rValue) { mpStream->WriteDouble(rValue); }
virtual void SerializePrimitive(TString& rValue) { mpStream->WriteSizedString(rValue); }
virtual void SerializePrimitive(TWideString& rValue) { mpStream->WriteSizedWString(rValue); }
virtual void SerializePrimitive(CFourCC& rValue) { rValue.Write(*mpStream); }
virtual void SerializePrimitive(CAssetID& rValue) { rValue.Write(*mpStream, CAssetID::GameIDLength(Game())); }
virtual void SerializeHexPrimitive(u8& rValue) { mpStream->WriteByte(rValue); } virtual void SerializePrimitive(bool& rValue, u32 Flags) { mpStream->WriteBool(rValue); }
virtual void SerializeHexPrimitive(u16& rValue) { mpStream->WriteShort(rValue); } virtual void SerializePrimitive(char& rValue, u32 Flags) { mpStream->WriteByte(rValue); }
virtual void SerializeHexPrimitive(u32& rValue) { mpStream->WriteLong(rValue); } virtual void SerializePrimitive(s8& rValue, u32 Flags) { mpStream->WriteByte(rValue); }
virtual void SerializeHexPrimitive(u64& rValue) { mpStream->WriteLongLong(rValue); } virtual void SerializePrimitive(u8& rValue, u32 Flags) { mpStream->WriteByte(rValue); }
virtual void SerializePrimitive(s16& rValue, u32 Flags) { mpStream->WriteShort(rValue); }
virtual void BulkSerialize(void* pData, u32 Size) { mpStream->WriteBytes(pData, Size); } virtual void SerializePrimitive(u16& rValue, u32 Flags) { mpStream->WriteShort(rValue); }
virtual void SerializePrimitive(s32& rValue, u32 Flags) { mpStream->WriteLong(rValue); }
virtual void SerializePrimitive(u32& rValue, u32 Flags) { mpStream->WriteLong(rValue); }
virtual void SerializePrimitive(s64& rValue, u32 Flags) { mpStream->WriteLongLong(rValue); }
virtual void SerializePrimitive(u64& rValue, u32 Flags) { mpStream->WriteLongLong(rValue); }
virtual void SerializePrimitive(float& rValue, u32 Flags) { mpStream->WriteFloat(rValue); }
virtual void SerializePrimitive(double& rValue, u32 Flags) { mpStream->WriteDouble(rValue); }
virtual void SerializePrimitive(TString& rValue, u32 Flags) { mpStream->WriteSizedString(rValue); }
virtual void SerializePrimitive(TWideString& rValue, u32 Flags) { mpStream->WriteSizedWString(rValue); }
virtual void SerializePrimitive(CFourCC& rValue, u32 Flags) { rValue.Write(*mpStream); }
virtual void SerializePrimitive(CAssetID& rValue, u32 Flags) { rValue.Write(*mpStream, CAssetID::GameIDLength(Game())); }
virtual void SerializeBulkData(void* pData, u32 Size, u32 Flags) { mpStream->WriteBytes(pData, Size); }
}; };
#endif // CBASICBINARYWRITER #endif // CBASICBINARYWRITER

View File

@ -7,43 +7,46 @@
class CBinaryReader : public IArchive class CBinaryReader : public IArchive
{ {
struct SParameter struct SBinaryParm
{ {
u32 Offset; u32 Offset;
u32 Size; u32 Size;
u32 NumChildren; u32 NumChildren;
u32 ChildIndex; u32 ChildIndex;
bool Abstract;
}; };
std::vector<SParameter> mParamStack; std::vector<SBinaryParm> mBinaryParmStack;
IInputStream *mpStream; IInputStream *mpStream;
bool mMagicValid; bool mMagicValid;
bool mOwnsStream; bool mOwnsStream;
bool mInAttribute;
public: public:
CBinaryReader(const TString& rkFilename, u32 Magic) CBinaryReader(const TString& rkFilename, u32 Magic)
: IArchive() : IArchive()
, mOwnsStream(true) , mOwnsStream(true)
, mInAttribute(false)
{ {
mArchiveFlags = AF_Reader | AF_Binary;
mpStream = new CFileInStream(rkFilename, IOUtil::eBigEndian); mpStream = new CFileInStream(rkFilename, IOUtil::eBigEndian);
if (mpStream->IsValid()) if (mpStream->IsValid())
{ {
mMagicValid = (mpStream->ReadLong() == Magic); mMagicValid = (mpStream->ReadLong() == Magic);
CSerialVersion Version(*mpStream);
SetVersion(Version);
} }
InitParamStack(); InitParamStack();
SerializeVersion();
} }
CBinaryReader(IInputStream *pStream, const CSerialVersion& rkVersion) CBinaryReader(IInputStream *pStream, const CSerialVersion& rkVersion)
: IArchive() : IArchive()
, mMagicValid(true) , mMagicValid(true)
, mOwnsStream(false) , mOwnsStream(false)
, mInAttribute(false)
{ {
ASSERT(pStream && pStream->IsValid()); ASSERT(pStream && pStream->IsValid());
mArchiveFlags = AF_Reader | AF_Binary;
mpStream = pStream; mpStream = pStream;
SetVersion(rkVersion); SetVersion(rkVersion);
@ -64,27 +67,23 @@ private:
u32 Size = ReadSize(); u32 Size = ReadSize();
u32 Offset = mpStream->Tell(); u32 Offset = mpStream->Tell();
u32 NumChildren = ReadSize(); u32 NumChildren = ReadSize();
mParamStack.push_back( SParameter { Offset, Size, NumChildren, 0, false } ); mBinaryParmStack.push_back( SBinaryParm { Offset, Size, NumChildren, 0 } );
mParamStack.reserve(20); mBinaryParmStack.reserve(20);
} }
public: public:
// Interface // Interface
virtual bool IsReader() const { return true; }
virtual bool IsWriter() const { return false; }
virtual bool IsTextFormat() const { return false; }
u32 ReadSize() u32 ReadSize()
{ {
return (mArchiveVersion < eArVer_32BitBinarySize ? (u32) mpStream->ReadShort() : mpStream->ReadLong()); return (mArchiveVersion < eArVer_32BitBinarySize ? (u32) mpStream->ReadShort() : mpStream->ReadLong());
} }
virtual bool ParamBegin(const char *pkName) virtual bool ParamBegin(const char *pkName, u32 Flags)
{ {
// If this is the parent parameter's first child, then read the child count // If this is the parent parameter's first child, then read the child count
if (mParamStack.back().NumChildren == 0xFFFFFFFF) if (mBinaryParmStack.back().NumChildren == 0xFFFFFFFF)
{ {
mParamStack.back().NumChildren = ReadSize(); mBinaryParmStack.back().NumChildren = ReadSize();
} }
// Save current offset // Save current offset
@ -92,26 +91,25 @@ public:
u32 ParamID = TString(pkName).Hash32(); u32 ParamID = TString(pkName).Hash32();
// Check the next parameter ID first and check whether it's a match for the current parameter // Check the next parameter ID first and check whether it's a match for the current parameter
if (mParamStack.back().ChildIndex < mParamStack.back().NumChildren) if (mBinaryParmStack.back().ChildIndex < mBinaryParmStack.back().NumChildren)
{ {
u32 NextID = mpStream->ReadLong(); u32 NextID = mpStream->ReadLong();
u32 NextSize = ReadSize(); u32 NextSize = ReadSize();
// Does the next parameter ID match the current one? // Does the next parameter ID match the current one?
if (NextID == ParamID) if (NextID == ParamID || (Flags & SH_IgnoreName))
{ {
mParamStack.push_back( SParameter { mpStream->Tell(), NextSize, 0xFFFFFFFF, 0, false } ); mBinaryParmStack.push_back( SBinaryParm { mpStream->Tell(), NextSize, 0xFFFFFFFF, 0 } );
return true; return true;
} }
} }
// It's not a match - return to the parent parameter's first child and check all children to find a match // It's not a match - return to the parent parameter's first child and check all children to find a match
if (!mParamStack.empty()) if (!mBinaryParmStack.empty())
{ {
bool ParentAbstract = mParamStack.back().Abstract; u32 ParentOffset = mBinaryParmStack.back().Offset;
u32 ParentOffset = mParamStack.back().Offset; u32 NumChildren = mBinaryParmStack.back().NumChildren;
u32 NumChildren = mParamStack.back().NumChildren; mpStream->GoTo(ParentOffset);
mpStream->GoTo(ParentOffset + (ParentAbstract ? 4 : 0));
for (u32 ChildIdx = 0; ChildIdx < NumChildren; ChildIdx++) for (u32 ChildIdx = 0; ChildIdx < NumChildren; ChildIdx++)
{ {
@ -122,8 +120,8 @@ public:
mpStream->Skip(ChildSize); mpStream->Skip(ChildSize);
else else
{ {
mParamStack.back().ChildIndex = ChildIdx; mBinaryParmStack.back().ChildIndex = ChildIdx;
mParamStack.push_back( SParameter { mpStream->Tell(), ChildSize, 0xFFFFFFFF, 0, false } ); mBinaryParmStack.push_back( SBinaryParm { mpStream->Tell(), ChildSize, 0xFFFFFFFF, 0 } );
return true; return true;
} }
} }
@ -137,14 +135,28 @@ public:
virtual void ParamEnd() virtual void ParamEnd()
{ {
// Make sure we're at the end of the parameter // Make sure we're at the end of the parameter
SParameter& rParam = mParamStack.back(); SBinaryParm& rParam = mBinaryParmStack.back();
u32 EndOffset = rParam.Offset + rParam.Size; u32 EndOffset = rParam.Offset + rParam.Size;
mpStream->GoTo(EndOffset); mpStream->GoTo(EndOffset);
mParamStack.pop_back(); mBinaryParmStack.pop_back();
// Increment parent child index // Increment parent child index
if (!mParamStack.empty()) if (!mBinaryParmStack.empty())
mParamStack.back().ChildIndex++; mBinaryParmStack.back().ChildIndex++;
}
virtual bool PreSerializePointer(void*& Pointer, u32 Flags)
{
if (ArchiveVersion() >= eArVer_Refactor)
{
bool ValidPtr = (Pointer != nullptr);
*this << SerialParameter("PointerValid", ValidPtr);
return ValidPtr;
}
else
{
return true;
}
} }
virtual void SerializeContainerSize(u32& rSize, const TString& /*rkElemName*/) virtual void SerializeContainerSize(u32& rSize, const TString& /*rkElemName*/)
@ -153,36 +165,23 @@ public:
rSize = (mArchiveVersion < eArVer_32BitBinarySize ? (u32) mpStream->PeekShort() : mpStream->PeekLong()); rSize = (mArchiveVersion < eArVer_32BitBinarySize ? (u32) mpStream->PeekShort() : mpStream->PeekLong());
} }
virtual void SerializeAbstractObjectType(u32& rType) virtual void SerializePrimitive(bool& rValue, u32 Flags) { rValue = mpStream->ReadBool(); }
{ virtual void SerializePrimitive(char& rValue, u32 Flags) { rValue = mpStream->ReadByte(); }
// Mark current parameter as abstract so we can account for the object type in the filestream virtual void SerializePrimitive(s8& rValue, u32 Flags) { rValue = mpStream->ReadByte(); }
rType = mpStream->ReadLong(); virtual void SerializePrimitive(u8& rValue, u32 Flags) { rValue = mpStream->ReadByte(); }
mParamStack.back().Abstract = true; virtual void SerializePrimitive(s16& rValue, u32 Flags) { rValue = mpStream->ReadShort(); }
} virtual void SerializePrimitive(u16& rValue, u32 Flags) { rValue = mpStream->ReadShort(); }
virtual void SerializePrimitive(s32& rValue, u32 Flags) { rValue = mpStream->ReadLong(); }
virtual void SerializePrimitive(bool& rValue) { rValue = mpStream->ReadBool(); } virtual void SerializePrimitive(u32& rValue, u32 Flags) { rValue = mpStream->ReadLong(); }
virtual void SerializePrimitive(char& rValue) { rValue = mpStream->ReadByte(); } virtual void SerializePrimitive(s64& rValue, u32 Flags) { rValue = mpStream->ReadLongLong(); }
virtual void SerializePrimitive(s8& rValue) { rValue = mpStream->ReadByte(); } virtual void SerializePrimitive(u64& rValue, u32 Flags) { rValue = mpStream->ReadLongLong(); }
virtual void SerializePrimitive(u8& rValue) { rValue = mpStream->ReadByte(); } virtual void SerializePrimitive(float& rValue, u32 Flags) { rValue = mpStream->ReadFloat(); }
virtual void SerializePrimitive(s16& rValue) { rValue = mpStream->ReadShort(); } virtual void SerializePrimitive(double& rValue, u32 Flags) { rValue = mpStream->ReadDouble(); }
virtual void SerializePrimitive(u16& rValue) { rValue = mpStream->ReadShort(); } virtual void SerializePrimitive(TString& rValue, u32 Flags) { rValue = mpStream->ReadSizedString(); }
virtual void SerializePrimitive(s32& rValue) { rValue = mpStream->ReadLong(); } virtual void SerializePrimitive(TWideString& rValue, u32 Flags) { rValue = mpStream->ReadSizedWString(); }
virtual void SerializePrimitive(u32& rValue) { rValue = mpStream->ReadLong(); } virtual void SerializePrimitive(CFourCC& rValue, u32 Flags) { rValue = CFourCC(*mpStream); }
virtual void SerializePrimitive(s64& rValue) { rValue = mpStream->ReadLongLong(); } virtual void SerializePrimitive(CAssetID& rValue, u32 Flags) { rValue = CAssetID(*mpStream, Game()); }
virtual void SerializePrimitive(u64& rValue) { rValue = mpStream->ReadLongLong(); } virtual void SerializeBulkData(void* pData, u32 Size, u32 Flags) { mpStream->ReadBytes(pData, Size); }
virtual void SerializePrimitive(float& rValue) { rValue = mpStream->ReadFloat(); }
virtual void SerializePrimitive(double& rValue) { rValue = mpStream->ReadDouble(); }
virtual void SerializePrimitive(TString& rValue) { rValue = mpStream->ReadSizedString(); }
virtual void SerializePrimitive(TWideString& rValue) { rValue = mpStream->ReadSizedWString(); }
virtual void SerializePrimitive(CFourCC& rValue) { rValue = CFourCC(*mpStream); }
virtual void SerializePrimitive(CAssetID& rValue) { rValue = CAssetID(*mpStream, Game()); }
virtual void SerializeHexPrimitive(u8& rValue) { rValue = mpStream->ReadByte(); }
virtual void SerializeHexPrimitive(u16& rValue) { rValue = mpStream->ReadShort(); }
virtual void SerializeHexPrimitive(u32& rValue) { rValue = mpStream->ReadLong(); }
virtual void SerializeHexPrimitive(u64& rValue) { rValue = mpStream->ReadLongLong(); }
virtual void BulkSerialize(void* pData, u32 Size) { mpStream->ReadBytes(pData, Size); }
}; };
#endif // CBINARYREADER #endif // CBINARYREADER

View File

@ -10,7 +10,6 @@ class CBinaryWriter : public IArchive
{ {
u32 Offset; u32 Offset;
u32 NumSubParams; u32 NumSubParams;
bool Abstract;
}; };
std::vector<SParameter> mParamStack; std::vector<SParameter> mParamStack;
@ -19,29 +18,31 @@ class CBinaryWriter : public IArchive
bool mOwnsStream; bool mOwnsStream;
public: public:
CBinaryWriter(const TString& rkFilename, u32 Magic, u16 FileVersion, EGame Game) CBinaryWriter(const TString& rkFilename, u32 Magic, u16 FileVersion = 0, EGame Game = eUnknownGame)
: IArchive() : IArchive()
, mMagic(Magic) , mMagic(Magic)
, mOwnsStream(true) , mOwnsStream(true)
{ {
mArchiveFlags = AF_Writer | AF_Binary;
mpStream = new CFileOutStream(rkFilename, IOUtil::eBigEndian); mpStream = new CFileOutStream(rkFilename, IOUtil::eBigEndian);
if (mpStream->IsValid()) if (mpStream->IsValid())
{ {
mpStream->WriteLong(0); // Magic is written after the rest of the file has been successfully written mpStream->WriteLong(0); // Magic is written after the rest of the file has been successfully written
SetVersion(skCurrentArchiveVersion, FileVersion, Game); SetVersion(skCurrentArchiveVersion, FileVersion, Game);
GetVersionInfo().Write(*mpStream);
} }
InitParamStack(); InitParamStack();
SerializeVersion();
} }
CBinaryWriter(IOutputStream *pStream, u16 FileVersion, EGame Game) CBinaryWriter(IOutputStream *pStream, u16 FileVersion = 0, EGame Game = eUnknownGame)
: IArchive() : IArchive()
, mMagic(0) , mMagic(0)
, mOwnsStream(false) , mOwnsStream(false)
{ {
ASSERT(pStream && pStream->IsValid()); ASSERT(pStream && pStream->IsValid());
mArchiveFlags = AF_Writer | AF_Binary;
mpStream = pStream; mpStream = pStream;
SetVersion(skCurrentArchiveVersion, FileVersion, Game); SetVersion(skCurrentArchiveVersion, FileVersion, Game);
InitParamStack(); InitParamStack();
@ -53,6 +54,7 @@ public:
, mOwnsStream(false) , mOwnsStream(false)
{ {
ASSERT(pStream && pStream->IsValid()); ASSERT(pStream && pStream->IsValid());
mArchiveFlags = AF_Writer | AF_Binary;
mpStream = pStream; mpStream = pStream;
SetVersion(rkVersion); SetVersion(rkVersion);
InitParamStack(); InitParamStack();
@ -83,16 +85,12 @@ private:
mParamStack.reserve(20); mParamStack.reserve(20);
mpStream->WriteLong(0xFFFFFFFF); mpStream->WriteLong(0xFFFFFFFF);
mpStream->WriteLong(0); // Size filler mpStream->WriteLong(0); // Size filler
mParamStack.push_back( SParameter { mpStream->Tell(), 0, false } ); mParamStack.push_back( SParameter { mpStream->Tell(), 0 } );
} }
public: public:
// Interface // Interface
virtual bool IsReader() const { return false; } virtual bool ParamBegin(const char *pkName, u32 Flags)
virtual bool IsWriter() const { return true; }
virtual bool IsTextFormat() const { return false; }
virtual bool ParamBegin(const char *pkName)
{ {
// Update parent param // Update parent param
mParamStack.back().NumSubParams++; mParamStack.back().NumSubParams++;
@ -106,7 +104,7 @@ public:
mpStream->WriteLong(-1); // Param size filler mpStream->WriteLong(-1); // Param size filler
// Add new param to the stack // Add new param to the stack
mParamStack.push_back( SParameter { mpStream->Tell(), 0, false } ); mParamStack.push_back( SParameter { mpStream->Tell(), 0 } );
return true; return true;
} }
@ -125,7 +123,6 @@ public:
// Write param child count // Write param child count
if (rParam.NumSubParams > 0 || mParamStack.size() == 1) if (rParam.NumSubParams > 0 || mParamStack.size() == 1)
{ {
if (rParam.Abstract) mpStream->Skip(4);
mpStream->WriteLong(rParam.NumSubParams); mpStream->WriteLong(rParam.NumSubParams);
} }
@ -133,6 +130,13 @@ public:
mParamStack.pop_back(); mParamStack.pop_back();
} }
virtual bool PreSerializePointer(void*& Pointer, u32 Flags)
{
bool ValidPtr = (Pointer != nullptr);
*this << SerialParameter("PointerValid", ValidPtr);
return ValidPtr;
}
virtual void SerializeContainerSize(u32& rSize, const TString& /*rkElemName*/) virtual void SerializeContainerSize(u32& rSize, const TString& /*rkElemName*/)
{ {
// Normally handled by ParamBegin and ParamEnd but we need to do something here to account for zero-sized containers // Normally handled by ParamBegin and ParamEnd but we need to do something here to account for zero-sized containers
@ -140,36 +144,23 @@ public:
mpStream->WriteLong(0); mpStream->WriteLong(0);
} }
virtual void SerializeAbstractObjectType(u32& rType) virtual void SerializePrimitive(bool& rValue, u32 Flags) { mpStream->WriteBool(rValue); }
{ virtual void SerializePrimitive(char& rValue, u32 Flags) { mpStream->WriteByte(rValue); }
// Mark this parameter as abstract so we can account for the object type in the filestream virtual void SerializePrimitive(s8& rValue, u32 Flags) { mpStream->WriteByte(rValue); }
mpStream->WriteLong(rType); virtual void SerializePrimitive(u8& rValue, u32 Flags) { mpStream->WriteByte(rValue); }
mParamStack.back().Abstract = true; virtual void SerializePrimitive(s16& rValue, u32 Flags) { mpStream->WriteShort(rValue); }
} virtual void SerializePrimitive(u16& rValue, u32 Flags) { mpStream->WriteShort(rValue); }
virtual void SerializePrimitive(s32& rValue, u32 Flags) { mpStream->WriteLong(rValue); }
virtual void SerializePrimitive(bool& rValue) { mpStream->WriteBool(rValue); } virtual void SerializePrimitive(u32& rValue, u32 Flags) { mpStream->WriteLong(rValue); }
virtual void SerializePrimitive(char& rValue) { mpStream->WriteByte(rValue); } virtual void SerializePrimitive(s64& rValue, u32 Flags) { mpStream->WriteLongLong(rValue); }
virtual void SerializePrimitive(s8& rValue) { mpStream->WriteByte(rValue); } virtual void SerializePrimitive(u64& rValue, u32 Flags) { mpStream->WriteLongLong(rValue); }
virtual void SerializePrimitive(u8& rValue) { mpStream->WriteByte(rValue); } virtual void SerializePrimitive(float& rValue, u32 Flags) { mpStream->WriteFloat(rValue); }
virtual void SerializePrimitive(s16& rValue) { mpStream->WriteShort(rValue); } virtual void SerializePrimitive(double& rValue, u32 Flags) { mpStream->WriteDouble(rValue); }
virtual void SerializePrimitive(u16& rValue) { mpStream->WriteShort(rValue); } virtual void SerializePrimitive(TString& rValue, u32 Flags) { mpStream->WriteSizedString(rValue); }
virtual void SerializePrimitive(s32& rValue) { mpStream->WriteLong(rValue); } virtual void SerializePrimitive(TWideString& rValue, u32 Flags) { mpStream->WriteSizedWString(rValue); }
virtual void SerializePrimitive(u32& rValue) { mpStream->WriteLong(rValue); } virtual void SerializePrimitive(CFourCC& rValue, u32 Flags) { rValue.Write(*mpStream); }
virtual void SerializePrimitive(s64& rValue) { mpStream->WriteLongLong(rValue); } virtual void SerializePrimitive(CAssetID& rValue, u32 Flags) { rValue.Write(*mpStream, CAssetID::GameIDLength(Game())); }
virtual void SerializePrimitive(u64& rValue) { mpStream->WriteLongLong(rValue); } virtual void SerializeBulkData(void* pData, u32 Size, u32 Flags) { mpStream->WriteBytes(pData, Size); }
virtual void SerializePrimitive(float& rValue) { mpStream->WriteFloat(rValue); }
virtual void SerializePrimitive(double& rValue) { mpStream->WriteDouble(rValue); }
virtual void SerializePrimitive(TString& rValue) { mpStream->WriteSizedString(rValue); }
virtual void SerializePrimitive(TWideString& rValue) { mpStream->WriteSizedWString(rValue); }
virtual void SerializePrimitive(CFourCC& rValue) { rValue.Write(*mpStream); }
virtual void SerializePrimitive(CAssetID& rValue) { rValue.Write(*mpStream, CAssetID::GameIDLength(Game())); }
virtual void SerializeHexPrimitive(u8& rValue) { mpStream->WriteByte(rValue); }
virtual void SerializeHexPrimitive(u16& rValue) { mpStream->WriteShort(rValue); }
virtual void SerializeHexPrimitive(u32& rValue) { mpStream->WriteLong(rValue); }
virtual void SerializeHexPrimitive(u64& rValue) { mpStream->WriteLongLong(rValue); }
virtual void BulkSerialize(void* pData, u32 Size) { mpStream->WriteBytes(pData, Size); }
}; };
#endif // CBINARYWRITER #endif // CBINARYWRITER

View File

@ -8,23 +8,24 @@ class CXMLReader : public IArchive
{ {
tinyxml2::XMLDocument mDoc; tinyxml2::XMLDocument mDoc;
tinyxml2::XMLElement *mpCurElem; // Points to the next element being read tinyxml2::XMLElement *mpCurElem; // Points to the next element being read
const char* mpAttribute; // Name of the parameter we are reading from an attribute
bool mJustEndedParam; // Indicates we just ended a primitive parameter bool mJustEndedParam; // Indicates we just ended a primitive parameter
public: public:
CXMLReader(const TString& rkFileName) CXMLReader(const TString& rkFileName)
: IArchive() : IArchive()
, mpAttribute(nullptr)
, mJustEndedParam(false) , mJustEndedParam(false)
{ {
mArchiveFlags = AF_Reader | AF_Text;
// Load XML and set current element to the root element; read version // Load XML and set current element to the root element; read version
mDoc.LoadFile(*rkFileName); mDoc.LoadFile(*rkFileName);
mpCurElem = mDoc.FirstChildElement(); mpCurElem = mDoc.FirstChildElement();
if (mpCurElem != nullptr) if (mpCurElem != nullptr)
{ {
mArchiveVersion = (u16) TString( mpCurElem->Attribute("ArchiveVer") ).ToInt32(10); SerializeVersion();
mFileVersion = (u16) TString( mpCurElem->Attribute("FileVer") ).ToInt32(10);
const char *pkGameAttr = mpCurElem->Attribute("Game");
mGame = pkGameAttr ? GetGameForID( CFourCC(pkGameAttr) ) : eUnknownGame;
} }
else else
{ {
@ -42,9 +43,17 @@ public:
virtual bool IsWriter() const { return false; } virtual bool IsWriter() const { return false; }
virtual bool IsTextFormat() const { return true; } virtual bool IsTextFormat() const { return true; }
virtual bool ParamBegin(const char *pkName) virtual bool ParamBegin(const char *pkName, u32 Flags)
{ {
ASSERT(IsValid()); ASSERT(IsValid());
ASSERT(!mpAttribute); // Attributes cannot have sub-children
// Store as an attribute if requested
if (Flags & SH_Attribute)
{
mpAttribute = mpCurElem->Attribute(pkName);
return mpAttribute != nullptr;
}
// Push new parent if needed // Push new parent if needed
if (!mJustEndedParam) if (!mJustEndedParam)
@ -55,7 +64,7 @@ public:
} }
// Verify the current element matches the name of the next serialized parameter. // Verify the current element matches the name of the next serialized parameter.
if ( strcmp(mpCurElem->Name(), pkName) == 0) if ( (Flags & SH_IgnoreName) || strcmp(mpCurElem->Name(), pkName) == 0 )
{ {
mJustEndedParam = false; mJustEndedParam = false;
return true; return true;
@ -87,6 +96,11 @@ public:
} }
virtual void ParamEnd() virtual void ParamEnd()
{
if (mpAttribute)
mpAttribute = nullptr;
else
{ {
if (mJustEndedParam) if (mJustEndedParam)
mpCurElem = mpCurElem->Parent()->ToElement(); mpCurElem = mpCurElem->Parent()->ToElement();
@ -97,50 +111,46 @@ public:
mJustEndedParam = true; mJustEndedParam = true;
} }
}
protected: protected:
TString ReadParam() TString ReadParam()
{ {
return TString(mpCurElem->GetText()); return TString( mpAttribute ? mpAttribute : mpCurElem->GetText() );
} }
public: public:
virtual void SerializeContainerSize(u32& rSize, const TString& rkElemName) virtual void SerializeArraySize(u32& Value)
{ {
rSize = 0; Value = 0;
for (tinyxml2::XMLElement *pElem = mpCurElem->FirstChildElement(*rkElemName); pElem; pElem = pElem->NextSiblingElement(*rkElemName)) for (tinyxml2::XMLElement *pElem = mpCurElem->FirstChildElement(); pElem; pElem = pElem->NextSiblingElement())
rSize++; Value++;
} }
virtual void SerializeAbstractObjectType(u32& rType) virtual bool PreSerializePointer(void*& InPointer, u32 Flags)
{ {
rType = TString(mpCurElem->Attribute("Type")).ToInt32(10); return mpCurElem->GetText() == nullptr || strcmp(mpCurElem->GetText(), "NULL") != 0;
} }
virtual void SerializePrimitive(bool& rValue) { rValue = (ReadParam() == "true" ? true : false); } virtual void SerializePrimitive(bool& rValue, u32 Flags) { rValue = (ReadParam() == "true" ? true : false); }
virtual void SerializePrimitive(char& rValue) { rValue = ReadParam().Front(); } virtual void SerializePrimitive(char& rValue, u32 Flags) { rValue = ReadParam().Front(); }
virtual void SerializePrimitive(s8& rValue) { rValue = (s8) ReadParam().ToInt32(10); } virtual void SerializePrimitive(s8& rValue, u32 Flags) { rValue = (s8) ReadParam().ToInt32( (Flags & SH_HexDisplay) ? 16 : 10 ); }
virtual void SerializePrimitive(u8& rValue) { rValue = (u8) ReadParam().ToInt32(10); } virtual void SerializePrimitive(u8& rValue, u32 Flags) { rValue = (u8) ReadParam().ToInt32( (Flags & SH_HexDisplay) ? 16 : 10 ); }
virtual void SerializePrimitive(s16& rValue) { rValue = (s16) ReadParam().ToInt32(10); } virtual void SerializePrimitive(s16& rValue, u32 Flags) { rValue = (s16) ReadParam().ToInt32( (Flags & SH_HexDisplay) ? 16 : 10 ); }
virtual void SerializePrimitive(u16& rValue) { rValue = (u16) ReadParam().ToInt32(10); } virtual void SerializePrimitive(u16& rValue, u32 Flags) { rValue = (u16) ReadParam().ToInt32( (Flags & SH_HexDisplay) ? 16 : 10 ); }
virtual void SerializePrimitive(s32& rValue) { rValue = (s32) ReadParam().ToInt32(10); } virtual void SerializePrimitive(s32& rValue, u32 Flags) { rValue = (s32) ReadParam().ToInt32( (Flags & SH_HexDisplay) ? 16 : 10 ); }
virtual void SerializePrimitive(u32& rValue) { rValue = (u32) ReadParam().ToInt32(10); } virtual void SerializePrimitive(u32& rValue, u32 Flags) { rValue = (u32) ReadParam().ToInt32( (Flags & SH_HexDisplay) ? 16 : 10 ); }
virtual void SerializePrimitive(s64& rValue) { rValue = (s64) ReadParam().ToInt64(10); } virtual void SerializePrimitive(s64& rValue, u32 Flags) { rValue = (s64) ReadParam().ToInt64( (Flags & SH_HexDisplay) ? 16 : 10 ); }
virtual void SerializePrimitive(u64& rValue) { rValue = (u64) ReadParam().ToInt64(10); } virtual void SerializePrimitive(u64& rValue, u32 Flags) { rValue = (u64) ReadParam().ToInt64( (Flags & SH_HexDisplay) ? 16 : 10 ); }
virtual void SerializePrimitive(float& rValue) { rValue = ReadParam().ToFloat(); } virtual void SerializePrimitive(float& rValue, u32 Flags) { rValue = ReadParam().ToFloat(); }
virtual void SerializePrimitive(double& rValue) { rValue = (double) ReadParam().ToFloat(); } virtual void SerializePrimitive(double& rValue, u32 Flags) { rValue = (double) ReadParam().ToFloat(); }
virtual void SerializePrimitive(TString& rValue) { rValue = ReadParam(); } virtual void SerializePrimitive(TString& rValue, u32 Flags) { rValue = ReadParam(); }
virtual void SerializePrimitive(TWideString& rValue) { rValue = ReadParam().ToUTF16(); } virtual void SerializePrimitive(TWideString& rValue, u32 Flags) { rValue = ReadParam().ToUTF16(); }
virtual void SerializePrimitive(CFourCC& rValue) { rValue = CFourCC( ReadParam() ); } virtual void SerializePrimitive(CFourCC& rValue, u32 Flags) { rValue = CFourCC( ReadParam() ); }
virtual void SerializePrimitive(CAssetID& rValue) { rValue = CAssetID::FromString( ReadParam() ); } virtual void SerializePrimitive(CAssetID& rValue, u32 Flags) { rValue = CAssetID::FromString( ReadParam() ); }
virtual void SerializeHexPrimitive(u8& rValue) { rValue = (u8) ReadParam().ToInt32(16); } virtual void SerializeBulkData(void* pData, u32 Size, u32 Flags)
virtual void SerializeHexPrimitive(u16& rValue) { rValue = (u16) ReadParam().ToInt32(16); }
virtual void SerializeHexPrimitive(u32& rValue) { rValue = (u32) ReadParam().ToInt32(16); }
virtual void SerializeHexPrimitive(u64& rValue) { rValue = (u64) ReadParam().ToInt32(16); }
virtual void BulkSerialize(void* pData, u32 Size)
{ {
char* pCharData = (char*) pData; char* pCharData = (char*) pData;
TString StringData = ReadParam(); TString StringData = ReadParam();

View File

@ -9,16 +9,19 @@
class CXMLWriter : public IArchive class CXMLWriter : public IArchive
{ {
tinyxml2::XMLDocument mDoc; tinyxml2::XMLDocument mDoc;
TString mOutFilename;
tinyxml2::XMLElement *mpCurElem; tinyxml2::XMLElement *mpCurElem;
TString mOutFilename;
const char* mpAttributeName;
bool mSaved; bool mSaved;
public: public:
CXMLWriter(const TString& rkFileName, const TString& rkRootName, u16 FileVersion, EGame Game = eUnknownGame) CXMLWriter(const TString& rkFileName, const TString& rkRootName, u16 FileVersion = 0, EGame Game = eUnknownGame)
: IArchive() : IArchive()
, mOutFilename(rkFileName) , mOutFilename(rkFileName)
, mpAttributeName(nullptr)
, mSaved(false) , mSaved(false)
{ {
mArchiveFlags = AF_Writer | AF_Text;
SetVersion(skCurrentArchiveVersion, FileVersion, Game); SetVersion(skCurrentArchiveVersion, FileVersion, Game);
// Create declaration and root node // Create declaration and root node
@ -29,9 +32,7 @@ public:
mDoc.LinkEndChild(mpCurElem); mDoc.LinkEndChild(mpCurElem);
// Write version data // Write version data
mpCurElem->SetAttribute("ArchiveVer", (int) skCurrentArchiveVersion); SerializeVersion();
mpCurElem->SetAttribute("FileVer", (int) FileVersion);
if (Game != eUnknownGame) mpCurElem->SetAttribute("Game", *GetGameID(Game).ToString());
} }
~CXMLWriter() ~CXMLWriter()
@ -69,71 +70,86 @@ public:
} }
// Interface // Interface
virtual bool IsReader() const { return false; } virtual bool ParamBegin(const char *pkName, u32 Flags)
virtual bool IsWriter() const { return true; }
virtual bool IsTextFormat() const { return true; }
virtual bool ParamBegin(const char *pkName)
{ {
ASSERT(IsValid()); ASSERT(IsValid());
ASSERT(!mpAttributeName); // Attributes cannot have sub-children
// Read as attribute if needed
if (Flags & SH_Attribute)
{
mpAttributeName = pkName;
}
else
{
tinyxml2::XMLElement *pElem = mDoc.NewElement(pkName); tinyxml2::XMLElement *pElem = mDoc.NewElement(pkName);
mpCurElem->LinkEndChild(pElem); mpCurElem->LinkEndChild(pElem);
mpCurElem = pElem; mpCurElem = pElem;
}
return true; return true;
} }
virtual void ParamEnd() virtual void ParamEnd()
{ {
if (mpAttributeName)
mpAttributeName = nullptr;
else
mpCurElem = mpCurElem->Parent()->ToElement(); mpCurElem = mpCurElem->Parent()->ToElement();
} }
protected: protected:
void WriteParam(const char *pkValue) void WriteParam(const char *pkValue)
{ {
if (mpAttributeName)
mpCurElem->SetAttribute(mpAttributeName, pkValue);
else
mpCurElem->SetText(pkValue); mpCurElem->SetText(pkValue);
} }
public: public:
virtual void SerializeContainerSize(u32&, const TString&) virtual bool PreSerializePointer(void*& Pointer, u32 Flags)
{ {
// Reader obtains container size from number of child elements if (!Pointer)
{
mpCurElem->SetText("NULL");
return false;
}
return true;
} }
virtual void SerializeAbstractObjectType(u32& rType) virtual void SerializeArraySize(u32& Value)
{ {
mpCurElem->SetAttribute("Type", (unsigned int) rType); // Do nothing. Reader obtains container size from number of child elements
} }
virtual void SerializePrimitive(bool& rValue) { WriteParam(rValue ? "true" : "false"); } virtual void SerializePrimitive(bool& rValue, u32 Flags) { WriteParam(rValue ? "true" : "false"); }
virtual void SerializePrimitive(char& rValue) { WriteParam(*TString(rValue)); } virtual void SerializePrimitive(char& rValue, u32 Flags) { WriteParam(*TString(rValue)); }
virtual void SerializePrimitive(s8& rValue) { WriteParam(*TString::FromInt32(rValue, 0, 10)); } virtual void SerializePrimitive(s8& rValue, u32 Flags) { WriteParam( (Flags & SH_HexDisplay) ? *TString::HexString((u8&) rValue, 0) : *TString::FromInt32(rValue, 0, 10) ); }
virtual void SerializePrimitive(u8& rValue) { WriteParam(*TString::FromInt32(rValue, 0, 10)); } virtual void SerializePrimitive(u8& rValue, u32 Flags) { WriteParam( (Flags & SH_HexDisplay) ? *TString::HexString((u8&) rValue, 0) : *TString::FromInt32(rValue, 0, 10) ); }
virtual void SerializePrimitive(s16& rValue) { WriteParam(*TString::FromInt32(rValue, 0, 10)); } virtual void SerializePrimitive(s16& rValue, u32 Flags) { WriteParam( (Flags & SH_HexDisplay) ? *TString::HexString((u16&) rValue, 0) : *TString::FromInt32(rValue, 0, 10) ); }
virtual void SerializePrimitive(u16& rValue) { WriteParam(*TString::FromInt32(rValue, 0, 10)); } virtual void SerializePrimitive(u16& rValue, u32 Flags) { WriteParam( (Flags & SH_HexDisplay) ? *TString::HexString((u16&) rValue, 0) : *TString::FromInt32(rValue, 0, 10) ); }
virtual void SerializePrimitive(s32& rValue) { WriteParam(*TString::FromInt32(rValue, 0, 10)); } virtual void SerializePrimitive(s32& rValue, u32 Flags) { WriteParam( (Flags & SH_HexDisplay) ? *TString::HexString((u32&) rValue, 0) : *TString::FromInt32(rValue, 0, 10) ); }
virtual void SerializePrimitive(u32& rValue) { WriteParam(*TString::FromInt32(rValue, 0, 10)); } virtual void SerializePrimitive(u32& rValue, u32 Flags) { WriteParam( (Flags & SH_HexDisplay) ? *TString::HexString((u32&) rValue, 0) : *TString::FromInt32(rValue, 0, 10) ); }
virtual void SerializePrimitive(s64& rValue) { WriteParam(*TString::FromInt64(rValue, 0, 10)); } virtual void SerializePrimitive(s64& rValue, u32 Flags) { WriteParam( *TString::FromInt64(rValue, 0, (Flags & SH_HexDisplay) ? 16 : 10) ); }
virtual void SerializePrimitive(u64& rValue) { WriteParam(*TString::FromInt64(rValue, 0, 10)); } virtual void SerializePrimitive(u64& rValue, u32 Flags) { WriteParam( *TString::FromInt64(rValue, 0, (Flags & SH_HexDisplay) ? 16 : 10) ); }
virtual void SerializePrimitive(float& rValue) { WriteParam(*TString::FromFloat(rValue)); } virtual void SerializePrimitive(float& rValue, u32 Flags) { WriteParam( *TString::FromFloat(rValue, 1, true) ); }
virtual void SerializePrimitive(double& rValue) { WriteParam(*TString::FromFloat((float) rValue)); } virtual void SerializePrimitive(double& rValue, u32 Flags) { WriteParam( *TString::FromFloat((float) rValue, 1, true) ); }
virtual void SerializePrimitive(TString& rValue) { WriteParam(*rValue); } virtual void SerializePrimitive(TString& rValue, u32 Flags) { WriteParam( *rValue ); }
virtual void SerializePrimitive(TWideString& rValue) { WriteParam(*rValue.ToUTF8()); } virtual void SerializePrimitive(TWideString& rValue, u32 Flags) { WriteParam( *rValue.ToUTF8() ); }
virtual void SerializePrimitive(CFourCC& rValue) { WriteParam(*rValue.ToString()); } virtual void SerializePrimitive(CFourCC& rValue, u32 Flags) { WriteParam( *rValue.ToString() ); }
virtual void SerializePrimitive(CAssetID& rValue) { WriteParam(*rValue.ToString( CAssetID::GameIDLength(Game()) )); } virtual void SerializePrimitive(CAssetID& rValue, u32 Flags) { WriteParam( *rValue.ToString( CAssetID::GameIDLength(Game()) ) ); }
virtual void SerializeHexPrimitive(u8& rValue) { WriteParam(*TString::HexString(rValue, 2)); } virtual void SerializeBulkData(void* pData, u32 Size, u32 Flags)
virtual void SerializeHexPrimitive(u16& rValue) { WriteParam(*TString::HexString(rValue, 4)); }
virtual void SerializeHexPrimitive(u32& rValue) { WriteParam(*TString::HexString(rValue, 8)); }
virtual void SerializeHexPrimitive(u64& rValue) { WriteParam(*TString::HexString((u32) rValue, 16)); }
virtual void BulkSerialize(void* pData, u32 Size)
{ {
char* pCharData = (char*) pData; char* pCharData = (char*) pData;
TString OutString(Size*2); TString OutString(Size*2);
for (u32 ByteIdx = 0; ByteIdx < Size; ByteIdx++) for (u32 ByteIdx = 0; ByteIdx < Size; ByteIdx++)
itoa(pCharData[ByteIdx], &OutString[ByteIdx*2], 16); {
//@todo: sloooooow. maybe replace with a LUT?
sprintf(&OutString[ByteIdx*2], "%02X", pCharData[ByteIdx]);
}
WriteParam(*OutString); WriteParam(*OutString);
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
#include "TString.h" #include "TString.h"
#include "Hash/CCRC32.h" #include "Hash/CCRC32.h"
#include "Hash/CFNV1A.h" #include "Hash/CFNV1A.h"
#include <FileIO/IOUtil.h> #include "FileIO/IOUtil.h"
#include <codecvt> #include <codecvt>
#include <locale> #include <locale>

View File

@ -930,14 +930,9 @@ public:
return SStream.str(); return SStream.str();
} }
static _TString FromFloat(float Value, int MinDecimals = 1) static _TString FromFloat(float Value, int MinDecimals = 1, bool Scientific = false)
{ {
// Initial float -> string conversion _TString Out = _TString::Format(Scientific ? "%.8g" : "%f", Value);
std::basic_stringstream<CharType> SStream;
if (MinDecimals > 0) SStream.setf(std::ios_base::showpoint);
SStream.setf(std::ios_base::fixed, std::ios_base::floatfield);
SStream << Value;
_TString Out = SStream.str();
// Make sure we have the right number of decimals // Make sure we have the right number of decimals
int DecIdx = Out.IndexOf(CHAR_LITERAL('.')); int DecIdx = Out.IndexOf(CHAR_LITERAL('.'));
@ -954,7 +949,7 @@ public:
if (NumZeroes < MinDecimals) if (NumZeroes < MinDecimals)
{ {
for (int iDec = 0; iDec < (MinDecimals - NumZeroes); iDec++) for (int iDec = 0; iDec < (MinDecimals - NumZeroes); iDec++)
Out.Append(CHAR_LITERAL('.')); Out.Append(CHAR_LITERAL('0'));
} }
// Remove unnecessary trailing zeroes from the end of the string // Remove unnecessary trailing zeroes from the end of the string

View File

@ -133,7 +133,7 @@ void CAssetNameMap::CopyFromStore(CResourceStore *pStore /*= gpResourceStore*/)
// ************ PRIVATE ************ // ************ PRIVATE ************
void CAssetNameMap::Serialize(IArchive& rArc) void CAssetNameMap::Serialize(IArchive& rArc)
{ {
rArc << SERIAL_CONTAINER("AssetNameMap", mMap, "Asset"); rArc << SerialParameter("AssetNameMap", mMap);
if (rArc.IsReader()) if (rArc.IsReader())
PostLoadValidate(); PostLoadValidate();

View File

@ -28,7 +28,11 @@ class CAssetNameMap
void Serialize(IArchive& rArc) void Serialize(IArchive& rArc)
{ {
rArc << SERIAL_AUTO(Name) << SERIAL_AUTO(Directory) << SERIAL_AUTO(Type) << SERIAL_AUTO(AutoGenName) << SERIAL_AUTO(AutoGenDir); rArc << SerialParameter("Name", Name)
<< SerialParameter("Directory", Directory)
<< SerialParameter("Type", Type)
<< SerialParameter("AutoGenName", AutoGenName)
<< SerialParameter("AutoGenDir", AutoGenDir);
} }
bool operator<(const SAssetNameInfo& rkOther) const bool operator<(const SAssetNameInfo& rkOther) const

View File

@ -5,8 +5,6 @@
#include "Core/Resource/Script/CScriptLayer.h" #include "Core/Resource/Script/CScriptLayer.h"
#include "Core/Resource/Script/CScriptObject.h" #include "Core/Resource/Script/CScriptObject.h"
CDependencyNodeFactory gDependencyNodeFactory;
// ************ IDependencyNode ************ // ************ IDependencyNode ************
IDependencyNode::~IDependencyNode() IDependencyNode::~IDependencyNode()
{ {
@ -31,6 +29,24 @@ void IDependencyNode::GetAllResourceReferences(std::set<CAssetID>& rOutSet) cons
mChildren[iChild]->GetAllResourceReferences(rOutSet); mChildren[iChild]->GetAllResourceReferences(rOutSet);
} }
// Serialization constructor
IDependencyNode* IDependencyNode::ArchiveConstructor(EDependencyNodeType Type)
{
switch (Type)
{
case eDNT_DependencyTree: return new CDependencyTree;
case eDNT_ResourceDependency: return new CResourceDependency;
case eDNT_ScriptInstance: return new CScriptInstanceDependency;
case eDNT_ScriptProperty: return new CPropertyDependency;
case eDNT_CharacterProperty: return new CCharPropertyDependency;
case eDNT_SetCharacter: return new CSetCharacterDependency;
case eDNT_SetAnimation: return new CSetAnimationDependency;
case eDNT_AnimEvent: return new CAnimEventDependency;
case eDNT_Area: return new CAreaDependencyTree;
default: ASSERT(false); return nullptr;
}
}
// ************ CDependencyTree ************ // ************ CDependencyTree ************
EDependencyNodeType CDependencyTree::Type() const EDependencyNodeType CDependencyTree::Type() const
{ {
@ -39,7 +55,7 @@ EDependencyNodeType CDependencyTree::Type() const
void CDependencyTree::Serialize(IArchive& rArc) void CDependencyTree::Serialize(IArchive& rArc)
{ {
rArc << SERIAL_ABSTRACT_CONTAINER("Children", mChildren, "Child", &gDependencyNodeFactory); rArc << SerialParameter("Children", mChildren);
} }
void CDependencyTree::AddChild(IDependencyNode *pNode) void CDependencyTree::AddChild(IDependencyNode *pNode)
@ -78,7 +94,7 @@ EDependencyNodeType CResourceDependency::Type() const
void CResourceDependency::Serialize(IArchive& rArc) void CResourceDependency::Serialize(IArchive& rArc)
{ {
rArc << SERIAL("ID", mID); rArc << SerialParameter("ID", mID);
} }
void CResourceDependency::GetAllResourceReferences(std::set<CAssetID>& rOutSet) const void CResourceDependency::GetAllResourceReferences(std::set<CAssetID>& rOutSet) const
@ -99,7 +115,7 @@ EDependencyNodeType CPropertyDependency::Type() const
void CPropertyDependency::Serialize(IArchive& rArc) void CPropertyDependency::Serialize(IArchive& rArc)
{ {
rArc << SERIAL("PropertyID", mIDString); rArc << SerialParameter("PropertyID", mIDString);
CResourceDependency::Serialize(rArc); CResourceDependency::Serialize(rArc);
} }
@ -112,7 +128,7 @@ EDependencyNodeType CCharPropertyDependency::Type() const
void CCharPropertyDependency::Serialize(IArchive& rArc) void CCharPropertyDependency::Serialize(IArchive& rArc)
{ {
CPropertyDependency::Serialize(rArc); CPropertyDependency::Serialize(rArc);
rArc << SERIAL("CharIndex", mUsedChar); rArc << SerialParameter("CharIndex", mUsedChar);
} }
// ************ CScriptInstanceDependency ************ // ************ CScriptInstanceDependency ************
@ -123,8 +139,8 @@ EDependencyNodeType CScriptInstanceDependency::Type() const
void CScriptInstanceDependency::Serialize(IArchive& rArc) void CScriptInstanceDependency::Serialize(IArchive& rArc)
{ {
rArc << SERIAL("ObjectType", mObjectType) rArc << SerialParameter("ObjectType", mObjectType)
<< SERIAL_ABSTRACT_CONTAINER("Properties", mChildren, "Property", &gDependencyNodeFactory); << SerialParameter("Properties", mChildren);
} }
// Static // Static
@ -210,8 +226,8 @@ EDependencyNodeType CSetCharacterDependency::Type() const
void CSetCharacterDependency::Serialize(IArchive& rArc) void CSetCharacterDependency::Serialize(IArchive& rArc)
{ {
rArc << SERIAL("CharSetIndex", mCharSetIndex) rArc << SerialParameter("CharSetIndex", mCharSetIndex)
<< SERIAL_ABSTRACT_CONTAINER("Children", mChildren, "Child", &gDependencyNodeFactory); << SerialParameter("Children", mChildren);
} }
CSetCharacterDependency* CSetCharacterDependency::BuildTree(const SSetCharacter& rkChar) CSetCharacterDependency* CSetCharacterDependency::BuildTree(const SSetCharacter& rkChar)
@ -255,8 +271,8 @@ EDependencyNodeType CSetAnimationDependency::Type() const
void CSetAnimationDependency::Serialize(IArchive& rArc) void CSetAnimationDependency::Serialize(IArchive& rArc)
{ {
rArc << SERIAL_CONTAINER("CharacterIndices", mCharacterIndices, "Index") rArc << SerialParameter("CharacterIndices", mCharacterIndices)
<< SERIAL_ABSTRACT_CONTAINER("Children", mChildren, "Child", &gDependencyNodeFactory); << SerialParameter("Children", mChildren);
} }
CSetAnimationDependency* CSetAnimationDependency::BuildTree(const CAnimSet *pkOwnerSet, u32 AnimIndex) CSetAnimationDependency* CSetAnimationDependency::BuildTree(const CAnimSet *pkOwnerSet, u32 AnimIndex)
@ -302,7 +318,7 @@ EDependencyNodeType CAnimEventDependency::Type() const
void CAnimEventDependency::Serialize(IArchive& rArc) void CAnimEventDependency::Serialize(IArchive& rArc)
{ {
CResourceDependency::Serialize(rArc); CResourceDependency::Serialize(rArc);
rArc << SERIAL("CharacterIndex", mCharIndex); rArc << SerialParameter("CharacterIndex", mCharIndex);
} }
// ************ CAreaDependencyTree ************ // ************ CAreaDependencyTree ************
@ -314,7 +330,7 @@ EDependencyNodeType CAreaDependencyTree::Type() const
void CAreaDependencyTree::Serialize(IArchive& rArc) void CAreaDependencyTree::Serialize(IArchive& rArc)
{ {
CDependencyTree::Serialize(rArc); CDependencyTree::Serialize(rArc);
rArc << SERIAL_CONTAINER("LayerOffsets", mLayerOffsets, "Offset"); rArc << SerialParameter("LayerOffsets", mLayerOffsets);
} }
void CAreaDependencyTree::AddScriptLayer(CScriptLayer *pLayer, const std::vector<CAssetID>& rkExtraDeps) void CAreaDependencyTree::AddScriptLayer(CScriptLayer *pLayer, const std::vector<CAssetID>& rkExtraDeps)

View File

@ -40,6 +40,9 @@ public:
virtual void GetAllResourceReferences(std::set<CAssetID>& rOutSet) const; virtual void GetAllResourceReferences(std::set<CAssetID>& rOutSet) const;
virtual bool HasDependency(const CAssetID& rkID) const; virtual bool HasDependency(const CAssetID& rkID) const;
// Serialization constructor
static IDependencyNode* ArchiveConstructor(EDependencyNodeType Type);
// Accessors // Accessors
inline u32 NumChildren() const { return mChildren.size(); } inline u32 NumChildren() const { return mChildren.size(); }
inline IDependencyNode* ChildByIndex(u32 Index) const { return mChildren[Index]; } inline IDependencyNode* ChildByIndex(u32 Index) const { return mChildren[Index]; }
@ -223,28 +226,5 @@ public:
inline u32 ScriptLayerOffset(u32 LayerIdx) const { return mLayerOffsets[LayerIdx]; } inline u32 ScriptLayerOffset(u32 LayerIdx) const { return mLayerOffsets[LayerIdx]; }
}; };
// Dependency node factory for serialization
class CDependencyNodeFactory
{
public:
IDependencyNode* SpawnObject(u32 NodeID)
{
switch (NodeID)
{
case eDNT_DependencyTree: return new CDependencyTree;
case eDNT_ResourceDependency: return new CResourceDependency;
case eDNT_ScriptInstance: return new CScriptInstanceDependency;
case eDNT_ScriptProperty: return new CPropertyDependency;
case eDNT_CharacterProperty: return new CCharPropertyDependency;
case eDNT_SetCharacter: return new CSetCharacterDependency;
case eDNT_SetAnimation: return new CSetAnimationDependency;
case eDNT_AnimEvent: return new CAnimEventDependency;
case eDNT_Area: return new CAreaDependencyTree;
default: ASSERT(false); return nullptr;
}
}
};
extern CDependencyNodeFactory gDependencyNodeFactory;
#endif // CDEPENDENCYTREE #endif // CDEPENDENCYTREE

View File

@ -41,10 +41,10 @@ void CGameInfo::Serialize(IArchive& rArc)
} }
// Serialize data // Serialize data
rArc << SERIAL_CONTAINER("GameBuilds", mBuilds, "Build"); rArc << SerialParameter("GameBuilds", mBuilds);
if (mGame <= ePrime) if (mGame <= ePrime)
rArc << SERIAL_CONTAINER("AreaNameMap", mAreaNameMap, "AreaName"); rArc << SerialParameter("AreaNameMap", mAreaNameMap);
} }
TString CGameInfo::GetBuildName(float BuildVer, ERegion Region) const TString CGameInfo::GetBuildName(float BuildVer, ERegion Region) const

View File

@ -24,7 +24,9 @@ class CGameInfo
void Serialize(IArchive& rArc) void Serialize(IArchive& rArc)
{ {
rArc << SERIAL_AUTO(Version) << SERIAL_AUTO(Region) << SERIAL_AUTO(Name); rArc << SerialParameter("Version", Version)
<< SerialParameter("Region", Region)
<< SerialParameter("Name", Name);
} }
}; };
std::vector<SBuildInfo> mBuilds; std::vector<SBuildInfo> mBuilds;

View File

@ -36,10 +36,10 @@ bool CGameProject::Save()
bool CGameProject::Serialize(IArchive& rArc) bool CGameProject::Serialize(IArchive& rArc)
{ {
rArc << SERIAL("Name", mProjectName) rArc << SerialParameter("Name", mProjectName)
<< SERIAL("Region", mRegion) << SerialParameter("Region", mRegion)
<< SERIAL("GameID", mGameID) << SerialParameter("GameID", mGameID)
<< SERIAL("BuildVersion", mBuildVersion); << SerialParameter("BuildVersion", mBuildVersion);
// Serialize package list // Serialize package list
std::vector<TString> PackageList; std::vector<TString> PackageList;
@ -50,7 +50,7 @@ bool CGameProject::Serialize(IArchive& rArc)
PackageList.push_back( mPackages[iPkg]->DefinitionPath(true) ); PackageList.push_back( mPackages[iPkg]->DefinitionPath(true) );
} }
rArc << SERIAL_CONTAINER("Packages", PackageList, "Package"); rArc << SerialParameter("Packages", PackageList);
// Load packages // Load packages
if (rArc.IsReader()) if (rArc.IsReader())

View File

@ -36,8 +36,8 @@ bool CPackage::Save()
void CPackage::Serialize(IArchive& rArc) void CPackage::Serialize(IArchive& rArc)
{ {
rArc << SERIAL("NeedsRecook", mNeedsRecook) rArc << SerialParameter("NeedsRecook", mNeedsRecook)
<< SERIAL_CONTAINER("NamedResources", mResources, "Resource"); << SerialParameter("NamedResources", mResources);
} }
void CPackage::AddResource(const TString& rkName, const CAssetID& rkID, const CFourCC& rkType) void CPackage::AddResource(const TString& rkName, const CAssetID& rkID, const CFourCC& rkType)

View File

@ -17,7 +17,9 @@ struct SNamedResource
void Serialize(IArchive& rArc) void Serialize(IArchive& rArc)
{ {
rArc << SERIAL_AUTO(Name) << SERIAL_AUTO(ID) << SERIAL_AUTO(Type); rArc << SerialParameter("Name", Name)
<< SerialParameter("ID", ID)
<< SerialParameter("Type", Type);
} }
}; };

View File

@ -127,9 +127,9 @@ void CResourceEntry::SerializeEntryInfo(IArchive& rArc, bool MetadataOnly)
{ {
CAssetID ID = mID; CAssetID ID = mID;
rArc << SERIAL("AssetID", ID) rArc << SerialParameter("AssetID", ID)
<< SERIAL("Type", mpTypeInfo) << SerialParameter("Type", mpTypeInfo)
<< SERIAL("Flags", mFlags); << SerialParameter("Flags", mFlags);
// Don't allow the file to override our asset ID if we already have a valid one. // Don't allow the file to override our asset ID if we already have a valid one.
if (rArc.IsReader() && !mID.IsValid()) if (rArc.IsReader() && !mID.IsValid())
@ -140,9 +140,9 @@ void CResourceEntry::SerializeEntryInfo(IArchive& rArc, bool MetadataOnly)
{ {
TString Dir = (mpDirectory ? mpDirectory->FullPath() : ""); TString Dir = (mpDirectory ? mpDirectory->FullPath() : "");
rArc << SERIAL("Name", mName) rArc << SerialParameter("Name", mName)
<< SERIAL("Directory", Dir) << SerialParameter("Directory", Dir)
<< SERIAL_ABSTRACT("Dependencies", mpDependencies, &gDependencyNodeFactory); << SerialParameter("Dependencies", mpDependencies);
if (rArc.IsReader()) if (rArc.IsReader())
{ {

View File

@ -62,17 +62,17 @@ void RecursiveGetListOfEmptyDirectories(CVirtualDirectory *pDir, TStringList& rO
bool CResourceStore::SerializeDatabaseCache(IArchive& rArc) bool CResourceStore::SerializeDatabaseCache(IArchive& rArc)
{ {
// Serialize resources // Serialize resources
if (rArc.ParamBegin("Resources")) if (rArc.ParamBegin("Resources", 0))
{ {
// Serialize resources // Serialize resources
u32 ResourceCount = mResourceEntries.size(); u32 ResourceCount = mResourceEntries.size();
rArc << SERIAL_AUTO(ResourceCount); rArc << SerialParameter("ResourceCount", ResourceCount);
if (rArc.IsReader()) if (rArc.IsReader())
{ {
for (u32 ResIdx = 0; ResIdx < ResourceCount; ResIdx++) for (u32 ResIdx = 0; ResIdx < ResourceCount; ResIdx++)
{ {
if (rArc.ParamBegin("Resource")) if (rArc.ParamBegin("Resource", 0))
{ {
CResourceEntry *pEntry = CResourceEntry::BuildFromArchive(this, rArc); CResourceEntry *pEntry = CResourceEntry::BuildFromArchive(this, rArc);
ASSERT( FindEntry(pEntry->ID()) == nullptr ); ASSERT( FindEntry(pEntry->ID()) == nullptr );
@ -85,7 +85,7 @@ bool CResourceStore::SerializeDatabaseCache(IArchive& rArc)
{ {
for (CResourceIterator It(this); It; ++It) for (CResourceIterator It(this); It; ++It)
{ {
if (rArc.ParamBegin("Resource")) if (rArc.ParamBegin("Resource", 0))
{ {
It->SerializeEntryInfo(rArc, false); It->SerializeEntryInfo(rArc, false);
rArc.ParamEnd(); rArc.ParamEnd();
@ -101,7 +101,7 @@ bool CResourceStore::SerializeDatabaseCache(IArchive& rArc)
if (!rArc.IsReader()) if (!rArc.IsReader())
RecursiveGetListOfEmptyDirectories(mpDatabaseRoot, EmptyDirectories); RecursiveGetListOfEmptyDirectories(mpDatabaseRoot, EmptyDirectories);
rArc << SERIAL_CONTAINER_AUTO(EmptyDirectories, "Directory"); rArc << SerialParameter("EmptyDirectories", EmptyDirectories);
if (rArc.IsReader()) if (rArc.IsReader())
{ {

View File

@ -15,6 +15,7 @@ CAnimationParameters::CAnimationParameters()
CAnimationParameters::CAnimationParameters(EGame Game) CAnimationParameters::CAnimationParameters(EGame Game)
: mGame(Game) : mGame(Game)
, mCharacterID( CAssetID::InvalidID(Game) )
, mCharIndex(0) , mCharIndex(0)
, mAnimIndex(0) , mAnimIndex(0)
, mUnknown2(0) , mUnknown2(0)
@ -141,17 +142,17 @@ void CAnimationParameters::Serialize(IArchive& rArc)
if (rArc.IsReader()) if (rArc.IsReader())
mGame = rArc.Game(); mGame = rArc.Game();
rArc << SERIAL("AnimationSetAsset", mCharacterID); rArc << SerialParameter("AnimationSetAsset", mCharacterID);
if (mGame <= eEchoes) if (mGame <= eEchoes)
rArc << SERIAL("CharacterID", mCharIndex); rArc << SerialParameter("CharacterID", mCharIndex);
rArc << SERIAL("AnimationID", mAnimIndex); rArc << SerialParameter("AnimationID", mAnimIndex);
if (mGame >= eReturns) if (mGame >= eReturns)
{ {
rArc << SERIAL("Unknown0", mUnknown2) rArc << SerialParameter("Unknown0", mUnknown2)
<< SERIAL("Unknown1", mUnknown3); << SerialParameter("Unknown1", mUnknown3);
} }
} }

View File

@ -35,11 +35,36 @@ public:
inline void SetCharIndex(u32 Index) { mCharIndex = Index; } inline void SetCharIndex(u32 Index) { mCharIndex = Index; }
inline void SetAnimIndex(u32 Index) { mAnimIndex = Index; } inline void SetAnimIndex(u32 Index) { mAnimIndex = Index; }
inline void SetGame(EGame Game)
{
mGame = Game;
if (!mCharacterID.IsValid())
{
mCharacterID = CAssetID::InvalidID(mGame);
}
else
{
ASSERT( mCharacterID.Length() == CAssetID::GameIDLength(mGame) );
}
}
u32 Unknown(u32 Index); u32 Unknown(u32 Index);
void SetResource(const CAssetID& rkID); void SetResource(const CAssetID& rkID);
void SetUnknown(u32 Index, u32 Value); void SetUnknown(u32 Index, u32 Value);
// Operators // Operators
inline CAnimationParameters& operator=(const CAnimationParameters& rkOther)
{
mGame = rkOther.mGame;
mCharacterID = rkOther.mCharacterID;
mCharIndex = rkOther.mCharIndex;
mAnimIndex = rkOther.mAnimIndex;
mUnknown2 = rkOther.mUnknown2;
mUnknown3 = rkOther.mUnknown3;
return *this;
}
inline bool operator==(const CAnimationParameters& rkOther) const inline bool operator==(const CAnimationParameters& rkOther) const
{ {
return ( (mGame == rkOther.mGame) && return ( (mGame == rkOther.mGame) &&

View File

@ -50,7 +50,7 @@ public:
void Serialize(IArchive& rArc) void Serialize(IArchive& rArc)
{ {
if (rArc.IsReader()) mGame = rArc.Game(); if (rArc.IsReader()) mGame = rArc.Game();
rArc << SERIAL_CONTAINER("AcceptedTypes", mAcceptedTypes, "Type"); rArc << SerialParameter("AcceptedTypes", mAcceptedTypes);
} }
inline bool Accepts(EResType Type) const inline bool Accepts(EResType Type) const

View File

@ -114,7 +114,7 @@ void Serialize(IArchive& rArc, CResTypeInfo*& rpType)
Ext = rpType->CookedExtension(rArc.Game()); Ext = rpType->CookedExtension(rArc.Game());
} }
rArc.SerializePrimitive(Ext); rArc.SerializePrimitive(Ext, 0);
if (rArc.IsReader()) if (rArc.IsReader())
{ {
@ -134,7 +134,7 @@ void Serialize(IArchive& rArc, EResType& rType)
Extension = pTypeInfo->CookedExtension(rArc.Game()); Extension = pTypeInfo->CookedExtension(rArc.Game());
} }
rArc.SerializePrimitive(Extension); rArc.SerializePrimitive(Extension, 0);
if (rArc.IsReader()) if (rArc.IsReader())
{ {

View File

@ -45,12 +45,20 @@ public:
} }
void Serialize(IArchive& rArc) void Serialize(IArchive& rArc)
{
if (rArc.IsBinaryFormat())
{
rArc.SerializePrimitive(m[0], 0);
rArc.SerializePrimitive(m[1], 0);
}
else
{ {
TString Str; TString Str;
if (rArc.IsWriter()) Str = ToString(); if (rArc.IsWriter()) Str = ToString();
rArc.SerializePrimitive(Str); rArc.SerializePrimitive(Str, 0);
if (rArc.IsReader()) *this = FromString(Str); if (rArc.IsReader()) *this = FromString(Str);
} }
}
// Operators // Operators
inline bool operator==(const CSavedStateID& rkOther) inline bool operator==(const CSavedStateID& rkOther)

View File

@ -92,87 +92,87 @@ u32 CWorld::AreaIndex(CAssetID AreaID) const
// ************ SERIALIZATION ************ // ************ SERIALIZATION ************
void CWorld::Serialize(IArchive& rArc) void CWorld::Serialize(IArchive& rArc)
{ {
rArc << SERIAL("Name", mName) rArc << SerialParameter("Name", mName)
<< SERIAL("NameString", mpWorldName); << SerialParameter("NameString", mpWorldName);
if (rArc.Game() == eEchoesDemo || rArc.Game() == eEchoes) if (rArc.Game() == eEchoesDemo || rArc.Game() == eEchoes)
rArc << SERIAL("DarkNameString", mpDarkWorldName); rArc << SerialParameter("DarkNameString", mpDarkWorldName);
rArc << SERIAL("WorldSaveInfo", mpSaveWorld) rArc << SerialParameter("WorldSaveInfo", mpSaveWorld)
<< SERIAL("WorldMap", mpMapWorld) << SerialParameter("WorldMap", mpMapWorld)
<< SERIAL("DefaultSkyModel", mpDefaultSkybox); << SerialParameter("DefaultSkyModel", mpDefaultSkybox);
if (rArc.Game() >= eEchoesDemo && rArc.Game() <= eCorruption) if (rArc.Game() >= eEchoesDemo && rArc.Game() <= eCorruption)
rArc << SERIAL("TempleKeyWorldIndex", mTempleKeyWorldIndex); rArc << SerialParameter("TempleKeyWorldIndex", mTempleKeyWorldIndex);
if (rArc.Game() == eReturns) if (rArc.Game() == eReturns)
rArc << SERIAL("TimeAttackData", mTimeAttackData); rArc << SerialParameter("TimeAttackData", mTimeAttackData);
if (rArc.Game() == ePrime) if (rArc.Game() == ePrime)
rArc << SERIAL_CONTAINER("MemoryRelays", mMemoryRelays, "MemoryRelay"); rArc << SerialParameter("MemoryRelays", mMemoryRelays);
rArc << SERIAL_CONTAINER("Areas", mAreas, "Area"); rArc << SerialParameter("Areas", mAreas);
} }
void Serialize(IArchive& rArc, CWorld::STimeAttackData& rData) void Serialize(IArchive& rArc, CWorld::STimeAttackData& rData)
{ {
rArc << SERIAL("HasTimeAttack", rData.HasTimeAttack) rArc << SerialParameter("HasTimeAttack", rData.HasTimeAttack)
<< SERIAL("ActNumber", rData.ActNumber) << SerialParameter("ActNumber", rData.ActNumber)
<< SERIAL("BronzeTime", rData.BronzeTime) << SerialParameter("BronzeTime", rData.BronzeTime)
<< SERIAL("SilverTime", rData.SilverTime) << SerialParameter("SilverTime", rData.SilverTime)
<< SERIAL("GoldTime", rData.GoldTime) << SerialParameter("GoldTime", rData.GoldTime)
<< SERIAL("ShinyGoldTime", rData.ShinyGoldTime); << SerialParameter("ShinyGoldTime", rData.ShinyGoldTime);
} }
void Serialize(IArchive& rArc, CWorld::SMemoryRelay& rMemRelay) void Serialize(IArchive& rArc, CWorld::SMemoryRelay& rMemRelay)
{ {
rArc << SERIAL_HEX("MemoryRelayID", rMemRelay.InstanceID) rArc << SerialParameter("MemoryRelayID", rMemRelay.InstanceID, SH_HexDisplay)
<< SERIAL_HEX("TargetID", rMemRelay.TargetID) << SerialParameter("TargetID", rMemRelay.TargetID, SH_HexDisplay)
<< SERIAL("Message", rMemRelay.Message) << SerialParameter("Message", rMemRelay.Message)
<< SERIAL("Active", rMemRelay.Active); << SerialParameter("Active", rMemRelay.Active);
} }
void Serialize(IArchive& rArc, CWorld::SArea& rArea) void Serialize(IArchive& rArc, CWorld::SArea& rArea)
{ {
rArc << SERIAL("Name", rArea.InternalName) rArc << SerialParameter("Name", rArea.InternalName)
<< SERIAL("NameString", rArea.pAreaName) << SerialParameter("NameString", rArea.pAreaName)
<< SERIAL("MREA", rArea.AreaResID) << SerialParameter("MREA", rArea.AreaResID)
<< SERIAL("ID", rArea.AreaID) << SerialParameter("ID", rArea.AreaID)
<< SERIAL("Transform", rArea.Transform) << SerialParameter("Transform", rArea.Transform)
<< SERIAL("BoundingBox", rArea.AetherBox) << SerialParameter("BoundingBox", rArea.AetherBox)
<< SERIAL("AllowPakDuplicates", rArea.AllowPakDuplicates) << SerialParameter("AllowPakDuplicates", rArea.AllowPakDuplicates)
<< SERIAL_CONTAINER("AttachedAreas", rArea.AttachedAreaIDs, "AreaIndex") << SerialParameter("AttachedAreas", rArea.AttachedAreaIDs)
<< SERIAL_CONTAINER("RelModules", rArea.RelFilenames, "Module") << SerialParameter("RelModules", rArea.RelFilenames)
<< SERIAL_CONTAINER("RelOffsets", rArea.RelOffsets, "Offset") << SerialParameter("RelOffsets", rArea.RelOffsets)
<< SERIAL_CONTAINER("Docks", rArea.Docks, "Dock") << SerialParameter("Docks", rArea.Docks)
<< SERIAL_CONTAINER("Layers", rArea.Layers, "Layer"); << SerialParameter("Layers", rArea.Layers);
} }
void Serialize(IArchive& rArc, CWorld::SArea::SDock& rDock) void Serialize(IArchive& rArc, CWorld::SArea::SDock& rDock)
{ {
rArc << SERIAL_CONTAINER("ConnectingDocks", rDock.ConnectingDocks, "ConnectingDock") rArc << SerialParameter("ConnectingDocks", rDock.ConnectingDocks)
<< SERIAL_CONTAINER("DockCoords", rDock.DockCoordinates, "Coord"); << SerialParameter("DockCoords", rDock.DockCoordinates);
} }
void Serialize(IArchive& rArc, CWorld::SArea::SDock::SConnectingDock& rDock) void Serialize(IArchive& rArc, CWorld::SArea::SDock::SConnectingDock& rDock)
{ {
rArc << SERIAL("AreaIndex", rDock.AreaIndex) rArc << SerialParameter("AreaIndex", rDock.AreaIndex)
<< SERIAL("DockIndex", rDock.DockIndex); << SerialParameter("DockIndex", rDock.DockIndex);
} }
void Serialize(IArchive& rArc, CWorld::SArea::SLayer& rLayer) void Serialize(IArchive& rArc, CWorld::SArea::SLayer& rLayer)
{ {
rArc << SERIAL("Name", rLayer.LayerName) rArc << SerialParameter("Name", rLayer.LayerName)
<< SERIAL("Active", rLayer.Active); << SerialParameter("Active", rLayer.Active);
if (rArc.Game() >= eCorruption) if (rArc.Game() >= eCorruption)
{ {
rArc << SERIAL("StateID", rLayer.LayerStateID); rArc << SerialParameter("StateID", rLayer.LayerStateID);
} }
} }
void Serialize(IArchive& rArc, CWorld::SAudioGrp& rAudioGrp) void Serialize(IArchive& rArc, CWorld::SAudioGrp& rAudioGrp)
{ {
rArc << SERIAL("GroupID", rAudioGrp.GroupID) rArc << SerialParameter("GroupID", rAudioGrp.GroupID)
<< SERIAL("AGSC", rAudioGrp.ResID); << SerialParameter("AGSC", rAudioGrp.ResID);
} }

View File

@ -95,14 +95,14 @@ void IPropertyNew::Serialize(IArchive& rArc)
{ {
if (rArc.Game() <= ePrime) if (rArc.Game() <= ePrime)
{ {
rArc << SERIAL("Name", mName); rArc << SerialParameter("Name", mName);
} }
rArc << SERIAL_HEX("ID", mID) rArc << SerialParameter("ID", mID, SH_HexDisplay | SH_Optional, (u32) 0xFFFFFFFF)
<< SERIAL("Description", mDescription) << SerialParameter("Description", mDescription, SH_Optional)
<< SERIAL("CookPref", mCookPreference) << SerialParameter("CookPref", mCookPreference, SH_Optional, ECookPreferenceNew::Default)
<< SERIAL("MinVersion", mMinVersion) << SerialParameter("MinVersion", mMinVersion, SH_Optional, 0.f)
<< SERIAL("MaxVersion", mMaxVersion); << SerialParameter("MaxVersion", mMaxVersion, SH_Optional, FLT_MAX);
// Children don't get serialized for most property types // Children don't get serialized for most property types
} }
@ -359,3 +359,12 @@ IPropertyNew* IPropertyNew::CreateIntrinsic(EPropertyTypeNew Type,
pOut->PostInitialize(); pOut->PostInitialize();
return pOut; return pOut;
} }
IPropertyNew* IPropertyNew::ArchiveConstructor(EPropertyTypeNew Type,
const IArchive& Arc)
{
IPropertyNew* pParent = Arc.FindParentObject<IPropertyNew>();
CScriptTemplate* pTemplate = (pParent ? pParent->ScriptTemplate() : Arc.FindParentObject<CScriptTemplate>());
EGame Game = Arc.Game();
return Create(Type, pParent, Game, pTemplate);
}

View File

@ -230,6 +230,9 @@ public:
IPropertyNew* pParent, IPropertyNew* pParent,
u32 Offset, u32 Offset,
const TString& rkName); const TString& rkName);
static IPropertyNew* ArchiveConstructor(EPropertyTypeNew Type,
const IArchive& Arc);
}; };
inline ECookPreferenceNew IPropertyNew::CookPreference() const inline ECookPreferenceNew IPropertyNew::CookPreference() const
@ -374,7 +377,43 @@ public:
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
IPropertyNew::Serialize(rArc); IPropertyNew::Serialize(rArc);
rArc << SERIAL("DefaultValue", mDefaultValue);
// Determine if default value should be serialized as optional.
// All MP1 properties should be optional. For MP2 and on, we set optional
// on property types that don't have default values in the game executable.
bool MakeOptional = false;
if (Game() <= ePrime)
{
MakeOptional = true;
}
else
{
switch (Type())
{
case EPropertyTypeNew::String:
case EPropertyTypeNew::Asset:
case EPropertyTypeNew::Animation:
case EPropertyTypeNew::AnimationSet:
case EPropertyTypeNew::Sequence:
case EPropertyTypeNew::Spline:
case EPropertyTypeNew::Guid:
MakeOptional = true;
break;
}
}
// Branch here to avoid constructing a default value if we don't need to.
if (MakeOptional)
rArc << SerialParameter("DefaultValue", mDefaultValue, SH_Optional, GetSerializationDefaultValue());
else
rArc << SerialParameter("DefaultValue", mDefaultValue);
}
/** Return default value for serialization - can be customized per type */
virtual PropType GetSerializationDefaultValue()
{
return PropType();
} }
}; };
@ -398,8 +437,8 @@ public:
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
TTypedPropertyNew::Serialize(rArc); TTypedPropertyNew::Serialize(rArc);
rArc << SERIAL("Min", mMinValue) rArc << SerialParameter("Min", mMinValue, SH_Optional, (PropType) -1)
<< SERIAL("Max", mMaxValue); << SerialParameter("Max", mMaxValue, SH_Optional, (PropType) -1);
} }
virtual void InitFromArchetype(IPropertyNew* pOther) virtual void InitFromArchetype(IPropertyNew* pOther)

View File

@ -15,7 +15,7 @@ protected:
public: public:
virtual void SerializeValue(void* pData, IArchive& rArc) const virtual void SerializeValue(void* pData, IArchive& rArc) const
{ {
rArc.SerializeHexPrimitive( (u32&) ValueRef(pData) ); rArc.SerializePrimitive( (u32&) ValueRef(pData), SH_HexDisplay );
} }
virtual TString ValueAsString(void* pData) const virtual TString ValueAsString(void* pData) const

View File

@ -13,6 +13,11 @@ protected:
{} {}
public: public:
virtual void PostInitialize()
{
mDefaultValue.SetGame(Game());
}
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
Value(pData).Serialize(Arc); Value(pData).Serialize(Arc);
@ -22,6 +27,11 @@ public:
{ {
return (Game() <= eEchoes ? "AnimationSet" : "CharacterAnimationSet"); return (Game() <= eEchoes ? "AnimationSet" : "CharacterAnimationSet");
} }
virtual CAnimationParameters GetSerializationDefaultValue()
{
return CAnimationParameters( Game() );
}
}; };
#endif // CANIMATIONSETPROPERTY_H #endif // CANIMATIONSETPROPERTY_H

View File

@ -108,20 +108,20 @@ public:
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
TTypedPropertyNew::Serialize(rArc); TTypedPropertyNew::Serialize(rArc);
//rArc << SERIAL("ItemArchetype", mpItemArchetype); rArc << SerialParameter("ItemArchetype", mpItemArchetype);
} }
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
u32 Count = ArrayCount(pData); u32 Count = ArrayCount(pData);
Arc.SerializeContainerSize(Count, "ArrayElement"); Arc.SerializeArraySize(Count);
if (Arc.IsReader()) if (Arc.IsReader())
Resize(pData, Count); Resize(pData, Count);
for (u32 ItemIdx = 0; ItemIdx < Count; ItemIdx++) for (u32 ItemIdx = 0; ItemIdx < Count; ItemIdx++)
{ {
if (Arc.ParamBegin("ArrayElement")) if (Arc.ParamBegin("ArrayElement", 0))
{ {
void* pItemData = ItemPointer(pData, ItemIdx); void* pItemData = ItemPointer(pData, ItemIdx);
mpItemArchetype->SerializeValue(pItemData, Arc); mpItemArchetype->SerializeValue(pItemData, Arc);

View File

@ -10,10 +10,19 @@ class CAssetProperty : public TSerializeableTypedProperty<CAssetID, EPropertyTyp
CResTypeFilter mTypeFilter; CResTypeFilter mTypeFilter;
public: public:
virtual void PostInitialize()
{
// Init default value to an invalid ID depending on the game
if (!mDefaultValue.IsValid())
{
mDefaultValue = CAssetID::InvalidID( mGame );
}
}
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
TSerializeableTypedProperty::Serialize(rArc); TSerializeableTypedProperty::Serialize(rArc);
rArc << SERIAL("AcceptedTypes", mTypeFilter); rArc << SerialParameter("TypeFilter", mTypeFilter);
} }
virtual void InitFromArchetype(IPropertyNew* pOther) virtual void InitFromArchetype(IPropertyNew* pOther)
@ -24,7 +33,7 @@ public:
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
Arc.SerializePrimitive( ValueRef(pData) ); Arc.SerializePrimitive( ValueRef(pData), 0 );
} }
virtual TString ValueAsString(void* pData) const virtual TString ValueAsString(void* pData) const
@ -32,6 +41,11 @@ public:
return Value(pData).ToString(); return Value(pData).ToString();
} }
virtual CAssetID GetSerializationDefaultValue()
{
return CAssetID::InvalidID(Game());
}
void SetTypeFilter(const TStringList& rkExtensions) void SetTypeFilter(const TStringList& rkExtensions)
{ {
mTypeFilter.SetAcceptedTypes(Game(), rkExtensions); mTypeFilter.SetAcceptedTypes(Game(), rkExtensions);

View File

@ -15,7 +15,7 @@ protected:
public: public:
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
Arc.SerializePrimitive( ValueRef(pData) ); Arc.SerializePrimitive( ValueRef(pData), 0 );
} }
virtual TString ValueAsString(void* pData) virtual TString ValueAsString(void* pData)

View File

@ -15,7 +15,7 @@ protected:
public: public:
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
Arc.SerializePrimitive( (u8&) ValueRef(pData) ); Arc.SerializePrimitive( (u8&) ValueRef(pData), 0 );
} }
virtual TString ValueAsString(void* pData) const virtual TString ValueAsString(void* pData) const

View File

@ -34,8 +34,8 @@ class TEnumPropertyBase : public TSerializeableTypedProperty<s32, TypeEnum>
void Serialize(IArchive& rArc) void Serialize(IArchive& rArc)
{ {
rArc << SERIAL_AUTO(Name) rArc << SerialParameter("Name", Name)
<< SERIAL_HEX_AUTO(ID); << SerialParameter("ID", ID, SH_HexDisplay);
} }
}; };
std::vector<SEnumValue> mValues; std::vector<SEnumValue> mValues;
@ -55,12 +55,12 @@ public:
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
TSerializeableTypedProperty::Serialize(rArc); TSerializeableTypedProperty::Serialize(rArc);
rArc << SERIAL_CONTAINER("Values", mValues, "Values"); rArc << SerialParameter("Values", mValues);
} }
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
Arc.SerializePrimitive( (u32&) ValueRef(pData) ); Arc.SerializePrimitive( (u32&) ValueRef(pData), 0 );
} }
virtual void InitFromArchetype(IPropertyNew* pOther) virtual void InitFromArchetype(IPropertyNew* pOther)

View File

@ -28,8 +28,8 @@ class CFlagsProperty : public TSerializeableTypedProperty<u32, EPropertyTypeNew:
void Serialize(IArchive& rArc) void Serialize(IArchive& rArc)
{ {
rArc << SERIAL("FlagName", Name) rArc << SerialParameter("Name", Name)
<< SERIAL_HEX("FlagMask", Mask); << SerialParameter("Mask", Mask, SH_HexDisplay);
} }
}; };
std::vector<SBitFlag> mBitFlags; std::vector<SBitFlag> mBitFlags;
@ -64,7 +64,7 @@ public:
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
TSerializeableTypedProperty::Serialize(rArc); TSerializeableTypedProperty::Serialize(rArc);
rArc << SERIAL_CONTAINER("Flags", mBitFlags, "Flag"); rArc << SerialParameter("Flags", mBitFlags);
} }
virtual void PostInitialize() virtual void PostInitialize()
@ -80,7 +80,7 @@ public:
virtual void SerializeValue(void* pData, IArchive& rArc) const virtual void SerializeValue(void* pData, IArchive& rArc) const
{ {
rArc.SerializeHexPrimitive( (u32&) ValueRef(pData) ); rArc.SerializePrimitive( (u32&) ValueRef(pData), SH_HexDisplay );
} }
virtual void InitFromArchetype(IPropertyNew* pOther) virtual void InitFromArchetype(IPropertyNew* pOther)

View File

@ -15,7 +15,7 @@ protected:
public: public:
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
Arc.SerializePrimitive( (float&) ValueRef(pData) ); Arc.SerializePrimitive( (float&) ValueRef(pData), 0 );
} }
virtual TString ValueAsString(void* pData) const virtual TString ValueAsString(void* pData) const

View File

@ -15,7 +15,7 @@ protected:
public: public:
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
Arc.SerializeBulkData( ValueRef(pData) ); Arc << SerialParameter("Data", ValueRef(pData));
} }
}; };

View File

@ -15,7 +15,7 @@ protected:
public: public:
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
Arc.SerializePrimitive( (u32&) ValueRef(pData) ); Arc.SerializePrimitive( ValueRef(pData), 0 );
} }
virtual TString ValueAsString(void* pData) const virtual TString ValueAsString(void* pData) const

View File

@ -15,7 +15,7 @@ protected:
public: public:
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
Arc.SerializePrimitive( (u16&) ValueRef(pData) ); Arc.SerializePrimitive( ValueRef(pData), 0 );
} }
virtual TString ValueAsString(void* pData) const virtual TString ValueAsString(void* pData) const

View File

@ -15,7 +15,7 @@ protected:
public: public:
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
Arc.SerializePrimitive( (u32&) ValueRef(pData) ); Arc.SerializePrimitive( ValueRef(pData), 0 );
} }
virtual TString ValueAsString(void* pData) virtual TString ValueAsString(void* pData)

View File

@ -15,7 +15,7 @@ protected:
public: public:
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
Arc.SerializeBulkData( ValueRef(pData) ); Arc << SerialParameter("Data", ValueRef(pData));
} }
}; };

View File

@ -15,7 +15,7 @@ protected:
public: public:
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
Arc.SerializePrimitive( ValueRef(pData) ); Arc.SerializePrimitive( ValueRef(pData), 0 );
} }
virtual TString ValueAsString(void* pData) const virtual TString ValueAsString(void* pData) const

View File

@ -90,43 +90,14 @@ public:
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
IPropertyNew::Serialize(rArc); IPropertyNew::Serialize(rArc);
rArc << SerialParameter("SubProperties", mChildren);
if (rArc.ParamBegin("SubProperties"))
{
u32 NumChildren = mChildren.size();
rArc.SerializeContainerSize(NumChildren, "Property");
if (rArc.IsReader())
{
mChildren.resize(NumChildren);
}
for (u32 ChildIdx = 0; ChildIdx < NumChildren; ChildIdx++)
{
if (rArc.ParamBegin("Property"))
{
EPropertyTypeNew Type = (rArc.IsWriter() ? mChildren[ChildIdx]->Type() : EPropertyTypeNew::Invalid);
rArc << SERIAL_AUTO(Type);
if (rArc.IsReader())
{
mChildren[ChildIdx] = Create(Type, this, mGame, mpScriptTemplate);
}
mChildren[ChildIdx]->Serialize(rArc);
rArc.ParamEnd();
}
}
rArc.ParamEnd();
}
} }
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {
for (u32 ChildIdx = 0; ChildIdx < mChildren.size(); ChildIdx++) for (u32 ChildIdx = 0; ChildIdx < mChildren.size(); ChildIdx++)
{ {
if (Arc.ParamBegin("Property")) if (Arc.ParamBegin("Property", 0))
{ {
mChildren[ChildIdx]->SerializeValue(pData, Arc); mChildren[ChildIdx]->SerializeValue(pData, Arc);
Arc.ParamEnd(); Arc.ParamEnd();

View File

@ -33,7 +33,7 @@ public:
inline void Serialize(IArchive& rArc) inline void Serialize(IArchive& rArc)
{ {
CAssetID ID = (mpRes && !rArc.IsReader() ? mpRes->ID() : CAssetID::InvalidID(rArc.Game())); CAssetID ID = (mpRes && !rArc.IsReader() ? mpRes->ID() : CAssetID::InvalidID(rArc.Game()));
rArc.SerializePrimitive(ID); rArc.SerializePrimitive(ID, 0);
if (rArc.IsReader()) if (rArc.IsReader())
{ {

View File

@ -24,8 +24,8 @@ CAABox::CAABox(IInputStream& rInput)
void CAABox::Serialize(IArchive& rArc) void CAABox::Serialize(IArchive& rArc)
{ {
rArc << SERIAL("Min", mMin) rArc << SerialParameter("Min", mMin)
<< SERIAL("Max", mMax); << SerialParameter("Max", mMax);
} }
void CAABox::Write(IOutputStream& rOutput) void CAABox::Write(IOutputStream& rOutput)

View File

@ -73,9 +73,9 @@ CTransform4f::CTransform4f(CVector3f Position, CVector3f Rotation, CVector3f Sca
void CTransform4f::Serialize(IArchive& rOut) void CTransform4f::Serialize(IArchive& rOut)
{ {
rOut << SERIAL("Row0Col0", m[0][0]) << SERIAL("Row0Col1", m[0][1]) << SERIAL("Row0Col2", m[0][2]) << SERIAL("Row0Col3", m[0][3]) rOut << SerialParameter("Row0Col0", m[0][0]) << SerialParameter("Row0Col1", m[0][1]) << SerialParameter("Row0Col2", m[0][2]) << SerialParameter("Row0Col3", m[0][3])
<< SERIAL("Row1Col0", m[1][0]) << SERIAL("Row1Col1", m[1][1]) << SERIAL("Row1Col2", m[1][2]) << SERIAL("Row1Col3", m[1][3]) << SerialParameter("Row1Col0", m[1][0]) << SerialParameter("Row1Col1", m[1][1]) << SerialParameter("Row1Col2", m[1][2]) << SerialParameter("Row1Col3", m[1][3])
<< SERIAL("Row2Col0", m[2][0]) << SERIAL("Row2Col1", m[2][1]) << SERIAL("Row2Col2", m[2][2]) << SERIAL("Row2Col3", m[2][3]); << SerialParameter("Row2Col0", m[2][0]) << SerialParameter("Row2Col1", m[2][1]) << SerialParameter("Row2Col2", m[2][2]) << SerialParameter("Row2Col3", m[2][3]);
} }
void CTransform4f::Write(IOutputStream& rOut) void CTransform4f::Write(IOutputStream& rOut)

View File

@ -38,7 +38,9 @@ void CVector3f::Write(IOutputStream& rOutput) const
void CVector3f::Serialize(IArchive& rArc) void CVector3f::Serialize(IArchive& rArc)
{ {
rArc << SERIAL_AUTO(X) << SERIAL_AUTO(Y) << SERIAL_AUTO(Z); rArc << SerialParameter("X", X)
<< SerialParameter("Y", Y)
<< SerialParameter("Z", Z);
} }
TString CVector3f::ToString() const TString CVector3f::ToString() const

View File

@ -559,7 +559,7 @@
<property ID="0x0D7E7E2C" name="BabyMetroidScale"/> <property ID="0x0D7E7E2C" name="BabyMetroidScale"/>
<property ID="0x0D7EF013" name="Unknown"/> <property ID="0x0D7EF013" name="Unknown"/>
<property ID="0x0D7F8C7F" name="PlayAlways"/> <property ID="0x0D7F8C7F" name="PlayAlways"/>
<property ID="0x0D7FAD55" name="Unknown"/> <property ID="0x0D7FAD55" name="DieOnCollision"/>
<property ID="0x0D8098BF" name="Unknown"/> <property ID="0x0D8098BF" name="Unknown"/>
<property ID="0x0D920DE2" name="ConnectorLocator"/> <property ID="0x0D920DE2" name="ConnectorLocator"/>
<property ID="0x0D9230D1" name="BodyVulnerability"/> <property ID="0x0D9230D1" name="BodyVulnerability"/>