Make enum properties track the enumerator ID internally instead of the index + CUniqueID bugfix
This commit is contained in:
parent
739e3c51bf
commit
7bd97f0fce
|
@ -40,6 +40,30 @@ CUniqueID::CUniqueID(u64 ID)
|
|||
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)
|
||||
{
|
||||
// Constructor for 128-bit IDs
|
||||
|
@ -295,6 +319,6 @@ CUniqueID CUniqueID::RandomID()
|
|||
}
|
||||
|
||||
// ************ STATIC MEMBER INITIALIZATION ************
|
||||
CUniqueID CUniqueID::skInvalidID32 = CUniqueID((u32) -1);
|
||||
CUniqueID CUniqueID::skInvalidID64 = CUniqueID((u64) -1);
|
||||
CUniqueID CUniqueID::skInvalidID32 = CUniqueID((u32) -1, e32Bit);
|
||||
CUniqueID CUniqueID::skInvalidID64 = CUniqueID((u64) -1, e64Bit);
|
||||
CUniqueID CUniqueID::skInvalidID128 = CUniqueID((u64) -1, (u64) -1);
|
||||
|
|
|
@ -21,6 +21,7 @@ class CUniqueID
|
|||
public:
|
||||
CUniqueID();
|
||||
CUniqueID(u64 ID);
|
||||
CUniqueID(u64 ID, EUIDLength Length);
|
||||
CUniqueID(u64 Part1, u64 Part2);
|
||||
CUniqueID(const char* ID);
|
||||
CUniqueID(IInputStream& Input, EUIDLength Length);
|
||||
|
|
|
@ -36,9 +36,7 @@ void CScriptCooker::WriteProperty(IProperty *pProp)
|
|||
case eEnumProperty:
|
||||
{
|
||||
TEnumProperty *pEnumCast = static_cast<TEnumProperty*>(pProp);
|
||||
CEnumTemplate *pEnumTemp = static_cast<CEnumTemplate*>(pEnumCast->Template());
|
||||
u32 ID = pEnumTemp->EnumeratorID(pEnumCast->Get());
|
||||
mpSCLY->WriteLong(ID);
|
||||
mpSCLY->WriteLong(pEnumCast->Get());
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,9 +63,12 @@ void CScriptLoader::ReadProperty(IProperty *pProp, u32 Size, IInputStream& SCLY)
|
|||
TEnumProperty *pEnumCast = static_cast<TEnumProperty*>(pProp);
|
||||
CEnumTemplate *pEnumTemp = static_cast<CEnumTemplate*>(pTemp);
|
||||
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));
|
||||
pEnumCast->Set(index);
|
||||
|
||||
// Validate
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -153,10 +153,7 @@ s32 CScriptTemplate::CheckVolumeConditions(CScriptObject *pObj, bool LogErrors)
|
|||
break;
|
||||
|
||||
case eEnumProperty: {
|
||||
TEnumProperty *pEnumCast = static_cast<TEnumProperty*>(pProp);
|
||||
CEnumTemplate *pEnumTemp = static_cast<CEnumTemplate*>(pEnumCast->Template());
|
||||
int index = static_cast<TEnumProperty*>(pProp)->Get();
|
||||
v = pEnumTemp->EnumeratorID(index);
|
||||
v = (int) static_cast<TEnumProperty*>(pProp)->Get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -416,8 +416,7 @@ public:
|
|||
virtual IProperty* InstantiateProperty(CPropertyStruct *pParent)
|
||||
{
|
||||
TEnumProperty *pEnum = new TEnumProperty(this, pParent);
|
||||
u32 Index = EnumeratorIndex(GetDefaultValue());
|
||||
pEnum->Set(Index);
|
||||
pEnum->Set(GetDefaultValue());
|
||||
return pEnum;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,13 @@ class CDamageableTriggerExtra : public CScriptExtra
|
|||
// Render fluid planes for doors in MP1
|
||||
enum ERenderSide
|
||||
{
|
||||
eNoRender = 0,
|
||||
eNorth = 1,
|
||||
eSouth = 2,
|
||||
eWest = 3,
|
||||
eEast = 4,
|
||||
eUp = 5,
|
||||
eDown = 6
|
||||
eNoRender = 0x0,
|
||||
eNorth = 0x1,
|
||||
eSouth = 0x2,
|
||||
eWest = 0x4,
|
||||
eEast = 0x8,
|
||||
eUp = 0x10,
|
||||
eDown = 0x20
|
||||
};
|
||||
|
||||
TVector3Property *mpSizeProp;
|
||||
|
|
|
@ -271,7 +271,8 @@ void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkInd
|
|||
{
|
||||
QComboBox *pComboBox = static_cast<QComboBox*>(pEditor);
|
||||
TEnumProperty *pEnum = static_cast<TEnumProperty*>(pProp);
|
||||
pComboBox->setCurrentIndex(pEnum->Get());
|
||||
CEnumTemplate *pTemp = static_cast<CEnumTemplate*>(pProp->Template());
|
||||
pComboBox->setCurrentIndex(pTemp->EnumeratorIndex(pEnum->Get()));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -421,7 +422,8 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo
|
|||
{
|
||||
QComboBox *pComboBox = static_cast<QComboBox*>(pEditor);
|
||||
TEnumProperty *pEnum = static_cast<TEnumProperty*>(pProp);
|
||||
pEnum->Set(pComboBox->currentIndex());
|
||||
CEnumTemplate *pTemp = static_cast<CEnumTemplate*>(pProp->Template());
|
||||
pEnum->Set(pTemp->EnumeratorID(pComboBox->currentIndex()));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -298,7 +298,7 @@ QVariant CPropertyModel::data(const QModelIndex& rkIndex, int Role) const
|
|||
{
|
||||
TEnumProperty *pEnum = static_cast<TEnumProperty*>(pProp);
|
||||
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 "";
|
||||
|
||||
|
|
Loading…
Reference in New Issue