forked from Mirrors/openclonk
Improve internal C4PropList interface for predefined property names
SetProperty now also has a wrapper, and the common case of GetPropertyVal(P_Foo) is now GetProperty(P_Foo).
parent
3684421010
commit
26c670b29d
|
@ -609,7 +609,7 @@ bool C4Def::Load(C4Group &hGroup,
|
|||
// Temporary flag
|
||||
if (dwLoadWhat & C4D_Load_Temporary) Temporary=true;
|
||||
|
||||
if (Carryable) SetProperty(Strings.P[P_Collectible], C4VTrue);
|
||||
if (Carryable) SetProperty(P_Collectible, C4VTrue);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -647,13 +647,13 @@ void C4Def::Draw(C4Facet &cgo, bool fSelected, DWORD iColor, C4Object *pObj, int
|
|||
if (pObj)
|
||||
{
|
||||
instance = pObj->pMeshInstance;
|
||||
pObj->GetPropertyVal(P_PictureTransformation, &value);
|
||||
pObj->GetProperty(P_PictureTransformation, &value);
|
||||
}
|
||||
else
|
||||
{
|
||||
dummy.reset(new StdMeshInstance(*graphics->Mesh));
|
||||
instance = dummy.get();
|
||||
GetPropertyVal(P_PictureTransformation, &value);
|
||||
GetProperty(P_PictureTransformation, &value);
|
||||
}
|
||||
|
||||
StdMeshMatrix matrix;
|
||||
|
@ -1354,9 +1354,9 @@ C4PropList *C4Def::GetActionByName(C4String *actname)
|
|||
// If we get the null string or ActIdle by name, return NULL action
|
||||
if (!actname || actname == Strings.P[P_Idle]) return NULL;
|
||||
// otherwise, query actmap
|
||||
C4Value ActMap; GetPropertyVal(P_ActMap, &ActMap);
|
||||
C4Value ActMap; GetProperty(P_ActMap, &ActMap);
|
||||
if (!ActMap.getPropList()) return false;
|
||||
C4Value Action; ActMap.getPropList()->GetPropertyVal(actname, &Action);
|
||||
C4Value Action; ActMap.getPropList()->GetPropertyByS(actname, &Action);
|
||||
if (!Action.getPropList()) return false;
|
||||
return Action.getPropList();
|
||||
}
|
||||
|
|
|
@ -736,12 +736,12 @@ void C4GraphicsOverlay::UpdateFacet()
|
|||
return;
|
||||
|
||||
C4Value v;
|
||||
pDef->GetPropertyVal(P_ActMap, &v);
|
||||
pDef->GetProperty(P_ActMap, &v);
|
||||
C4PropList *actmap = v.getPropList();
|
||||
if (!actmap)
|
||||
return;
|
||||
|
||||
actmap->GetPropertyVal(::Strings.RegString(Action), &v);
|
||||
actmap->GetPropertyByS(::Strings.RegString(Action), &v);
|
||||
C4PropList *action = v.getPropList();
|
||||
if (!action)
|
||||
return;
|
||||
|
@ -1083,7 +1083,7 @@ void C4GraphicsOverlay::Draw(C4TargetFacet &cgo, C4Object *pForObj, int32_t iByP
|
|||
}
|
||||
|
||||
C4Value value;
|
||||
pDef->GetPropertyVal(P_MeshTransformation, &value);
|
||||
pDef->GetProperty(P_MeshTransformation, &value);
|
||||
StdMeshMatrix matrix;
|
||||
if (C4ValueToMatrix(value, &matrix))
|
||||
lpDDraw->SetMeshTransform(&matrix);
|
||||
|
@ -1108,7 +1108,7 @@ void C4GraphicsOverlay::Draw(C4TargetFacet &cgo, C4Object *pForObj, int32_t iByP
|
|||
}
|
||||
|
||||
C4Value value;
|
||||
pDef->GetPropertyVal(P_PictureTransformation, &value);
|
||||
pDef->GetProperty(P_PictureTransformation, &value);
|
||||
StdMeshMatrix matrix;
|
||||
if (C4ValueToMatrix(value, &matrix))
|
||||
lpDDraw->SetMeshTransform(&matrix);
|
||||
|
@ -1186,7 +1186,7 @@ void C4GraphicsOverlay::DrawPicture(C4Facet &cgo, C4Object *pForObj, C4DrawTrans
|
|||
C4Def *pDef = pSourceGfx->pDef;
|
||||
|
||||
C4Value value;
|
||||
pDef->GetPropertyVal(P_PictureTransformation, &value);
|
||||
pDef->GetProperty(P_PictureTransformation, &value);
|
||||
StdMeshMatrix matrix;
|
||||
if (C4ValueToMatrix(value, &matrix))
|
||||
lpDDraw->SetMeshTransform(&matrix);
|
||||
|
|
|
@ -237,7 +237,7 @@ bool C4Object::Init(C4PropList *pDef, C4Object *pCreator,
|
|||
LastEnergyLossCausePlayer=NO_OWNER;
|
||||
Info=pInfo;
|
||||
Def=pDef->GetDef(); assert(Def);
|
||||
SetProperty(Strings.P[P_Prototype], C4VPropList(pDef));
|
||||
SetProperty(P_Prototype, C4VPropList(pDef));
|
||||
id=Def->id;
|
||||
if (Info) SetName(pInfo->Name);
|
||||
Category=Def->Category;
|
||||
|
@ -549,7 +549,7 @@ void C4Object::DrawFaceImpl(C4TargetFacet &cgo, bool action, float fx, float fy,
|
|||
break;
|
||||
case C4DefGraphics::TYPE_Mesh:
|
||||
C4Value value;
|
||||
GetPropertyVal(P_MeshTransformation, &value);
|
||||
GetProperty(P_MeshTransformation, &value);
|
||||
StdMeshMatrix matrix;
|
||||
if (!C4ValueToMatrix(value, &matrix))
|
||||
matrix = StdMeshMatrix::Identity();
|
||||
|
@ -1293,7 +1293,7 @@ bool C4Object::ChangeDef(C4ID idNew)
|
|||
Def->Count--;
|
||||
// Def change
|
||||
Def=pDef;
|
||||
SetProperty(Strings.P[P_Prototype], C4VPropList(pDef));
|
||||
SetProperty(P_Prototype, C4VPropList(pDef));
|
||||
id=pDef->id;
|
||||
Def->Count++;
|
||||
// new def: Needs to be resorted
|
||||
|
@ -2659,7 +2659,7 @@ void C4Object::DrawLine(C4TargetFacet &cgo)
|
|||
// additive mode?
|
||||
PrepareDrawing();
|
||||
// Draw line segments
|
||||
C4Value colorsV; GetPropertyVal(P_LineColors, &colorsV);
|
||||
C4Value colorsV; GetProperty(P_LineColors, &colorsV);
|
||||
C4ValueArray *colors = colorsV.getArray();
|
||||
int32_t color0 = 0xFFFF00FF, color1 = 0xFFFF00FF; // use bright colors so author notices
|
||||
if (colors)
|
||||
|
@ -3330,7 +3330,7 @@ void C4Object::Resort()
|
|||
C4PropList* C4Object::GetAction()
|
||||
{
|
||||
C4Value value;
|
||||
GetPropertyVal(P_Action, &value);
|
||||
GetProperty(P_Action, &value);
|
||||
return value.getPropList();
|
||||
}
|
||||
|
||||
|
@ -3379,7 +3379,7 @@ bool C4Object::SetAction(C4PropList * Act, C4Object *pTarget, C4Object *pTarget2
|
|||
}
|
||||
// Set new action
|
||||
|
||||
SetProperty(::Strings.P[P_Action], C4VPropList(Act));
|
||||
SetProperty(P_Action, C4VPropList(Act));
|
||||
Action.Phase=Action.PhaseDelay=0;
|
||||
// Set target if specified
|
||||
if (pTarget) Action.Target=pTarget;
|
||||
|
@ -3470,9 +3470,9 @@ bool C4Object::SetActionByName(C4String *ActName,
|
|||
// If we get the null string or ActIdle by name, set ActIdle
|
||||
if (!ActName || ActName == Strings.P[P_Idle])
|
||||
return SetAction(0,0,0,iCalls,fForce);
|
||||
C4Value ActMap; GetPropertyVal(P_ActMap, &ActMap);
|
||||
C4Value ActMap; GetProperty(P_ActMap, &ActMap);
|
||||
if (!ActMap.getPropList()) return false;
|
||||
C4Value Action; ActMap.getPropList()->GetPropertyVal(ActName, &Action);
|
||||
C4Value Action; ActMap.getPropList()->GetPropertyByS(ActName, &Action);
|
||||
if (!Action.getPropList()) return false;
|
||||
return SetAction(Action.getPropList(),pTarget,pTarget2,iCalls,fForce);
|
||||
}
|
||||
|
@ -4556,7 +4556,7 @@ void C4Object::ExecAction()
|
|||
int32_t attachVertex0,attachVertex1;
|
||||
attachVertex0=attachVertex1=0;
|
||||
{
|
||||
C4Value lineAttachV; GetPropertyVal(P_LineAttach, &lineAttachV);
|
||||
C4Value lineAttachV; GetProperty(P_LineAttach, &lineAttachV);
|
||||
C4ValueArray *lineAttach = lineAttachV.getArray();
|
||||
if (lineAttach)
|
||||
{
|
||||
|
@ -4801,7 +4801,7 @@ bool C4Object::IsVisible(int32_t iForPlr, bool fAsOverlay)
|
|||
{
|
||||
bool fDraw;
|
||||
C4Value vis;
|
||||
if (!GetPropertyVal(P_Visibility, &vis))
|
||||
if (!GetProperty(P_Visibility, &vis))
|
||||
return true;
|
||||
|
||||
int32_t Visibility;
|
||||
|
@ -5026,7 +5026,7 @@ void C4Object::GetParallaxity(int32_t *parX, int32_t *parY)
|
|||
return;
|
||||
}
|
||||
if (!(Category & C4D_Parallax)) return;
|
||||
C4Value parV; GetPropertyVal(P_Parallaxity, &parV);
|
||||
C4Value parV; GetProperty(P_Parallaxity, &parV);
|
||||
C4ValueArray *par = parV.getArray();
|
||||
if (!par) return;
|
||||
*parX = par->GetItem(0).getInt();
|
||||
|
@ -5036,7 +5036,7 @@ void C4Object::GetParallaxity(int32_t *parX, int32_t *parY)
|
|||
bool C4Object::GetDragImage(C4Object **drag_object, C4ID *drag_id)
|
||||
{
|
||||
// drag is possible if MouseDragImage is assigned
|
||||
C4Value parV; GetPropertyVal(P_MouseDragImage, &parV);
|
||||
C4Value parV; GetProperty(P_MouseDragImage, &parV);
|
||||
if (!parV) return false;
|
||||
// determine drag object/id
|
||||
C4Object *obj=NULL; C4ID id;
|
||||
|
|
|
@ -638,7 +638,7 @@ bool C4FindObjectActionTarget::Check(C4Object *pObj)
|
|||
bool C4FindObjectProcedure::Check(C4Object *pObj)
|
||||
{
|
||||
C4Value v;
|
||||
pObj->GetAction()->GetPropertyVal(P_Procedure, &v);
|
||||
pObj->GetAction()->GetProperty(P_Procedure, &v);
|
||||
return v != C4VNull && v.getInt() == procedure;
|
||||
}
|
||||
|
||||
|
|
|
@ -993,7 +993,7 @@ static C4Value FnGetProperty_C4V(C4AulContext *cthr, C4Value * key_C4V, C4Value
|
|||
C4String * key = key_C4V->_getStr();
|
||||
if (!key) return C4VNull;
|
||||
C4Value r;
|
||||
pObj->GetPropertyVal(key, &r);
|
||||
pObj->GetPropertyByS(key, &r);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -1007,7 +1007,7 @@ static C4Value FnSetProperty_C4V(C4AulContext *cthr, C4Value * key_C4V, C4Value
|
|||
if (!key) return C4VFalse;
|
||||
if (pObj->IsFrozen())
|
||||
throw new C4AulExecError(cthr->Obj, "proplist write: proplist is readonly");
|
||||
pObj->SetProperty(key, *to);
|
||||
pObj->SetPropertyByS(key, *to);
|
||||
return C4VTrue;
|
||||
}
|
||||
|
||||
|
|
|
@ -229,18 +229,18 @@ C4Value C4AulExec::Exec(C4AulBCC *pCPos, bool fPassErrors)
|
|||
if (!pCurCtx->Obj)
|
||||
throw new C4AulExecError(pCurCtx->Obj, "can't access local variables in a definition call");
|
||||
PushNullVals(1);
|
||||
pCurCtx->Obj->GetPropertyVal(pCPos->Par.s, pCurVal);
|
||||
pCurCtx->Obj->GetPropertyByS(pCPos->Par.s, pCurVal);
|
||||
break;
|
||||
case AB_LOCALN_SET:
|
||||
if (!pCurCtx->Obj)
|
||||
throw new C4AulExecError(pCurCtx->Obj, "can't access local variables in a definition call");
|
||||
pCurCtx->Obj->SetProperty(pCPos->Par.s, pCurVal[0]);
|
||||
pCurCtx->Obj->SetPropertyByS(pCPos->Par.s, pCurVal[0]);
|
||||
break;
|
||||
|
||||
case AB_PROP:
|
||||
if (!(pCurVal->ConvertTo(C4V_PropList) && pCurVal->_getPropList()))
|
||||
throw new C4AulExecError(pCurCtx->Obj, FormatString("proplist access: proplist expected, got %s", pCurVal->GetTypeName()).getData());
|
||||
if (!pCurVal->_getPropList()->GetPropertyVal(pCPos->Par.s, pCurVal))
|
||||
if (!pCurVal->_getPropList()->GetPropertyByS(pCPos->Par.s, pCurVal))
|
||||
pCurVal->Set0();
|
||||
break;
|
||||
case AB_PROP_SET:
|
||||
|
@ -250,7 +250,7 @@ C4Value C4AulExec::Exec(C4AulBCC *pCPos, bool fPassErrors)
|
|||
throw new C4AulExecError(pCurCtx->Obj, FormatString("proplist write: proplist expected, got %s", pPropList->GetTypeName()).getData());
|
||||
if (pPropList->_getPropList()->IsFrozen())
|
||||
throw new C4AulExecError(pCurCtx->Obj, "proplist write: proplist is readonly");
|
||||
pPropList->_getPropList()->SetProperty(pCPos->Par.s, pCurVal[0]);
|
||||
pPropList->_getPropList()->SetPropertyByS(pCPos->Par.s, pCurVal[0]);
|
||||
pPropList->Set(pCurVal[0]);
|
||||
PopValue();
|
||||
break;
|
||||
|
@ -459,7 +459,7 @@ C4Value C4AulExec::Exec(C4AulBCC *pCPos, bool fPassErrors)
|
|||
throw new C4AulExecError(pCurCtx->Obj, FormatString("internal error: proplist expected, got %s", pPropSet->GetTypeName()).getData());
|
||||
if (!pKey->ConvertTo(C4V_String))
|
||||
throw new C4AulExecError(pCurCtx->Obj, FormatString("internal error: string expected, got %s", pPropSet->GetTypeName()).getData());
|
||||
pPropSet->_getPropList()->SetProperty(pKey->_getStr(), *pValue);
|
||||
pPropSet->_getPropList()->SetPropertyByS(pKey->_getStr(), *pValue);
|
||||
PopValues(2);
|
||||
break;
|
||||
}
|
||||
|
@ -476,7 +476,7 @@ C4Value C4AulExec::Exec(C4AulBCC *pCPos, bool fPassErrors)
|
|||
{
|
||||
assert(pStruct->GetType() == C4V_PropList || pStruct->GetType() == C4V_C4Object);
|
||||
C4PropList *pPropList = pStruct->_getPropList();
|
||||
if (!pPropList->GetPropertyVal(pIndex->_getStr(), pResult))
|
||||
if (!pPropList->GetPropertyByS(pIndex->_getStr(), pResult))
|
||||
pResult->Set0();
|
||||
}
|
||||
// Remove index
|
||||
|
@ -497,7 +497,7 @@ C4Value C4AulExec::Exec(C4AulBCC *pCPos, bool fPassErrors)
|
|||
C4PropList *pPropList = pStruct->_getPropList();
|
||||
if (pPropList->IsFrozen())
|
||||
throw new C4AulExecError(pCurCtx->Obj, "proplist write: proplist is readonly");
|
||||
pPropList->SetProperty(pIndex->_getStr(), *pValue);
|
||||
pPropList->SetPropertyByS(pIndex->_getStr(), *pValue);
|
||||
}
|
||||
// Set result, remove array and index from stack
|
||||
*pResult = *pValue;
|
||||
|
|
|
@ -2853,7 +2853,7 @@ void C4AulParseState::Parse_Local()
|
|||
Shift(Ref, false);
|
||||
// register as constant
|
||||
if (Type == PREPARSER)
|
||||
a->Def->SetProperty(Strings.RegString(Name), Parse_ConstExpression());
|
||||
a->Def->SetPropertyByS(Strings.RegString(Name), Parse_ConstExpression());
|
||||
else
|
||||
Parse_ConstExpression();
|
||||
}
|
||||
|
@ -3010,7 +3010,7 @@ C4Value C4AulParseState::Parse_ConstExpression()
|
|||
UnexpectedToken("':' or '='");
|
||||
Shift();
|
||||
if (Type == PREPARSER)
|
||||
r._getPropList()->SetProperty(pKey, Parse_ConstExpression());
|
||||
r._getPropList()->SetPropertyByS(pKey, Parse_ConstExpression());
|
||||
else
|
||||
Parse_ConstExpression();
|
||||
if (TokenType == ATT_COMMA)
|
||||
|
|
|
@ -101,7 +101,7 @@ C4PropList::C4PropList(C4PropList * prototype):
|
|||
FirstRef(NULL), prototype(prototype), constant(false)
|
||||
{
|
||||
if (prototype)
|
||||
SetProperty(Strings.P[P_Prototype], C4VPropList(prototype));
|
||||
SetProperty(P_Prototype, C4VPropList(prototype));
|
||||
}
|
||||
|
||||
void C4PropList::DenumeratePointers()
|
||||
|
@ -113,7 +113,7 @@ void C4PropList::DenumeratePointers()
|
|||
p = Properties.Next(p);
|
||||
}
|
||||
C4Value v;
|
||||
if(GetPropertyVal(Strings.P[P_Prototype], &v))
|
||||
if(GetProperty(P_Prototype, &v))
|
||||
prototype = v.getPropList();
|
||||
}
|
||||
|
||||
|
@ -231,8 +231,7 @@ void C4PropList::SetName(const char* NewName)
|
|||
ResetProperty(Strings.P[P_Name]);
|
||||
else
|
||||
{
|
||||
C4Value v = C4VString(NewName);
|
||||
SetProperty(Strings.P[P_Name], v);
|
||||
SetProperty(P_Name, C4VString(NewName));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,7 +281,7 @@ unsigned int C4Set<C4Property>::Hash<C4Property>(C4Property p)
|
|||
return p.Key->Hash;
|
||||
}
|
||||
|
||||
bool C4PropList::GetPropertyVal(C4String * k, C4Value *pResult) const
|
||||
bool C4PropList::GetPropertyByS(C4String * k, C4Value *pResult) const
|
||||
{
|
||||
if (Properties.Has(k))
|
||||
{
|
||||
|
@ -290,7 +289,7 @@ bool C4PropList::GetPropertyVal(C4String * k, C4Value *pResult) const
|
|||
return true;
|
||||
}
|
||||
else if(prototype)
|
||||
return prototype->GetPropertyVal(k, pResult);
|
||||
return prototype->GetPropertyByS(k, pResult);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
@ -323,7 +322,7 @@ int32_t C4PropList::GetPropertyInt(C4PropertyName n) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
void C4PropList::SetProperty(C4String * k, const C4Value & to)
|
||||
void C4PropList::SetPropertyByS(C4String * k, const C4Value & to)
|
||||
{
|
||||
assert(!constant);
|
||||
assert(Strings.Set.Has(k));
|
||||
|
|
|
@ -40,7 +40,8 @@ public:
|
|||
C4String * Key;
|
||||
C4Value Value;
|
||||
operator const void * () const { return Key; }
|
||||
C4Property & operator = (void * p) { assert(!p); if (Key) Key->DecRef(); Key = 0; Value.Set0(); return *this; }
|
||||
C4Property & operator = (void * p)
|
||||
{ assert(!p); if (Key) Key->DecRef(); Key = 0; Value.Set0(); return *this; }
|
||||
};
|
||||
class C4PropListNumbered;
|
||||
class C4PropList
|
||||
|
@ -62,12 +63,15 @@ public:
|
|||
// Whether this proplist should be saved as a reference to a C4Def
|
||||
virtual bool IsDef() const { return false; }
|
||||
|
||||
bool GetPropertyVal(C4String *k, C4Value *pResult) const;
|
||||
bool GetPropertyVal(C4PropertyName k, C4Value *pResult) const { return GetPropertyVal(Strings.P[k], pResult); }
|
||||
bool GetPropertyByS(C4String *k, C4Value *pResult) const;
|
||||
bool GetProperty(C4PropertyName k, C4Value *pResult) const
|
||||
{ return GetPropertyByS(Strings.P[k], pResult); }
|
||||
C4String * GetPropertyStr(C4PropertyName k) const;
|
||||
int32_t GetPropertyInt(C4PropertyName k) const;
|
||||
// not allowed on frozen proplists
|
||||
void SetProperty(C4String * k, const C4Value & to);
|
||||
void SetPropertyByS(C4String * k, const C4Value & to);
|
||||
void SetProperty(C4PropertyName k, const C4Value & to)
|
||||
{ SetPropertyByS(Strings.P[k], to); }
|
||||
void ResetProperty(C4String * k);
|
||||
|
||||
static C4PropList * New(C4PropList * prototype = 0);
|
||||
|
|
Loading…
Reference in New Issue