Rename VM_OnEvent to VM_OnEvent_ and add move the checks for whether the event is actually defined or not to a wrapper declared static inline

git-svn-id: https://svn.eduke32.com/eduke32@4673 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2014-10-25 03:33:53 +00:00
parent f15a25a144
commit 62f13fad76
2 changed files with 46 additions and 38 deletions

View file

@ -117,56 +117,49 @@ static void VM_KillIt(int32_t iActor, int32_t iPlayer)
} }
// May recurse, e.g. through EVENT_XXX -> ... -> EVENT_KILLIT // May recurse, e.g. through EVENT_XXX -> ... -> EVENT_KILLIT
int32_t VM_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t iReturn) int32_t VM_OnEvent_(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t iReturn)
{ {
#ifdef LUNATIC #ifdef LUNATIC
if (L_IsInitialized(&g_ElState) && El_HaveEvent(iEventID)) const double t = gethiticks();
{ int32_t ret = El_CallEvent(&g_ElState, iEventID, iActor, iPlayer, lDist, &iReturn);
const double t = gethiticks();
int32_t ret = El_CallEvent(&g_ElState, iEventID, iActor, iPlayer, lDist, &iReturn);
// NOTE: the run times are those of the called event plus any events // NOTE: the run times are those of the called event plus any events
// called by it, *not* "self" time. // called by it, *not* "self" time.
g_eventTotalMs[iEventID] += gethiticks()-t; g_eventTotalMs[iEventID] += gethiticks()-t;
g_eventCalls[iEventID]++; g_eventCalls[iEventID]++;
if (ret == 1) if (ret == 1)
VM_KillIt(iActor, iPlayer); VM_KillIt(iActor, iPlayer);
}
#else #else
intptr_t *oinsptr=insptr;
vmstate_t vm_backup;
if (apScriptGameEvent[iEventID]) vmstate_t tempvm ={ iActor, iPlayer, lDist,
{ iActor >= 0 ? &actor[iActor].t_data[0] : NULL,
intptr_t *oinsptr=insptr; iActor >= 0 ? &sprite[iActor] : NULL,
vmstate_t vm_backup; 0 };
vmstate_t tempvm = { iActor, iPlayer, lDist, int32_t backupReturnVar = aGameVars[g_iReturnVarID].val.lValue;
iActor >= 0 ? &actor[iActor].t_data[0] : NULL, int32_t backupEventExec = g_currentEventExec;
iActor >= 0 ? &sprite[iActor] : NULL,
0 };
int32_t backupReturnVar = aGameVars[g_iReturnVarID].val.lValue; aGameVars[g_iReturnVarID].val.lValue = iReturn;
int32_t backupEventExec = g_currentEventExec; g_currentEventExec = iEventID;
insptr = apScriptGameEvent[iEventID];
aGameVars[g_iReturnVarID].val.lValue = iReturn; Bmemcpy(&vm_backup, &vm, sizeof(vmstate_t));
g_currentEventExec = iEventID; Bmemcpy(&vm, &tempvm, sizeof(vmstate_t));
insptr = apScriptGameEvent[iEventID];
Bmemcpy(&vm_backup, &vm, sizeof(vmstate_t)); VM_Execute(1);
Bmemcpy(&vm, &tempvm, sizeof(vmstate_t));
VM_Execute(1); if (vm.g_flags & VM_KILL)
VM_KillIt(iActor, iPlayer);
if (vm.g_flags & VM_KILL) Bmemcpy(&vm, &vm_backup, sizeof(vmstate_t));
VM_KillIt(iActor, iPlayer); insptr = oinsptr;
Bmemcpy(&vm, &vm_backup, sizeof(vmstate_t)); g_currentEventExec = backupEventExec;
insptr = oinsptr; iReturn = aGameVars[g_iReturnVarID].val.lValue;
aGameVars[g_iReturnVarID].val.lValue = backupReturnVar;
g_currentEventExec = backupEventExec;
iReturn = aGameVars[g_iReturnVarID].val.lValue;
aGameVars[g_iReturnVarID].val.lValue = backupReturnVar;
}
#endif #endif
return iReturn; return iReturn;

View file

@ -152,7 +152,22 @@ void A_GetZLimits(int32_t iActor);
int32_t G_GetAngleDelta(int32_t a,int32_t na); int32_t G_GetAngleDelta(int32_t a,int32_t na);
void G_RestoreMapState(); void G_RestoreMapState();
void G_SaveMapState(); void G_SaveMapState();
int32_t VM_OnEvent(int32_t iEventID,int32_t iActor,int32_t iPlayer,int32_t lDist, int32_t iReturn);
int32_t VM_OnEvent_(int32_t iEventID,int32_t iActor,int32_t iPlayer,int32_t lDist, int32_t iReturn);
static inline int32_t VM_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t iReturn)
{
#ifdef LUNATIC
if (!L_IsInitialized(&g_ElState) || !El_HaveEvent(iEventID))
return iReturn;
#else
if (!apScriptGameEvent[iEventID])
return iReturn;
#endif
return VM_OnEvent_(iEventID, iActor, iPlayer, lDist, iReturn);
}
void VM_ScriptInfo(void); void VM_ScriptInfo(void);
#define CON_ERRPRINTF(Text, ...) do { \ #define CON_ERRPRINTF(Text, ...) do { \