From 6682313e87fcf35054582db69a6f37fa00c070ad Mon Sep 17 00:00:00 2001 From: helixhorned Date: Thu, 21 Feb 2013 18:54:07 +0000 Subject: [PATCH] gameexec.c: factor out 2x used code into VM_KillIt. Also, for Lunatic, handle killit from events. git-svn-id: https://svn.eduke32.com/eduke32@3514 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/gameexec.c | 45 ++++++++++++++++--------------- polymer/eduke32/source/gameexec.h | 3 ++- polymer/eduke32/source/premap.c | 2 +- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 70d6017a2..bde3f2296 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -103,18 +103,34 @@ void VM_ScriptInfo(void) #endif } +static void VM_KillIt(int32_t iActor, int32_t iPlayer) +{ + if (iActor >= 0) + { + // if player was set to squish, first stop that... + if (iPlayer >= 0 && g_player[iPlayer].ps->actorsqu == iActor) + g_player[iPlayer].ps->actorsqu = -1; + + A_DeleteSprite(iActor); + } +} + // 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) { #ifdef LUNATIC + int32_t killit; const double t = gethitickms(); // TODO: handling of RETURN gamevar / iReturn / this function's return value if (L_IsInitialized(&g_ElState) && El_HaveEvent(iEventID)) - El_CallEvent(&g_ElState, iEventID, iActor, iPlayer, lDist); -#endif + if (El_CallEvent(&g_ElState, iEventID, iActor, iPlayer, lDist)==1) + VM_KillIt(iActor, iPlayer); + + g_eventTotalMs[iEventID] += gethitickms()-t; + g_eventCalls[iEventID]++; +#else -#if !defined LUNATIC if (apScriptGameEvent[iEventID]) { intptr_t *oinsptr=insptr; @@ -138,13 +154,7 @@ int32_t VM_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lD VM_Execute(1); if (vm.g_flags & VM_KILL) - { - // if player was set to squish, first stop that... - if (vm.g_p >= 0 && g_player[vm.g_p].ps->actorsqu == vm.g_i) - g_player[vm.g_p].ps->actorsqu = -1; - - A_DeleteSprite(vm.g_i); - } + VM_KillIt(iActor, iPlayer); Bmemcpy(&vm, &vm_backup, sizeof(vmstate_t)); insptr = oinsptr; @@ -155,10 +165,6 @@ int32_t VM_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lD } #endif -#ifdef LUNATIC - g_eventTotalMs[iEventID] += gethitickms()-t; - g_eventCalls[iEventID]++; -#endif return iReturn; } @@ -5124,12 +5130,10 @@ finish_qsprintf: } } } -#endif // NORECURSE void A_LoadActor(int32_t iActor) { -#if !defined LUNATIC vm.g_i = iActor; // Sprite ID vm.g_p = -1; // iPlayer; // Player ID vm.g_x = -1; // lDist; // ? @@ -5155,8 +5159,9 @@ void A_LoadActor(int32_t iActor) if (vm.g_flags & VM_KILL) A_DeleteSprite(vm.g_i); -#endif + } +#endif // NORECURSE void A_Execute(int32_t iActor,int32_t iPlayer,int32_t lDist) @@ -5244,11 +5249,7 @@ void A_Execute(int32_t iActor,int32_t iPlayer,int32_t lDist) #endif ) { - // if player was set to squish, first stop that... - if (vm.g_p >= 0 && g_player[vm.g_p].ps->actorsqu == vm.g_i) - g_player[vm.g_p].ps->actorsqu = -1; - - A_DeleteSprite(vm.g_i); + VM_KillIt(iActor, iPlayer); return; } diff --git a/polymer/eduke32/source/gameexec.h b/polymer/eduke32/source/gameexec.h index 2495170c1..671ce3ec1 100644 --- a/polymer/eduke32/source/gameexec.h +++ b/polymer/eduke32/source/gameexec.h @@ -135,6 +135,8 @@ extern vmstate_t vm; extern int32_t g_tw; extern int32_t g_errorLineNum; extern int32_t g_currentEventExec; + +void A_LoadActor(int32_t iActor); #endif void A_Execute(int32_t iActor,int32_t iPlayer,int32_t lDist); @@ -142,7 +144,6 @@ void A_Fall(int32_t iActor); int32_t A_FurthestVisiblePoint(int32_t iActor,spritetype *ts,int32_t *dax,int32_t *day); int32_t A_GetFurthestAngle(int32_t iActor,int32_t angs); void A_GetZLimits(int32_t iActor); -void A_LoadActor(int32_t iActor); int32_t G_GetAngleDelta(int32_t a,int32_t na); void G_RestoreMapState(mapstate_t *save); void G_RestoreMapState(mapstate_t *save); diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index 8aab2a3a9..a58ff95de 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -1142,8 +1142,8 @@ static inline void prelevel(char g) nexti = nextspritestat[i]; #if !defined LUNATIC A_ResetVars(i); -#endif A_LoadActor(i); +#endif VM_OnEvent(EVENT_LOADACTOR, i, -1, -1, 0); if (sprite[i].lotag == UINT16_MAX && (sprite[i].cstat&16)) {