Make enum properties track the enumerator ID internally instead of the index + CUniqueID bugfix

This commit is contained in:
parax0 2016-02-10 18:48:34 -07:00
parent 739e3c51bf
commit 7bd97f0fce
9 changed files with 48 additions and 24 deletions

View File

@ -40,6 +40,30 @@ CUniqueID::CUniqueID(u64 ID)
Reverse(); Reverse();
} }
CUniqueID::CUniqueID(u64 ID, EUIDLength Length)
{
// This constructor shouldn't be used for 128-bit
memset(mID, 0xFF, 16);
// 64-bit
if (Length == e64Bit || Length == e128Bit)
{
memcpy(&mID, &ID, 8);
mLength = e64Bit;
}
// 32-bit
else
{
memcpy(mID, &ID, 4);
mLength = e32Bit;
}
// Reverse for Big Endian
if (kSystemEndianness == eBigEndian)
Reverse();
}
CUniqueID::CUniqueID(u64 Part1, u64 Part2) CUniqueID::CUniqueID(u64 Part1, u64 Part2)
{ {
// Constructor for 128-bit IDs // Constructor for 128-bit IDs
@ -295,6 +319,6 @@ CUniqueID CUniqueID::RandomID()
} }
// ************ STATIC MEMBER INITIALIZATION ************ // ************ STATIC MEMBER INITIALIZATION ************
CUniqueID CUniqueID::skInvalidID32 = CUniqueID((u32) -1); CUniqueID CUniqueID::skInvalidID32 = CUniqueID((u32) -1, e32Bit);
CUniqueID CUniqueID::skInvalidID64 = CUniqueID((u64) -1); CUniqueID CUniqueID::skInvalidID64 = CUniqueID((u64) -1, e64Bit);
CUniqueID CUniqueID::skInvalidID128 = CUniqueID((u64) -1, (u64) -1); CUniqueID CUniqueID::skInvalidID128 = CUniqueID((u64) -1, (u64) -1);

View File

@ -21,6 +21,7 @@ class CUniqueID
public: public:
CUniqueID(); CUniqueID();
CUniqueID(u64 ID); CUniqueID(u64 ID);
CUniqueID(u64 ID, EUIDLength Length);
CUniqueID(u64 Part1, u64 Part2); CUniqueID(u64 Part1, u64 Part2);
CUniqueID(const char* ID); CUniqueID(const char* ID);
CUniqueID(IInputStream& Input, EUIDLength Length); CUniqueID(IInputStream& Input, EUIDLength Length);

View File

@ -36,9 +36,7 @@ void CScriptCooker::WriteProperty(IProperty *pProp)
case eEnumProperty: case eEnumProperty:
{ {
TEnumProperty *pEnumCast = static_cast<TEnumProperty*>(pProp); TEnumProperty *pEnumCast = static_cast<TEnumProperty*>(pProp);
CEnumTemplate *pEnumTemp = static_cast<CEnumTemplate*>(pEnumCast->Template()); mpSCLY->WriteLong(pEnumCast->Get());
u32 ID = pEnumTemp->EnumeratorID(pEnumCast->Get());
mpSCLY->WriteLong(ID);
break; break;
} }

View File

@ -63,9 +63,12 @@ void CScriptLoader::ReadProperty(IProperty *pProp, u32 Size, IInputStream& SCLY)
TEnumProperty *pEnumCast = static_cast<TEnumProperty*>(pProp); TEnumProperty *pEnumCast = static_cast<TEnumProperty*>(pProp);
CEnumTemplate *pEnumTemp = static_cast<CEnumTemplate*>(pTemp); CEnumTemplate *pEnumTemp = static_cast<CEnumTemplate*>(pTemp);
u32 ID = SCLY.ReadLong(); u32 ID = SCLY.ReadLong();
u32 index = pEnumTemp->EnumeratorIndex(ID);
if (index == -1) Log::FileError(SCLY.GetSourceString(), SCLY.Tell() - 4, "Enum property \"" + pEnumTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has invalid enumerator value: " + TString::HexString(ID, true, true, 8)); // Validate
pEnumCast->Set(index); u32 Index = pEnumTemp->EnumeratorIndex(ID);
if (Index == -1) Log::FileError(SCLY.GetSourceString(), SCLY.Tell() - 4, "Enum property \"" + pEnumTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has invalid enumerator value: " + TString::HexString(ID, true, true, 8));
pEnumCast->Set(ID);
break; break;
} }

View File

@ -153,10 +153,7 @@ s32 CScriptTemplate::CheckVolumeConditions(CScriptObject *pObj, bool LogErrors)
break; break;
case eEnumProperty: { case eEnumProperty: {
TEnumProperty *pEnumCast = static_cast<TEnumProperty*>(pProp); v = (int) static_cast<TEnumProperty*>(pProp)->Get();
CEnumTemplate *pEnumTemp = static_cast<CEnumTemplate*>(pEnumCast->Template());
int index = static_cast<TEnumProperty*>(pProp)->Get();
v = pEnumTemp->EnumeratorID(index);
break; break;
} }
} }

View File

@ -416,8 +416,7 @@ public:
virtual IProperty* InstantiateProperty(CPropertyStruct *pParent) virtual IProperty* InstantiateProperty(CPropertyStruct *pParent)
{ {
TEnumProperty *pEnum = new TEnumProperty(this, pParent); TEnumProperty *pEnum = new TEnumProperty(this, pParent);
u32 Index = EnumeratorIndex(GetDefaultValue()); pEnum->Set(GetDefaultValue());
pEnum->Set(Index);
return pEnum; return pEnum;
} }

View File

@ -8,13 +8,13 @@ class CDamageableTriggerExtra : public CScriptExtra
// Render fluid planes for doors in MP1 // Render fluid planes for doors in MP1
enum ERenderSide enum ERenderSide
{ {
eNoRender = 0, eNoRender = 0x0,
eNorth = 1, eNorth = 0x1,
eSouth = 2, eSouth = 0x2,
eWest = 3, eWest = 0x4,
eEast = 4, eEast = 0x8,
eUp = 5, eUp = 0x10,
eDown = 6 eDown = 0x20
}; };
TVector3Property *mpSizeProp; TVector3Property *mpSizeProp;

View File

@ -271,7 +271,8 @@ void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkInd
{ {
QComboBox *pComboBox = static_cast<QComboBox*>(pEditor); QComboBox *pComboBox = static_cast<QComboBox*>(pEditor);
TEnumProperty *pEnum = static_cast<TEnumProperty*>(pProp); TEnumProperty *pEnum = static_cast<TEnumProperty*>(pProp);
pComboBox->setCurrentIndex(pEnum->Get()); CEnumTemplate *pTemp = static_cast<CEnumTemplate*>(pProp->Template());
pComboBox->setCurrentIndex(pTemp->EnumeratorIndex(pEnum->Get()));
break; break;
} }
@ -421,7 +422,8 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo
{ {
QComboBox *pComboBox = static_cast<QComboBox*>(pEditor); QComboBox *pComboBox = static_cast<QComboBox*>(pEditor);
TEnumProperty *pEnum = static_cast<TEnumProperty*>(pProp); TEnumProperty *pEnum = static_cast<TEnumProperty*>(pProp);
pEnum->Set(pComboBox->currentIndex()); CEnumTemplate *pTemp = static_cast<CEnumTemplate*>(pProp->Template());
pEnum->Set(pTemp->EnumeratorID(pComboBox->currentIndex()));
break; break;
} }

View File

@ -298,7 +298,7 @@ QVariant CPropertyModel::data(const QModelIndex& rkIndex, int Role) const
{ {
TEnumProperty *pEnum = static_cast<TEnumProperty*>(pProp); TEnumProperty *pEnum = static_cast<TEnumProperty*>(pProp);
CEnumTemplate *pTemp = static_cast<CEnumTemplate*>(pEnum->Template()); CEnumTemplate *pTemp = static_cast<CEnumTemplate*>(pEnum->Template());
return TO_QSTRING(pTemp->EnumeratorName(pEnum->Get())); return TO_QSTRING(pTemp->EnumeratorName( pTemp->EnumeratorIndex(pEnum->Get()) ));
} }
else return ""; else return "";