General: Remove unnecessary inline specifiers and add overrides

This commit is contained in:
Lioncash
2020-06-11 14:10:22 -04:00
parent 2d76c5865a
commit 012da6fb6d
107 changed files with 885 additions and 1055 deletions

View File

@@ -19,12 +19,12 @@ struct SObjId
CFourCC ID_4CC;
};
inline SObjId() {}
inline SObjId(uint32 InID) : ID(InID) {}
inline SObjId(CFourCC InID) : ID_4CC(InID) {}
SObjId() {}
SObjId(uint32 InID) : ID(InID) {}
SObjId(CFourCC InID) : ID_4CC(InID) {}
inline operator uint32() const { return ID; }
inline operator CFourCC() const { return ID_4CC; }
operator uint32() const { return ID; }
operator CFourCC() const { return ID_4CC; }
void Serialize(IArchive& Arc)
{
@@ -61,8 +61,8 @@ struct TTemplatePath
}
};
typedef TTemplatePath<CScriptTemplate> SScriptTemplatePath;
typedef TTemplatePath<IProperty> SPropertyTemplatePath;
using SScriptTemplatePath = TTemplatePath<CScriptTemplate>;
using SPropertyTemplatePath = TTemplatePath<IProperty>;
/** CGameTemplate - Per-game template data */
class CGameTemplate
@@ -106,12 +106,12 @@ public:
CScriptTemplate* FindMiscTemplate(const TString& kTemplateName);
TString GetGameDirectory() const;
// Inline Accessors
inline EGame Game() const { return mGame; }
inline uint32 NumScriptTemplates() const { return mScriptTemplates.size(); }
inline uint32 NumStates() const { return mStates.size(); }
inline uint32 NumMessages() const { return mMessages.size(); }
inline bool IsLoadedSuccessfully() { return mFullyLoaded; }
// Accessors
EGame Game() const { return mGame; }
uint32 NumScriptTemplates() const { return mScriptTemplates.size(); }
uint32 NumStates() const { return mStates.size(); }
uint32 NumMessages() const { return mMessages.size(); }
bool IsLoadedSuccessfully() const { return mFullyLoaded; }
};
#endif // CGAMETEMPLATE_H

View File

@@ -63,18 +63,14 @@ struct SMessage
class CLink
{
CGameArea *mpArea;
uint32 mStateID;
uint32 mMessageID;
uint32 mSenderID;
uint32 mReceiverID;
uint32 mStateID = UINT32_MAX;
uint32 mMessageID = UINT32_MAX;
uint32 mSenderID = UINT32_MAX;
uint32 mReceiverID = UINT32_MAX;
public:
CLink(CGameArea *pArea)
: mpArea(pArea)
, mStateID(-1)
, mMessageID(-1)
, mSenderID(-1)
, mReceiverID(-1)
{}
CLink(CGameArea *pArea, uint32 StateID, uint32 MessageID, uint32 SenderID, uint32 ReceiverID)
@@ -140,31 +136,31 @@ public:
}
// Operators
bool operator==(const CLink& rkOther)
bool operator==(const CLink& rkOther) const
{
return ( (mpArea == rkOther.mpArea) &&
(mStateID == rkOther.mStateID) &&
(mMessageID == rkOther.mMessageID) &&
(mSenderID == rkOther.mSenderID) &&
(mReceiverID == rkOther.mReceiverID) );
return (mpArea == rkOther.mpArea) &&
(mStateID == rkOther.mStateID) &&
(mMessageID == rkOther.mMessageID) &&
(mSenderID == rkOther.mSenderID) &&
(mReceiverID == rkOther.mReceiverID);
}
bool operator!=(const CLink& rkOther)
bool operator!=(const CLink& rkOther) const
{
return (!(*this == rkOther));
}
// Accessors
inline CGameArea* Area() const { return mpArea; }
inline uint32 State() const { return mStateID; }
inline uint32 Message() const { return mMessageID; }
inline uint32 SenderID() const { return mSenderID; }
inline uint32 ReceiverID() const { return mReceiverID; }
inline CScriptObject* Sender() const { return mpArea->InstanceByID(mSenderID); }
inline CScriptObject* Receiver() const { return mpArea->InstanceByID(mReceiverID); }
CGameArea* Area() const { return mpArea; }
uint32 State() const { return mStateID; }
uint32 Message() const { return mMessageID; }
uint32 SenderID() const { return mSenderID; }
uint32 ReceiverID() const { return mReceiverID; }
CScriptObject* Sender() const { return mpArea->InstanceByID(mSenderID); }
CScriptObject* Receiver() const { return mpArea->InstanceByID(mReceiverID); }
inline void SetState(uint32 StateID) { mStateID = StateID; }
inline void SetMessage(uint32 MessageID) { mMessageID = MessageID; }
void SetState(uint32 StateID) { mStateID = StateID; }
void SetMessage(uint32 MessageID) { mMessageID = MessageID; }
};

View File

@@ -11,15 +11,13 @@ class CScriptLayer
{
CGameArea *mpArea;
TString mLayerName;
bool mActive;
bool mVisible;
bool mActive = true;
bool mVisible = true;
std::vector<CScriptObject*> mInstances;
public:
CScriptLayer(CGameArea *pArea)
: mpArea(pArea)
, mLayerName("New Layer")
, mActive(true)
, mVisible(true)
{
}
@@ -78,14 +76,14 @@ public:
}
// Accessors
inline CGameArea* Area() const { return mpArea; }
inline TString Name() const { return mLayerName; }
inline bool IsActive() const { return mActive; }
inline bool IsVisible() const { return mVisible; }
inline uint32 NumInstances() const { return mInstances.size(); }
inline CScriptObject* InstanceByIndex(uint32 Index) const { return mInstances[Index]; }
CGameArea* Area() const { return mpArea; }
TString Name() const { return mLayerName; }
bool IsActive() const { return mActive; }
bool IsVisible() const { return mVisible; }
uint32 NumInstances() const { return mInstances.size(); }
CScriptObject* InstanceByIndex(uint32 Index) const { return mInstances[Index]; }
inline CScriptObject* InstanceByID(uint32 ID) const
CScriptObject* InstanceByID(uint32 ID) const
{
for (auto it = mInstances.begin(); it != mInstances.end(); it++)
{
@@ -96,11 +94,11 @@ public:
return nullptr;
}
inline void SetName(const TString& rkName) { mLayerName = rkName; }
inline void SetActive(bool Active) { mActive = Active; }
inline void SetVisible(bool Visible) { mVisible = Visible; }
void SetName(const TString& rkName) { mLayerName = rkName; }
void SetActive(bool Active) { mActive = Active; }
void SetVisible(bool Visible) { mVisible = Visible; }
inline uint32 AreaIndex() const
uint32 AreaIndex() const
{
for (uint32 iLyr = 0; iLyr < mpArea->NumScriptLayers(); iLyr++)
{

View File

@@ -7,10 +7,7 @@ CScriptObject::CScriptObject(uint32 InstanceID, CGameArea *pArea, CScriptLayer *
: mpTemplate(pTemplate)
, mpArea(pArea)
, mpLayer(pLayer)
, mVersion(0)
, mInstanceID(InstanceID)
, mHasInGameModel(false)
, mIsCheckingNearVisibleActivation(false)
{
mpTemplate->AddObject(this);

View File

@@ -20,13 +20,13 @@ class CInstanceID
{
uint32 mId = 0;
public:
operator uint32() const { return mId; }
CInstanceID() = default;
CInstanceID(uint32 id) : mId(id) {}
CInstanceID& operator=(uint32 id) { mId = id; return *this; }
uint8 Layer() const { return uint8((mId >> 26u) & 0x3fu); }
uint16 Area() const { return uint16((mId >> 16u) & 0x3ffu); }
uint16 Id() const { return uint16(mId & 0xffffu); }
constexpr operator uint32() const { return mId; }
constexpr CInstanceID() = default;
constexpr CInstanceID(uint32 id) : mId(id) {}
constexpr CInstanceID& operator=(uint32 id) { mId = id; return *this; }
[[nodiscard]] constexpr uint8 Layer() const { return uint8((mId >> 26u) & 0x3fu); }
[[nodiscard]] constexpr uint16 Area() const { return uint16((mId >> 16u) & 0x3ffu); }
[[nodiscard]] constexpr uint16 Id() const { return uint16(mId & 0xffffu); }
};
class CScriptObject
@@ -37,7 +37,7 @@ class CScriptObject
CScriptTemplate *mpTemplate;
CGameArea *mpArea;
CScriptLayer *mpLayer;
uint32 mVersion;
uint32 mVersion = 0;
CInstanceID mInstanceID;
std::vector<CLink*> mOutLinks;
@@ -53,15 +53,15 @@ class CScriptObject
TResPtr<CResource> mpDisplayAsset;
TResPtr<CCollisionMeshGroup> mpCollision;
uint32 mActiveCharIndex;
uint32 mActiveAnimIndex;
bool mHasInGameModel;
uint32 mActiveCharIndex = 0;
uint32 mActiveAnimIndex = 0;
bool mHasInGameModel = false;
EVolumeShape mVolumeShape;
float mVolumeScale;
EVolumeShape mVolumeShape{};
float mVolumeScale = 0.0f;
// Recursion guard
mutable bool mIsCheckingNearVisibleActivation;
mutable bool mIsCheckingNearVisibleActivation = false;
public:
CScriptObject(uint32 InstanceID, CGameArea *pArea, CScriptLayer *pLayer, CScriptTemplate *pTemplate);

View File

@@ -5,45 +5,19 @@
#include "Core/Resource/Animation/CAnimSet.h"
#include <Common/Log.h>
#include <iostream>
#include <string>
// Old constructor
CScriptTemplate::CScriptTemplate(CGameTemplate *pGame)
: mpGame(pGame)
, mpProperties(nullptr)
, mVisible(true)
, mDirty(false)
, mpNameProperty(nullptr)
, mpPositionProperty(nullptr)
, mpRotationProperty(nullptr)
, mpScaleProperty(nullptr)
, mpActiveProperty(nullptr)
, mpLightParametersProperty(nullptr)
, mPreviewScale(1.f)
, mVolumeShape(EVolumeShape::NoShape)
, mVolumeScale(1.f)
{
}
// New constructor
CScriptTemplate::CScriptTemplate(CGameTemplate* pInGame, uint32 InObjectID, const TString& kInFilePath)
: mRotationType(ERotationType::RotationEnabled)
, mScaleType(EScaleType::ScaleEnabled)
, mPreviewScale(1.f)
, mVolumeShape(EVolumeShape::NoShape)
, mVolumeScale(1.f)
, mSourceFile(kInFilePath)
: mSourceFile(kInFilePath)
, mObjectID(InObjectID)
, mpGame(pInGame)
, mpNameProperty(nullptr)
, mpPositionProperty(nullptr)
, mpRotationProperty(nullptr)
, mpScaleProperty(nullptr)
, mpActiveProperty(nullptr)
, mpLightParametersProperty(nullptr)
, mVisible(true)
, mDirty(false)
{
// Load
CXMLReader Reader(kInFilePath);
@@ -62,9 +36,7 @@ CScriptTemplate::CScriptTemplate(CGameTemplate* pInGame, uint32 InObjectID, cons
if (!mLightParametersIDString.IsEmpty()) mpLightParametersProperty = TPropCast<CStructProperty>( mpProperties->ChildByIDString(mLightParametersIDString) );
}
CScriptTemplate::~CScriptTemplate()
{
}
CScriptTemplate::~CScriptTemplate() = default;
void CScriptTemplate::Serialize(IArchive& Arc)
{

View File

@@ -80,17 +80,17 @@ private:
std::vector<SEditorAsset> mAssets;
std::vector<SAttachment> mAttachments;
ERotationType mRotationType;
EScaleType mScaleType;
float mPreviewScale;
ERotationType mRotationType{ERotationType::RotationEnabled};
EScaleType mScaleType{EScaleType::ScaleEnabled};
float mPreviewScale = 1.0f;
// Preview Volume
EVolumeShape mVolumeShape;
float mVolumeScale;
EVolumeShape mVolumeShape{EVolumeShape::NoShape};
float mVolumeScale = 1.0f;
TIDString mVolumeConditionIDString;
TString mSourceFile;
uint32 mObjectID;
uint32 mObjectID = 0;
// Editor Properties
TIDString mNameIDString;
@@ -103,12 +103,12 @@ private:
CGameTemplate* mpGame;
std::list<CScriptObject*> mObjectList;
CStringProperty* mpNameProperty;
CVectorProperty* mpPositionProperty;
CVectorProperty* mpRotationProperty;
CVectorProperty* mpScaleProperty;
CBoolProperty* mpActiveProperty;
CStructProperty* mpLightParametersProperty;
CStringProperty* mpNameProperty = nullptr;
CVectorProperty* mpPositionProperty = nullptr;
CVectorProperty* mpRotationProperty = nullptr;
CVectorProperty* mpScaleProperty = nullptr;
CBoolProperty* mpActiveProperty = nullptr;
CStructProperty* mpLightParametersProperty = nullptr;
struct SVolumeCondition {
uint32 Value;
@@ -123,14 +123,14 @@ private:
}
};
std::vector<SVolumeCondition> mVolumeConditions;
bool mVisible;
bool mDirty;
bool mVisible = true;
bool mDirty = false;
public:
// Default constructor. Don't use. This is only here so the serializer doesn't complain
CScriptTemplate() { ASSERT(false); }
// Old constructor
CScriptTemplate(CGameTemplate *pGame);
explicit CScriptTemplate(CGameTemplate *pGame);
// New constructor
CScriptTemplate(CGameTemplate* pGame, uint32 ObjectID, const TString& kFilePath);
~CScriptTemplate();
@@ -145,29 +145,29 @@ public:
CCollisionMeshGroup* FindCollision(void* pPropertyData);
// Accessors
inline CGameTemplate* GameTemplate() const { return mpGame; }
inline TString Name() const { return mpProperties->Name(); }
inline ERotationType RotationType() const { return mRotationType; }
inline EScaleType ScaleType() const { return mScaleType; }
inline float PreviewScale() const { return mPreviewScale; }
inline uint32 ObjectID() const { return mObjectID; }
inline bool IsVisible() const { return mVisible; }
inline TString SourceFile() const { return mSourceFile; }
inline CStructProperty* Properties() const { return mpProperties.get(); }
inline uint32 NumAttachments() const { return mAttachments.size(); }
CGameTemplate* GameTemplate() const { return mpGame; }
TString Name() const { return mpProperties->Name(); }
ERotationType RotationType() const { return mRotationType; }
EScaleType ScaleType() const { return mScaleType; }
float PreviewScale() const { return mPreviewScale; }
uint32 ObjectID() const { return mObjectID; }
bool IsVisible() const { return mVisible; }
TString SourceFile() const { return mSourceFile; }
CStructProperty* Properties() const { return mpProperties.get(); }
uint32 NumAttachments() const { return mAttachments.size(); }
const SAttachment& Attachment(uint32 Index) const { return mAttachments[Index]; }
const std::vector<TString>& RequiredModules() const { return mModules; }
inline CStringProperty* NameProperty() const { return mpNameProperty; }
inline CVectorProperty* PositionProperty() const { return mpPositionProperty; }
inline CVectorProperty* RotationProperty() const { return mpRotationProperty; }
inline CVectorProperty* ScaleProperty() const { return mpScaleProperty; }
inline CBoolProperty* ActiveProperty() const { return mpActiveProperty; }
inline CStructProperty* LightParametersProperty() const { return mpLightParametersProperty; }
CStringProperty* NameProperty() const { return mpNameProperty; }
CVectorProperty* PositionProperty() const { return mpPositionProperty; }
CVectorProperty* RotationProperty() const { return mpRotationProperty; }
CVectorProperty* ScaleProperty() const { return mpScaleProperty; }
CBoolProperty* ActiveProperty() const { return mpActiveProperty; }
CStructProperty* LightParametersProperty() const { return mpLightParametersProperty; }
inline void SetVisible(bool Visible) { mVisible = Visible; }
inline void MarkDirty() { mDirty = true; }
inline bool IsDirty() const { return mDirty || mpProperties->IsDirty(); }
void SetVisible(bool Visible) { mVisible = Visible; }
void MarkDirty() { mDirty = true; }
bool IsDirty() const { return mDirty || mpProperties->IsDirty(); }
// Object Tracking
uint32 NumObjects() const;

View File

@@ -66,7 +66,7 @@ public:
const char* Name() const;
const char* TypeName() const;
operator bool() const;
explicit operator bool() const;
void operator ++();
};

View File

@@ -14,16 +14,7 @@
/** IProperty */
IProperty::IProperty(EGame Game)
: mpParent( nullptr )
, mpPointerParent( nullptr )
, mpArchetype( nullptr )
, mGame( Game )
, mpScriptTemplate( nullptr )
, mOffset( -1 )
, mID( -1 )
, mCookPreference( ECookPreference::Default )
, mMinVersion( 0.0f )
, mMaxVersion( FLT_MAX )
: mGame(Game)
{}
void IProperty::_ClearChildren()

View File

@@ -13,33 +13,33 @@ class CGameTemplate;
class CScriptTemplate;
class CStructProperty;
/** Typedefs */
typedef TString TIDString;
/** Aliases */
using TIDString = TString;
/** Property flags */
enum class EPropertyFlag : uint32
{
/** Property has been fully initialized and has had PostLoad called */
IsInitialized = 0x1,
IsInitialized = 0x1,
/** Property is an archetype (a template for other properties to copy from) */
IsArchetype = 0x2,
IsArchetype = 0x2,
/** Property is an array archetype (a template for elements of an array property) */
IsArrayArchetype = 0x4,
IsArrayArchetype = 0x4,
/** This property and all its children are a single unit and do not have individual property IDs, sizes, etc. */
IsAtomic = 0x8,
IsAtomic = 0x8,
/** This is a property of a C++ class, not a script object */
IsIntrinsic = 0x10,
IsIntrinsic = 0x10,
/** Property has been modified, and needs to be resaved. Only valid on archetypes */
IsDirty = 0x20,
IsDirty = 0x20,
/** We have cached whether the property name is correct */
HasCachedNameCheck = 0x40000000,
HasCachedNameCheck = 0x40000000,
/** The name of the property is a match for the property ID hash */
HasCorrectPropertyName = 0x80000000,
HasCorrectPropertyName = 0x80000000,
/** Flags that are left intact when copying from an archetype */
ArchetypeCopyFlags = EPropertyFlag::IsAtomic,
ArchetypeCopyFlags = IsAtomic,
/** Flags that are inheritable from parent */
InheritableFlags = EPropertyFlag::IsArchetype | EPropertyFlag::IsArrayArchetype | EPropertyFlag::IsAtomic,
InheritableFlags = IsArchetype | IsArrayArchetype | IsAtomic,
};
DECLARE_FLAGS_ENUMCLASS(EPropertyFlag, FPropertyFlags)
@@ -117,14 +117,14 @@ protected:
FPropertyFlags mFlags;
/** Parent property */
IProperty* mpParent;
IProperty* mpParent = nullptr;
/** Pointer parent; if non-null, this parent needs to be dereferenced to access the correct
* memory region that our property data is stored in */
IProperty* mpPointerParent;
IProperty* mpPointerParent = nullptr;
/** Archetype property; source property that we copied metadata from */
IProperty* mpArchetype;
IProperty* mpArchetype = nullptr;
/** Sub-instances of archetype properties. For non-archetypes, will be empty.
* @todo this really oughta be a linked list */
@@ -137,29 +137,29 @@ protected:
EGame mGame;
/** Script template that this property belongs to. Null for struct/enum/flag archetypes. */
CScriptTemplate* mpScriptTemplate;
CScriptTemplate* mpScriptTemplate = nullptr;
/** Offset of this property within the property block */
uint32 mOffset;
uint32 mOffset = UINT32_MAX;
/** Property ID. This ID is used to uniquely identify this property within this struct. */
uint32 mID;
uint32 mID = UINT32_MAX;
/** Property metadata */
TString mName;
TString mDescription;
TString mSuffix;
ECookPreference mCookPreference;
ECookPreference mCookPreference{ECookPreference::Default};
/** Min/max allowed version number. These numbers correspond to the game's internal build number.
* This is not used yet but in the future it can be used to configure certain properties to only
* show up when certain versions of the game are being edited. The default values allow the
* property to show up in all versions. */
float mMinVersion;
float mMaxVersion;
float mMinVersion = 0.0f;
float mMaxVersion = FLT_MAX;
/** Private constructor - use static methods to instantiate */
IProperty(EGame Game);
explicit IProperty(EGame Game);
void _ClearChildren();
public:
@@ -207,29 +207,69 @@ public:
/** Accessors */
EGame Game() const;
inline ECookPreference CookPreference() const;
inline uint32 NumChildren() const;
inline IProperty* ChildByIndex(uint32 ChildIndex) const;
inline IProperty* Parent() const;
inline IProperty* RootParent();
inline IProperty* Archetype() const;
inline IProperty* RootArchetype();
inline CScriptTemplate* ScriptTemplate() const;
inline TString Name() const;
inline TString Description() const;
inline TString Suffix() const;
inline TIDString IDString(bool FullyQualified) const;
inline uint32 Offset() const;
inline uint32 ID() const;
ECookPreference CookPreference() const { return mCookPreference; }
uint32 NumChildren() const { return mChildren.size(); }
inline bool IsInitialized() const { return mFlags.HasFlag(EPropertyFlag::IsInitialized); }
inline bool IsArchetype() const { return mFlags.HasFlag(EPropertyFlag::IsArchetype); }
inline bool IsArrayArchetype() const { return mFlags.HasFlag(EPropertyFlag::IsArrayArchetype); }
inline bool IsAtomic() const { return mFlags.HasFlag(EPropertyFlag::IsAtomic); }
inline bool IsIntrinsic() const { return mFlags.HasFlag(EPropertyFlag::IsIntrinsic); }
inline bool IsDirty() const { return mFlags.HasFlag(EPropertyFlag::IsDirty); }
inline bool IsRootParent() const { return mpParent == nullptr; }
inline bool IsRootArchetype() const { return mpArchetype == nullptr; }
IProperty* ChildByIndex(uint32 ChildIndex) const
{
ASSERT(ChildIndex >= 0 && ChildIndex < mChildren.size());
return mChildren[ChildIndex];
}
IProperty* Parent() const { return mpParent; }
IProperty* RootParent()
{
IProperty* pParent = Parent();
IProperty* pOut = this;
while (pParent)
{
pOut = pParent;
pParent = pParent->Parent();
}
return pOut;
}
IProperty* Archetype() const { return mpArchetype; }
IProperty* RootArchetype()
{
IProperty* pArchetype = Archetype();
IProperty* pOut = this;
while (pArchetype)
{
pOut = pArchetype;
pArchetype = pArchetype->Archetype();
}
return pOut;
}
CScriptTemplate* ScriptTemplate() const { return mpScriptTemplate; }
TString Name() const { return mName; }
TString Description() const { return mDescription; }
TString Suffix() const { return mSuffix; }
TIDString IDString(bool FullyQualified) const
{
if (FullyQualified && mpParent != nullptr && mpParent->Parent() != nullptr)
return mpParent->IDString(FullyQualified) + ":" + TString::HexString(mID);
else
return TString::HexString(mID);
}
uint32 Offset() const { return mOffset; }
uint32 ID() const { return mID; }
bool IsInitialized() const { return mFlags.HasFlag(EPropertyFlag::IsInitialized); }
bool IsArchetype() const { return mFlags.HasFlag(EPropertyFlag::IsArchetype); }
bool IsArrayArchetype() const { return mFlags.HasFlag(EPropertyFlag::IsArrayArchetype); }
bool IsAtomic() const { return mFlags.HasFlag(EPropertyFlag::IsAtomic); }
bool IsIntrinsic() const { return mFlags.HasFlag(EPropertyFlag::IsIntrinsic); }
bool IsDirty() const { return mFlags.HasFlag(EPropertyFlag::IsDirty); }
bool IsRootParent() const { return mpParent == nullptr; }
bool IsRootArchetype() const { return mpArchetype == nullptr; }
/** Create */
static IProperty* Create(EPropertyType Type,
@@ -251,130 +291,42 @@ public:
const IArchive& Arc);
};
inline ECookPreference IProperty::CookPreference() const
{
return mCookPreference;
}
inline uint32 IProperty::NumChildren() const
{
return mChildren.size();
}
inline IProperty* IProperty::ChildByIndex(uint32 ChildIndex) const
{
ASSERT(ChildIndex >= 0 && ChildIndex < mChildren.size());
return mChildren[ChildIndex];
}
inline IProperty* IProperty::Parent() const
{
return mpParent;
}
inline IProperty* IProperty::RootParent()
{
IProperty* pParent = Parent();
IProperty* pOut = this;
while (pParent)
{
pOut = pParent;
pParent = pParent->Parent();
}
return pOut;
}
inline IProperty* IProperty::Archetype() const
{
return mpArchetype;
}
inline IProperty* IProperty::RootArchetype()
{
IProperty* pArchetype = Archetype();
IProperty* pOut = this;
while (pArchetype)
{
pOut = pArchetype;
pArchetype = pArchetype->Archetype();
}
return pOut;
}
inline CScriptTemplate* IProperty::ScriptTemplate() const
{
return mpScriptTemplate;
}
inline TString IProperty::Name() const
{
return mName;
}
inline TString IProperty::Description() const
{
return mDescription;
}
inline TString IProperty::Suffix() const
{
return mSuffix;
}
inline TString IProperty::IDString(bool FullyQualified) const
{
if (FullyQualified && mpParent != nullptr && mpParent->Parent() != nullptr)
return mpParent->IDString(FullyQualified) + ":" + TString::HexString(mID);
else
return TString::HexString(mID);
}
inline uint32 IProperty::Offset() const
{
return mOffset;
}
inline uint32 IProperty::ID() const
{
return mID;
}
template<typename PropType, EPropertyType PropEnum>
class TTypedProperty : public IProperty
{
friend class IProperty;
friend class CTemplateLoader;
public:
typedef PropType ValueType;
using ValueType = PropType;
protected:
PropType mDefaultValue = {};
TTypedProperty(EGame Game) : IProperty(Game) {}
explicit TTypedProperty(EGame Game) : IProperty(Game) {}
public:
virtual EPropertyType Type() const { return PropEnum; }
virtual uint32 DataSize() const { return sizeof(PropType); }
virtual uint32 DataAlignment() const { return alignof(PropType); }
virtual void Construct(void* pData) const { new(ValuePtr(pData)) PropType(mDefaultValue); }
virtual void Destruct(void* pData) const { ValueRef(pData).~PropType(); }
virtual bool MatchesDefault(void* pData) const { return ValueRef(pData) == mDefaultValue; }
virtual void RevertToDefault(void* pData) const { ValueRef(pData) = mDefaultValue; }
virtual void SetDefaultFromData(void* pData) { mDefaultValue = ValueRef(pData); MarkDirty(); }
EPropertyType Type() const override { return PropEnum; }
uint32 DataSize() const override { return sizeof(PropType); }
uint32 DataAlignment() const override { return alignof(PropType); }
void Construct(void* pData) const override { new (ValuePtr(pData)) PropType(mDefaultValue); }
void Destruct(void* pData) const override { ValueRef(pData).~PropType(); }
bool MatchesDefault(void* pData) const override { return ValueRef(pData) == mDefaultValue; }
void RevertToDefault(void* pData) const override { ValueRef(pData) = mDefaultValue; }
void SetDefaultFromData(void* pData) override
{
mDefaultValue = ValueRef(pData);
MarkDirty();
}
virtual bool CanHaveDefault() const { return true; }
virtual void InitFromArchetype(IProperty* pOther)
void InitFromArchetype(IProperty* pOther) override
{
IProperty::InitFromArchetype(pOther);
mDefaultValue = static_cast<TTypedProperty*>(pOther)->mDefaultValue;
}
virtual void CopyDefaultValueTo(IProperty* pOtherProperty)
void CopyDefaultValueTo(IProperty* pOtherProperty) override
{
// WARNING: We don't do any type checking here because this function is used for type conversion,
// which necessitates that the property class is allowed to be different. The underlying type is
@@ -384,32 +336,32 @@ public:
pTypedOther->mDefaultValue = mDefaultValue;
}
inline PropType* ValuePtr(void* pData) const
PropType* ValuePtr(void* pData) const
{
return (PropType*) RawValuePtr(pData);
}
inline PropType& ValueRef(void* pData) const
PropType& ValueRef(void* pData) const
{
return *ValuePtr(pData);
}
inline PropType Value(void* pData) const
PropType Value(void* pData) const
{
return *ValuePtr(pData);
}
inline const PropType& DefaultValue() const
const PropType& DefaultValue() const
{
return mDefaultValue;
}
inline void SetDefaultValue(const PropType& kInDefaultValue)
void SetDefaultValue(const PropType& kInDefaultValue)
{
mDefaultValue = kInDefaultValue;
}
inline static EPropertyType StaticType() { return PropEnum; }
static EPropertyType StaticType() { return PropEnum; }
};
template<typename PropType, EPropertyType PropEnum>
@@ -417,12 +369,12 @@ class TSerializeableTypedProperty : public TTypedProperty<PropType, PropEnum>
{
using base = TTypedProperty<PropType, PropEnum>;
protected:
TSerializeableTypedProperty(EGame Game)
explicit TSerializeableTypedProperty(EGame Game)
: base(Game)
{}
public:
virtual void Serialize(IArchive& rArc)
void Serialize(IArchive& rArc) override
{
base::Serialize(rArc);
TSerializeableTypedProperty* pArchetype = static_cast<TSerializeableTypedProperty*>(base::mpArchetype);
@@ -462,7 +414,7 @@ public:
rArc << SerialParameter("DefaultValue", base::mDefaultValue);
}
virtual bool ShouldSerialize() const
bool ShouldSerialize() const override
{
base* pArchetype = static_cast<base*>(base::mpArchetype);
@@ -485,17 +437,15 @@ class TNumericalProperty : public TSerializeableTypedProperty<PropType, PropEnum
friend class CTemplateLoader;
protected:
PropType mMinValue;
PropType mMaxValue;
PropType mMinValue = -1;
PropType mMaxValue = -1;
TNumericalProperty(EGame Game)
explicit TNumericalProperty(EGame Game)
: base(Game)
, mMinValue( -1 )
, mMaxValue( -1 )
{}
public:
virtual void Serialize(IArchive& rArc)
void Serialize(IArchive& rArc) override
{
base::Serialize(rArc);
TNumericalProperty* pArchetype = static_cast<TNumericalProperty*>(base::mpArchetype);
@@ -504,7 +454,7 @@ public:
<< SerialParameter("Max", mMaxValue, SH_Optional, pArchetype ? pArchetype->mMaxValue : (PropType) -1);
}
virtual bool ShouldSerialize() const
bool ShouldSerialize() const override
{
TNumericalProperty* pArchetype = static_cast<TNumericalProperty*>(base::mpArchetype);
return base::ShouldSerialize() ||
@@ -512,7 +462,7 @@ public:
mMaxValue != pArchetype->mMaxValue;
}
virtual void InitFromArchetype(IProperty* pOther)
void InitFromArchetype(IProperty* pOther) override
{
base::InitFromArchetype(pOther);
TNumericalProperty* pCastOther = static_cast<TNumericalProperty*>(pOther);
@@ -520,7 +470,7 @@ public:
mMaxValue = pCastOther->mMaxValue;
}
virtual void PropertyValueChanged(void* pPropertyData)
void PropertyValueChanged(void* pPropertyData) override
{
base::PropertyValueChanged(pPropertyData);
@@ -534,7 +484,7 @@ public:
/** Property casting with dynamic type checking */
template<class PropertyClass>
inline PropertyClass* TPropCast(IProperty* pProperty)
PropertyClass* TPropCast(IProperty* pProperty)
{
if (pProperty && pProperty->Type() == PropertyClass::StaticType())
{

View File

@@ -27,15 +27,13 @@ template<class PropertyClass, typename ValueType = typename PropertyClass::Value
class TPropertyRef
{
/** Property data being referenced */
void* mpPropertyData;
void* mpPropertyData = nullptr;
/** Property being referenced */
PropertyClass* mpProperty;
PropertyClass* mpProperty = nullptr;
public:
TPropertyRef()
: mpPropertyData(nullptr), mpProperty(nullptr)
{}
TPropertyRef() = default;
explicit TPropertyRef(void* pInData, IProperty* pInProperty)
: mpPropertyData(pInData), mpProperty( TPropCast<PropertyClass>(pInProperty) )
@@ -48,19 +46,19 @@ public:
}
/** Accessors */
inline void* DataPointer() const { return mpPropertyData; }
inline PropertyClass* Property() const { return mpProperty; }
inline ValueType Get() const { return IsValid() ? *((ValueType*) mpProperty->RawValuePtr( mpPropertyData )) : ValueType(); }
inline void Set(const ValueType& kIn) const { if (IsValid()) *((ValueType*) mpProperty->RawValuePtr( mpPropertyData )) = kIn; }
inline bool IsValid() const { return mpPropertyData != nullptr && mpProperty != nullptr; }
void* DataPointer() const { return mpPropertyData; }
PropertyClass* Property() const { return mpProperty; }
ValueType Get() const { return IsValid() ? *((ValueType*) mpProperty->RawValuePtr( mpPropertyData )) : ValueType(); }
void Set(const ValueType& kIn) const { if (IsValid()) *((ValueType*) mpProperty->RawValuePtr( mpPropertyData )) = kIn; }
bool IsValid() const { return mpPropertyData != nullptr && mpProperty != nullptr; }
/** Inline operators */
inline operator ValueType() const
operator ValueType() const
{
return Get();
}
inline bool operator==(IProperty* pProperty) const
bool operator==(IProperty* pProperty) const
{
return mpProperty == pProperty;
}
@@ -72,25 +70,25 @@ public:
};
/** Convenience typedefs */
typedef TPropertyRef<CBoolProperty> CBoolRef;
typedef TPropertyRef<CByteProperty> CByteRef;
typedef TPropertyRef<CShortProperty> CShortRef;
typedef TPropertyRef<CIntProperty> CIntRef;
typedef TPropertyRef<CFloatProperty> CFloatRef;
typedef TPropertyRef<CFlagsProperty> CFlagsRef;
typedef TPropertyRef<CStringProperty> CStringRef;
typedef TPropertyRef<CVectorProperty> CVectorRef;
typedef TPropertyRef<CColorProperty> CColorRef;
typedef TPropertyRef<CAssetProperty> CAssetRef;
typedef TPropertyRef<CSoundProperty> CSoundRef;
typedef TPropertyRef<CAnimationProperty> CAnimationRef;
typedef TPropertyRef<CAnimationSetProperty> CAnimationSetRef;
typedef TPropertyRef<CSequenceProperty> CSequenceRef;
typedef TPropertyRef<CSplineProperty> CSplineRef;
typedef TPropertyRef<CGuidProperty> CGuidRef;
typedef TPropertyRef<CPointerProperty> CPointerRef;
typedef TPropertyRef<CStructProperty> CStructRef;
typedef TPropertyRef<CArrayProperty> CArrayRef;
using CAnimationRef = TPropertyRef<CAnimationProperty>;
using CAnimationSetRef = TPropertyRef<CAnimationSetProperty>;
using CArrayRef = TPropertyRef<CArrayProperty>;
using CAssetRef = TPropertyRef<CAssetProperty>;
using CBoolRef = TPropertyRef<CBoolProperty>;
using CByteRef = TPropertyRef<CByteProperty>;
using CColorRef = TPropertyRef<CColorProperty>;
using CFlagsRef = TPropertyRef<CFlagsProperty>;
using CFloatRef = TPropertyRef<CFloatProperty>;
using CGuidRef = TPropertyRef<CGuidProperty>;
using CIntRef = TPropertyRef<CIntProperty>;
using CPointerRef = TPropertyRef<CPointerProperty>;
using CSequenceRef = TPropertyRef<CSequenceProperty>;
using CShortRef = TPropertyRef<CShortProperty>;
using CSoundRef = TPropertyRef<CSoundProperty>;
using CSplineRef = TPropertyRef<CSplineProperty>;
using CStringRef = TPropertyRef<CStringProperty>;
using CStructRef = TPropertyRef<CStructProperty>;
using CVectorRef = TPropertyRef<CVectorProperty>;
/** Special version for enums */
template<typename ValueType>