mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-17 08:57:09 +00:00
Massive overhaul of property system done over the last few months. There is unfinished/broken stuff still, but it compiles now.
This commit is contained in:
@@ -1,118 +1,146 @@
|
||||
#include "CScriptCooker.h"
|
||||
#include "Core/Resource/Script/CLink.h"
|
||||
#include <Core/Resource/Script/Property/CArrayProperty.h>
|
||||
#include <Core/Resource/Script/Property/CAssetProperty.h>
|
||||
#include <Core/Resource/Script/Property/CEnumProperty.h>
|
||||
#include <Core/Resource/Script/Property/CFlagsProperty.h>
|
||||
|
||||
void CScriptCooker::WriteProperty(IOutputStream& rOut,IProperty *pProp, bool InSingleStruct)
|
||||
void CScriptCooker::WriteProperty(IOutputStream& rOut, IPropertyNew* pProperty, bool InAtomicStruct)
|
||||
{
|
||||
u32 SizeOffset = 0, PropStart = 0;
|
||||
void* pData = (mpArrayItemData ? mpArrayItemData : mpObject->PropertyData());
|
||||
|
||||
if (mGame >= eEchoesDemo && !InSingleStruct)
|
||||
if (mGame >= eEchoesDemo && !InAtomicStruct)
|
||||
{
|
||||
rOut.WriteLong(pProp->ID());
|
||||
rOut.WriteLong(pProperty->ID());
|
||||
SizeOffset = rOut.Tell();
|
||||
rOut.WriteShort(0x0);
|
||||
PropStart = rOut.Tell();
|
||||
}
|
||||
|
||||
switch (pProp->Type())
|
||||
switch (pProperty->Type())
|
||||
{
|
||||
|
||||
case eBoolProperty:
|
||||
case EPropertyTypeNew::Bool:
|
||||
{
|
||||
TBoolProperty *pBoolCast = static_cast<TBoolProperty*>(pProp);
|
||||
rOut.WriteBool(pBoolCast->Get());
|
||||
CBoolProperty* pBool = TPropCast<CBoolProperty>(pProperty);
|
||||
rOut.WriteBool( pBool->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case eByteProperty:
|
||||
case EPropertyTypeNew::Byte:
|
||||
{
|
||||
TByteProperty *pByteCast = static_cast<TByteProperty*>(pProp);
|
||||
rOut.WriteByte(pByteCast->Get());
|
||||
CByteProperty* pByte = TPropCast<CByteProperty>(pProperty);
|
||||
rOut.WriteByte( pByte->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case eShortProperty:
|
||||
case EPropertyTypeNew::Short:
|
||||
{
|
||||
TShortProperty *pShortCast = static_cast<TShortProperty*>(pProp);
|
||||
rOut.WriteShort(pShortCast->Get());
|
||||
CShortProperty* pShort = TPropCast<CShortProperty>(pProperty);
|
||||
rOut.WriteShort( pShort->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case eLongProperty:
|
||||
case EPropertyTypeNew::Int:
|
||||
{
|
||||
TLongProperty *pLongCast = static_cast<TLongProperty*>(pProp);
|
||||
rOut.WriteLong(pLongCast->Get());
|
||||
CIntProperty* pInt = TPropCast<CIntProperty>(pProperty);
|
||||
rOut.WriteLong( pInt->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case eEnumProperty:
|
||||
case EPropertyTypeNew::Float:
|
||||
{
|
||||
TEnumProperty *pEnumCast = static_cast<TEnumProperty*>(pProp);
|
||||
rOut.WriteLong(pEnumCast->Get());
|
||||
CFloatProperty* pFloat = TPropCast<CFloatProperty>(pProperty);
|
||||
rOut.WriteFloat( pFloat->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case eBitfieldProperty:
|
||||
case EPropertyTypeNew::Choice:
|
||||
{
|
||||
TBitfieldProperty *pBitfieldCast = static_cast<TBitfieldProperty*>(pProp);
|
||||
rOut.WriteLong(pBitfieldCast->Get());
|
||||
CChoiceProperty* pChoice = TPropCast<CChoiceProperty>(pProperty);
|
||||
rOut.WriteLong( pChoice->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case eFloatProperty:
|
||||
case EPropertyTypeNew::Enum:
|
||||
{
|
||||
TFloatProperty *pFloatCast = static_cast<TFloatProperty*>(pProp);
|
||||
rOut.WriteFloat(pFloatCast->Get());
|
||||
CEnumProperty* pEnum = TPropCast<CEnumProperty>(pProperty);
|
||||
rOut.WriteLong( pEnum->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case eStringProperty:
|
||||
case EPropertyTypeNew::Flags:
|
||||
{
|
||||
TStringProperty *pStringCast = static_cast<TStringProperty*>(pProp);
|
||||
rOut.WriteString(pStringCast->Get());
|
||||
CFlagsProperty* pFlags = TPropCast<CFlagsProperty>(pProperty);
|
||||
rOut.WriteLong( pFlags->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case eVector3Property:
|
||||
case EPropertyTypeNew::String:
|
||||
{
|
||||
TVector3Property *pVectorCast = static_cast<TVector3Property*>(pProp);
|
||||
pVectorCast->Get().Write(rOut);
|
||||
CStringProperty* pString = TPropCast<CStringProperty>(pProperty);
|
||||
rOut.WriteString( pString->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case eColorProperty:
|
||||
case EPropertyTypeNew::Vector:
|
||||
{
|
||||
TColorProperty *pColorCast = static_cast<TColorProperty*>(pProp);
|
||||
pColorCast->Get().Write(rOut, false);
|
||||
CVectorProperty* pVector = TPropCast<CVectorProperty>(pProperty);
|
||||
pVector->ValueRef(pData).Write(rOut);
|
||||
break;
|
||||
}
|
||||
|
||||
case eSoundProperty:
|
||||
case EPropertyTypeNew::Color:
|
||||
{
|
||||
TSoundProperty *pSoundCast = static_cast<TSoundProperty*>(pProp);
|
||||
rOut.WriteLong(pSoundCast->Get());
|
||||
CColorProperty* pColor = TPropCast<CColorProperty>(pProperty);
|
||||
pColor->ValueRef(pData).Write(rOut);
|
||||
break;
|
||||
}
|
||||
|
||||
case eAssetProperty:
|
||||
case EPropertyTypeNew::Asset:
|
||||
{
|
||||
TAssetProperty *pAssetCast = static_cast<TAssetProperty*>(pProp);
|
||||
pAssetCast->Get().Write(rOut);
|
||||
CAssetProperty* pAsset = TPropCast<CAssetProperty>(pProperty);
|
||||
pAsset->ValueRef(pData).Write(rOut);
|
||||
break;
|
||||
}
|
||||
|
||||
case eCharacterProperty:
|
||||
case EPropertyTypeNew::Sound:
|
||||
{
|
||||
TCharacterProperty *pCharCast = static_cast<TCharacterProperty*>(pProp);
|
||||
pCharCast->Get().Write(rOut);
|
||||
CSoundProperty* pSound = TPropCast<CSoundProperty>(pProperty);
|
||||
rOut.WriteLong( pSound->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case eMayaSplineProperty:
|
||||
case EPropertyTypeNew::Animation:
|
||||
{
|
||||
TMayaSplineProperty *pSplineCast = static_cast<TMayaSplineProperty*>(pProp);
|
||||
std::vector<u8> Buffer = pSplineCast->Get();
|
||||
if (!Buffer.empty()) rOut.WriteBytes(Buffer.data(), Buffer.size());
|
||||
CAnimationProperty* pAnim = TPropCast<CAnimationProperty>(pProperty);
|
||||
rOut.WriteLong( pAnim->Value(pData) );
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyTypeNew::AnimationSet:
|
||||
{
|
||||
CAnimationSetProperty* pAnimSet = TPropCast<CAnimationSetProperty>(pProperty);
|
||||
pAnimSet->ValueRef(pData).Write(rOut);
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyTypeNew::Sequence:
|
||||
{
|
||||
// TODO
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyTypeNew::Spline:
|
||||
{
|
||||
CSplineProperty* pSpline = TPropCast<CSplineProperty>(pProperty);
|
||||
std::vector<char>& rBuffer = pSpline->ValueRef(pData);
|
||||
|
||||
if (!rBuffer.empty())
|
||||
{
|
||||
rOut.WriteBytes( rBuffer.data(), rBuffer.size() );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mGame < eReturns)
|
||||
@@ -132,26 +160,35 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut,IProperty *pProp, bool InS
|
||||
rOut.WriteByte(1);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case eStructProperty:
|
||||
case EPropertyTypeNew::Guid:
|
||||
{
|
||||
CPropertyStruct *pStruct = static_cast<CPropertyStruct*>(pProp);
|
||||
CStructTemplate *pTemp = static_cast<CStructTemplate*>(pStruct->Template());
|
||||
CGuidProperty* pGuid = TPropCast<CGuidProperty>(pProperty);
|
||||
std::vector<char>& rBuffer = pGuid->ValueRef(pData);
|
||||
|
||||
std::vector<IProperty*> PropertiesToWrite;
|
||||
if (rBuffer.empty())
|
||||
rBuffer.resize(16, 0);
|
||||
|
||||
for (u32 iProp = 0; iProp < pStruct->Count(); iProp++)
|
||||
rOut.WriteBytes( rBuffer.data(), rBuffer.size() );
|
||||
break;
|
||||
}
|
||||
|
||||
case EPropertyTypeNew::Struct:
|
||||
{
|
||||
CStructPropertyNew* pStruct = TPropCast<CStructPropertyNew>(pProperty);
|
||||
std::vector<IPropertyNew*> PropertiesToWrite;
|
||||
|
||||
for (u32 ChildIdx = 0; ChildIdx < pStruct->NumChildren(); ChildIdx++)
|
||||
{
|
||||
IProperty *pSubProp = pStruct->PropertyByIndex(iProp);\
|
||||
IPropertyNew *pChild = pStruct->ChildByIndex(ChildIdx);
|
||||
|
||||
if (pTemp->IsSingleProperty() || pSubProp->ShouldCook())
|
||||
PropertiesToWrite.push_back(pSubProp);
|
||||
if (pStruct->IsAtomic() || pChild->ShouldCook(pData))
|
||||
PropertiesToWrite.push_back(pChild);
|
||||
}
|
||||
|
||||
if (!pTemp->IsSingleProperty())
|
||||
if (!pStruct->IsAtomic())
|
||||
{
|
||||
if (mGame <= ePrime)
|
||||
rOut.WriteLong(PropertiesToWrite.size());
|
||||
@@ -159,20 +196,27 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut,IProperty *pProp, bool InS
|
||||
rOut.WriteShort((u16) PropertiesToWrite.size());
|
||||
}
|
||||
|
||||
for (u32 iProp = 0; iProp < PropertiesToWrite.size(); iProp++)
|
||||
WriteProperty(rOut, PropertiesToWrite[iProp], pTemp->IsSingleProperty());
|
||||
for (u32 PropertyIdx = 0; PropertyIdx < PropertiesToWrite.size(); PropertyIdx++)
|
||||
WriteProperty(rOut, PropertiesToWrite[PropertyIdx], pStruct->IsAtomic());
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case eArrayProperty:
|
||||
case EPropertyTypeNew::Array:
|
||||
{
|
||||
CArrayProperty *pArray = static_cast<CArrayProperty*>(pProp);
|
||||
rOut.WriteLong(pArray->Count());
|
||||
CArrayProperty* pArray = TPropCast<CArrayProperty>(pProperty);
|
||||
u32 Count = pArray->ArrayCount(pData);
|
||||
rOut.WriteLong(Count);
|
||||
|
||||
for (u32 iProp = 0; iProp < pArray->Count(); iProp++)
|
||||
WriteProperty(rOut, pArray->PropertyByIndex(iProp), true);
|
||||
void* pOldItemData = mpArrayItemData;
|
||||
|
||||
for (u32 ElementIdx = 0; ElementIdx < pArray->ArrayCount(pData); ElementIdx++)
|
||||
{
|
||||
mpArrayItemData = pArray->ItemPointer(pData, ElementIdx);
|
||||
WriteProperty(rOut, pArray->ArchetypeProperty(), true);
|
||||
}
|
||||
|
||||
mpArrayItemData = pOldItemData;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -209,15 +253,16 @@ void CScriptCooker::WriteInstance(IOutputStream& rOut, CScriptObject *pInstance)
|
||||
u32 NumLinks = pInstance->NumLinks(eOutgoing);
|
||||
IsPrime1 ? rOut.WriteLong(NumLinks) : rOut.WriteShort((u16) NumLinks);
|
||||
|
||||
for (u32 iLink = 0; iLink < pInstance->NumLinks(eOutgoing); iLink++)
|
||||
for (u32 LinkIdx = 0; LinkIdx < NumLinks; LinkIdx++)
|
||||
{
|
||||
CLink *pLink = pInstance->Link(eOutgoing, iLink);
|
||||
CLink *pLink = pInstance->Link(eOutgoing, LinkIdx);
|
||||
rOut.WriteLong(pLink->State());
|
||||
rOut.WriteLong(pLink->Message());
|
||||
rOut.WriteLong(pLink->ReceiverID());
|
||||
}
|
||||
|
||||
WriteProperty(rOut, pInstance->Properties(), false);
|
||||
mpObject = pInstance;
|
||||
WriteProperty(rOut, pInstance->Template()->Properties(), false);
|
||||
u32 InstanceEnd = rOut.Tell();
|
||||
|
||||
rOut.Seek(SizeOffset, SEEK_SET);
|
||||
@@ -302,6 +347,6 @@ void CScriptCooker::WriteGeneratedLayer(IOutputStream& rOut)
|
||||
rOut.WriteByte(1); // Version
|
||||
rOut.WriteLong(mGeneratedObjects.size());
|
||||
|
||||
for (u32 InstIdx = 0; InstIdx < mGeneratedObjects.size(); InstIdx++)
|
||||
WriteInstance(rOut, mGeneratedObjects[InstIdx]);
|
||||
for (u32 ObjectIdx = 0; ObjectIdx < mGeneratedObjects.size(); ObjectIdx++)
|
||||
WriteInstance(rOut, mGeneratedObjects[ObjectIdx]);
|
||||
}
|
||||
|
||||
@@ -10,14 +10,18 @@
|
||||
class CScriptCooker
|
||||
{
|
||||
EGame mGame;
|
||||
CScriptObject* mpObject;
|
||||
void* mpArrayItemData;
|
||||
std::vector<CScriptObject*> mGeneratedObjects;
|
||||
bool mWriteGeneratedSeparately;
|
||||
|
||||
void WriteProperty(IOutputStream& rOut,IProperty *pProp, bool InSingleStruct);
|
||||
void WriteProperty(IOutputStream& rOut, IPropertyNew* pProperty, bool InAtomicStruct);
|
||||
|
||||
public:
|
||||
CScriptCooker(EGame Game, bool WriteGeneratedObjectsSeparately = true)
|
||||
: mGame(Game)
|
||||
, mpObject(nullptr)
|
||||
, mpArrayItemData(nullptr)
|
||||
, mWriteGeneratedSeparately(WriteGeneratedObjectsSeparately && mGame >= eEchoesDemo)
|
||||
{}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include "CTemplateWriter.h"
|
||||
#include "CAreaCooker.h"
|
||||
#include <Common/FileUtil.h>
|
||||
#include <Core/Resource/Script/IPropertyTemplate.h>
|
||||
|
||||
#include <tinyxml2.h>
|
||||
|
||||
#if 0
|
||||
using namespace tinyxml2;
|
||||
TString CTemplateWriter::smTemplatesDir = "../templates/";
|
||||
|
||||
@@ -802,9 +804,9 @@ void CTemplateWriter::SavePropertyOverrides(XMLDocument *pDoc, XMLElement *pPare
|
||||
// Struct/array-specific parameters
|
||||
else if (pProp->Type() == eStructProperty || pProp->Type() == eArrayProperty)
|
||||
{
|
||||
CStructTemplate *pStruct = static_cast<CStructTemplate*>(pProp);
|
||||
CStructTemplate *pChildStruct = static_cast<CStructTemplate*>(pProp);
|
||||
CStructTemplate *pSourceStruct = static_cast<CStructTemplate*>(pSource);
|
||||
SavePropertyOverrides(pDoc, pElem, pStruct, pSourceStruct);
|
||||
SavePropertyOverrides(pDoc, pElem, pChildStruct, pSourceStruct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -839,3 +841,4 @@ void CTemplateWriter::SaveBitFlags(XMLDocument *pDoc, XMLElement *pParent, CBitf
|
||||
pFlags->LinkEndChild(pElem);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Core/Resource/Script/CScriptTemplate.h"
|
||||
#include <tinyxml2.h>
|
||||
|
||||
#if 0
|
||||
class CTemplateWriter
|
||||
{
|
||||
CTemplateWriter();
|
||||
@@ -24,5 +25,6 @@ public:
|
||||
static void SaveEnumerators(tinyxml2::XMLDocument *pDoc, tinyxml2::XMLElement *pParent, CEnumTemplate *pTemp);
|
||||
static void SaveBitFlags(tinyxml2::XMLDocument *pDoc, tinyxml2::XMLElement *pParent, CBitfieldTemplate *pTemp);
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // CTEMPLATEWRITER_H
|
||||
|
||||
Reference in New Issue
Block a user