forked from Mirrors/openclonk
Script: Effects are now proplists, too
This doesn't yet affect any script interfaces,
parent
f801ab61f5
commit
e2c6a5fd17
|
@ -36,6 +36,7 @@ class C4Config;
|
|||
class C4Console;
|
||||
class C4Def;
|
||||
class C4DefList;
|
||||
class C4Effect;
|
||||
class C4Facet;
|
||||
class C4FacetSurface;
|
||||
class C4Game;
|
||||
|
|
|
@ -88,7 +88,7 @@ void C4GameObjects::CompileFunc(StdCompiler *pComp, bool fSkipPlayerObjects)
|
|||
pComp->NameEnd();
|
||||
}*/
|
||||
for (C4PropListNumbered * const * ppPropList = PropLists.First(); ppPropList; ppPropList = PropLists.Next(ppPropList))
|
||||
if (!dynamic_cast<C4Object *>(*ppPropList) && !dynamic_cast<C4Def *>(*ppPropList))
|
||||
if ((*ppPropList)->IsScriptPropList())
|
||||
{
|
||||
pComp->Value(mkNamingAdapt(**ppPropList, "PropList"));
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ void C4GameObjects::CompileFunc(StdCompiler *pComp, bool fSkipPlayerObjects)
|
|||
// Load proplists
|
||||
for (int i = 0; i < iPropListCnt; i++)
|
||||
{
|
||||
C4PropListNumbered *pPropList = NULL;
|
||||
C4PropListScript *pPropList = NULL;
|
||||
try
|
||||
{
|
||||
pComp->Value(mkNamingAdapt(mkPtrAdaptNoNull(pPropList), "PropList"));
|
||||
|
@ -642,8 +642,9 @@ int C4GameObjects::Load(C4Group &hGroup, bool fKeepInactive)
|
|||
C4ObjectLink *pInFirst = NULL;
|
||||
if (fObjectNumberCollision) { pInFirst = InactiveObjects.First; InactiveObjects.First = NULL; }
|
||||
// denumerate pointers
|
||||
Denumerate();
|
||||
for (C4PropListNumbered * const * ppPropList = PropLists.First(); ppPropList; ppPropList = PropLists.Next(ppPropList))
|
||||
(*ppPropList)->DenumeratePointers();
|
||||
if ((*ppPropList)->IsScriptPropList()) (*ppPropList)->DenumeratePointers();
|
||||
// update object enumeration index now, because calls like UpdateTransferZone might create objects
|
||||
Game.ObjectEnumerationIndex = Max(Game.ObjectEnumerationIndex, iMaxObjectNumber);
|
||||
// end faking and adjust object numbers
|
||||
|
|
|
@ -75,6 +75,7 @@ C4Effect::C4Effect(C4Object *pForObj, const char *szName, int32_t iPrio, int32_t
|
|||
CommandTarget = pCmdTarget;
|
||||
idCommandTarget = idCmdTarget;
|
||||
AssignCallbackFunctions();
|
||||
AcquireNumber();
|
||||
// get effect target
|
||||
C4Effect **ppEffectList = pForObj ? &pForObj->pEffects : &Game.pGlobalEffects;
|
||||
// assign a unique number for that object
|
||||
|
@ -189,6 +190,7 @@ void C4Effect::DenumeratePointers()
|
|||
pEff->EffectVars.DenumeratePointers();
|
||||
// assign any callback functions
|
||||
pEff->AssignCallbackFunctions();
|
||||
pEff->C4PropList::DenumeratePointers();
|
||||
}
|
||||
while ((pEff=pEff->pNext));
|
||||
}
|
||||
|
@ -520,7 +522,9 @@ void C4Effect::CompileFunc(StdCompiler *pComp)
|
|||
// read object number
|
||||
pComp->Value(CommandTarget); pComp->Separator();
|
||||
// read ID
|
||||
pComp->Value(idCommandTarget);
|
||||
pComp->Value(idCommandTarget); pComp->Separator();
|
||||
// proplist
|
||||
C4PropListNumbered::CompileFuncNonames(pComp);
|
||||
pComp->Separator(StdCompiler::SEP_END); // ')'
|
||||
// read variables
|
||||
if (pComp->isCompiler() || EffectVars.GetSize() > 0)
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
#define C4Fx_FireParticle2 "Fire2"
|
||||
|
||||
// generic object effect
|
||||
class C4Effect
|
||||
class C4Effect: public C4PropListNumbered
|
||||
{
|
||||
public:
|
||||
char Name[C4MaxDefString+1]; // name of effect
|
||||
|
@ -139,6 +139,7 @@ public:
|
|||
void OnObjectChangedDef(C4Object *pObj);
|
||||
|
||||
void CompileFunc(StdCompiler *pComp);
|
||||
virtual C4Effect * GetEffect() { return this; }
|
||||
|
||||
protected:
|
||||
void TempRemoveUpperEffects(C4Object *pObj, bool fTempRemoveThis, C4Effect **ppLastRemovedEffect); // temp remove all effects with higher priority
|
||||
|
|
|
@ -42,22 +42,21 @@ void C4PropList::DelRef(const C4Value * pRef, C4Value * pNextRef)
|
|||
pVal->NextRef = pNextRef;
|
||||
}
|
||||
if (FirstRef) return;
|
||||
// These classes have their own memory management
|
||||
if (dynamic_cast<C4Object *>(this)) return;
|
||||
if (dynamic_cast<C4Def *>(this)) return;
|
||||
delete this;
|
||||
// Only pure script proplists are garbage collected here, host proplists
|
||||
// like definitions and effects have their own memory management.
|
||||
if (IsScriptPropList()) delete this;
|
||||
}
|
||||
|
||||
C4PropList * C4PropList::New(C4PropList * prototype)
|
||||
{
|
||||
C4PropListNumbered * r = new C4PropListNumbered(prototype);
|
||||
C4PropListNumbered * r = new C4PropListScript(prototype);
|
||||
r->AcquireNumber();
|
||||
return r;
|
||||
}
|
||||
|
||||
C4PropList * C4PropList::NewAnon(C4PropList * prototype)
|
||||
{
|
||||
C4PropList * r = new C4PropList(prototype);
|
||||
C4PropList * r = new C4PropListAnonScript(prototype);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -88,6 +87,16 @@ void C4PropListNumbered::CompileFunc(StdCompiler *pComp)
|
|||
::Objects.PropLists.Add(this);
|
||||
}
|
||||
|
||||
void C4PropListNumbered::CompileFuncNonames(StdCompiler *pComp)
|
||||
{
|
||||
pComp->Value(Number);
|
||||
pComp->Separator();
|
||||
// reuse C4PropList::CompileFunc(pComp);
|
||||
pComp->Value(static_cast<C4PropList&>(*this));
|
||||
if (pComp->isCompiler())
|
||||
::Objects.PropLists.Add(this);
|
||||
}
|
||||
|
||||
C4PropListNumbered::~C4PropListNumbered()
|
||||
{
|
||||
if (Number != -1)
|
||||
|
@ -261,6 +270,12 @@ C4PropListNumbered * C4PropList::GetPropListNumbered()
|
|||
return 0;
|
||||
}
|
||||
|
||||
C4Effect * C4PropList::GetEffect()
|
||||
{
|
||||
if (prototype) return prototype->GetEffect();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
template<> template<>
|
||||
unsigned int C4Set<C4Property>::Hash<C4String *>(C4String * e)
|
||||
|
|
|
@ -56,11 +56,14 @@ public:
|
|||
virtual C4Def const * GetDef() const;
|
||||
virtual C4Def * GetDef();
|
||||
virtual C4Object * GetObject();
|
||||
virtual C4Effect * GetEffect();
|
||||
virtual C4PropListNumbered * GetPropListNumbered();
|
||||
C4PropList * GetPrototype() const { return prototype; }
|
||||
|
||||
// Whether this proplist should be saved as a reference to a C4Def
|
||||
virtual bool IsDef() const { return false; }
|
||||
// Whether this proplist is a pure script proplist, not a host object
|
||||
virtual bool IsScriptPropList() { return false; }
|
||||
|
||||
bool GetPropertyByS(C4String *k, C4Value *pResult) const;
|
||||
bool GetProperty(C4PropertyName k, C4Value *pResult) const
|
||||
|
@ -108,12 +111,27 @@ class C4PropListNumbered: public C4PropList
|
|||
{
|
||||
public:
|
||||
int32_t Number;
|
||||
C4PropListNumbered(C4PropList * prototype = 0);
|
||||
~C4PropListNumbered();
|
||||
void CompileFunc(StdCompiler *pComp);
|
||||
void CompileFuncNonames(StdCompiler *pComp);
|
||||
virtual C4PropListNumbered * GetPropListNumbered();
|
||||
void AcquireNumber();
|
||||
protected:
|
||||
C4PropListNumbered(C4PropList * prototype = 0);
|
||||
};
|
||||
|
||||
class C4PropListScript: public C4PropListNumbered
|
||||
{
|
||||
public:
|
||||
C4PropListScript(C4PropList * prototype = 0): C4PropListNumbered(prototype) { }
|
||||
bool IsScriptPropList() { return true; }
|
||||
};
|
||||
|
||||
class C4PropListAnonScript: public C4PropList
|
||||
{
|
||||
public:
|
||||
C4PropListAnonScript(C4PropList * prototype = 0): C4PropList(prototype) { }
|
||||
bool IsScriptPropList() { return true; }
|
||||
};
|
||||
|
||||
#endif // C4PROPLIST_H
|
||||
|
|
Loading…
Reference in New Issue