Major refactor of serialization system
This commit is contained in:
parent
91650a2924
commit
5182f436b8
|
@ -65,7 +65,10 @@ void CColor::Write(IOutputStream &rOutput, bool Integral /*= false*/) const
|
|||
|
||||
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
|
||||
|
|
|
@ -62,7 +62,7 @@ TString GetGameShortName(EGame Game)
|
|||
void Serialize(IArchive& rArc, EGame& rGame)
|
||||
{
|
||||
CFourCC GameID = GetGameID(rGame);
|
||||
rArc.SerializePrimitive(GameID);
|
||||
rArc.SerializePrimitive(GameID, 0);
|
||||
if (rArc.IsReader()) rGame = GetGameForID(GameID);
|
||||
}
|
||||
|
||||
|
@ -83,16 +83,3 @@ ERegion GetRegionForName(const TString& rkName)
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -38,6 +38,5 @@ enum ERegion
|
|||
};
|
||||
TString GetRegionName(ERegion Region);
|
||||
ERegion GetRegionForName(const TString& rkName);
|
||||
void Serialize(IArchive& rArc, ERegion& rRegion);
|
||||
|
||||
#endif // EGAME_H
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
inline void ClearFlag(FlagEnum Flag) { mValue &= ~((u32) Flag); }
|
||||
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;
|
||||
|
||||
|
|
|
@ -53,8 +53,10 @@ bool InitLog(const TString& rkFilename)
|
|||
fprintf(gpLogFile, "Opened log file at %s\n", Buffer);
|
||||
fflush(gpLogFile);
|
||||
|
||||
#ifdef APP_FULL_NAME
|
||||
// Print app name and version
|
||||
fprintf(gpLogFile, APP_FULL_NAME"\n");
|
||||
#endif
|
||||
|
||||
// Print any messages that were attempted before we initialized
|
||||
if (!gPreInitLogs.empty())
|
||||
|
|
|
@ -20,13 +20,13 @@ public:
|
|||
: IArchive()
|
||||
, mOwnsStream(true)
|
||||
{
|
||||
mArchiveFlags = AF_Binary | AF_Reader;
|
||||
mpStream = new CFileInStream(rkFilename, IOUtil::eBigEndian);
|
||||
|
||||
if (mpStream->IsValid())
|
||||
{
|
||||
mMagicValid = (mpStream->ReadLong() == Magic);
|
||||
CSerialVersion Version(*mpStream);
|
||||
SetVersion(Version);
|
||||
SerializeVersion();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,8 @@ public:
|
|||
, mMagicValid(true)
|
||||
, mOwnsStream(false)
|
||||
{
|
||||
mArchiveFlags = AF_Binary | AF_Reader;
|
||||
|
||||
ASSERT(pStream->IsValid());
|
||||
mpStream = pStream;
|
||||
SetVersion(rkVersion);
|
||||
|
@ -45,6 +47,7 @@ public:
|
|||
, mMagicValid(true)
|
||||
, mOwnsStream(true)
|
||||
{
|
||||
mArchiveFlags = AF_Binary | AF_Reader;
|
||||
mpStream = new CMemoryInStream(pData, DataSize, Endian);
|
||||
SetVersion(rkVersion);
|
||||
}
|
||||
|
@ -61,34 +64,29 @@ public:
|
|||
virtual bool IsWriter() const { return false; }
|
||||
virtual bool IsTextFormat() const { return false; }
|
||||
|
||||
virtual bool ParamBegin(const char*) { return true; }
|
||||
virtual void ParamEnd() { }
|
||||
virtual bool ParamBegin(const char*, u32) { return true; }
|
||||
virtual void ParamEnd() { }
|
||||
|
||||
virtual void SerializeContainerSize(u32& rSize, const TString&) { SerializePrimitive(rSize); }
|
||||
virtual void SerializeAbstractObjectType(u32& rType) { SerializePrimitive(rType); }
|
||||
virtual void SerializePrimitive(bool& rValue) { rValue = mpStream->ReadBool(); }
|
||||
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 bool PreSerializePointer(void*& Pointer, u32 Flags) { return ArchiveVersion() >= eArVer_Refactor ? mpStream->ReadBool() : true; }
|
||||
virtual void SerializeContainerSize(u32& rSize, const TString&, u32 Flags) { SerializePrimitive(rSize, Flags); }
|
||||
virtual void SerializeBulkData(void* pData, u32 Size, u32 Flags) { mpStream->ReadBytes(pData, Size); }
|
||||
|
||||
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); }
|
||||
virtual void SerializePrimitive(bool& rValue, u32 Flags) { rValue = mpStream->ReadBool(); }
|
||||
virtual void SerializePrimitive(char& rValue, u32 Flags) { rValue = mpStream->ReadByte(); }
|
||||
virtual void SerializePrimitive(s8& rValue, u32 Flags) { rValue = mpStream->ReadByte(); }
|
||||
virtual void SerializePrimitive(u8& rValue, u32 Flags) { rValue = mpStream->ReadByte(); }
|
||||
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(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
|
||||
|
|
|
@ -20,13 +20,14 @@ public:
|
|||
, mMagic(Magic)
|
||||
, mOwnsStream(true)
|
||||
{
|
||||
mArchiveFlags = AF_Binary | AF_Writer;
|
||||
mpStream = new CFileOutStream(rkFilename, IOUtil::eBigEndian);
|
||||
|
||||
if (mpStream->IsValid())
|
||||
{
|
||||
mpStream->WriteLong(0); // Magic is written after the rest of the file is successfully saved
|
||||
SetVersion(skCurrentArchiveVersion, FileVersion, Game);
|
||||
GetVersionInfo().Write(*mpStream);
|
||||
SerializeVersion();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,6 +36,7 @@ public:
|
|||
, mOwnsStream(false)
|
||||
{
|
||||
ASSERT(pStream->IsValid());
|
||||
mArchiveFlags = AF_Binary | AF_Writer;
|
||||
mpStream = pStream;
|
||||
SetVersion(skCurrentArchiveVersion, FileVersion, Game);
|
||||
}
|
||||
|
@ -44,6 +46,7 @@ public:
|
|||
, mOwnsStream(false)
|
||||
{
|
||||
ASSERT(pStream->IsValid());
|
||||
mArchiveFlags = AF_Binary | AF_Writer;
|
||||
mpStream = pStream;
|
||||
SetVersion(rkVersion);
|
||||
}
|
||||
|
@ -66,34 +69,35 @@ public:
|
|||
virtual bool IsWriter() const { return true; }
|
||||
virtual bool IsTextFormat() const { return false; }
|
||||
|
||||
virtual bool ParamBegin(const char*) { return true; }
|
||||
virtual void ParamEnd() { }
|
||||
virtual bool ParamBegin(const char*, u32) { return true; }
|
||||
virtual void ParamEnd() { }
|
||||
|
||||
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 bool PreSerializePointer(void*& Pointer, u32 Flags)
|
||||
{
|
||||
bool ValidPtr = (Pointer != nullptr);
|
||||
mpStream->WriteBool(ValidPtr);
|
||||
return ValidPtr;
|
||||
}
|
||||
|
||||
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 SerializeContainerSize(u32& rSize, const TString&) { mpStream->WriteLong(rSize); }
|
||||
|
||||
virtual void BulkSerialize(void* pData, u32 Size) { mpStream->WriteBytes(pData, Size); }
|
||||
virtual void SerializePrimitive(bool& rValue, u32 Flags) { mpStream->WriteBool(rValue); }
|
||||
virtual void SerializePrimitive(char& rValue, u32 Flags) { mpStream->WriteByte(rValue); }
|
||||
virtual void SerializePrimitive(s8& rValue, u32 Flags) { mpStream->WriteByte(rValue); }
|
||||
virtual void SerializePrimitive(u8& rValue, u32 Flags) { mpStream->WriteByte(rValue); }
|
||||
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(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
|
||||
|
|
|
@ -7,43 +7,46 @@
|
|||
|
||||
class CBinaryReader : public IArchive
|
||||
{
|
||||
struct SParameter
|
||||
struct SBinaryParm
|
||||
{
|
||||
u32 Offset;
|
||||
u32 Size;
|
||||
u32 NumChildren;
|
||||
u32 ChildIndex;
|
||||
bool Abstract;
|
||||
};
|
||||
std::vector<SParameter> mParamStack;
|
||||
std::vector<SBinaryParm> mBinaryParmStack;
|
||||
|
||||
IInputStream *mpStream;
|
||||
bool mMagicValid;
|
||||
bool mOwnsStream;
|
||||
bool mInAttribute;
|
||||
|
||||
public:
|
||||
CBinaryReader(const TString& rkFilename, u32 Magic)
|
||||
: IArchive()
|
||||
, mOwnsStream(true)
|
||||
, mInAttribute(false)
|
||||
{
|
||||
mArchiveFlags = AF_Reader | AF_Binary;
|
||||
mpStream = new CFileInStream(rkFilename, IOUtil::eBigEndian);
|
||||
|
||||
if (mpStream->IsValid())
|
||||
{
|
||||
mMagicValid = (mpStream->ReadLong() == Magic);
|
||||
CSerialVersion Version(*mpStream);
|
||||
SetVersion(Version);
|
||||
}
|
||||
|
||||
InitParamStack();
|
||||
SerializeVersion();
|
||||
}
|
||||
|
||||
CBinaryReader(IInputStream *pStream, const CSerialVersion& rkVersion)
|
||||
: IArchive()
|
||||
, mMagicValid(true)
|
||||
, mOwnsStream(false)
|
||||
, mInAttribute(false)
|
||||
{
|
||||
ASSERT(pStream && pStream->IsValid());
|
||||
mArchiveFlags = AF_Reader | AF_Binary;
|
||||
mpStream = pStream;
|
||||
SetVersion(rkVersion);
|
||||
|
||||
|
@ -64,27 +67,23 @@ private:
|
|||
u32 Size = ReadSize();
|
||||
u32 Offset = mpStream->Tell();
|
||||
u32 NumChildren = ReadSize();
|
||||
mParamStack.push_back( SParameter { Offset, Size, NumChildren, 0, false } );
|
||||
mParamStack.reserve(20);
|
||||
mBinaryParmStack.push_back( SBinaryParm { Offset, Size, NumChildren, 0 } );
|
||||
mBinaryParmStack.reserve(20);
|
||||
}
|
||||
|
||||
public:
|
||||
// Interface
|
||||
virtual bool IsReader() const { return true; }
|
||||
virtual bool IsWriter() const { return false; }
|
||||
virtual bool IsTextFormat() const { return false; }
|
||||
|
||||
u32 ReadSize()
|
||||
{
|
||||
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 (mParamStack.back().NumChildren == 0xFFFFFFFF)
|
||||
if (mBinaryParmStack.back().NumChildren == 0xFFFFFFFF)
|
||||
{
|
||||
mParamStack.back().NumChildren = ReadSize();
|
||||
mBinaryParmStack.back().NumChildren = ReadSize();
|
||||
}
|
||||
|
||||
// Save current offset
|
||||
|
@ -92,26 +91,25 @@ public:
|
|||
u32 ParamID = TString(pkName).Hash32();
|
||||
|
||||
// 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 NextSize = ReadSize();
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 = mParamStack.back().Offset;
|
||||
u32 NumChildren = mParamStack.back().NumChildren;
|
||||
mpStream->GoTo(ParentOffset + (ParentAbstract ? 4 : 0));
|
||||
u32 ParentOffset = mBinaryParmStack.back().Offset;
|
||||
u32 NumChildren = mBinaryParmStack.back().NumChildren;
|
||||
mpStream->GoTo(ParentOffset);
|
||||
|
||||
for (u32 ChildIdx = 0; ChildIdx < NumChildren; ChildIdx++)
|
||||
{
|
||||
|
@ -122,8 +120,8 @@ public:
|
|||
mpStream->Skip(ChildSize);
|
||||
else
|
||||
{
|
||||
mParamStack.back().ChildIndex = ChildIdx;
|
||||
mParamStack.push_back( SParameter { mpStream->Tell(), ChildSize, 0xFFFFFFFF, 0, false } );
|
||||
mBinaryParmStack.back().ChildIndex = ChildIdx;
|
||||
mBinaryParmStack.push_back( SBinaryParm { mpStream->Tell(), ChildSize, 0xFFFFFFFF, 0 } );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -137,14 +135,28 @@ public:
|
|||
virtual void ParamEnd()
|
||||
{
|
||||
// Make sure we're at the end of the parameter
|
||||
SParameter& rParam = mParamStack.back();
|
||||
SBinaryParm& rParam = mBinaryParmStack.back();
|
||||
u32 EndOffset = rParam.Offset + rParam.Size;
|
||||
mpStream->GoTo(EndOffset);
|
||||
mParamStack.pop_back();
|
||||
mBinaryParmStack.pop_back();
|
||||
|
||||
// Increment parent child index
|
||||
if (!mParamStack.empty())
|
||||
mParamStack.back().ChildIndex++;
|
||||
if (!mBinaryParmStack.empty())
|
||||
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*/)
|
||||
|
@ -153,36 +165,23 @@ public:
|
|||
rSize = (mArchiveVersion < eArVer_32BitBinarySize ? (u32) mpStream->PeekShort() : mpStream->PeekLong());
|
||||
}
|
||||
|
||||
virtual void SerializeAbstractObjectType(u32& rType)
|
||||
{
|
||||
// Mark current parameter as abstract so we can account for the object type in the filestream
|
||||
rType = mpStream->ReadLong();
|
||||
mParamStack.back().Abstract = true;
|
||||
}
|
||||
|
||||
virtual void SerializePrimitive(bool& rValue) { rValue = mpStream->ReadBool(); }
|
||||
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, 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); }
|
||||
virtual void SerializePrimitive(bool& rValue, u32 Flags) { rValue = mpStream->ReadBool(); }
|
||||
virtual void SerializePrimitive(char& rValue, u32 Flags) { rValue = mpStream->ReadByte(); }
|
||||
virtual void SerializePrimitive(s8& rValue, u32 Flags) { rValue = mpStream->ReadByte(); }
|
||||
virtual void SerializePrimitive(u8& rValue, u32 Flags) { rValue = mpStream->ReadByte(); }
|
||||
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(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, Game()); }
|
||||
virtual void SerializeBulkData(void* pData, u32 Size, u32 Flags) { mpStream->ReadBytes(pData, Size); }
|
||||
};
|
||||
|
||||
#endif // CBINARYREADER
|
||||
|
|
|
@ -10,7 +10,6 @@ class CBinaryWriter : public IArchive
|
|||
{
|
||||
u32 Offset;
|
||||
u32 NumSubParams;
|
||||
bool Abstract;
|
||||
};
|
||||
std::vector<SParameter> mParamStack;
|
||||
|
||||
|
@ -19,29 +18,31 @@ class CBinaryWriter : public IArchive
|
|||
bool mOwnsStream;
|
||||
|
||||
public:
|
||||
CBinaryWriter(const TString& rkFilename, u32 Magic, u16 FileVersion, EGame Game)
|
||||
CBinaryWriter(const TString& rkFilename, u32 Magic, u16 FileVersion = 0, EGame Game = eUnknownGame)
|
||||
: IArchive()
|
||||
, mMagic(Magic)
|
||||
, mOwnsStream(true)
|
||||
{
|
||||
mArchiveFlags = AF_Writer | AF_Binary;
|
||||
mpStream = new CFileOutStream(rkFilename, IOUtil::eBigEndian);
|
||||
|
||||
if (mpStream->IsValid())
|
||||
{
|
||||
mpStream->WriteLong(0); // Magic is written after the rest of the file has been successfully written
|
||||
SetVersion(skCurrentArchiveVersion, FileVersion, Game);
|
||||
GetVersionInfo().Write(*mpStream);
|
||||
}
|
||||
|
||||
InitParamStack();
|
||||
SerializeVersion();
|
||||
}
|
||||
|
||||
CBinaryWriter(IOutputStream *pStream, u16 FileVersion, EGame Game)
|
||||
CBinaryWriter(IOutputStream *pStream, u16 FileVersion = 0, EGame Game = eUnknownGame)
|
||||
: IArchive()
|
||||
, mMagic(0)
|
||||
, mOwnsStream(false)
|
||||
{
|
||||
ASSERT(pStream && pStream->IsValid());
|
||||
mArchiveFlags = AF_Writer | AF_Binary;
|
||||
mpStream = pStream;
|
||||
SetVersion(skCurrentArchiveVersion, FileVersion, Game);
|
||||
InitParamStack();
|
||||
|
@ -53,6 +54,7 @@ public:
|
|||
, mOwnsStream(false)
|
||||
{
|
||||
ASSERT(pStream && pStream->IsValid());
|
||||
mArchiveFlags = AF_Writer | AF_Binary;
|
||||
mpStream = pStream;
|
||||
SetVersion(rkVersion);
|
||||
InitParamStack();
|
||||
|
@ -83,16 +85,12 @@ private:
|
|||
mParamStack.reserve(20);
|
||||
mpStream->WriteLong(0xFFFFFFFF);
|
||||
mpStream->WriteLong(0); // Size filler
|
||||
mParamStack.push_back( SParameter { mpStream->Tell(), 0, false } );
|
||||
mParamStack.push_back( SParameter { mpStream->Tell(), 0 } );
|
||||
}
|
||||
|
||||
public:
|
||||
// Interface
|
||||
virtual bool IsReader() const { return false; }
|
||||
virtual bool IsWriter() const { return true; }
|
||||
virtual bool IsTextFormat() const { return false; }
|
||||
|
||||
virtual bool ParamBegin(const char *pkName)
|
||||
virtual bool ParamBegin(const char *pkName, u32 Flags)
|
||||
{
|
||||
// Update parent param
|
||||
mParamStack.back().NumSubParams++;
|
||||
|
@ -106,7 +104,7 @@ public:
|
|||
mpStream->WriteLong(-1); // Param size filler
|
||||
|
||||
// Add new param to the stack
|
||||
mParamStack.push_back( SParameter { mpStream->Tell(), 0, false } );
|
||||
mParamStack.push_back( SParameter { mpStream->Tell(), 0 } );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -125,7 +123,6 @@ public:
|
|||
// Write param child count
|
||||
if (rParam.NumSubParams > 0 || mParamStack.size() == 1)
|
||||
{
|
||||
if (rParam.Abstract) mpStream->Skip(4);
|
||||
mpStream->WriteLong(rParam.NumSubParams);
|
||||
}
|
||||
|
||||
|
@ -133,6 +130,13 @@ public:
|
|||
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*/)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
virtual void SerializeAbstractObjectType(u32& rType)
|
||||
{
|
||||
// Mark this parameter as abstract so we can account for the object type in the filestream
|
||||
mpStream->WriteLong(rType);
|
||||
mParamStack.back().Abstract = true;
|
||||
}
|
||||
|
||||
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 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); }
|
||||
virtual void SerializePrimitive(bool& rValue, u32 Flags) { mpStream->WriteBool(rValue); }
|
||||
virtual void SerializePrimitive(char& rValue, u32 Flags) { mpStream->WriteByte(rValue); }
|
||||
virtual void SerializePrimitive(s8& rValue, u32 Flags) { mpStream->WriteByte(rValue); }
|
||||
virtual void SerializePrimitive(u8& rValue, u32 Flags) { mpStream->WriteByte(rValue); }
|
||||
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(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 // CBINARYWRITER
|
||||
|
|
|
@ -8,23 +8,24 @@ class CXMLReader : public IArchive
|
|||
{
|
||||
tinyxml2::XMLDocument mDoc;
|
||||
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
|
||||
|
||||
public:
|
||||
CXMLReader(const TString& rkFileName)
|
||||
: IArchive()
|
||||
, mpAttribute(nullptr)
|
||||
, mJustEndedParam(false)
|
||||
{
|
||||
mArchiveFlags = AF_Reader | AF_Text;
|
||||
|
||||
// Load XML and set current element to the root element; read version
|
||||
mDoc.LoadFile(*rkFileName);
|
||||
mpCurElem = mDoc.FirstChildElement();
|
||||
|
||||
if (mpCurElem != nullptr)
|
||||
{
|
||||
mArchiveVersion = (u16) TString( mpCurElem->Attribute("ArchiveVer") ).ToInt32(10);
|
||||
mFileVersion = (u16) TString( mpCurElem->Attribute("FileVer") ).ToInt32(10);
|
||||
const char *pkGameAttr = mpCurElem->Attribute("Game");
|
||||
mGame = pkGameAttr ? GetGameForID( CFourCC(pkGameAttr) ) : eUnknownGame;
|
||||
SerializeVersion();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -42,9 +43,17 @@ public:
|
|||
virtual bool IsWriter() const { return false; }
|
||||
virtual bool IsTextFormat() const { return true; }
|
||||
|
||||
virtual bool ParamBegin(const char *pkName)
|
||||
virtual bool ParamBegin(const char *pkName, u32 Flags)
|
||||
{
|
||||
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
|
||||
if (!mJustEndedParam)
|
||||
|
@ -55,7 +64,7 @@ public:
|
|||
}
|
||||
|
||||
// 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;
|
||||
return true;
|
||||
|
@ -88,59 +97,60 @@ public:
|
|||
|
||||
virtual void ParamEnd()
|
||||
{
|
||||
if (mJustEndedParam)
|
||||
mpCurElem = mpCurElem->Parent()->ToElement();
|
||||
if (mpAttribute)
|
||||
mpAttribute = nullptr;
|
||||
|
||||
tinyxml2::XMLElement *pElem = mpCurElem->NextSiblingElement();
|
||||
if (pElem)
|
||||
mpCurElem = pElem;
|
||||
else
|
||||
{
|
||||
if (mJustEndedParam)
|
||||
mpCurElem = mpCurElem->Parent()->ToElement();
|
||||
|
||||
mJustEndedParam = true;
|
||||
tinyxml2::XMLElement *pElem = mpCurElem->NextSiblingElement();
|
||||
if (pElem)
|
||||
mpCurElem = pElem;
|
||||
|
||||
mJustEndedParam = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
TString ReadParam()
|
||||
{
|
||||
return TString(mpCurElem->GetText());
|
||||
return TString( mpAttribute ? mpAttribute : mpCurElem->GetText() );
|
||||
}
|
||||
|
||||
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))
|
||||
rSize++;
|
||||
for (tinyxml2::XMLElement *pElem = mpCurElem->FirstChildElement(); pElem; pElem = pElem->NextSiblingElement())
|
||||
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(char& rValue) { rValue = ReadParam().Front(); }
|
||||
virtual void SerializePrimitive(s8& rValue) { rValue = (s8) ReadParam().ToInt32(10); }
|
||||
virtual void SerializePrimitive(u8& rValue) { rValue = (u8) ReadParam().ToInt32(10); }
|
||||
virtual void SerializePrimitive(s16& rValue) { rValue = (s16) ReadParam().ToInt32(10); }
|
||||
virtual void SerializePrimitive(u16& rValue) { rValue = (u16) ReadParam().ToInt32(10); }
|
||||
virtual void SerializePrimitive(s32& rValue) { rValue = (s32) ReadParam().ToInt32(10); }
|
||||
virtual void SerializePrimitive(u32& rValue) { rValue = (u32) ReadParam().ToInt32(10); }
|
||||
virtual void SerializePrimitive(s64& rValue) { rValue = (s64) ReadParam().ToInt64(10); }
|
||||
virtual void SerializePrimitive(u64& rValue) { rValue = (u64) ReadParam().ToInt64(10); }
|
||||
virtual void SerializePrimitive(float& rValue) { rValue = ReadParam().ToFloat(); }
|
||||
virtual void SerializePrimitive(double& rValue) { rValue = (double) ReadParam().ToFloat(); }
|
||||
virtual void SerializePrimitive(TString& rValue) { rValue = ReadParam(); }
|
||||
virtual void SerializePrimitive(TWideString& rValue) { rValue = ReadParam().ToUTF16(); }
|
||||
virtual void SerializePrimitive(CFourCC& rValue) { rValue = CFourCC( ReadParam() ); }
|
||||
virtual void SerializePrimitive(CAssetID& rValue) { rValue = CAssetID::FromString( ReadParam() ); }
|
||||
virtual void SerializePrimitive(bool& rValue, u32 Flags) { rValue = (ReadParam() == "true" ? true : false); }
|
||||
virtual void SerializePrimitive(char& rValue, u32 Flags) { rValue = ReadParam().Front(); }
|
||||
virtual void SerializePrimitive(s8& rValue, u32 Flags) { rValue = (s8) ReadParam().ToInt32( (Flags & SH_HexDisplay) ? 16 : 10 ); }
|
||||
virtual void SerializePrimitive(u8& rValue, u32 Flags) { rValue = (u8) ReadParam().ToInt32( (Flags & SH_HexDisplay) ? 16 : 10 ); }
|
||||
virtual void SerializePrimitive(s16& rValue, u32 Flags) { rValue = (s16) ReadParam().ToInt32( (Flags & SH_HexDisplay) ? 16 : 10 ); }
|
||||
virtual void SerializePrimitive(u16& rValue, u32 Flags) { rValue = (u16) ReadParam().ToInt32( (Flags & SH_HexDisplay) ? 16 : 10 ); }
|
||||
virtual void SerializePrimitive(s32& rValue, u32 Flags) { rValue = (s32) ReadParam().ToInt32( (Flags & SH_HexDisplay) ? 16 : 10 ); }
|
||||
virtual void SerializePrimitive(u32& rValue, u32 Flags) { rValue = (u32) ReadParam().ToInt32( (Flags & SH_HexDisplay) ? 16 : 10 ); }
|
||||
virtual void SerializePrimitive(s64& rValue, u32 Flags) { rValue = (s64) ReadParam().ToInt64( (Flags & SH_HexDisplay) ? 16 : 10 ); }
|
||||
virtual void SerializePrimitive(u64& rValue, u32 Flags) { rValue = (u64) ReadParam().ToInt64( (Flags & SH_HexDisplay) ? 16 : 10 ); }
|
||||
virtual void SerializePrimitive(float& rValue, u32 Flags) { rValue = ReadParam().ToFloat(); }
|
||||
virtual void SerializePrimitive(double& rValue, u32 Flags) { rValue = (double) ReadParam().ToFloat(); }
|
||||
virtual void SerializePrimitive(TString& rValue, u32 Flags) { rValue = ReadParam(); }
|
||||
virtual void SerializePrimitive(TWideString& rValue, u32 Flags) { rValue = ReadParam().ToUTF16(); }
|
||||
virtual void SerializePrimitive(CFourCC& rValue, u32 Flags) { rValue = CFourCC( ReadParam() ); }
|
||||
virtual void SerializePrimitive(CAssetID& rValue, u32 Flags) { rValue = CAssetID::FromString( ReadParam() ); }
|
||||
|
||||
virtual void SerializeHexPrimitive(u8& rValue) { rValue = (u8) ReadParam().ToInt32(16); }
|
||||
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)
|
||||
virtual void SerializeBulkData(void* pData, u32 Size, u32 Flags)
|
||||
{
|
||||
char* pCharData = (char*) pData;
|
||||
TString StringData = ReadParam();
|
||||
|
|
|
@ -9,16 +9,19 @@
|
|||
class CXMLWriter : public IArchive
|
||||
{
|
||||
tinyxml2::XMLDocument mDoc;
|
||||
TString mOutFilename;
|
||||
tinyxml2::XMLElement *mpCurElem;
|
||||
TString mOutFilename;
|
||||
const char* mpAttributeName;
|
||||
bool mSaved;
|
||||
|
||||
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()
|
||||
, mOutFilename(rkFileName)
|
||||
, mpAttributeName(nullptr)
|
||||
, mSaved(false)
|
||||
{
|
||||
mArchiveFlags = AF_Writer | AF_Text;
|
||||
SetVersion(skCurrentArchiveVersion, FileVersion, Game);
|
||||
|
||||
// Create declaration and root node
|
||||
|
@ -29,9 +32,7 @@ public:
|
|||
mDoc.LinkEndChild(mpCurElem);
|
||||
|
||||
// Write version data
|
||||
mpCurElem->SetAttribute("ArchiveVer", (int) skCurrentArchiveVersion);
|
||||
mpCurElem->SetAttribute("FileVer", (int) FileVersion);
|
||||
if (Game != eUnknownGame) mpCurElem->SetAttribute("Game", *GetGameID(Game).ToString());
|
||||
SerializeVersion();
|
||||
}
|
||||
|
||||
~CXMLWriter()
|
||||
|
@ -69,71 +70,86 @@ public:
|
|||
}
|
||||
|
||||
// Interface
|
||||
virtual bool IsReader() const { return false; }
|
||||
virtual bool IsWriter() 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(!mpAttributeName); // Attributes cannot have sub-children
|
||||
|
||||
// Read as attribute if needed
|
||||
if (Flags & SH_Attribute)
|
||||
{
|
||||
mpAttributeName = pkName;
|
||||
}
|
||||
else
|
||||
{
|
||||
tinyxml2::XMLElement *pElem = mDoc.NewElement(pkName);
|
||||
mpCurElem->LinkEndChild(pElem);
|
||||
mpCurElem = pElem;
|
||||
}
|
||||
|
||||
tinyxml2::XMLElement *pElem = mDoc.NewElement(pkName);
|
||||
mpCurElem->LinkEndChild(pElem);
|
||||
mpCurElem = pElem;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void ParamEnd()
|
||||
{
|
||||
mpCurElem = mpCurElem->Parent()->ToElement();
|
||||
if (mpAttributeName)
|
||||
mpAttributeName = nullptr;
|
||||
else
|
||||
mpCurElem = mpCurElem->Parent()->ToElement();
|
||||
}
|
||||
|
||||
protected:
|
||||
void WriteParam(const char *pkValue)
|
||||
{
|
||||
mpCurElem->SetText(pkValue);
|
||||
if (mpAttributeName)
|
||||
mpCurElem->SetAttribute(mpAttributeName, pkValue);
|
||||
else
|
||||
mpCurElem->SetText(pkValue);
|
||||
}
|
||||
|
||||
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(char& rValue) { WriteParam(*TString(rValue)); }
|
||||
virtual void SerializePrimitive(s8& rValue) { WriteParam(*TString::FromInt32(rValue, 0, 10)); }
|
||||
virtual void SerializePrimitive(u8& rValue) { WriteParam(*TString::FromInt32(rValue, 0, 10)); }
|
||||
virtual void SerializePrimitive(s16& rValue) { WriteParam(*TString::FromInt32(rValue, 0, 10)); }
|
||||
virtual void SerializePrimitive(u16& rValue) { WriteParam(*TString::FromInt32(rValue, 0, 10)); }
|
||||
virtual void SerializePrimitive(s32& rValue) { WriteParam(*TString::FromInt32(rValue, 0, 10)); }
|
||||
virtual void SerializePrimitive(u32& rValue) { WriteParam(*TString::FromInt32(rValue, 0, 10)); }
|
||||
virtual void SerializePrimitive(s64& rValue) { WriteParam(*TString::FromInt64(rValue, 0, 10)); }
|
||||
virtual void SerializePrimitive(u64& rValue) { WriteParam(*TString::FromInt64(rValue, 0, 10)); }
|
||||
virtual void SerializePrimitive(float& rValue) { WriteParam(*TString::FromFloat(rValue)); }
|
||||
virtual void SerializePrimitive(double& rValue) { WriteParam(*TString::FromFloat((float) rValue)); }
|
||||
virtual void SerializePrimitive(TString& rValue) { WriteParam(*rValue); }
|
||||
virtual void SerializePrimitive(TWideString& rValue) { WriteParam(*rValue.ToUTF8()); }
|
||||
virtual void SerializePrimitive(CFourCC& rValue) { WriteParam(*rValue.ToString()); }
|
||||
virtual void SerializePrimitive(CAssetID& rValue) { WriteParam(*rValue.ToString( CAssetID::GameIDLength(Game()) )); }
|
||||
virtual void SerializePrimitive(bool& rValue, u32 Flags) { WriteParam(rValue ? "true" : "false"); }
|
||||
virtual void SerializePrimitive(char& rValue, u32 Flags) { WriteParam(*TString(rValue)); }
|
||||
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, u32 Flags) { WriteParam( (Flags & SH_HexDisplay) ? *TString::HexString((u8&) rValue, 0) : *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, u32 Flags) { WriteParam( (Flags & SH_HexDisplay) ? *TString::HexString((u16&) rValue, 0) : *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, u32 Flags) { WriteParam( (Flags & SH_HexDisplay) ? *TString::HexString((u32&) rValue, 0) : *TString::FromInt32(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, u32 Flags) { WriteParam( *TString::FromInt64(rValue, 0, (Flags & SH_HexDisplay) ? 16 : 10) ); }
|
||||
virtual void SerializePrimitive(float& rValue, u32 Flags) { WriteParam( *TString::FromFloat(rValue, 1, true) ); }
|
||||
virtual void SerializePrimitive(double& rValue, u32 Flags) { WriteParam( *TString::FromFloat((float) rValue, 1, true) ); }
|
||||
virtual void SerializePrimitive(TString& rValue, u32 Flags) { WriteParam( *rValue ); }
|
||||
virtual void SerializePrimitive(TWideString& rValue, u32 Flags) { WriteParam( *rValue.ToUTF8() ); }
|
||||
virtual void SerializePrimitive(CFourCC& rValue, u32 Flags) { WriteParam( *rValue.ToString() ); }
|
||||
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 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)
|
||||
virtual void SerializeBulkData(void* pData, u32 Size, u32 Flags)
|
||||
{
|
||||
char* pCharData = (char*) pData;
|
||||
TString OutString(Size*2);
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,7 @@
|
|||
#include "TString.h"
|
||||
#include "Hash/CCRC32.h"
|
||||
#include "Hash/CFNV1A.h"
|
||||
#include <FileIO/IOUtil.h>
|
||||
#include "FileIO/IOUtil.h"
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
|
||||
|
|
|
@ -930,14 +930,9 @@ public:
|
|||
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
|
||||
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();
|
||||
_TString Out = _TString::Format(Scientific ? "%.8g" : "%f", Value);
|
||||
|
||||
// Make sure we have the right number of decimals
|
||||
int DecIdx = Out.IndexOf(CHAR_LITERAL('.'));
|
||||
|
@ -954,7 +949,7 @@ public:
|
|||
if (NumZeroes < MinDecimals)
|
||||
{
|
||||
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
|
||||
|
|
|
@ -133,7 +133,7 @@ void CAssetNameMap::CopyFromStore(CResourceStore *pStore /*= gpResourceStore*/)
|
|||
// ************ PRIVATE ************
|
||||
void CAssetNameMap::Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL_CONTAINER("AssetNameMap", mMap, "Asset");
|
||||
rArc << SerialParameter("AssetNameMap", mMap);
|
||||
|
||||
if (rArc.IsReader())
|
||||
PostLoadValidate();
|
||||
|
|
|
@ -28,7 +28,11 @@ class CAssetNameMap
|
|||
|
||||
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
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
#include "Core/Resource/Script/CScriptLayer.h"
|
||||
#include "Core/Resource/Script/CScriptObject.h"
|
||||
|
||||
CDependencyNodeFactory gDependencyNodeFactory;
|
||||
|
||||
// ************ IDependencyNode ************
|
||||
IDependencyNode::~IDependencyNode()
|
||||
{
|
||||
|
@ -31,6 +29,24 @@ void IDependencyNode::GetAllResourceReferences(std::set<CAssetID>& rOutSet) cons
|
|||
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 ************
|
||||
EDependencyNodeType CDependencyTree::Type() const
|
||||
{
|
||||
|
@ -39,7 +55,7 @@ EDependencyNodeType CDependencyTree::Type() const
|
|||
|
||||
void CDependencyTree::Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL_ABSTRACT_CONTAINER("Children", mChildren, "Child", &gDependencyNodeFactory);
|
||||
rArc << SerialParameter("Children", mChildren);
|
||||
}
|
||||
|
||||
void CDependencyTree::AddChild(IDependencyNode *pNode)
|
||||
|
@ -78,7 +94,7 @@ EDependencyNodeType CResourceDependency::Type() const
|
|||
|
||||
void CResourceDependency::Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL("ID", mID);
|
||||
rArc << SerialParameter("ID", mID);
|
||||
}
|
||||
|
||||
void CResourceDependency::GetAllResourceReferences(std::set<CAssetID>& rOutSet) const
|
||||
|
@ -99,7 +115,7 @@ EDependencyNodeType CPropertyDependency::Type() const
|
|||
|
||||
void CPropertyDependency::Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL("PropertyID", mIDString);
|
||||
rArc << SerialParameter("PropertyID", mIDString);
|
||||
CResourceDependency::Serialize(rArc);
|
||||
}
|
||||
|
||||
|
@ -112,7 +128,7 @@ EDependencyNodeType CCharPropertyDependency::Type() const
|
|||
void CCharPropertyDependency::Serialize(IArchive& rArc)
|
||||
{
|
||||
CPropertyDependency::Serialize(rArc);
|
||||
rArc << SERIAL("CharIndex", mUsedChar);
|
||||
rArc << SerialParameter("CharIndex", mUsedChar);
|
||||
}
|
||||
|
||||
// ************ CScriptInstanceDependency ************
|
||||
|
@ -123,8 +139,8 @@ EDependencyNodeType CScriptInstanceDependency::Type() const
|
|||
|
||||
void CScriptInstanceDependency::Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL("ObjectType", mObjectType)
|
||||
<< SERIAL_ABSTRACT_CONTAINER("Properties", mChildren, "Property", &gDependencyNodeFactory);
|
||||
rArc << SerialParameter("ObjectType", mObjectType)
|
||||
<< SerialParameter("Properties", mChildren);
|
||||
}
|
||||
|
||||
// Static
|
||||
|
@ -210,8 +226,8 @@ EDependencyNodeType CSetCharacterDependency::Type() const
|
|||
|
||||
void CSetCharacterDependency::Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL("CharSetIndex", mCharSetIndex)
|
||||
<< SERIAL_ABSTRACT_CONTAINER("Children", mChildren, "Child", &gDependencyNodeFactory);
|
||||
rArc << SerialParameter("CharSetIndex", mCharSetIndex)
|
||||
<< SerialParameter("Children", mChildren);
|
||||
}
|
||||
|
||||
CSetCharacterDependency* CSetCharacterDependency::BuildTree(const SSetCharacter& rkChar)
|
||||
|
@ -255,8 +271,8 @@ EDependencyNodeType CSetAnimationDependency::Type() const
|
|||
|
||||
void CSetAnimationDependency::Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL_CONTAINER("CharacterIndices", mCharacterIndices, "Index")
|
||||
<< SERIAL_ABSTRACT_CONTAINER("Children", mChildren, "Child", &gDependencyNodeFactory);
|
||||
rArc << SerialParameter("CharacterIndices", mCharacterIndices)
|
||||
<< SerialParameter("Children", mChildren);
|
||||
}
|
||||
|
||||
CSetAnimationDependency* CSetAnimationDependency::BuildTree(const CAnimSet *pkOwnerSet, u32 AnimIndex)
|
||||
|
@ -302,7 +318,7 @@ EDependencyNodeType CAnimEventDependency::Type() const
|
|||
void CAnimEventDependency::Serialize(IArchive& rArc)
|
||||
{
|
||||
CResourceDependency::Serialize(rArc);
|
||||
rArc << SERIAL("CharacterIndex", mCharIndex);
|
||||
rArc << SerialParameter("CharacterIndex", mCharIndex);
|
||||
}
|
||||
|
||||
// ************ CAreaDependencyTree ************
|
||||
|
@ -314,7 +330,7 @@ EDependencyNodeType CAreaDependencyTree::Type() const
|
|||
void CAreaDependencyTree::Serialize(IArchive& rArc)
|
||||
{
|
||||
CDependencyTree::Serialize(rArc);
|
||||
rArc << SERIAL_CONTAINER("LayerOffsets", mLayerOffsets, "Offset");
|
||||
rArc << SerialParameter("LayerOffsets", mLayerOffsets);
|
||||
}
|
||||
|
||||
void CAreaDependencyTree::AddScriptLayer(CScriptLayer *pLayer, const std::vector<CAssetID>& rkExtraDeps)
|
||||
|
|
|
@ -40,6 +40,9 @@ public:
|
|||
virtual void GetAllResourceReferences(std::set<CAssetID>& rOutSet) const;
|
||||
virtual bool HasDependency(const CAssetID& rkID) const;
|
||||
|
||||
// Serialization constructor
|
||||
static IDependencyNode* ArchiveConstructor(EDependencyNodeType Type);
|
||||
|
||||
// Accessors
|
||||
inline u32 NumChildren() const { return mChildren.size(); }
|
||||
inline IDependencyNode* ChildByIndex(u32 Index) const { return mChildren[Index]; }
|
||||
|
@ -223,28 +226,5 @@ public:
|
|||
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
|
||||
|
||||
|
|
|
@ -41,10 +41,10 @@ void CGameInfo::Serialize(IArchive& rArc)
|
|||
}
|
||||
|
||||
// Serialize data
|
||||
rArc << SERIAL_CONTAINER("GameBuilds", mBuilds, "Build");
|
||||
rArc << SerialParameter("GameBuilds", mBuilds);
|
||||
|
||||
if (mGame <= ePrime)
|
||||
rArc << SERIAL_CONTAINER("AreaNameMap", mAreaNameMap, "AreaName");
|
||||
rArc << SerialParameter("AreaNameMap", mAreaNameMap);
|
||||
}
|
||||
|
||||
TString CGameInfo::GetBuildName(float BuildVer, ERegion Region) const
|
||||
|
|
|
@ -24,7 +24,9 @@ class CGameInfo
|
|||
|
||||
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;
|
||||
|
|
|
@ -36,10 +36,10 @@ bool CGameProject::Save()
|
|||
|
||||
bool CGameProject::Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL("Name", mProjectName)
|
||||
<< SERIAL("Region", mRegion)
|
||||
<< SERIAL("GameID", mGameID)
|
||||
<< SERIAL("BuildVersion", mBuildVersion);
|
||||
rArc << SerialParameter("Name", mProjectName)
|
||||
<< SerialParameter("Region", mRegion)
|
||||
<< SerialParameter("GameID", mGameID)
|
||||
<< SerialParameter("BuildVersion", mBuildVersion);
|
||||
|
||||
// Serialize package list
|
||||
std::vector<TString> PackageList;
|
||||
|
@ -50,7 +50,7 @@ bool CGameProject::Serialize(IArchive& rArc)
|
|||
PackageList.push_back( mPackages[iPkg]->DefinitionPath(true) );
|
||||
}
|
||||
|
||||
rArc << SERIAL_CONTAINER("Packages", PackageList, "Package");
|
||||
rArc << SerialParameter("Packages", PackageList);
|
||||
|
||||
// Load packages
|
||||
if (rArc.IsReader())
|
||||
|
|
|
@ -36,8 +36,8 @@ bool CPackage::Save()
|
|||
|
||||
void CPackage::Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL("NeedsRecook", mNeedsRecook)
|
||||
<< SERIAL_CONTAINER("NamedResources", mResources, "Resource");
|
||||
rArc << SerialParameter("NeedsRecook", mNeedsRecook)
|
||||
<< SerialParameter("NamedResources", mResources);
|
||||
}
|
||||
|
||||
void CPackage::AddResource(const TString& rkName, const CAssetID& rkID, const CFourCC& rkType)
|
||||
|
|
|
@ -17,7 +17,9 @@ struct SNamedResource
|
|||
|
||||
void Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL_AUTO(Name) << SERIAL_AUTO(ID) << SERIAL_AUTO(Type);
|
||||
rArc << SerialParameter("Name", Name)
|
||||
<< SerialParameter("ID", ID)
|
||||
<< SerialParameter("Type", Type);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -127,9 +127,9 @@ void CResourceEntry::SerializeEntryInfo(IArchive& rArc, bool MetadataOnly)
|
|||
{
|
||||
CAssetID ID = mID;
|
||||
|
||||
rArc << SERIAL("AssetID", ID)
|
||||
<< SERIAL("Type", mpTypeInfo)
|
||||
<< SERIAL("Flags", mFlags);
|
||||
rArc << SerialParameter("AssetID", ID)
|
||||
<< SerialParameter("Type", mpTypeInfo)
|
||||
<< SerialParameter("Flags", mFlags);
|
||||
|
||||
// Don't allow the file to override our asset ID if we already have a valid one.
|
||||
if (rArc.IsReader() && !mID.IsValid())
|
||||
|
@ -140,9 +140,9 @@ void CResourceEntry::SerializeEntryInfo(IArchive& rArc, bool MetadataOnly)
|
|||
{
|
||||
TString Dir = (mpDirectory ? mpDirectory->FullPath() : "");
|
||||
|
||||
rArc << SERIAL("Name", mName)
|
||||
<< SERIAL("Directory", Dir)
|
||||
<< SERIAL_ABSTRACT("Dependencies", mpDependencies, &gDependencyNodeFactory);
|
||||
rArc << SerialParameter("Name", mName)
|
||||
<< SerialParameter("Directory", Dir)
|
||||
<< SerialParameter("Dependencies", mpDependencies);
|
||||
|
||||
if (rArc.IsReader())
|
||||
{
|
||||
|
|
|
@ -62,17 +62,17 @@ void RecursiveGetListOfEmptyDirectories(CVirtualDirectory *pDir, TStringList& rO
|
|||
bool CResourceStore::SerializeDatabaseCache(IArchive& rArc)
|
||||
{
|
||||
// Serialize resources
|
||||
if (rArc.ParamBegin("Resources"))
|
||||
if (rArc.ParamBegin("Resources", 0))
|
||||
{
|
||||
// Serialize resources
|
||||
u32 ResourceCount = mResourceEntries.size();
|
||||
rArc << SERIAL_AUTO(ResourceCount);
|
||||
rArc << SerialParameter("ResourceCount", ResourceCount);
|
||||
|
||||
if (rArc.IsReader())
|
||||
{
|
||||
for (u32 ResIdx = 0; ResIdx < ResourceCount; ResIdx++)
|
||||
{
|
||||
if (rArc.ParamBegin("Resource"))
|
||||
if (rArc.ParamBegin("Resource", 0))
|
||||
{
|
||||
CResourceEntry *pEntry = CResourceEntry::BuildFromArchive(this, rArc);
|
||||
ASSERT( FindEntry(pEntry->ID()) == nullptr );
|
||||
|
@ -85,7 +85,7 @@ bool CResourceStore::SerializeDatabaseCache(IArchive& rArc)
|
|||
{
|
||||
for (CResourceIterator It(this); It; ++It)
|
||||
{
|
||||
if (rArc.ParamBegin("Resource"))
|
||||
if (rArc.ParamBegin("Resource", 0))
|
||||
{
|
||||
It->SerializeEntryInfo(rArc, false);
|
||||
rArc.ParamEnd();
|
||||
|
@ -101,7 +101,7 @@ bool CResourceStore::SerializeDatabaseCache(IArchive& rArc)
|
|||
if (!rArc.IsReader())
|
||||
RecursiveGetListOfEmptyDirectories(mpDatabaseRoot, EmptyDirectories);
|
||||
|
||||
rArc << SERIAL_CONTAINER_AUTO(EmptyDirectories, "Directory");
|
||||
rArc << SerialParameter("EmptyDirectories", EmptyDirectories);
|
||||
|
||||
if (rArc.IsReader())
|
||||
{
|
||||
|
|
|
@ -15,6 +15,7 @@ CAnimationParameters::CAnimationParameters()
|
|||
|
||||
CAnimationParameters::CAnimationParameters(EGame Game)
|
||||
: mGame(Game)
|
||||
, mCharacterID( CAssetID::InvalidID(Game) )
|
||||
, mCharIndex(0)
|
||||
, mAnimIndex(0)
|
||||
, mUnknown2(0)
|
||||
|
@ -141,17 +142,17 @@ void CAnimationParameters::Serialize(IArchive& rArc)
|
|||
if (rArc.IsReader())
|
||||
mGame = rArc.Game();
|
||||
|
||||
rArc << SERIAL("AnimationSetAsset", mCharacterID);
|
||||
rArc << SerialParameter("AnimationSetAsset", mCharacterID);
|
||||
|
||||
if (mGame <= eEchoes)
|
||||
rArc << SERIAL("CharacterID", mCharIndex);
|
||||
rArc << SerialParameter("CharacterID", mCharIndex);
|
||||
|
||||
rArc << SERIAL("AnimationID", mAnimIndex);
|
||||
rArc << SerialParameter("AnimationID", mAnimIndex);
|
||||
|
||||
if (mGame >= eReturns)
|
||||
{
|
||||
rArc << SERIAL("Unknown0", mUnknown2)
|
||||
<< SERIAL("Unknown1", mUnknown3);
|
||||
rArc << SerialParameter("Unknown0", mUnknown2)
|
||||
<< SerialParameter("Unknown1", mUnknown3);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,11 +35,36 @@ public:
|
|||
inline void SetCharIndex(u32 Index) { mCharIndex = 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);
|
||||
void SetResource(const CAssetID& rkID);
|
||||
void SetUnknown(u32 Index, u32 Value);
|
||||
|
||||
// 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
|
||||
{
|
||||
return ( (mGame == rkOther.mGame) &&
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
void Serialize(IArchive& rArc)
|
||||
{
|
||||
if (rArc.IsReader()) mGame = rArc.Game();
|
||||
rArc << SERIAL_CONTAINER("AcceptedTypes", mAcceptedTypes, "Type");
|
||||
rArc << SerialParameter("AcceptedTypes", mAcceptedTypes);
|
||||
}
|
||||
|
||||
inline bool Accepts(EResType Type) const
|
||||
|
|
|
@ -114,7 +114,7 @@ void Serialize(IArchive& rArc, CResTypeInfo*& rpType)
|
|||
Ext = rpType->CookedExtension(rArc.Game());
|
||||
}
|
||||
|
||||
rArc.SerializePrimitive(Ext);
|
||||
rArc.SerializePrimitive(Ext, 0);
|
||||
|
||||
if (rArc.IsReader())
|
||||
{
|
||||
|
@ -134,7 +134,7 @@ void Serialize(IArchive& rArc, EResType& rType)
|
|||
Extension = pTypeInfo->CookedExtension(rArc.Game());
|
||||
}
|
||||
|
||||
rArc.SerializePrimitive(Extension);
|
||||
rArc.SerializePrimitive(Extension, 0);
|
||||
|
||||
if (rArc.IsReader())
|
||||
{
|
||||
|
|
|
@ -46,10 +46,18 @@ public:
|
|||
|
||||
void Serialize(IArchive& rArc)
|
||||
{
|
||||
TString Str;
|
||||
if (rArc.IsWriter()) Str = ToString();
|
||||
rArc.SerializePrimitive(Str);
|
||||
if (rArc.IsReader()) *this = FromString(Str);
|
||||
if (rArc.IsBinaryFormat())
|
||||
{
|
||||
rArc.SerializePrimitive(m[0], 0);
|
||||
rArc.SerializePrimitive(m[1], 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
TString Str;
|
||||
if (rArc.IsWriter()) Str = ToString();
|
||||
rArc.SerializePrimitive(Str, 0);
|
||||
if (rArc.IsReader()) *this = FromString(Str);
|
||||
}
|
||||
}
|
||||
|
||||
// Operators
|
||||
|
|
|
@ -92,87 +92,87 @@ u32 CWorld::AreaIndex(CAssetID AreaID) const
|
|||
// ************ SERIALIZATION ************
|
||||
void CWorld::Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL("Name", mName)
|
||||
<< SERIAL("NameString", mpWorldName);
|
||||
rArc << SerialParameter("Name", mName)
|
||||
<< SerialParameter("NameString", mpWorldName);
|
||||
|
||||
if (rArc.Game() == eEchoesDemo || rArc.Game() == eEchoes)
|
||||
rArc << SERIAL("DarkNameString", mpDarkWorldName);
|
||||
rArc << SerialParameter("DarkNameString", mpDarkWorldName);
|
||||
|
||||
rArc << SERIAL("WorldSaveInfo", mpSaveWorld)
|
||||
<< SERIAL("WorldMap", mpMapWorld)
|
||||
<< SERIAL("DefaultSkyModel", mpDefaultSkybox);
|
||||
rArc << SerialParameter("WorldSaveInfo", mpSaveWorld)
|
||||
<< SerialParameter("WorldMap", mpMapWorld)
|
||||
<< SerialParameter("DefaultSkyModel", mpDefaultSkybox);
|
||||
|
||||
if (rArc.Game() >= eEchoesDemo && rArc.Game() <= eCorruption)
|
||||
rArc << SERIAL("TempleKeyWorldIndex", mTempleKeyWorldIndex);
|
||||
rArc << SerialParameter("TempleKeyWorldIndex", mTempleKeyWorldIndex);
|
||||
|
||||
if (rArc.Game() == eReturns)
|
||||
rArc << SERIAL("TimeAttackData", mTimeAttackData);
|
||||
rArc << SerialParameter("TimeAttackData", mTimeAttackData);
|
||||
|
||||
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)
|
||||
{
|
||||
rArc << SERIAL("HasTimeAttack", rData.HasTimeAttack)
|
||||
<< SERIAL("ActNumber", rData.ActNumber)
|
||||
<< SERIAL("BronzeTime", rData.BronzeTime)
|
||||
<< SERIAL("SilverTime", rData.SilverTime)
|
||||
<< SERIAL("GoldTime", rData.GoldTime)
|
||||
<< SERIAL("ShinyGoldTime", rData.ShinyGoldTime);
|
||||
rArc << SerialParameter("HasTimeAttack", rData.HasTimeAttack)
|
||||
<< SerialParameter("ActNumber", rData.ActNumber)
|
||||
<< SerialParameter("BronzeTime", rData.BronzeTime)
|
||||
<< SerialParameter("SilverTime", rData.SilverTime)
|
||||
<< SerialParameter("GoldTime", rData.GoldTime)
|
||||
<< SerialParameter("ShinyGoldTime", rData.ShinyGoldTime);
|
||||
}
|
||||
|
||||
void Serialize(IArchive& rArc, CWorld::SMemoryRelay& rMemRelay)
|
||||
{
|
||||
rArc << SERIAL_HEX("MemoryRelayID", rMemRelay.InstanceID)
|
||||
<< SERIAL_HEX("TargetID", rMemRelay.TargetID)
|
||||
<< SERIAL("Message", rMemRelay.Message)
|
||||
<< SERIAL("Active", rMemRelay.Active);
|
||||
rArc << SerialParameter("MemoryRelayID", rMemRelay.InstanceID, SH_HexDisplay)
|
||||
<< SerialParameter("TargetID", rMemRelay.TargetID, SH_HexDisplay)
|
||||
<< SerialParameter("Message", rMemRelay.Message)
|
||||
<< SerialParameter("Active", rMemRelay.Active);
|
||||
}
|
||||
|
||||
void Serialize(IArchive& rArc, CWorld::SArea& rArea)
|
||||
{
|
||||
rArc << SERIAL("Name", rArea.InternalName)
|
||||
<< SERIAL("NameString", rArea.pAreaName)
|
||||
<< SERIAL("MREA", rArea.AreaResID)
|
||||
<< SERIAL("ID", rArea.AreaID)
|
||||
<< SERIAL("Transform", rArea.Transform)
|
||||
<< SERIAL("BoundingBox", rArea.AetherBox)
|
||||
<< SERIAL("AllowPakDuplicates", rArea.AllowPakDuplicates)
|
||||
<< SERIAL_CONTAINER("AttachedAreas", rArea.AttachedAreaIDs, "AreaIndex")
|
||||
<< SERIAL_CONTAINER("RelModules", rArea.RelFilenames, "Module")
|
||||
<< SERIAL_CONTAINER("RelOffsets", rArea.RelOffsets, "Offset")
|
||||
<< SERIAL_CONTAINER("Docks", rArea.Docks, "Dock")
|
||||
<< SERIAL_CONTAINER("Layers", rArea.Layers, "Layer");
|
||||
rArc << SerialParameter("Name", rArea.InternalName)
|
||||
<< SerialParameter("NameString", rArea.pAreaName)
|
||||
<< SerialParameter("MREA", rArea.AreaResID)
|
||||
<< SerialParameter("ID", rArea.AreaID)
|
||||
<< SerialParameter("Transform", rArea.Transform)
|
||||
<< SerialParameter("BoundingBox", rArea.AetherBox)
|
||||
<< SerialParameter("AllowPakDuplicates", rArea.AllowPakDuplicates)
|
||||
<< SerialParameter("AttachedAreas", rArea.AttachedAreaIDs)
|
||||
<< SerialParameter("RelModules", rArea.RelFilenames)
|
||||
<< SerialParameter("RelOffsets", rArea.RelOffsets)
|
||||
<< SerialParameter("Docks", rArea.Docks)
|
||||
<< SerialParameter("Layers", rArea.Layers);
|
||||
}
|
||||
|
||||
void Serialize(IArchive& rArc, CWorld::SArea::SDock& rDock)
|
||||
{
|
||||
rArc << SERIAL_CONTAINER("ConnectingDocks", rDock.ConnectingDocks, "ConnectingDock")
|
||||
<< SERIAL_CONTAINER("DockCoords", rDock.DockCoordinates, "Coord");
|
||||
rArc << SerialParameter("ConnectingDocks", rDock.ConnectingDocks)
|
||||
<< SerialParameter("DockCoords", rDock.DockCoordinates);
|
||||
}
|
||||
|
||||
void Serialize(IArchive& rArc, CWorld::SArea::SDock::SConnectingDock& rDock)
|
||||
{
|
||||
rArc << SERIAL("AreaIndex", rDock.AreaIndex)
|
||||
<< SERIAL("DockIndex", rDock.DockIndex);
|
||||
rArc << SerialParameter("AreaIndex", rDock.AreaIndex)
|
||||
<< SerialParameter("DockIndex", rDock.DockIndex);
|
||||
}
|
||||
|
||||
void Serialize(IArchive& rArc, CWorld::SArea::SLayer& rLayer)
|
||||
{
|
||||
rArc << SERIAL("Name", rLayer.LayerName)
|
||||
<< SERIAL("Active", rLayer.Active);
|
||||
rArc << SerialParameter("Name", rLayer.LayerName)
|
||||
<< SerialParameter("Active", rLayer.Active);
|
||||
|
||||
if (rArc.Game() >= eCorruption)
|
||||
{
|
||||
rArc << SERIAL("StateID", rLayer.LayerStateID);
|
||||
rArc << SerialParameter("StateID", rLayer.LayerStateID);
|
||||
}
|
||||
}
|
||||
|
||||
void Serialize(IArchive& rArc, CWorld::SAudioGrp& rAudioGrp)
|
||||
{
|
||||
rArc << SERIAL("GroupID", rAudioGrp.GroupID)
|
||||
<< SERIAL("AGSC", rAudioGrp.ResID);
|
||||
rArc << SerialParameter("GroupID", rAudioGrp.GroupID)
|
||||
<< SerialParameter("AGSC", rAudioGrp.ResID);
|
||||
}
|
||||
|
|
|
@ -95,14 +95,14 @@ void IPropertyNew::Serialize(IArchive& rArc)
|
|||
{
|
||||
if (rArc.Game() <= ePrime)
|
||||
{
|
||||
rArc << SERIAL("Name", mName);
|
||||
rArc << SerialParameter("Name", mName);
|
||||
}
|
||||
|
||||
rArc << SERIAL_HEX("ID", mID)
|
||||
<< SERIAL("Description", mDescription)
|
||||
<< SERIAL("CookPref", mCookPreference)
|
||||
<< SERIAL("MinVersion", mMinVersion)
|
||||
<< SERIAL("MaxVersion", mMaxVersion);
|
||||
rArc << SerialParameter("ID", mID, SH_HexDisplay | SH_Optional, (u32) 0xFFFFFFFF)
|
||||
<< SerialParameter("Description", mDescription, SH_Optional)
|
||||
<< SerialParameter("CookPref", mCookPreference, SH_Optional, ECookPreferenceNew::Default)
|
||||
<< SerialParameter("MinVersion", mMinVersion, SH_Optional, 0.f)
|
||||
<< SerialParameter("MaxVersion", mMaxVersion, SH_Optional, FLT_MAX);
|
||||
|
||||
// Children don't get serialized for most property types
|
||||
}
|
||||
|
@ -359,3 +359,12 @@ IPropertyNew* IPropertyNew::CreateIntrinsic(EPropertyTypeNew Type,
|
|||
pOut->PostInitialize();
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -230,6 +230,9 @@ public:
|
|||
IPropertyNew* pParent,
|
||||
u32 Offset,
|
||||
const TString& rkName);
|
||||
|
||||
static IPropertyNew* ArchiveConstructor(EPropertyTypeNew Type,
|
||||
const IArchive& Arc);
|
||||
};
|
||||
|
||||
inline ECookPreferenceNew IPropertyNew::CookPreference() const
|
||||
|
@ -374,7 +377,43 @@ public:
|
|||
virtual void Serialize(IArchive& 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)
|
||||
{
|
||||
TTypedPropertyNew::Serialize(rArc);
|
||||
rArc << SERIAL("Min", mMinValue)
|
||||
<< SERIAL("Max", mMaxValue);
|
||||
rArc << SerialParameter("Min", mMinValue, SH_Optional, (PropType) -1)
|
||||
<< SerialParameter("Max", mMaxValue, SH_Optional, (PropType) -1);
|
||||
}
|
||||
|
||||
virtual void InitFromArchetype(IPropertyNew* pOther)
|
||||
|
|
|
@ -15,7 +15,7 @@ protected:
|
|||
public:
|
||||
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
|
||||
|
|
|
@ -13,6 +13,11 @@ protected:
|
|||
{}
|
||||
|
||||
public:
|
||||
virtual void PostInitialize()
|
||||
{
|
||||
mDefaultValue.SetGame(Game());
|
||||
}
|
||||
|
||||
virtual void SerializeValue(void* pData, IArchive& Arc) const
|
||||
{
|
||||
Value(pData).Serialize(Arc);
|
||||
|
@ -22,6 +27,11 @@ public:
|
|||
{
|
||||
return (Game() <= eEchoes ? "AnimationSet" : "CharacterAnimationSet");
|
||||
}
|
||||
|
||||
virtual CAnimationParameters GetSerializationDefaultValue()
|
||||
{
|
||||
return CAnimationParameters( Game() );
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CANIMATIONSETPROPERTY_H
|
||||
|
|
|
@ -108,20 +108,20 @@ public:
|
|||
virtual void Serialize(IArchive& rArc)
|
||||
{
|
||||
TTypedPropertyNew::Serialize(rArc);
|
||||
//rArc << SERIAL("ItemArchetype", mpItemArchetype);
|
||||
rArc << SerialParameter("ItemArchetype", mpItemArchetype);
|
||||
}
|
||||
|
||||
virtual void SerializeValue(void* pData, IArchive& Arc) const
|
||||
{
|
||||
u32 Count = ArrayCount(pData);
|
||||
Arc.SerializeContainerSize(Count, "ArrayElement");
|
||||
Arc.SerializeArraySize(Count);
|
||||
|
||||
if (Arc.IsReader())
|
||||
Resize(pData, Count);
|
||||
|
||||
for (u32 ItemIdx = 0; ItemIdx < Count; ItemIdx++)
|
||||
{
|
||||
if (Arc.ParamBegin("ArrayElement"))
|
||||
if (Arc.ParamBegin("ArrayElement", 0))
|
||||
{
|
||||
void* pItemData = ItemPointer(pData, ItemIdx);
|
||||
mpItemArchetype->SerializeValue(pItemData, Arc);
|
||||
|
|
|
@ -10,10 +10,19 @@ class CAssetProperty : public TSerializeableTypedProperty<CAssetID, EPropertyTyp
|
|||
CResTypeFilter mTypeFilter;
|
||||
|
||||
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)
|
||||
{
|
||||
TSerializeableTypedProperty::Serialize(rArc);
|
||||
rArc << SERIAL("AcceptedTypes", mTypeFilter);
|
||||
rArc << SerialParameter("TypeFilter", mTypeFilter);
|
||||
}
|
||||
|
||||
virtual void InitFromArchetype(IPropertyNew* pOther)
|
||||
|
@ -24,7 +33,7 @@ public:
|
|||
|
||||
virtual void SerializeValue(void* pData, IArchive& Arc) const
|
||||
{
|
||||
Arc.SerializePrimitive( ValueRef(pData) );
|
||||
Arc.SerializePrimitive( ValueRef(pData), 0 );
|
||||
}
|
||||
|
||||
virtual TString ValueAsString(void* pData) const
|
||||
|
@ -32,6 +41,11 @@ public:
|
|||
return Value(pData).ToString();
|
||||
}
|
||||
|
||||
virtual CAssetID GetSerializationDefaultValue()
|
||||
{
|
||||
return CAssetID::InvalidID(Game());
|
||||
}
|
||||
|
||||
void SetTypeFilter(const TStringList& rkExtensions)
|
||||
{
|
||||
mTypeFilter.SetAcceptedTypes(Game(), rkExtensions);
|
||||
|
|
|
@ -15,7 +15,7 @@ protected:
|
|||
public:
|
||||
virtual void SerializeValue(void* pData, IArchive& Arc) const
|
||||
{
|
||||
Arc.SerializePrimitive( ValueRef(pData) );
|
||||
Arc.SerializePrimitive( ValueRef(pData), 0 );
|
||||
}
|
||||
|
||||
virtual TString ValueAsString(void* pData)
|
||||
|
|
|
@ -15,7 +15,7 @@ protected:
|
|||
public:
|
||||
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
|
||||
|
|
|
@ -34,8 +34,8 @@ class TEnumPropertyBase : public TSerializeableTypedProperty<s32, TypeEnum>
|
|||
|
||||
void Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL_AUTO(Name)
|
||||
<< SERIAL_HEX_AUTO(ID);
|
||||
rArc << SerialParameter("Name", Name)
|
||||
<< SerialParameter("ID", ID, SH_HexDisplay);
|
||||
}
|
||||
};
|
||||
std::vector<SEnumValue> mValues;
|
||||
|
@ -55,12 +55,12 @@ public:
|
|||
virtual void Serialize(IArchive& rArc)
|
||||
{
|
||||
TSerializeableTypedProperty::Serialize(rArc);
|
||||
rArc << SERIAL_CONTAINER("Values", mValues, "Values");
|
||||
rArc << SerialParameter("Values", mValues);
|
||||
}
|
||||
|
||||
virtual void SerializeValue(void* pData, IArchive& Arc) const
|
||||
{
|
||||
Arc.SerializePrimitive( (u32&) ValueRef(pData) );
|
||||
Arc.SerializePrimitive( (u32&) ValueRef(pData), 0 );
|
||||
}
|
||||
|
||||
virtual void InitFromArchetype(IPropertyNew* pOther)
|
||||
|
|
|
@ -28,8 +28,8 @@ class CFlagsProperty : public TSerializeableTypedProperty<u32, EPropertyTypeNew:
|
|||
|
||||
void Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL("FlagName", Name)
|
||||
<< SERIAL_HEX("FlagMask", Mask);
|
||||
rArc << SerialParameter("Name", Name)
|
||||
<< SerialParameter("Mask", Mask, SH_HexDisplay);
|
||||
}
|
||||
};
|
||||
std::vector<SBitFlag> mBitFlags;
|
||||
|
@ -64,7 +64,7 @@ public:
|
|||
virtual void Serialize(IArchive& rArc)
|
||||
{
|
||||
TSerializeableTypedProperty::Serialize(rArc);
|
||||
rArc << SERIAL_CONTAINER("Flags", mBitFlags, "Flag");
|
||||
rArc << SerialParameter("Flags", mBitFlags);
|
||||
}
|
||||
|
||||
virtual void PostInitialize()
|
||||
|
@ -80,7 +80,7 @@ public:
|
|||
|
||||
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)
|
||||
|
|
|
@ -15,7 +15,7 @@ protected:
|
|||
public:
|
||||
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
|
||||
|
|
|
@ -15,7 +15,7 @@ protected:
|
|||
public:
|
||||
virtual void SerializeValue(void* pData, IArchive& Arc) const
|
||||
{
|
||||
Arc.SerializeBulkData( ValueRef(pData) );
|
||||
Arc << SerialParameter("Data", ValueRef(pData));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ protected:
|
|||
public:
|
||||
virtual void SerializeValue(void* pData, IArchive& Arc) const
|
||||
{
|
||||
Arc.SerializePrimitive( (u32&) ValueRef(pData) );
|
||||
Arc.SerializePrimitive( ValueRef(pData), 0 );
|
||||
}
|
||||
|
||||
virtual TString ValueAsString(void* pData) const
|
||||
|
|
|
@ -15,7 +15,7 @@ protected:
|
|||
public:
|
||||
virtual void SerializeValue(void* pData, IArchive& Arc) const
|
||||
{
|
||||
Arc.SerializePrimitive( (u16&) ValueRef(pData) );
|
||||
Arc.SerializePrimitive( ValueRef(pData), 0 );
|
||||
}
|
||||
|
||||
virtual TString ValueAsString(void* pData) const
|
||||
|
|
|
@ -15,7 +15,7 @@ protected:
|
|||
public:
|
||||
virtual void SerializeValue(void* pData, IArchive& Arc) const
|
||||
{
|
||||
Arc.SerializePrimitive( (u32&) ValueRef(pData) );
|
||||
Arc.SerializePrimitive( ValueRef(pData), 0 );
|
||||
}
|
||||
|
||||
virtual TString ValueAsString(void* pData)
|
||||
|
|
|
@ -15,7 +15,7 @@ protected:
|
|||
public:
|
||||
virtual void SerializeValue(void* pData, IArchive& Arc) const
|
||||
{
|
||||
Arc.SerializeBulkData( ValueRef(pData) );
|
||||
Arc << SerialParameter("Data", ValueRef(pData));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ protected:
|
|||
public:
|
||||
virtual void SerializeValue(void* pData, IArchive& Arc) const
|
||||
{
|
||||
Arc.SerializePrimitive( ValueRef(pData) );
|
||||
Arc.SerializePrimitive( ValueRef(pData), 0 );
|
||||
}
|
||||
|
||||
virtual TString ValueAsString(void* pData) const
|
||||
|
|
|
@ -90,43 +90,14 @@ public:
|
|||
virtual void Serialize(IArchive& rArc)
|
||||
{
|
||||
IPropertyNew::Serialize(rArc);
|
||||
|
||||
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();
|
||||
}
|
||||
rArc << SerialParameter("SubProperties", mChildren);
|
||||
}
|
||||
|
||||
virtual void SerializeValue(void* pData, IArchive& Arc) const
|
||||
{
|
||||
for (u32 ChildIdx = 0; ChildIdx < mChildren.size(); ChildIdx++)
|
||||
{
|
||||
if (Arc.ParamBegin("Property"))
|
||||
if (Arc.ParamBegin("Property", 0))
|
||||
{
|
||||
mChildren[ChildIdx]->SerializeValue(pData, Arc);
|
||||
Arc.ParamEnd();
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
inline void Serialize(IArchive& rArc)
|
||||
{
|
||||
CAssetID ID = (mpRes && !rArc.IsReader() ? mpRes->ID() : CAssetID::InvalidID(rArc.Game()));
|
||||
rArc.SerializePrimitive(ID);
|
||||
rArc.SerializePrimitive(ID, 0);
|
||||
|
||||
if (rArc.IsReader())
|
||||
{
|
||||
|
|
|
@ -24,8 +24,8 @@ CAABox::CAABox(IInputStream& rInput)
|
|||
|
||||
void CAABox::Serialize(IArchive& rArc)
|
||||
{
|
||||
rArc << SERIAL("Min", mMin)
|
||||
<< SERIAL("Max", mMax);
|
||||
rArc << SerialParameter("Min", mMin)
|
||||
<< SerialParameter("Max", mMax);
|
||||
}
|
||||
|
||||
void CAABox::Write(IOutputStream& rOutput)
|
||||
|
|
|
@ -73,9 +73,9 @@ CTransform4f::CTransform4f(CVector3f Position, CVector3f Rotation, CVector3f Sca
|
|||
|
||||
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])
|
||||
<< SERIAL("Row1Col0", m[1][0]) << SERIAL("Row1Col1", m[1][1]) << SERIAL("Row1Col2", m[1][2]) << SERIAL("Row1Col3", m[1][3])
|
||||
<< SERIAL("Row2Col0", m[2][0]) << SERIAL("Row2Col1", m[2][1]) << SERIAL("Row2Col2", m[2][2]) << SERIAL("Row2Col3", m[2][3]);
|
||||
rOut << SerialParameter("Row0Col0", m[0][0]) << SerialParameter("Row0Col1", m[0][1]) << SerialParameter("Row0Col2", m[0][2]) << SerialParameter("Row0Col3", m[0][3])
|
||||
<< SerialParameter("Row1Col0", m[1][0]) << SerialParameter("Row1Col1", m[1][1]) << SerialParameter("Row1Col2", m[1][2]) << SerialParameter("Row1Col3", m[1][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)
|
||||
|
|
|
@ -38,7 +38,9 @@ void CVector3f::Write(IOutputStream& rOutput) const
|
|||
|
||||
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
|
||||
|
|
|
@ -559,7 +559,7 @@
|
|||
<property ID="0x0D7E7E2C" name="BabyMetroidScale"/>
|
||||
<property ID="0x0D7EF013" name="Unknown"/>
|
||||
<property ID="0x0D7F8C7F" name="PlayAlways"/>
|
||||
<property ID="0x0D7FAD55" name="Unknown"/>
|
||||
<property ID="0x0D7FAD55" name="DieOnCollision"/>
|
||||
<property ID="0x0D8098BF" name="Unknown"/>
|
||||
<property ID="0x0D920DE2" name="ConnectorLocator"/>
|
||||
<property ID="0x0D9230D1" name="BodyVulnerability"/>
|
||||
|
|
Loading…
Reference in New Issue