WIP start of property serialization support

This commit is contained in:
Aruki 2018-07-30 20:30:43 -06:00
parent 148449e50b
commit 6a72bae97a
20 changed files with 89 additions and 76 deletions

View File

@ -109,6 +109,7 @@ private:
public: public:
CScriptTemplate(CMasterTemplate *pMaster); CScriptTemplate(CMasterTemplate *pMaster);
~CScriptTemplate(); ~CScriptTemplate();
void Serialize(IArchive& rArc);
void PostLoad(); void PostLoad();
EGame Game() const; EGame Game() const;

View File

@ -91,7 +91,6 @@ void* IPropertyNew::GetChildDataPointer(void* pPropertyData) const
return pPropertyData; return pPropertyData;
} }
#if 0
void IPropertyNew::Serialize(IArchive& rArc) void IPropertyNew::Serialize(IArchive& rArc)
{ {
if (rArc.Game() <= ePrime) if (rArc.Game() <= ePrime)
@ -101,13 +100,12 @@ void IPropertyNew::Serialize(IArchive& rArc)
rArc << SERIAL_HEX("ID", mID) rArc << SERIAL_HEX("ID", mID)
<< SERIAL("Description", mDescription) << SERIAL("Description", mDescription)
<< SERIAL("CookPref", mCookPref) << SERIAL("CookPref", mCookPreference)
<< SERIAL("MinVersion", mMinVersion) << SERIAL("MinVersion", mMinVersion)
<< SERIAL("MaxVersion", mMaxVersion); << SERIAL("MaxVersion", mMaxVersion);
// Children don't get serialized for most property types // Children don't get serialized for most property types
} }
#endif
void IPropertyNew::InitFromArchetype(IPropertyNew* pOther) void IPropertyNew::InitFromArchetype(IPropertyNew* pOther)
{ {

View File

@ -190,9 +190,7 @@ public:
virtual const char* HashableTypeName() const; virtual const char* HashableTypeName() const;
virtual void* GetChildDataPointer(void* pPropertyData) const; virtual void* GetChildDataPointer(void* pPropertyData) const;
#if 0
virtual void Serialize(IArchive& rArc); virtual void Serialize(IArchive& rArc);
#endif
virtual void InitFromArchetype(IPropertyNew* pOther); virtual void InitFromArchetype(IPropertyNew* pOther);
virtual TString GetTemplateFileName(); virtual TString GetTemplateFileName();
@ -215,7 +213,6 @@ public:
inline IPropertyNew* RootParent(); inline IPropertyNew* RootParent();
inline IPropertyNew* Archetype() const; inline IPropertyNew* Archetype() const;
inline CScriptTemplate* ScriptTemplate() const; inline CScriptTemplate* ScriptTemplate() const;
inline CMasterTemplate* MasterTemplate() const;
inline TString Name() const; inline TString Name() const;
inline TString Description() const; inline TString Description() const;
inline TString Suffix() const; inline TString Suffix() const;
@ -349,14 +346,6 @@ public:
virtual bool CanHaveDefault() const { return true; } virtual bool CanHaveDefault() const { return true; }
#if 0
virtual void Serialize(IArchive& rArc)
{
IPropertyNew::Serialize(rArc);
rArc << SERIAL("DefaultValue", mDefaultValue);
}
#endif
virtual void InitFromArchetype(IPropertyNew* pOther) virtual void InitFromArchetype(IPropertyNew* pOther)
{ {
IPropertyNew::InitFromArchetype(pOther); IPropertyNew::InitFromArchetype(pOther);
@ -382,7 +371,23 @@ public:
}; };
template<typename PropType, EPropertyTypeNew PropEnum> template<typename PropType, EPropertyTypeNew PropEnum>
class TNumericalPropertyNew : public TTypedPropertyNew<PropType, PropEnum> class TSerializeableTypedProperty : public TTypedPropertyNew<PropType, PropEnum>
{
protected:
TSerializeableTypedProperty()
: TTypedPropertyNew()
{}
public:
virtual void Serialize(IArchive& rArc)
{
IPropertyNew::Serialize(rArc);
rArc << SERIAL("DefaultValue", mDefaultValue);
}
};
template<typename PropType, EPropertyTypeNew PropEnum>
class TNumericalPropertyNew : public TSerializeableTypedProperty<PropType, PropEnum>
{ {
friend class IPropertyNew; friend class IPropertyNew;
friend class CTemplateLoader; friend class CTemplateLoader;
@ -392,20 +397,18 @@ protected:
PropType mMaxValue; PropType mMaxValue;
TNumericalPropertyNew() TNumericalPropertyNew()
: TTypedPropertyNew() : TSerializeableTypedProperty()
, mMinValue( -1 ) , mMinValue( -1 )
, mMaxValue( -1 ) , mMaxValue( -1 )
{} {}
public: public:
#if 0
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
TTypedPropertyNew::Serialize(rArc); TTypedPropertyNew::Serialize(rArc);
rArc << SERIAL("Min", mMin) rArc << SERIAL("Min", mMinValue)
<< SERIAL("Max", mMax); << SERIAL("Max", mMaxValue);
} }
#endif
virtual void InitFromArchetype(IPropertyNew* pOther) virtual void InitFromArchetype(IPropertyNew* pOther)
{ {

View File

@ -3,13 +3,13 @@
#include "../IPropertyNew.h" #include "../IPropertyNew.h"
class CAnimationProperty : public TTypedPropertyNew< int, EPropertyTypeNew::Animation > class CAnimationProperty : public TSerializeableTypedProperty< u32, EPropertyTypeNew::Animation >
{ {
friend class IPropertyNew; friend class IPropertyNew;
protected: protected:
CAnimationProperty() CAnimationProperty()
: TTypedPropertyNew() : TSerializeableTypedProperty()
{} {}
public: public:

View File

@ -3,13 +3,13 @@
#include "../IPropertyNew.h" #include "../IPropertyNew.h"
class CAnimationSetProperty : public TTypedPropertyNew< CAnimationParameters, EPropertyTypeNew::AnimationSet > class CAnimationSetProperty : public TSerializeableTypedProperty< CAnimationParameters, EPropertyTypeNew::AnimationSet >
{ {
friend class IPropertyNew; friend class IPropertyNew;
protected: protected:
CAnimationSetProperty() CAnimationSetProperty()
: TTypedPropertyNew() : TSerializeableTypedProperty()
{} {}
public: public:

View File

@ -20,7 +20,7 @@ struct SScriptArray
/** You probably shouldn't use this on intrinsic classes; script only */ /** You probably shouldn't use this on intrinsic classes; script only */
/** @todo proper support of default values for arrays (this would be used for prefabs) */ /** @todo proper support of default values for arrays (this would be used for prefabs) */
class CArrayProperty : public TTypedPropertyNew<int, EPropertyTypeNew::Array> class CArrayProperty : public TTypedPropertyNew<u32, EPropertyTypeNew::Array>
{ {
friend class IPropertyNew; friend class IPropertyNew;
friend class CTemplateLoader; friend class CTemplateLoader;
@ -105,6 +105,12 @@ public:
Resize(pPropertyData, rArray.Count); Resize(pPropertyData, rArray.Count);
} }
virtual void Serialize(IArchive& rArc)
{
TTypedPropertyNew::Serialize(rArc);
//rArc << SERIAL("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);

View File

@ -4,19 +4,17 @@
#include "../IPropertyNew.h" #include "../IPropertyNew.h"
#include "Core/Resource/CResTypeFilter.h" #include "Core/Resource/CResTypeFilter.h"
class CAssetProperty : public TTypedPropertyNew<CAssetID, EPropertyTypeNew::Asset> class CAssetProperty : public TSerializeableTypedProperty<CAssetID, EPropertyTypeNew::Asset>
{ {
friend class CTemplateLoader; friend class CTemplateLoader;
CResTypeFilter mTypeFilter; CResTypeFilter mTypeFilter;
public: public:
#if 0
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
TTypedPropertyNew::Serialize(rArc); TSerializeableTypedProperty::Serialize(rArc);
rArc << SERIAL("AcceptedTypes", mTypeFilter); rArc << SERIAL("AcceptedTypes", mTypeFilter);
} }
#endif
virtual void InitFromArchetype(IPropertyNew* pOther) virtual void InitFromArchetype(IPropertyNew* pOther)
{ {

View File

@ -3,13 +3,13 @@
#include "../IPropertyNew.h" #include "../IPropertyNew.h"
class CBoolProperty : public TTypedPropertyNew< bool, EPropertyTypeNew::Bool > class CBoolProperty : public TSerializeableTypedProperty< bool, EPropertyTypeNew::Bool >
{ {
friend class IPropertyNew; friend class IPropertyNew;
protected: protected:
CBoolProperty() CBoolProperty()
: TTypedPropertyNew() : TSerializeableTypedProperty()
{} {}
public: public:

View File

@ -3,7 +3,7 @@
#include "../IPropertyNew.h" #include "../IPropertyNew.h"
class CByteProperty : public TNumericalPropertyNew< char, EPropertyTypeNew::Byte > class CByteProperty : public TNumericalPropertyNew< s8, EPropertyTypeNew::Byte >
{ {
friend class IPropertyNew; friend class IPropertyNew;

View File

@ -3,13 +3,13 @@
#include "../IPropertyNew.h" #include "../IPropertyNew.h"
class CColorProperty : public TTypedPropertyNew< CColor, EPropertyTypeNew::Color > class CColorProperty : public TSerializeableTypedProperty< CColor, EPropertyTypeNew::Color >
{ {
friend class IPropertyNew; friend class IPropertyNew;
protected: protected:
CColorProperty() CColorProperty()
: TTypedPropertyNew() : TSerializeableTypedProperty()
{} {}
public: public:

View File

@ -11,7 +11,7 @@
* In PWE, however, they are both implemented the same way under the hood. * In PWE, however, they are both implemented the same way under the hood.
*/ */
template<EPropertyTypeNew TypeEnum> template<EPropertyTypeNew TypeEnum>
class TEnumPropertyBase : public TTypedPropertyNew<int, TypeEnum> class TEnumPropertyBase : public TSerializeableTypedProperty<s32, TypeEnum>
{ {
friend class CTemplateLoader; friend class CTemplateLoader;
struct SEnumValue struct SEnumValue
@ -19,13 +19,24 @@ class TEnumPropertyBase : public TTypedPropertyNew<int, TypeEnum>
TString Name; TString Name;
u32 ID; u32 ID;
SEnumValue()
: ID(0)
{}
SEnumValue(const TString& rkInName, u32 InID) SEnumValue(const TString& rkInName, u32 InID)
: Name(rkInName), ID(InID) {} : Name(rkInName), ID(InID) {}
inline bool operator==(const SEnumValue& rkOther) const inline bool operator==(const SEnumValue& rkOther) const
{ {
return( Name == rkOther.Name && ID == rkOther.ID ); return( Name == rkOther.Name && ID == rkOther.ID );
} }
void Serialize(IArchive& rArc)
{
rArc << SERIAL_AUTO(Name)
<< SERIAL_HEX_AUTO(ID);
}
}; };
std::vector<SEnumValue> mValues; std::vector<SEnumValue> mValues;
@ -41,6 +52,12 @@ public:
return "choice"; return "choice";
} }
virtual void Serialize(IArchive& rArc)
{
TSerializeableTypedProperty::Serialize(rArc);
rArc << SERIAL_CONTAINER("Values", mValues, "Values");
}
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) );

View File

@ -3,7 +3,7 @@
#include "../IPropertyNew.h" #include "../IPropertyNew.h"
class CFlagsProperty : public TTypedPropertyNew<int, EPropertyTypeNew::Flags> class CFlagsProperty : public TSerializeableTypedProperty<u32, EPropertyTypeNew::Flags>
{ {
friend class CTemplateLoader; friend class CTemplateLoader;
friend class IPropertyNew; friend class IPropertyNew;
@ -13,6 +13,10 @@ class CFlagsProperty : public TTypedPropertyNew<int, EPropertyTypeNew::Flags>
TString Name; TString Name;
u32 Mask; u32 Mask;
SBitFlag()
: Mask(0)
{}
SBitFlag(const TString& rkInName, u32 InMask) SBitFlag(const TString& rkInName, u32 InMask)
: Name(rkInName), Mask(InMask) : Name(rkInName), Mask(InMask)
{} {}
@ -22,13 +26,11 @@ class CFlagsProperty : public TTypedPropertyNew<int, EPropertyTypeNew::Flags>
return( Name == rkOther.Name && Mask == rkOther.Mask ); return( Name == rkOther.Name && Mask == rkOther.Mask );
} }
#if 0
void Serialize(IArchive& rArc) void Serialize(IArchive& rArc)
{ {
rArc << SERIAL("FlagName", Name) rArc << SERIAL("FlagName", Name)
<< SERIAL_HEX("FlagMask", Mask); << SERIAL_HEX("FlagMask", Mask);
} }
#endif
}; };
std::vector<SBitFlag> mBitFlags; std::vector<SBitFlag> mBitFlags;
u32 mAllFlags; u32 mAllFlags;
@ -37,7 +39,7 @@ class CFlagsProperty : public TTypedPropertyNew<int, EPropertyTypeNew::Flags>
TString mSourceFile; TString mSourceFile;
CFlagsProperty() CFlagsProperty()
: TTypedPropertyNew() : TSerializeableTypedProperty()
, mAllFlags(0) , mAllFlags(0)
{} {}
@ -59,21 +61,11 @@ public:
return mBitFlags[Idx].Mask; return mBitFlags[Idx].Mask;
} }
#if 0
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
TTypedPropertyNew::Serialize(rArc); TSerializeableTypedProperty::Serialize(rArc);
rArc << SERIAL_CONTAINER("Flags", mFlags, "Flag"); rArc << SERIAL_CONTAINER("Flags", mBitFlags, "Flag");
// Initialize the "all flags" cache
if (rArc.IsReader())
{
mAllFlags = 0;
for (u32 FlagIdx = 0; FlagIdx < mFlags.size(); FlagIdx++)
mAllFlags |= mFlags[FlagIdx].Mask;
} }
}
#endif
virtual void PostInitialize() virtual void PostInitialize()
{ {

View File

@ -3,7 +3,7 @@
#include "../IPropertyNew.h" #include "../IPropertyNew.h"
class CIntProperty : public TNumericalPropertyNew< int, EPropertyTypeNew::Int > class CIntProperty : public TNumericalPropertyNew< s32, EPropertyTypeNew::Int >
{ {
friend class IPropertyNew; friend class IPropertyNew;

View File

@ -3,7 +3,7 @@
#include "../IPropertyNew.h" #include "../IPropertyNew.h"
class CSequenceProperty : public TTypedPropertyNew< int, EPropertyTypeNew::Sequence > class CSequenceProperty : public TTypedPropertyNew< s32, EPropertyTypeNew::Sequence >
{ {
friend class IPropertyNew; friend class IPropertyNew;

View File

@ -3,7 +3,7 @@
#include "../IPropertyNew.h" #include "../IPropertyNew.h"
class CShortProperty : public TNumericalPropertyNew< short, EPropertyTypeNew::Short > class CShortProperty : public TNumericalPropertyNew< s16, EPropertyTypeNew::Short >
{ {
friend class IPropertyNew; friend class IPropertyNew;

View File

@ -3,13 +3,13 @@
#include "../IPropertyNew.h" #include "../IPropertyNew.h"
class CSoundProperty : public TTypedPropertyNew< int, EPropertyTypeNew::Sound > class CSoundProperty : public TSerializeableTypedProperty< s32, EPropertyTypeNew::Sound >
{ {
friend class IPropertyNew; friend class IPropertyNew;
protected: protected:
CSoundProperty() CSoundProperty()
: TTypedPropertyNew() : TSerializeableTypedProperty()
{} {}
public: public:

View File

@ -3,13 +3,13 @@
#include "../IPropertyNew.h" #include "../IPropertyNew.h"
class CStringProperty : public TTypedPropertyNew< TString, EPropertyTypeNew::String > class CStringProperty : public TSerializeableTypedProperty< TString, EPropertyTypeNew::String >
{ {
friend class IPropertyNew; friend class IPropertyNew;
protected: protected:
CStringProperty() CStringProperty()
: TTypedPropertyNew() : TSerializeableTypedProperty()
{} {}
public: public:

View File

@ -87,14 +87,13 @@ public:
return mpArchetype->HashableTypeName(); return mpArchetype->HashableTypeName();
} }
#if 0
virtual void Serialize(IArchive& rArc) virtual void Serialize(IArchive& rArc)
{ {
IPropertyNew::Serialize(rArc); IPropertyNew::Serialize(rArc);
if (rArc.ParamBegin("SubProperties")) if (rArc.ParamBegin("SubProperties"))
{ {
u32 NumChildren; u32 NumChildren = mChildren.size();
rArc.SerializeContainerSize(NumChildren, "Property"); rArc.SerializeContainerSize(NumChildren, "Property");
if (rArc.IsReader()) if (rArc.IsReader())
@ -111,7 +110,7 @@ public:
if (rArc.IsReader()) if (rArc.IsReader())
{ {
mChildren[ChildIdx] = Create(Type, this, mpMasterTemplate, mpScriptTemplate); mChildren[ChildIdx] = Create(Type, this, mGame, mpScriptTemplate);
} }
mChildren[ChildIdx]->Serialize(rArc); mChildren[ChildIdx]->Serialize(rArc);
@ -122,7 +121,6 @@ public:
rArc.ParamEnd(); rArc.ParamEnd();
} }
} }
#endif
virtual void SerializeValue(void* pData, IArchive& Arc) const virtual void SerializeValue(void* pData, IArchive& Arc) const
{ {

View File

@ -3,13 +3,13 @@
#include "../IPropertyNew.h" #include "../IPropertyNew.h"
class CVectorProperty : public TTypedPropertyNew< CVector3f, EPropertyTypeNew::Vector > class CVectorProperty : public TSerializeableTypedProperty< CVector3f, EPropertyTypeNew::Vector >
{ {
friend class IPropertyNew; friend class IPropertyNew;
protected: protected:
CVectorProperty() CVectorProperty()
: TTypedPropertyNew() : TSerializeableTypedProperty()
{} {}
public: public:

View File

@ -132,7 +132,7 @@ void CTemplateEditDialog::AddTemplate(IPropertyNew* pProp)
if (!Source.IsEmpty()) if (!Source.IsEmpty())
{ {
CStructPropertyNew* pStruct = pProp->MasterTemplate()->StructAtSource(Source); CStructPropertyNew* pStruct = CMasterTemplate::MasterForGame(pProp->Game())->StructAtSource(Source);
if (!mStructTemplatesToResave.contains(pStruct)) if (!mStructTemplatesToResave.contains(pStruct))
mStructTemplatesToResave << pStruct; mStructTemplatesToResave << pStruct;
@ -161,7 +161,7 @@ void CTemplateEditDialog::UpdateDescription(const TString& rkNewDesc)
AddTemplate(mpProperty); AddTemplate(mpProperty);
// Update all copies of this property in memory with the new description // Update all copies of this property in memory with the new description
TString SourceFile = mpProperty->FindStructSource(); TString SourceFile = mpProperty->GetTemplateFileName();
if (!SourceFile.IsEmpty()) if (!SourceFile.IsEmpty())
{ {
@ -171,10 +171,10 @@ void CTemplateEditDialog::UpdateDescription(const TString& rkNewDesc)
{ {
for (u32 TemplateIdx = 0; TemplateIdx < pkTemplates->size(); TemplateIdx++) for (u32 TemplateIdx = 0; TemplateIdx < pkTemplates->size(); TemplateIdx++)
{ {
IPropertyNew* pTemp = pkTemplates->at(TemplateIdx); IPropertyNew* pProp = pkTemplates->at(TemplateIdx);
if (pTemp->FindStructSource() == SourceFile && pTemp->Description() == mOriginalDescription) if (pProp->GetTemplateFileName() == SourceFile && pProp->Description() == mOriginalDescription)
pTemp->SetDescription(rkNewDesc); pProp->SetDescription(rkNewDesc);
} }
} }
} }