From 3548c50724a842d695a6a0da7d3c6bccd685facd Mon Sep 17 00:00:00 2001 From: terminx Date: Tue, 15 May 2012 23:39:48 +0000 Subject: [PATCH] Fix a potential issue with nested event execution git-svn-id: https://svn.eduke32.com/eduke32@2655 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 2 +- polymer/eduke32/source/gameexec.c | 6 +- polymer/eduke32/source/sector.c | 176 +++++++++++++++--------------- polymer/eduke32/source/sector.h | 2 +- 4 files changed, 94 insertions(+), 92 deletions(-) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index af068d084..b66a209cc 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -10895,7 +10895,7 @@ int32_t G_DoMoveThings(void) if (sprite[g_player[i].ps->i].pal != 1) sprite[g_player[i].ps->i].pal = g_player[i].pcolor; - G_HandleSharedKeys(i); + P_HandleSharedKeys(i); if (ud.pause_on == 0) { diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 1624c183a..cc26a8e80 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -110,6 +110,9 @@ void VM_OnEvent(register int32_t iEventID, register int32_t iActor, register int iActor >= 0 ? &actor[iActor].t_data[0] : NULL, iActor >= 0 ? &sprite[iActor] : NULL, 0 }; + + int32_t backupReturnVar = aGameVars[g_iReturnVarID].val.lValue; + int32_t backupEventExec = g_currentEventExec; g_currentEventExec = iEventID; insptr = apScriptGameEvent[iEventID]; @@ -131,7 +134,8 @@ void VM_OnEvent(register int32_t iEventID, register int32_t iActor, register int Bmemcpy(&vm, &vm_backup, sizeof(vmstate_t)); insptr = oinsptr; - g_currentEventExec = -1; + g_currentEventExec = backupEventExec; + aGameVars[g_iReturnVarID].val.lValue = backupReturnVar; } } diff --git a/polymer/eduke32/source/sector.c b/polymer/eduke32/source/sector.c index d05c118cf..11af4ac9d 100644 --- a/polymer/eduke32/source/sector.c +++ b/polymer/eduke32/source/sector.c @@ -2468,7 +2468,7 @@ void allignwarpelevators(void) } } -void G_HandleSharedKeys(int32_t snum) +void P_HandleSharedKeys(int32_t snum) { int32_t i, k = 0, dainv; uint32_t sb_snum = g_player[snum].sync->bits, j; @@ -2618,104 +2618,102 @@ void G_HandleSharedKeys(int32_t snum) return; // is there significance to returning? } if (p->refresh_inventory) - { sb_snum |= BIT(SK_INV_LEFT); // emulate move left... - } - if (p->newowner == -1) - if (TEST_SYNC_KEY(sb_snum, SK_INV_LEFT) || TEST_SYNC_KEY(sb_snum, SK_INV_RIGHT)) - { - p->invdisptime = GAMETICSPERSEC*2; - if (TEST_SYNC_KEY(sb_snum, SK_INV_RIGHT)) k = 1; - else k = 0; + if (p->newowner == -1 && (TEST_SYNC_KEY(sb_snum, SK_INV_LEFT) || TEST_SYNC_KEY(sb_snum, SK_INV_RIGHT))) + { + p->invdisptime = GAMETICSPERSEC*2; - if (p->refresh_inventory) p->refresh_inventory = 0; - dainv = p->inven_icon; + if (TEST_SYNC_KEY(sb_snum, SK_INV_RIGHT)) k = 1; + else k = 0; - i = 0; + if (p->refresh_inventory) p->refresh_inventory = 0; + dainv = p->inven_icon; + + i = 0; CHECKINV1: - if (i < 9) - { - i++; + if (i < 9) + { + i++; - switch (dainv) - { - case 4: - if (p->inv_amount[GET_JETPACK] > 0 && i > 1) - break; - if (k) dainv++; - else dainv--; - goto CHECKINV1; - case 6: - if (p->inv_amount[GET_SCUBA] > 0 && i > 1) - break; - if (k) dainv++; - else dainv--; - goto CHECKINV1; - case 2: - if (p->inv_amount[GET_STEROIDS] > 0 && i > 1) - break; - if (k) dainv++; - else dainv--; - goto CHECKINV1; - case 3: - if (p->inv_amount[GET_HOLODUKE] > 0 && i > 1) - break; - if (k) dainv++; - else dainv--; - goto CHECKINV1; - case 0: - case 1: - if (p->inv_amount[GET_FIRSTAID] > 0 && i > 1) - break; - if (k) dainv = 2; - else dainv = 7; - goto CHECKINV1; - case 5: - if (p->inv_amount[GET_HEATS] > 0 && i > 1) - break; - if (k) dainv++; - else dainv--; - goto CHECKINV1; - case 7: - if (p->inv_amount[GET_BOOTS] > 0 && i > 1) - break; - if (k) dainv = 1; - else dainv = 6; - goto CHECKINV1; - } - } - else dainv = 0; - - if (TEST_SYNC_KEY(sb_snum, SK_INV_LEFT)) // Inventory_Left + switch (dainv) { - /*Gv_SetVar(g_iReturnVarID,dainv,g_player[snum].ps->i,snum);*/ - aGameVars[g_iReturnVarID].val.lValue = dainv; - VM_OnEvent(EVENT_INVENTORYLEFT,g_player[snum].ps->i,snum, -1); - dainv=aGameVars[g_iReturnVarID].val.lValue; - } - else if (TEST_SYNC_KEY(sb_snum, SK_INV_RIGHT)) // Inventory_Right - { - /*Gv_SetVar(g_iReturnVarID,dainv,g_player[snum].ps->i,snum);*/ - aGameVars[g_iReturnVarID].val.lValue = dainv; - VM_OnEvent(EVENT_INVENTORYRIGHT,g_player[snum].ps->i,snum, -1); - dainv=aGameVars[g_iReturnVarID].val.lValue; - } - - if (dainv >= 1) - { - p->inven_icon = dainv; - - if (dainv || p->inv_amount[GET_FIRSTAID]) - { - static const int32_t i[8] = { QUOTE_MEDKIT, QUOTE_STEROIDS, QUOTE_HOLODUKE, - QUOTE_JETPACK, QUOTE_NVG, QUOTE_SCUBA, QUOTE_BOOTS, 0 }; - if (dainv>=1 && dainv<=9) - P_DoQuote(i[dainv-1], p); - } + case 4: + if (p->inv_amount[GET_JETPACK] > 0 && i > 1) + break; + if (k) dainv++; + else dainv--; + goto CHECKINV1; + case 6: + if (p->inv_amount[GET_SCUBA] > 0 && i > 1) + break; + if (k) dainv++; + else dainv--; + goto CHECKINV1; + case 2: + if (p->inv_amount[GET_STEROIDS] > 0 && i > 1) + break; + if (k) dainv++; + else dainv--; + goto CHECKINV1; + case 3: + if (p->inv_amount[GET_HOLODUKE] > 0 && i > 1) + break; + if (k) dainv++; + else dainv--; + goto CHECKINV1; + case 0: + case 1: + if (p->inv_amount[GET_FIRSTAID] > 0 && i > 1) + break; + if (k) dainv = 2; + else dainv = 7; + goto CHECKINV1; + case 5: + if (p->inv_amount[GET_HEATS] > 0 && i > 1) + break; + if (k) dainv++; + else dainv--; + goto CHECKINV1; + case 7: + if (p->inv_amount[GET_BOOTS] > 0 && i > 1) + break; + if (k) dainv = 1; + else dainv = 6; + goto CHECKINV1; } } + else dainv = 0; + + if (TEST_SYNC_KEY(sb_snum, SK_INV_LEFT)) // Inventory_Left + { + /*Gv_SetVar(g_iReturnVarID,dainv,g_player[snum].ps->i,snum);*/ + aGameVars[g_iReturnVarID].val.lValue = dainv; + VM_OnEvent(EVENT_INVENTORYLEFT,g_player[snum].ps->i,snum, -1); + dainv=aGameVars[g_iReturnVarID].val.lValue; + } + else if (TEST_SYNC_KEY(sb_snum, SK_INV_RIGHT)) // Inventory_Right + { + /*Gv_SetVar(g_iReturnVarID,dainv,g_player[snum].ps->i,snum);*/ + aGameVars[g_iReturnVarID].val.lValue = dainv; + VM_OnEvent(EVENT_INVENTORYRIGHT,g_player[snum].ps->i,snum, -1); + dainv=aGameVars[g_iReturnVarID].val.lValue; + } + + if (dainv >= 1) + { + p->inven_icon = dainv; + + if (dainv || p->inv_amount[GET_FIRSTAID]) + { + static const int32_t i[8] = { QUOTE_MEDKIT, QUOTE_STEROIDS, QUOTE_HOLODUKE, + QUOTE_JETPACK, QUOTE_NVG, QUOTE_SCUBA, QUOTE_BOOTS, 0 }; + if (dainv>=1 && dainv<=9) + P_DoQuote(i[dainv-1], p); + } + } + } j = ((sb_snum&(15<>SK_WEAPON_BITS) - 1; diff --git a/polymer/eduke32/source/sector.h b/polymer/eduke32/source/sector.h index a9256cad6..96e3db53a 100644 --- a/polymer/eduke32/source/sector.h +++ b/polymer/eduke32/source/sector.h @@ -111,12 +111,12 @@ int32_t G_ActivateWarpElevators(int32_t s,int32_t d); int32_t G_CheckActivatorMotion(int32_t lotag); extern inline int32_t G_CheckPlayerInSector(int32_t sect); void G_DoSectorAnimations(void); -void G_HandleSharedKeys(int32_t snum); void G_OperateActivators(int32_t low,int32_t snum); void G_OperateForceFields(int32_t s,int32_t low); void G_OperateMasterSwitches(int32_t low); void G_OperateRespawns(int32_t low); void G_OperateSectors(int32_t sn,int32_t ii); +void P_HandleSharedKeys(int32_t snum); int32_t GetAnimationGoal(const int32_t *animptr); int32_t isanearoperator(int32_t lotag); int32_t isanunderoperator(int32_t lotag);