Fixed a lot of property bugs, fixed more various VS2017 compiler errors, property editor works correctly now

This commit is contained in:
Aruki
2018-07-08 21:59:01 -06:00
parent 6cbc2a3208
commit 4faadbda61
30 changed files with 466 additions and 314 deletions

View File

@@ -112,7 +112,7 @@ public:
inline void SetOptions(FMaterialOptions Options) { mOptions = Options; Update(); }
inline void SetVertexDescription(FVertexDescription Desc) { mVtxDesc = Desc; Update(); }
inline void SetBlendMode(GLenum SrcFac, GLenum DstFac) { mBlendSrcFac = SrcFac; mBlendDstFac = DstFac; mRecalcHash = true; }
inline void SetKonst(CColor& Konst, u32 KIndex) { mKonstColors[KIndex] = Konst; Update(); }
inline void SetKonst(const CColor& Konst, u32 KIndex) { mKonstColors[KIndex] = Konst; Update(); }
inline void SetIndTexture(CTexture *pTex) { mpIndirectTexture = pTex; }
inline void SetLightingEnabled(bool Enabled) { mLightingEnabled = Enabled; Update(); }

View File

@@ -24,7 +24,7 @@ public:
CVertex() {}
CVertex(CVector3f& rPos)
CVertex(const CVector3f& rPos)
{
Position = rPos;
}

View File

@@ -88,6 +88,9 @@ bool CScriptObject::IsEditorProperty(IPropertyNew *pProp)
(pProp == mScale.Property()) ||
(pProp == mActive.Property()) ||
(pProp == mLightParameters.Property()) ||
(pProp->Parent() == mPosition.Property()) ||
(pProp->Parent() == mRotation.Property()) ||
(pProp->Parent() == mScale.Property()) ||
(pProp->Parent() == mLightParameters.Property())
);
}

View File

@@ -55,11 +55,6 @@ void IPropertyNew::_CalcOffset()
}
}
u32 IPropertyNew::_GetOffset() const
{
return mOffset;
}
void IPropertyNew::_ClearChildren()
{
for (int ChildIdx = 0; ChildIdx < mChildren.size(); ChildIdx++)
@@ -118,7 +113,7 @@ void IPropertyNew::InitFromArchetype(IPropertyNew* pOther)
{
//@todo maybe somehow use Serialize for this instead?
mpArchetype = pOther;
mFlags = pOther->mFlags & ~EPropertyFlag::ArchetypeCopyFlags;
mFlags = pOther->mFlags & EPropertyFlag::ArchetypeCopyFlags;
mID = pOther->mID;
mName = pOther->mName;
mDescription = pOther->mDescription;
@@ -161,7 +156,8 @@ void* IPropertyNew::RawValuePtr(void* pData) const
return pData;
void* pBasePtr = (mpPointerParent ? mpPointerParent->GetChildDataPointer(pData) : pData);
return ((char*)pBasePtr + mOffset);
void* pValuePtr = ((char*)pBasePtr + mOffset);
return pValuePtr;
}
IPropertyNew* IPropertyNew::ChildByID(u32 ID) const
@@ -342,8 +338,7 @@ IPropertyNew* IPropertyNew::Create(EPropertyTypeNew Type,
}
IPropertyNew* IPropertyNew::CreateCopy(IPropertyNew* pArchetype,
IPropertyNew* pParent,
bool CallPostInit /*= true*/)
IPropertyNew* pParent)
{
// Note this is mainly going to be used to create copies from struct/enum/flag archetype properties.
// Properties that have archetypes will never be the root property of a script template, and there
@@ -354,11 +349,5 @@ IPropertyNew* IPropertyNew::CreateCopy(IPropertyNew* pArchetype,
IPropertyNew* pOut = Create(pArchetype->Type(), pParent, pParent->mpMasterTemplate, pParent->mpScriptTemplate, false);
pOut->InitFromArchetype(pArchetype);
pArchetype->mSubInstances.push_back(pOut);
if (CallPostInit)
{
pOut->PostInitialize();
}
return pOut;
}

View File

@@ -157,7 +157,6 @@ protected:
/** Private constructor - use static methods to instantiate */
IPropertyNew();
void _CalcOffset();
u32 _GetOffset() const;
void _ClearChildren();
/** Called after property is created and fully initialized */
@@ -213,6 +212,7 @@ public:
inline TString Description() const;
inline TString Suffix() const;
inline TIDString IDString(bool FullyQualified) const;
inline u32 Offset() const;
inline u32 ID() const;
inline bool IsArchetype() const { return mFlags.HasFlag(EPropertyFlag::IsArchetype); }
@@ -227,8 +227,7 @@ public:
bool CallPostInit = true);
static IPropertyNew* CreateCopy(IPropertyNew* pArchetype,
IPropertyNew* pParent,
bool CallPostInit = true);
IPropertyNew* pParent);
};
inline ECookPreferenceNew IPropertyNew::CookPreference() const
@@ -298,12 +297,17 @@ inline TString IPropertyNew::Suffix() const
inline TString IPropertyNew::IDString(bool FullyQualified) const
{
if (FullyQualified && mpParent != nullptr)
if (FullyQualified && mpParent != nullptr && mpParent->Parent() != nullptr)
return mpParent->IDString(FullyQualified) + ":" + TString::HexString(mID);
else
return TString::HexString(mID);
}
inline u32 IPropertyNew::Offset() const
{
return mOffset;
}
inline u32 IPropertyNew::ID() const
{
return mID;

View File

@@ -24,8 +24,9 @@ class CArrayProperty : public TTypedPropertyNew<int, EPropertyTypeNew::Array>
{
friend class CTemplateLoader;
/** This class inherits from TTypedPropertyNew<int> in order to expose the array
* count value. Outside users can edit this value and we respond by updating the
* allocated space, handling destruction/construction, etc.
* count value (the first member of SScriptArray). Outside users can edit this
* value and we respond by updating the allocated space, handling item destruction
* and construction, etc.
*/
IPropertyNew* mpItemArchetype;
@@ -99,7 +100,7 @@ public:
virtual void SerializeValue(void* pData, IArchive& Arc) const
{
u32 Count = ArrayCount(pData);
Arc.SerializePrimitive(Count);
Arc.SerializeContainerSize(Count, "ArrayElement");
if (Arc.IsReader())
Resize(pData, Count);
@@ -115,6 +116,13 @@ public:
}
}
virtual void InitFromArchetype(IPropertyNew* pOther)
{
TTypedPropertyNew::InitFromArchetype(pOther);
CArrayProperty* pOtherArray = static_cast<CArrayProperty*>(pOther);
mpItemArchetype = IPropertyNew::CreateCopy(pOtherArray->mpItemArchetype, this);
}
u32 ArrayCount(void* pPropertyData) const
{
return ValueRef(pPropertyData);

View File

@@ -18,6 +18,12 @@ public:
}
#endif
virtual void InitFromArchetype(IPropertyNew* pOther)
{
TTypedPropertyNew::InitFromArchetype(pOther);
mTypeFilter = static_cast<CAssetProperty*>(pOther)->mTypeFilter;
}
virtual void SerializeValue(void* pData, IArchive& Arc) const
{
Arc.SerializePrimitive( ValueRef(pData) );

View File

@@ -46,6 +46,13 @@ public:
Arc.SerializePrimitive( (u32&) ValueRef(pData) );
}
virtual void InitFromArchetype(IPropertyNew* pOther)
{
TTypedPropertyNew::InitFromArchetype(pOther);
TEnumPropertyBase* pOtherEnum = static_cast<TEnumPropertyBase*>(pOther);
mValues = pOtherEnum->mValues;
}
virtual TString GetTemplateFileName()
{
ASSERT(IsArchetype() || mpArchetype);

View File

@@ -75,11 +75,30 @@ public:
}
#endif
virtual void PostInitialize()
{
TTypedPropertyNew::PostInitialize();
// Create AllFlags mask
mAllFlags = 0;
for (int FlagIdx = 0; FlagIdx < mBitFlags.size(); FlagIdx++)
mAllFlags |= mBitFlags[FlagIdx].Mask;
}
virtual void SerializeValue(void* pData, IArchive& rArc) const
{
rArc.SerializeHexPrimitive( (u32&) ValueRef(pData) );
}
virtual void InitFromArchetype(IPropertyNew* pOther)
{
TTypedPropertyNew::InitFromArchetype(pOther);
CFlagsProperty* pOtherFlags = static_cast<CFlagsProperty*>(pOther);
mBitFlags = pOtherFlags->mBitFlags;
mAllFlags = pOtherFlags->mAllFlags;
}
virtual TString GetTemplateFileName()
{
ASSERT(IsArchetype() || mpArchetype);

View File

@@ -18,7 +18,7 @@ public:
Arc.SerializePrimitive( (float&) ValueRef(pData) );
}
virtual TString ValueAsString(void* pData)
virtual TString ValueAsString(void* pData) const
{
return TString::FromFloat( Value(pData) );
}

View File

@@ -18,7 +18,7 @@ public:
Arc.SerializePrimitive( (u32&) ValueRef(pData) );
}
virtual TString ValueAsString(void* pData)
virtual TString ValueAsString(void* pData) const
{
return TString::FromInt32( Value(pData), 0, 10 );
}

View File

@@ -26,7 +26,7 @@ public:
if (!mChildren.empty())
{
IPropertyNew* pLastChild = mChildren.back();
return _GetOffset() + pLastChild->DataSize();
return (pLastChild->Offset() - Offset()) + pLastChild->DataSize();
}
else
{
@@ -36,7 +36,11 @@ public:
virtual u32 DataAlignment() const
{
return (mChildren.empty() ? 1 : mChildren[0]->DataAlignment());
// TODO. Should be aligned with the first child, but this function is called before children are loaded.
// So for now just use 8 to ensure correct alignment for all child types, but this is wasteful...
return 8;
//return (mChildren.empty() ? 1 : mChildren[0]->DataAlignment());
}
virtual void Construct(void* pData) const

View File

@@ -50,7 +50,7 @@ public:
/** Accessors */
inline CScriptObject* Object() const { return mpObject; }
inline PropertyClass* Property() const { return mpProperty; }
inline ValueType Get() const { ASSERT(IsValid()); return *((ValueType*) mpProperty->RawValuePtr( mpObject->PropertyData() )); }
inline ValueType Get() const { return IsValid() ? *((ValueType*) mpProperty->RawValuePtr( mpObject->PropertyData() )) : ValueType(); }
inline void Set(const ValueType& kIn) const { if (IsValid()) *((ValueType*) mpProperty->RawValuePtr( mpObject->PropertyData() )) = kIn; }
inline bool IsValid() const { return mpObject != nullptr && mpProperty != nullptr; }

View File

@@ -496,13 +496,13 @@ void CScriptNode::PropertyModified(IPropertyNew* pProp)
if (pProp == pTemplate->NameProperty())
SetName("[" + mpInstance->Template()->Name() + "] " + mpInstance->InstanceName());
else if (pProp == pTemplate->PositionProperty())
else if (pProp == pTemplate->PositionProperty() || pProp->Parent() == pTemplate->PositionProperty())
mPosition = mpInstance->Position();
else if (pProp == pTemplate->RotationProperty())
else if (pProp == pTemplate->RotationProperty() || pProp->Parent() == pTemplate->RotationProperty())
mRotation = CQuaternion::FromEuler(mpInstance->Rotation());
else if (pProp == pTemplate->ScaleProperty())
else if (pProp == pTemplate->ScaleProperty() || pProp->Parent() == pTemplate->ScaleProperty())
mScale = mpInstance->Scale();
MarkTransformChanged();
@@ -560,7 +560,7 @@ void CScriptNode::GeneratePosition()
if (!mHasValidPosition)
{
// Default to center of the active area; this is to prevent recursion issues
CTransform4f& AreaTransform = mpScene->ActiveArea()->Transform();
CTransform4f AreaTransform = mpScene->ActiveArea()->Transform();
mPosition = CVector3f(AreaTransform[0][3], AreaTransform[1][3], AreaTransform[2][3]);
mHasValidPosition = true;
MarkTransformChanged();