Remove function cache from C4DefScriptHost

rope
Günther Brammer 2011-10-15 01:59:15 +02:00
parent bb3861d4f1
commit a01bb2cf9c
6 changed files with 26 additions and 41 deletions

View File

@ -1561,12 +1561,7 @@ void C4Command::Transfer()
// Call target transfer script // Call target transfer script
if (!::Game.iTick5) if (!::Game.iTick5)
{ {
if (!Target->Call(PSF_ControlTransfer, &C4AulParSet(C4VObj(cObj), Tx, C4VInt(Ty))).getBool())
C4AulScriptFunc *f;
bool fHandled = (f = Target->Def->Script.SFn_ControlTransfer) != NULL;
if (fHandled) fHandled = f->Exec(Target,&C4AulParSet(C4VObj(cObj), Tx, C4VInt(Ty))).getBool();
if (!fHandled)
// Transfer not handled by target: done // Transfer not handled by target: done
{ Finish(true); return; } { Finish(true); return; }
} }

View File

@ -562,21 +562,16 @@ void C4Def::Draw(C4Facet &cgo, bool fSelected, DWORD iColor, C4Object *pObj, int
int32_t C4Def::GetValue(C4Object *pInBase, int32_t iBuyPlayer) int32_t C4Def::GetValue(C4Object *pInBase, int32_t iBuyPlayer)
{ {
// CalcDefValue defined? C4Value r = Call(PSF_CalcDefValue, &C4AulParSet(C4VObj(pInBase), C4VInt(iBuyPlayer)));
C4AulFunc *pCalcValueFn = Script.GetSFunc(PSF_CalcDefValue, AA_PROTECTED); int32_t iValue = Value;
int32_t iValue; if (r != C4VNull)
if (pCalcValueFn) iValue = r.getInt();
// then call it!
iValue = pCalcValueFn->Exec(NULL, &C4AulParSet(C4VObj(pInBase), C4VInt(iBuyPlayer))).getInt();
else
// otherwise, use default value
iValue = Value;
// do any adjustments based on where the item is bought // do any adjustments based on where the item is bought
if (pInBase) if (pInBase)
{ {
C4AulFunc *pFn; r = pInBase->Call(PSF_CalcBuyValue, &C4AulParSet(C4VPropList(this), C4VInt(iValue)));
if ((pFn = pInBase->Def->Script.GetSFunc(PSF_CalcBuyValue, AA_PROTECTED))) if (r != C4VNull)
iValue = pFn->Exec(pInBase, &C4AulParSet(C4VPropList(this), C4VInt(iValue))).getInt(); iValue = r.getInt();
} }
return iValue; return iValue;
} }

View File

@ -1808,11 +1808,10 @@ void C4Object::SetName(const char * NewName)
int32_t C4Object::GetValue(C4Object *pInBase, int32_t iForPlayer) int32_t C4Object::GetValue(C4Object *pInBase, int32_t iForPlayer)
{ {
C4Value r = Call(PSF_CalcValue, &C4AulParSet(C4VObj(pInBase), C4VInt(iForPlayer)));
int32_t iValue; int32_t iValue;
if (r != C4VNull)
// value by script? iValue = r.getInt();
if (C4AulScriptFunc *f = Def->Script.SFn_CalcValue)
iValue = f->Exec(this, &C4AulParSet(C4VObj(pInBase), C4VInt(iForPlayer))).getInt();
else else
{ {
// get value of def // get value of def
@ -1822,14 +1821,13 @@ int32_t C4Object::GetValue(C4Object *pInBase, int32_t iForPlayer)
} }
// Con percentage // Con percentage
iValue = iValue * Con / FullCon; iValue = iValue * Con / FullCon;
// value adjustments buy base function // do any adjustments based on where the item is bought
if (pInBase) if (pInBase)
{ {
C4AulFunc *pFn; r = pInBase->Call(PSF_CalcSellValue, &C4AulParSet(C4VObj(this), C4VInt(iValue)));
if ((pFn = pInBase->Def->Script.GetSFunc(PSF_CalcSellValue, AA_PROTECTED))) if (r != C4VNull)
iValue = pFn->Exec(pInBase, &C4AulParSet(C4VObj(this), C4VInt(iValue))).getInt(); iValue = r.getInt();
} }
// Return value
return iValue; return iValue;
} }

View File

@ -117,7 +117,6 @@ bool C4ValueToMatrix(const C4ValueArray& array, StdMeshMatrix* matrix);
#define PSF_UpdateTransferZone "~UpdateTransferZone" #define PSF_UpdateTransferZone "~UpdateTransferZone"
#define PSF_CalcValue "~CalcValue" // C4Object *pInBase, int iForPlayer #define PSF_CalcValue "~CalcValue" // C4Object *pInBase, int iForPlayer
#define PSF_CalcDefValue "~CalcDefValue" // C4Object *pInBase, int iForPlayer #define PSF_CalcDefValue "~CalcDefValue" // C4Object *pInBase, int iForPlayer
#define PSF_SellTo "~SellTo" // int iByPlr
#define PSF_InputCallback "InputCallback" // const char *szText #define PSF_InputCallback "InputCallback" // const char *szText
#define PSF_MenuQueryCancel "~MenuQueryCancel" // int iSelection #define PSF_MenuQueryCancel "~MenuQueryCancel" // int iSelection
#define PSF_IsFulfilled "~IsFulfilled" // int for_plr #define PSF_IsFulfilled "~IsFulfilled" // int for_plr

View File

@ -160,13 +160,15 @@ bool C4DefScriptHost::Load(C4Group & g, const char * f, const char * l, C4LangSt
return r; return r;
} }
void C4DefScriptHost::Clear()
{
if (Def) Def->TimerCall = 0;
C4ScriptHost::Clear();
}
void C4DefScriptHost::AfterLink() void C4DefScriptHost::AfterLink()
{ {
C4AulScript::AfterLink(); C4ScriptHost::AfterLink();
// Search cached functions
SFn_CalcValue = GetSFunc(PSF_CalcValue , AA_PROTECTED);
SFn_SellTo = GetSFunc(PSF_SellTo , AA_PROTECTED);
SFn_ControlTransfer = GetSFunc(PSF_ControlTransfer, AA_PROTECTED);
if (Def && Def->STimerCall[0]) if (Def && Def->STimerCall[0])
{ {
Def->TimerCall = Def->GetFunc(Def->STimerCall); Def->TimerCall = Def->GetFunc(Def->STimerCall);

View File

@ -70,9 +70,9 @@ protected:
class C4DefScriptHost : public C4ScriptHost class C4DefScriptHost : public C4ScriptHost
{ {
public: public:
C4DefScriptHost(C4Def * Def) : C4ScriptHost(), Def(Def) { SFn_CalcValue = SFn_SellTo = SFn_ControlTransfer = NULL; } C4DefScriptHost(C4Def * Def) : C4ScriptHost(), Def(Def) { }
C4Value Call(const char *szFunction, C4Object *pObj=0, C4AulParSet *pPars=0, bool fPrivateCall=false, bool fPassError=false); C4Value Call(const char *szFunction, C4Object *pObj=0, C4AulParSet *pPars=0, bool fPrivateCall=false, bool fPassError=false);
void Clear() { SFn_CalcValue = SFn_SellTo = SFn_ControlTransfer = NULL; C4ScriptHost::Clear(); } void Clear();
bool Delete() { return false; } // do NOT delete this - it's just a class member! bool Delete() { return false; } // do NOT delete this - it's just a class member!
virtual bool Load(C4Group &, const char *, const char *, C4LangStringTable *); virtual bool Load(C4Group &, const char *, const char *, C4LangStringTable *);
@ -80,10 +80,6 @@ public:
protected: protected:
C4Def *Def; // owning def file C4Def *Def; // owning def file
void AfterLink(); // get common funcs void AfterLink(); // get common funcs
public:
C4AulScriptFunc *SFn_CalcValue; // get object value
C4AulScriptFunc *SFn_SellTo; // player par(0) sold the object
C4AulScriptFunc *SFn_ControlTransfer; // object par(0) tries to get to par(1)/par(2)
}; };