diff --git a/polymer/eduke32/source/actors.c b/polymer/eduke32/source/actors.c index 73fa335e1..72ccdfbe5 100644 --- a/polymer/eduke32/source/actors.c +++ b/polymer/eduke32/source/actors.c @@ -592,38 +592,35 @@ void A_DeleteSprite(int32_t s) { if (EDUKE32_PREDICT_FALSE(block_deletesprite)) { - OSD_Printf(OSD_ERROR "A_DeleteSprite(): tried to remove sprite %d in EVENT_EGS\n",s); + OSD_Printf(OSD_ERROR "A_DeleteSprite(): tried to remove sprite %d in EVENT_EGS\n", s); return; } if (VM_HaveEvent(EVENT_KILLIT)) { - int32_t p, pl=A_FindPlayer(&sprite[s],&p); + int32_t p, pl = A_FindPlayer(&sprite[s], &p); - if (VM_OnEvent_(EVENT_KILLIT, s, pl, p, 0)) + if (VM_OnEventWithDist_(EVENT_KILLIT, s, pl, p)) return; } #ifdef POLYMER - if (getrendermode() == REND_POLYMER && actor[s].lightptr != NULL) + if (actor[s].lightptr != NULL && getrendermode() == REND_POLYMER) A_DeleteLight(s); #endif - if (sprite[s].picnum == MUSICANDSFX && actor[s].t_data[0]==1) - { - // AMBIENT_SFX_PLAYING + // AMBIENT_SFX_PLAYING + if (sprite[s].picnum == MUSICANDSFX && actor[s].t_data[0] == 1) S_StopEnvSound(sprite[s].lotag, s); - } // NetAlloc if (Net_IsRelevantSprite(s)) { Net_DeleteSprite(s); + return; } - else - { - deletesprite(s); - } + + deletesprite(s); } void A_AddToDeleteQueue(int32_t i) @@ -727,9 +724,10 @@ LUNATIC_EXTERN int32_t G_ToggleWallInterpolation(int32_t w, int32_t doset) } } -static void Sect_ToggleInterpolation(int32_t sectnum, int32_t doset) +void Sect_ToggleInterpolation(int sectnum, int doset) { - int32_t k, j = sector[sectnum].wallptr, endwall = j+sector[sectnum].wallnum; + int k, j = sector[sectnum].wallptr; + const int endwall = sector[sectnum].wallptr + sector[sectnum].wallnum; for (; jx += (s->xvel * (sintable[(s->ang + 512) & 2047])) >> 14; + s->y += (s->xvel * (sintable[s->ang & 2047])) >> 14; - s->x += (s->xvel*(sintable[(s->ang+512)&2047]))>>14; - s->y += (s->xvel*(sintable[s->ang&2047]))>>14; + const int endwall = sector[s->sectnum].wallptr + sector[s->sectnum].wallnum; + for (i = sector[s->sectnum].wallptr; i < endwall; i++) { - int32_t x = sector[s->sectnum].wallptr, endwall = x+sector[s->sectnum].wallnum; + rotatepoint(0, 0, msx[j], msy[j], k & 2047, &tx, &ty); + dragpoint(i, s->x + tx, s->y + ty, 0); - for (; xx+tx,s->y+ty,0); - - j++; - } + j++; } } #if !defined LUNATIC // NOTE: T5 is AC_ACTION_ID -# define LIGHTRAD_PICOFS (T5 ? *(script+T5) + (*(script+T5+2))*AC_CURFRAME(actor[i].t_data) : 0) +# define LIGHTRAD_PICOFS (T5 ? *(script + T5) + (*(script + T5 + 2)) * AC_CURFRAME(actor[i].t_data) : 0) #else // startframe + viewtype*[cyclic counter] -# define LIGHTRAD_PICOFS (actor[i].ac.startframe + actor[i].ac.viewtype*AC_CURFRAME(actor[i].t_data)) +# define LIGHTRAD_PICOFS (actor[i].ac.startframe + actor[i].ac.viewtype * AC_CURFRAME(actor[i].t_data)) #endif // this is the same crap as in game.c's tspr manipulation. puke. // XXX: may access tilesizy out-of-bounds by bad user code. #define LIGHTRAD (s->yrepeat * tilesiz[s->picnum + LIGHTRAD_PICOFS].y) -#define LIGHTRAD2 (((s->yrepeat) + (rand()%(s->yrepeat>>2))) * tilesiz[s->picnum + LIGHTRAD_PICOFS].y) +#define LIGHTRAD2 (((s->yrepeat) + (rand() % (s->yrepeat >> 2))) * tilesiz[s->picnum + LIGHTRAD_PICOFS].y) void G_AddGameLight(int32_t radius, int32_t srcsprite, int32_t zoffset, int32_t range, int32_t color, int32_t priority) { @@ -817,7 +802,7 @@ void G_AddGameLight(int32_t radius, int32_t srcsprite, int32_t zoffset, int32_t if (actor[srcsprite].lightptr == NULL) { -#pragma pack(push,1) +#pragma pack(push, 1) _prlight mylight; #pragma pack(pop) Bmemset(&mylight, 0, sizeof(mylight)); @@ -825,10 +810,10 @@ void G_AddGameLight(int32_t radius, int32_t srcsprite, int32_t zoffset, int32_t mylight.sector = s->sectnum; mylight.x = s->x; mylight.y = s->y; - mylight.z = s->z-zoffset; - mylight.color[0] = color&255; - mylight.color[1] = (color>>8)&255; - mylight.color[2] = (color>>16)&255; + mylight.z = s->z - zoffset; + mylight.color[0] = color & 255; + mylight.color[1] = (color >> 8) & 255; + mylight.color[2] = (color >> 16) & 255; mylight.radius = radius; actor[srcsprite].lightmaxrange = mylight.range = range; @@ -846,12 +831,11 @@ void G_AddGameLight(int32_t radius, int32_t srcsprite, int32_t zoffset, int32_t s->z -= zoffset; - if (range < actor[srcsprite].lightmaxrange>>1) + if (range> 1) actor[srcsprite].lightmaxrange = 0; - if (range > actor[srcsprite].lightmaxrange || - priority != actor[srcsprite].lightptr->priority || - Bmemcmp(&sprite[srcsprite], actor[srcsprite].lightptr, sizeof(int32_t) * 3)) + if (range > actor[srcsprite].lightmaxrange || priority != actor[srcsprite].lightptr->priority || + Bmemcmp(&sprite[srcsprite], actor[srcsprite].lightptr, sizeof(int32_t) * 3)) { if (range > actor[srcsprite].lightmaxrange) actor[srcsprite].lightmaxrange = range; @@ -863,9 +847,9 @@ void G_AddGameLight(int32_t radius, int32_t srcsprite, int32_t zoffset, int32_t actor[srcsprite].lightptr->priority = priority; actor[srcsprite].lightptr->range = range; - actor[srcsprite].lightptr->color[0] = color&255; - actor[srcsprite].lightptr->color[1] = (color>>8)&255; - actor[srcsprite].lightptr->color[2] = (color>>16)&255; + actor[srcsprite].lightptr->color[0] = color & 255; + actor[srcsprite].lightptr->color[1] = (color >> 8) & 255; + actor[srcsprite].lightptr->color[2] = (color >> 16) & 255; s->z += zoffset; @@ -986,21 +970,19 @@ ACTOR_STATIC void G_MoveZombieActors(void) } // stupid name, but it's what the function does. -static inline int32_t G_FindExplosionInSector(int32_t sectnum) +FORCE_INLINE int G_FindExplosionInSector(int sectnum) { - int32_t i; - - for (SPRITES_OF(STAT_MISC, i)) + for (int SPRITES_OF(STAT_MISC, i)) if (PN == EXPLOSION2 && sectnum == SECT) return i; return -1; } -static void P_Nudge(int32_t p, int32_t sn, int32_t shl) +FORCE_INLINE void P_Nudge(int p, int sn, int shl) { - g_player[p].ps->vel.x += actor[sn].extra*(sintable[(actor[sn].ang+512)&2047])<vel.y += actor[sn].extra*(sintable[actor[sn].ang&2047])<vel.x += actor[sn].extra * (sintable[(actor[sn].ang + 512) & 2047]) << shl; + g_player[p].ps->vel.y += actor[sn].extra * (sintable[actor[sn].ang & 2047]) << shl; } int32_t A_IncurDamage(int32_t sn) @@ -1017,9 +999,10 @@ int32_t A_IncurDamage(int32_t sn) if (targ->picnum == APLAYER) { - int32_t p = P_GetP(targ); + const int p = P_GetP(targ); - if (ud.god && dmg->picnum != SHRINKSPARK) return -1; + if (ud.god && dmg->picnum != SHRINKSPARK) + return -1; if (dmg->owner >= 0 && ud.ffire == 0 && sprite[dmg->owner].picnum == APLAYER && (GametypeFlags[ud.coop] & GAMETYPE_PLAYERSFRIENDLY || @@ -1044,30 +1027,31 @@ int32_t A_IncurDamage(int32_t sn) switch (DYNAMICTILEMAP(dmg->picnum)) { - case RADIUSEXPLOSION__STATIC: - case RPG__STATIC: - case HYDRENT__STATIC: - case HEAVYHBOMB__STATIC: - case SEENINE__STATIC: - case OOZFILTER__STATIC: - case EXPLODINGBARREL__STATIC: - P_Nudge(p, sn, 2); - break; - - default: - if (A_CheckSpriteTileFlags(dmg->picnum, SFLAG_PROJECTILE) && (SpriteProjectile[sn].workslike & PROJECTILE_RPG)) + case RADIUSEXPLOSION__STATIC: + case RPG__STATIC: + case HYDRENT__STATIC: + case HEAVYHBOMB__STATIC: + case SEENINE__STATIC: + case OOZFILTER__STATIC: + case EXPLODINGBARREL__STATIC: P_Nudge(p, sn, 2); - else P_Nudge(p, sn, 1); - break; + break; + + default: + if (A_CheckSpriteTileFlags(dmg->picnum, SFLAG_PROJECTILE) && + (SpriteProjectile[sn].workslike & PROJECTILE_RPG)) + P_Nudge(p, sn, 2); + else + P_Nudge(p, sn, 1); + break; } dmg->extra = -1; return dmg->picnum; } - if (dmg->extra == 0) - if (dmg->picnum == SHRINKSPARK && targ->xrepeat < 24) - return -1; + if (dmg->extra == 0 && dmg->picnum == SHRINKSPARK && targ->xrepeat < 24) + return -1; targ->extra -= dmg->extra; @@ -1075,6 +1059,7 @@ int32_t A_IncurDamage(int32_t sn) targ->owner = dmg->owner; dmg->extra = -1; + return dmg->picnum; } @@ -8278,7 +8263,7 @@ void G_MoveWorld(void) } pl = A_FindPlayer(&sprite[i], &p); - VM_OnEvent_(EVENT_PREGAME, i, pl, p, 0); + VM_OnEventWithDist_(EVENT_PREGAME, i, pl, p); i = j; } @@ -8330,7 +8315,7 @@ void G_MoveWorld(void) j = nextspritestat[i]; pl = A_FindPlayer(&sprite[i], &p); - VM_OnEvent_(EVENT_GAME, i, pl, p, 0); + VM_OnEventWithDist_(EVENT_GAME, i, pl, p); i = j; } diff --git a/polymer/eduke32/source/actors.h b/polymer/eduke32/source/actors.h index 317772b54..01256439e 100644 --- a/polymer/eduke32/source/actors.h +++ b/polymer/eduke32/source/actors.h @@ -326,8 +326,9 @@ int32_t G_SetInterpolation(int32_t *posptr); void G_StopInterpolation(int32_t *posptr); // PK 20110701: changed input argument: int32_t i (== sprite, whose sectnum...) --> sectnum directly -void Sect_ClearInterpolation(int32_t sectnum); -void Sect_SetInterpolation(int32_t sectnum); +void Sect_ToggleInterpolation(int sectnum, int doset); +FORCE_INLINE void Sect_ClearInterpolation(int sectnum) { Sect_ToggleInterpolation(sectnum, 0); } +FORCE_INLINE void Sect_SetInterpolation(int sectnum) { Sect_ToggleInterpolation(sectnum, 1); } #include "actors_inline.h" diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index daa269dfd..bbf5bc04a 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -3676,7 +3676,7 @@ void G_DisplayRest(int32_t smoothratio) if (pp->invdisptime > 0) G_DrawInventory(pp); - if (VM_OnEvent(EVENT_DISPLAYSBAR, g_player[screenpeek].ps->i, screenpeek, -1, 0) == 0) + if (VM_OnEvent(EVENT_DISPLAYSBAR, g_player[screenpeek].ps->i, screenpeek) == 0) G_DrawStatusBar(screenpeek); #ifdef SPLITSCREEN_MOD_HACKS @@ -3740,13 +3740,13 @@ void G_DisplayRest(int32_t smoothratio) if (VM_HaveEvent(EVENT_DISPLAYREST)) { int32_t vr=viewingrange, asp=yxaspect; - VM_OnEvent_(EVENT_DISPLAYREST, g_player[screenpeek].ps->i, screenpeek, -1, 0); + VM_OnEvent_(EVENT_DISPLAYREST, g_player[screenpeek].ps->i, screenpeek); setaspect(vr, asp); } if (g_player[myconnectindex].ps->newowner == -1 && ud.overhead_on == 0 && ud.crosshair && ud.camerasprite == -1) { - int32_t a = VM_OnEvent(EVENT_DISPLAYCROSSHAIR, g_player[screenpeek].ps->i, screenpeek, -1, 0); + int32_t a = VM_OnEvent(EVENT_DISPLAYCROSSHAIR, g_player[screenpeek].ps->i, screenpeek); if (a == 0 || a > 1) { @@ -4010,7 +4010,7 @@ void G_DrawBackground(void) // when not rendering a game, fullscreen wipe // Gv_SetVar(g_iReturnVarID,tilesizx[MENUTILE]==320&&tilesizy[MENUTILE]==200?MENUTILE:BIGHOLE, -1, -1); - bgtile = VM_OnEvent(EVENT_GETMENUTILE, -1, myconnectindex, -1, bgtile); + bgtile = VM_OnEventWithReturn(EVENT_GETMENUTILE, -1, myconnectindex, bgtile); // MENU_TILE: is the menu tile tileable? #if !defined LUNATIC if (Gv_GetVarByLabel("MENU_TILE", !fstilep, -1, -1)) @@ -4670,7 +4670,7 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) dont_draw = 0; // NOTE: might be rendering off-screen here, so CON commands that draw stuff // like showview must cope with that situation or bail out! - dont_draw = VM_OnEvent(EVENT_DISPLAYROOMS, g_player[screenpeek].ps->i, screenpeek, -1, 0); + dont_draw = VM_OnEvent(EVENT_DISPLAYROOMS, g_player[screenpeek].ps->i, screenpeek); CAMERA(horiz) = clamp(CAMERA(horiz), HORIZ_MIN, HORIZ_MAX); @@ -5035,7 +5035,7 @@ int32_t A_InsertSprite(int32_t whatsect,int32_t s_x,int32_t s_y,int32_t s_z,int3 int32_t pl=A_FindPlayer(s, &p); block_deletesprite++; - VM_OnEvent_(EVENT_EGS, i, pl, p, 0); + VM_OnEventWithDist_(EVENT_EGS, i, pl, p); block_deletesprite--; } @@ -7035,7 +7035,7 @@ SPAWN_END: { int32_t p; int32_t pl=A_FindPlayer(&sprite[i],&p); - VM_OnEvent_(EVENT_SPAWN,i, pl, p, 0); + VM_OnEventWithDist_(EVENT_SPAWN,i, pl, p); } return i; @@ -7165,7 +7165,7 @@ static void G_DoEventAnimSprites(int32_t j) spriteext[ow].tspr = &tsprite[j]; // XXX: wouldn't screenpeek be more meaningful as current player? - VM_OnEvent_(EVENT_ANIMATESPRITES, ow, myconnectindex, -1, 0); + VM_OnEvent_(EVENT_ANIMATESPRITES, ow, myconnectindex); spriteext[ow].tspr = NULL; } @@ -8023,7 +8023,7 @@ skip: } #ifdef LUNATIC - VM_OnEvent(EVENT_ANIMATEALLSPRITES, -1, -1, -1, 0); + VM_OnEvent(EVENT_ANIMATEALLSPRITES, -1, -1); #endif #ifdef DEBUGGINGAIDS g_spriteStat.numonscreen = spritesortcnt; @@ -8065,7 +8065,7 @@ char CheatStrings[][MAXCHEATLEN] = static void doinvcheat(int32_t invidx, int32_t defaultnum, int32_t event) { - defaultnum = VM_OnEvent(event, g_player[myconnectindex].ps->i, myconnectindex, -1, defaultnum); + defaultnum = VM_OnEventWithReturn(event, g_player[myconnectindex].ps->i, myconnectindex, defaultnum); if (defaultnum >= 0) g_player[myconnectindex].ps->inv_amount[invidx] = defaultnum; } @@ -8156,7 +8156,7 @@ GAME_STATIC void G_DoCheats(void) FOUNDCHEAT: - i = VM_OnEvent(EVENT_ACTIVATECHEAT, g_player[myconnectindex].ps->i, myconnectindex, -1, k); + i = VM_OnEventWithReturn(EVENT_ACTIVATECHEAT, g_player[myconnectindex].ps->i, myconnectindex, k); if (k != CHEAT_COMEGETSOME) // Users are not allowed to interfere with TX's debugging cheat. k = i; @@ -10603,7 +10603,7 @@ static void G_DisplayLogo(void) #ifdef LUNATIC g_elEventError = 0; #endif - VM_OnEvent(EVENT_LOGO, -1, screenpeek, -1, 0); + VM_OnEvent(EVENT_LOGO, -1, screenpeek); G_HandleAsync(); if (g_restorePalette) @@ -10755,7 +10755,7 @@ static void G_CompileScripts(void) Bmemset(sector, 0, MAXSECTORS*sizeof(sectortype)); Bmemset(wall, 0, MAXWALLS*sizeof(walltype)); - VM_OnEvent(EVENT_INIT, -1, -1, -1, 0); + VM_OnEvent(EVENT_INIT, -1, -1); pathsearchmode = psm; #endif } @@ -10904,7 +10904,7 @@ static void G_Startup(void) #ifdef LUNATIC // NOTE: This is only effective for CON-defined EVENT_INIT. See EVENT_INIT // not in defs.ilua. - VM_OnEvent(EVENT_INIT, -1, -1, -1, 0); + VM_OnEvent(EVENT_INIT, -1, -1); #endif if (g_netServer || ud.multimode > 1) G_CheckGametype(); @@ -12827,7 +12827,7 @@ void G_BonusScreen(int32_t bonusonly) else break; - VM_OnEvent(EVENT_DISPLAYBONUSSCREEN, g_player[screenpeek].ps->i, screenpeek, -1, 0); + VM_OnEvent(EVENT_DISPLAYBONUSSCREEN, g_player[screenpeek].ps->i, screenpeek); nextpage(); } while (1); diff --git a/polymer/eduke32/source/gamedef.h b/polymer/eduke32/source/gamedef.h index 98cba3d1c..862a6c0d8 100644 --- a/polymer/eduke32/source/gamedef.h +++ b/polymer/eduke32/source/gamedef.h @@ -76,9 +76,7 @@ extern intptr_t *g_scriptPtr; typedef struct { const char *name; - int32_t lId; - int32_t flags; - int32_t maxParm2; + int lId, flags, maxParm2; } memberlabel_t; extern const memberlabel_t SectorLabels[]; @@ -96,10 +94,10 @@ void C_InitQuotes(void); void C_InitProjectiles(void); typedef struct { - int32_t g_i, g_p, g_x; + int g_i, g_p, g_x; int32_t *g_t; spritetype *g_sp; - int32_t g_flags; + int g_flags; } vmstate_t; extern vmstate_t vm; diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 228c1e48c..0d664371e 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -68,12 +68,12 @@ GAMEEXEC_STATIC void VM_Execute(int32_t loop); #endif #define VM_CONDITIONAL(xxx) \ - { \ - if ((xxx) || ((insptr = (intptr_t *)*(insptr + 1)) && (((*insptr) & 0xfff) == CON_ELSE))) \ - { \ - insptr += 2; \ - VM_Execute(0); \ - } \ + { \ + if ((xxx) || ((insptr = (intptr_t *)*(insptr + 1)) && (((*insptr) & 0xfff) == CON_ELSE))) \ + { \ + insptr += 2; \ + VM_Execute(0); \ + } \ } void VM_ScriptInfo(void) @@ -110,7 +110,7 @@ void VM_ScriptInfo(void) #endif } -static void VM_KillIt(int32_t iActor, int32_t iPlayer) +static void VM_DeleteSprite(int32_t iActor, int32_t iPlayer) { if (EDUKE32_PREDICT_FALSE((unsigned) iActor >= MAXSPRITES)) return; @@ -123,9 +123,9 @@ static void VM_KillIt(int32_t iActor, int32_t iPlayer) } // 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 +FORCE_INLINE int32_t VM_EventCommon_(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t iReturn) +{ const double t = gethiticks(); int32_t ret = El_CallEvent(&g_ElState, iEventID, iActor, iPlayer, lDist, &iReturn); @@ -135,54 +135,89 @@ int32_t VM_OnEvent_(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t l g_eventCalls[iEventID]++; if (ret == 1) - VM_KillIt(iActor, iPlayer); + VM_DeleteSprite(iActor, iPlayer); + + return iReturn; +} #else +FORCE_INLINE int32_t VM_EventCommon_(const int32_t iEventID, const int32_t iActor, const int32_t iPlayer, + const int32_t lDist, int32_t iReturn) +{ + // this is initialized first thing because iActor, iPlayer, lDist, etc are already right there on the stack + // from the function call + const vmstate_t tempvm = { iActor, iPlayer, lDist, &actor[(unsigned)iActor].t_data[0], + &sprite[(unsigned)iActor], 0 }; + + // since we're targeting C99 and C++ now, we can interweave these to avoid + // having to load addresses for things twice + // for example, because we are loading backupReturnVar with the value of + // aGameVars[g_iReturnVarID].val.lValue, the compiler can avoid having to + // reload the address of aGameVars[g_iReturnVarID].val.lValue in order to + // set it to the value of iReturn (...which should still be on the stack!) + + const int32_t backupReturnVar = aGameVars[g_iReturnVarID].val.lValue; + aGameVars[g_iReturnVarID].val.lValue = iReturn; + + const int32_t backupEventExec = g_currentEventExec; + g_currentEventExec = iEventID; + + intptr_t *oinsptr = insptr; + insptr = apScriptGameEvent[iEventID]; + const vmstate_t vm_backup = vm; - vmstate_t tempvm = { - iActor, iPlayer, lDist, - NULL, NULL, // to be set in a moment - 0 - }; + vm = tempvm; - int32_t backupReturnVar = aGameVars[g_iReturnVarID].val.lValue; - int32_t backupEventExec = g_currentEventExec; - intptr_t *oinsptr=insptr; - - if ((unsigned)iActor >= (unsigned)Numsprites) + // check tempvm instead of vm... this way, we are not actually loading + // FROM vm anywhere until VM_Execute() is called + if ((unsigned)tempvm.g_i >= MAXSPRITES) { static spritetype dummy_sprite; static int32_t dummy_t[ARRAY_SIZE(actor[0].t_data)]; - tempvm.g_sp = &dummy_sprite; - tempvm.g_t = dummy_t; + vm.g_sp = &dummy_sprite; + vm.g_t = dummy_t; } - else - { - tempvm.g_sp = &sprite[iActor]; - tempvm.g_t = &actor[iActor].t_data[0]; - } - - vm = tempvm; - - aGameVars[g_iReturnVarID].val.lValue = iReturn; - g_currentEventExec = iEventID; - insptr = apScriptGameEvent[iEventID]; VM_Execute(1); if (vm.g_flags & VM_KILL) - VM_KillIt(iActor, iPlayer); + VM_DeleteSprite(vm.g_i, vm.g_p); + // this needs to happen after VM_DeleteSprite() because VM_DeleteSprite() + // can trigger additional events vm = vm_backup; insptr = oinsptr; - g_currentEventExec = backupEventExec; iReturn = aGameVars[g_iReturnVarID].val.lValue; aGameVars[g_iReturnVarID].val.lValue = backupReturnVar; -#endif return iReturn; } +#endif + +// the idea here is that the compiler inlines the call to VM_EventCommon_() and gives us a set of full functions +// which are not only optimized further based on lDist or iReturn (or both) having values known at compile time, +// but are called faster due to having less parameters + +int32_t VM_OnEventWithBoth_(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t iReturn) +{ + return VM_EventCommon_(iEventID, iActor, iPlayer, lDist, iReturn); +} + +int32_t VM_OnEventWithReturn_(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t iReturn) +{ + return VM_EventCommon_(iEventID, iActor, iPlayer, -1, iReturn); +} + +int32_t VM_OnEventWithDist_(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist) +{ + return VM_EventCommon_(iEventID, iActor, iPlayer, lDist, 0); +} + +int32_t VM_OnEvent_(int32_t iEventID, int32_t iActor, int32_t iPlayer) +{ + return VM_EventCommon_(iEventID, iActor, iPlayer, -1, 0); +} static int32_t VM_CheckSquished(void) { @@ -562,8 +597,11 @@ static void VM_FacePlayer(int32_t shr) ////////// TROR get*zofslope ////////// // These rather belong into the engine. -static int32_t yax_getceilzofslope(int16_t sectnum, int32_t dax, int32_t day) +static int32_t VM_GetCeilZOfSlope(void) { + const int dax = vm.g_sp->x, day = vm.g_sp->y; + const int sectnum = vm.g_sp->sectnum; + #ifdef YAX_ENABLE if ((sector[sectnum].ceilingstat&512)==0) { @@ -575,8 +613,11 @@ static int32_t yax_getceilzofslope(int16_t sectnum, int32_t dax, int32_t day) return getceilzofslope(sectnum, dax, day); } -static int32_t yax_getflorzofslope(int16_t sectnum, int32_t dax, int32_t day) +static int32_t VM_GetFlorZOfSlope(void) { + const int dax = vm.g_sp->x, day = vm.g_sp->y; + const int sectnum = vm.g_sp->sectnum; + #ifdef YAX_ENABLE if ((sector[sectnum].floorstat&512)==0) { @@ -600,11 +641,10 @@ GAMEEXEC_STATIC void VM_Move(void) const uint16_t *movflagsptr = &AC_MOVFLAGS(vm.g_sp, &actor[vm.g_i]); const int32_t movflags = /*(*movflagsptr==-1) ? 0 :*/ *movflagsptr; const int32_t deadflag = (A_CheckEnemySprite(vm.g_sp) && vm.g_sp->extra <= 0); - int32_t badguyp, angdif; + int32_t badguyp; AC_COUNT(vm.g_t)++; - // If the move ID is zero, or the movflags are 0 if (AC_MOVE_ID(vm.g_t) == 0 || movflags == 0) { if (deadflag || (actor[vm.g_i].bpos.x != vm.g_sp->x) || (actor[vm.g_i].bpos.y != vm.g_sp->y)) @@ -675,7 +715,8 @@ dead: if (vm.g_sp->xvel || vm.g_sp->zvel) { - int32_t daxvel; + int32_t daxvel = vm.g_sp->xvel; + int32_t angdif = vm.g_sp->ang; if (badguyp && vm.g_sp->picnum != ROTATEGUN) { @@ -686,14 +727,14 @@ dead: int32_t l; // NOTE: COMMANDER updates both actor[].floorz and // .ceilingz regardless of its zvel. - actor[vm.g_i].floorz = l = yax_getflorzofslope(vm.g_sp->sectnum,vm.g_sp->x,vm.g_sp->y); + actor[vm.g_i].floorz = l = VM_GetFlorZOfSlope(); if (vm.g_sp->z > l-(8<<8)) { vm.g_sp->z = l-(8<<8); vm.g_sp->zvel = 0; } - actor[vm.g_i].ceilingz = l = yax_getceilzofslope(vm.g_sp->sectnum,vm.g_sp->x,vm.g_sp->y); + actor[vm.g_i].ceilingz = l = VM_GetCeilZOfSlope(); if (vm.g_sp->z < l+(80<<8)) { vm.g_sp->z = l+(80<<8); @@ -706,13 +747,13 @@ dead: // The DRONE updates either .floorz or .ceilingz, not both. if (vm.g_sp->zvel > 0) { - actor[vm.g_i].floorz = l = yax_getflorzofslope(vm.g_sp->sectnum,vm.g_sp->x,vm.g_sp->y); + actor[vm.g_i].floorz = l = VM_GetFlorZOfSlope(); if (vm.g_sp->z > l-(30<<8)) vm.g_sp->z = l-(30<<8); } else { - actor[vm.g_i].ceilingz = l = yax_getceilzofslope(vm.g_sp->sectnum,vm.g_sp->x,vm.g_sp->y); + actor[vm.g_i].ceilingz = l = VM_GetCeilZOfSlope(); if (vm.g_sp->z < l+(50<<8)) { vm.g_sp->z = l+(50<<8); @@ -729,7 +770,7 @@ dead: vm.g_sp->z = actor[vm.g_i].floorz; if (vm.g_sp->zvel < 0) { - const int32_t l = yax_getceilzofslope(vm.g_sp->sectnum,vm.g_sp->x,vm.g_sp->y); + const int32_t l = VM_GetCeilZOfSlope(); if (vm.g_sp->z < l+(66<<8)) { @@ -738,22 +779,13 @@ dead: } } } - } - else if (vm.g_sp->picnum == APLAYER) - if (vm.g_sp->z < actor[vm.g_i].ceilingz+(32<<8)) - vm.g_sp->z = actor[vm.g_i].ceilingz+(32<<8); - daxvel = vm.g_sp->xvel; - angdif = vm.g_sp->ang; - - if (badguyp && vm.g_sp->picnum != ROTATEGUN) - { DukePlayer_t *const ps = g_player[vm.g_p].ps; if (vm.g_x < 960 && vm.g_sp->xrepeat > 16) { - daxvel = -(1024-vm.g_x); - angdif = getangle(ps->pos.x-vm.g_sp->x, ps->pos.y-vm.g_sp->y); + daxvel = -(1024 - vm.g_x); + angdif = getangle(ps->pos.x - vm.g_sp->x, ps->pos.y - vm.g_sp->y); if (vm.g_x < 512) { @@ -762,8 +794,8 @@ dead: } else { - ps->vel.x = mulscale16(ps->vel.x, ps->runspeed-0x2000); - ps->vel.y = mulscale16(ps->vel.y, ps->runspeed-0x2000); + ps->vel.x = mulscale16(ps->vel.x, ps->runspeed - 0x2000); + ps->vel.y = mulscale16(ps->vel.y, ps->runspeed - 0x2000); } } else if (vm.g_sp->picnum != DRONE && vm.g_sp->picnum != SHARK && vm.g_sp->picnum != COMMANDER) @@ -773,30 +805,29 @@ dead: if (!A_CheckSpriteFlags(vm.g_i, SFLAG_SMOOTHMOVE)) { - if (AC_COUNT(vm.g_t)&1) + if (AC_COUNT(vm.g_t) & 1) return; daxvel <<= 1; } } } + else if (vm.g_sp->picnum == APLAYER) + if (vm.g_sp->z < actor[vm.g_i].ceilingz+(32<<8)) + vm.g_sp->z = actor[vm.g_i].ceilingz+(32<<8); - { - vec3_t tmpvect = { (daxvel*(sintable[(angdif+512)&2047]))>>14, - (daxvel*(sintable[angdif&2047]))>>14, - vm.g_sp->zvel - }; + vec3_t tmpvect = { (daxvel * (sintable[(angdif + 512) & 2047])) >> 14, + (daxvel * (sintable[angdif & 2047])) >> 14, vm.g_sp->zvel }; - actor[vm.g_i].movflag = A_MoveSprite( - vm.g_i,&tmpvect, (A_CheckSpriteFlags(vm.g_i, SFLAG_NOCLIP) ? 0 : CLIPMASK0)); - } + actor[vm.g_i].movflag = + A_MoveSprite(vm.g_i, &tmpvect, (A_CheckSpriteFlags(vm.g_i, SFLAG_NOCLIP) ? 0 : CLIPMASK0)); } if (!badguyp) return; - if (sector[vm.g_sp->sectnum].ceilingstat&1) - vm.g_sp->shade += (sector[vm.g_sp->sectnum].ceilingshade-vm.g_sp->shade)>>1; - else vm.g_sp->shade += (sector[vm.g_sp->sectnum].floorshade-vm.g_sp->shade)>>1; + vm.g_sp->shade += (sector[vm.g_sp->sectnum].ceilingstat & 1) ? + (sector[vm.g_sp->sectnum].ceilingshade - vm.g_sp->shade) >> 1 : + (sector[vm.g_sp->sectnum].floorshade - vm.g_sp->shade) >> 1; } static void P_AddWeaponMaybeSwitch(DukePlayer_t *ps, int32_t weap) @@ -1142,16 +1173,16 @@ LUNATIC_EXTERN void G_ShowView(int32_t x, int32_t y, int32_t z, int32_t a, int32 } #if !defined LUNATIC -GAMEEXEC_STATIC void VM_Execute(int32_t loop) +GAMEEXEC_STATIC void VM_Execute(int loop) { - int32_t tw = *insptr; + int tw = *insptr; // jump directly into the loop, saving us from the checks during the first iteration goto skip_check; while (loop) { - if (vm.g_flags & (VM_RETURN|VM_KILL|VM_NOEXECUTE)) + if (vm.g_flags & (VM_RETURN | VM_KILL | VM_NOEXECUTE)) return; tw = *insptr; @@ -1161,7 +1192,7 @@ skip_check: // AddLog(g_szBuf); g_errorLineNum = tw>>12; - g_tw = tw &= 0xFFF; + g_tw = tw &= 0xfff; switch (tw) { @@ -1641,7 +1672,7 @@ skip_check: if (ps->ammo_amount[weap] >= ps->max_ammo_amount[weap]) { vm.g_flags |= VM_NOEXECUTE; - break; + return; } P_AddWeaponAmmoCommon(ps, weap, amount); @@ -1683,7 +1714,7 @@ skip_check: case CON_KILLIT: insptr++; vm.g_flags |= VM_KILL; - continue; + return; case CON_ADDWEAPON: insptr++; @@ -4458,7 +4489,7 @@ finish_qsprintf: aGameArrays[j].szLabel, aGameArrays[j].size, numelts);*/ int32_t numbytes = numelts * sizeof(int32_t); #ifdef BITNESS64 - int32_t *tmpar = Xmalloc(numbytes); + int32_t *tmpar = (int32_t *)Xmalloc(numbytes); kread(fil, tmpar, numbytes); #endif Baligned_free(aGameArrays[j].plValues); @@ -5368,21 +5399,19 @@ finish_qsprintf: // NORECURSE void A_LoadActor(int32_t iActor) { - vm.g_i = iActor; // Sprite ID - vm.g_p = -1; // iPlayer; // Player ID - vm.g_x = -1; // lDist; // ? - vm.g_sp = &sprite[vm.g_i]; // Pointer to sprite structure - vm.g_t = &actor[vm.g_i].t_data[0]; // Sprite's 'extra' data + vm.g_i = iActor; // Sprite ID + vm.g_sp = &sprite[iActor]; // Pointer to sprite structure + vm.g_t = &actor[iActor].t_data[0]; // Sprite's 'extra' data + vm.g_p = -1; // Player ID + vm.g_x = -1; // Distance if (g_tile[vm.g_sp->picnum].loadPtr == NULL) return; - vm.g_flags &= ~(VM_RETURN|VM_KILL|VM_NOEXECUTE); + vm.g_flags &= ~(VM_RETURN | VM_KILL | VM_NOEXECUTE); if ((unsigned)vm.g_sp->sectnum >= MAXSECTORS) { - // if(A_CheckEnemySprite(vm.g_sp)) - // g_player[vm.g_p].ps->actors_killed++; A_DeleteSprite(vm.g_i); return; } @@ -5393,21 +5422,20 @@ void A_LoadActor(int32_t iActor) if (vm.g_flags & VM_KILL) A_DeleteSprite(vm.g_i); - } #endif // NORECURSE void A_Execute(int32_t iActor, int32_t iPlayer, int32_t lDist) { + vmstate_t tempvm = { iActor, iPlayer, lDist, &actor[iActor].t_data[0], &sprite[iActor], 0 }; + vm = tempvm; + #ifdef LUNATIC int32_t killit=0; #else intptr_t actionofs, *actionptr; #endif - vmstate_t tempvm = { iActor, iPlayer, lDist, &actor[iActor].t_data[0], - &sprite[iActor], 0 - }; /* if (g_netClient && A_CheckSpriteFlags(iActor, SFLAG_NULL)) @@ -5420,24 +5448,18 @@ void A_Execute(int32_t iActor, int32_t iPlayer, int32_t lDist) if (g_netServer || g_netClient) randomseed = ticrandomseed; - Bmemcpy(&vm, &tempvm, sizeof(vmstate_t)); - if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_sp->sectnum >= MAXSECTORS)) { if (A_CheckEnemySprite(vm.g_sp)) g_player[vm.g_p].ps->actors_killed++; + A_DeleteSprite(vm.g_i); return; } - /* Qbix: Changed variables to be aware of the sizeof *insptr - * (whether it is int32_t vs intptr_t), Although it is specifically cast to intptr_t* - * which might be corrected if the code is converted to use offsets */ - /* Helixhorned: let's do away with intptr_t's... */ #if !defined LUNATIC actionofs = AC_ACTION_ID(vm.g_t); - actionptr = (actionofs!=0 && actionofs+4u < (unsigned)g_scriptSize) ? - &script[actionofs] : NULL; + actionptr = (actionofs != 0 && actionofs + 4u < (unsigned)g_scriptSize) ? &script[actionofs] : NULL; if (actionptr != NULL) #endif @@ -5456,9 +5478,8 @@ void A_Execute(int32_t iActor, int32_t iPlayer, int32_t lDist) if (*actionticsptr > action_delay) { - AC_ACTION_COUNT(vm.g_t)++; *actionticsptr = 0; - + AC_ACTION_COUNT(vm.g_t)++; AC_CURFRAME(vm.g_t) += action_incval; } @@ -5495,43 +5516,46 @@ void A_Execute(int32_t iActor, int32_t iPlayer, int32_t lDist) if (vm.g_flags & VM_KILL) #endif { - VM_KillIt(iActor, iPlayer); + VM_DeleteSprite(iActor, iPlayer); return; } VM_Move(); - if (vm.g_sp->statnum == STAT_STANDABLE) - switch (DYNAMICTILEMAP(vm.g_sp->picnum)) - { - case RUBBERCAN__STATIC: - case EXPLODINGBARREL__STATIC: - case WOODENHORSE__STATIC: - case HORSEONSIDE__STATIC: - case CANWITHSOMETHING__STATIC: - case FIREBARREL__STATIC: - case NUKEBARREL__STATIC: - case NUKEBARRELDENTED__STATIC: - case NUKEBARRELLEAKED__STATIC: - case TRIPBOMB__STATIC: - case EGG__STATIC: - if (actor[vm.g_i].timetosleep > 1) - actor[vm.g_i].timetosleep--; - else if (actor[vm.g_i].timetosleep == 1) - changespritestat(vm.g_i,STAT_ZOMBIEACTOR); - default: - return; - } - if (vm.g_sp->statnum != STAT_ACTOR) + { + if (vm.g_sp->statnum == STAT_STANDABLE) + { + switch (DYNAMICTILEMAP(vm.g_sp->picnum)) + { + case RUBBERCAN__STATIC: + case EXPLODINGBARREL__STATIC: + case WOODENHORSE__STATIC: + case HORSEONSIDE__STATIC: + case CANWITHSOMETHING__STATIC: + case FIREBARREL__STATIC: + case NUKEBARREL__STATIC: + case NUKEBARRELDENTED__STATIC: + case NUKEBARRELLEAKED__STATIC: + case TRIPBOMB__STATIC: + case EGG__STATIC: + if (actor[vm.g_i].timetosleep > 1) + actor[vm.g_i].timetosleep--; + else if (actor[vm.g_i].timetosleep == 1) + changespritestat(vm.g_i, STAT_ZOMBIEACTOR); + default: return; + } + } return; + } if (A_CheckEnemySprite(vm.g_sp)) { - if (vm.g_sp->xrepeat > 60) return; - if (ud.respawn_monsters == 1 && vm.g_sp->extra <= 0) return; + if (vm.g_sp->xrepeat > 60 || (ud.respawn_monsters == 1 && vm.g_sp->extra <= 0)) + return; } - else if (EDUKE32_PREDICT_FALSE(ud.respawn_items == 1 && (vm.g_sp->cstat&32768))) return; + else if (EDUKE32_PREDICT_FALSE(ud.respawn_items == 1 && (vm.g_sp->cstat & 32768))) + return; if (A_CheckSpriteFlags(vm.g_i, SFLAG_USEACTIVATOR) && sector[vm.g_sp->sectnum].lotag & 16384) changespritestat(vm.g_i, STAT_ZOMBIEACTOR); diff --git a/polymer/eduke32/source/gameexec.h b/polymer/eduke32/source/gameexec.h index 294a39ab9..6360aed48 100644 --- a/polymer/eduke32/source/gameexec.h +++ b/polymer/eduke32/source/gameexec.h @@ -52,7 +52,10 @@ int32_t G_GetAngleDelta(int32_t a,int32_t na); void G_RestoreMapState(); 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_OnEventWithBoth_(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t iReturn); +int32_t VM_OnEventWithReturn_(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t iReturn); +int32_t VM_OnEventWithDist_(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist); +int32_t VM_OnEvent_(int32_t iEventID, int32_t iActor, int32_t iPlayer); static inline int32_t VM_HaveEvent(int32_t iEventID) { @@ -63,9 +66,24 @@ static inline int32_t VM_HaveEvent(int32_t iEventID) #endif } -static inline int32_t VM_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t iReturn) +static inline int32_t VM_OnEventWithBoth(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t iReturn) { - return VM_HaveEvent(iEventID) ? VM_OnEvent_(iEventID, iActor, iPlayer, lDist, iReturn) : iReturn; + return VM_HaveEvent(iEventID) ? VM_OnEventWithBoth_(iEventID, iActor, iPlayer, lDist, iReturn) : iReturn; +} + +static inline int32_t VM_OnEventWithReturn(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t iReturn) +{ + return VM_HaveEvent(iEventID) ? VM_OnEventWithReturn_(iEventID, iActor, iPlayer, iReturn) : iReturn; +} + +static inline int32_t VM_OnEventWithDist(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist) +{ + return VM_HaveEvent(iEventID) ? VM_OnEventWithDist_(iEventID, iActor, iPlayer, lDist) : 0; +} + +static inline int32_t VM_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlayer) +{ + return VM_HaveEvent(iEventID) ? VM_OnEvent_(iEventID, iActor, iPlayer) : 0; } void VM_ScriptInfo(void); diff --git a/polymer/eduke32/source/gamevars.h b/polymer/eduke32/source/gamevars.h index ac8d7dd0a..9c5cdbbb1 100644 --- a/polymer/eduke32/source/gamevars.h +++ b/polymer/eduke32/source/gamevars.h @@ -108,16 +108,16 @@ void __fastcall Gv_SetVarX(int32_t id, int32_t lValue); int32_t Gv_GetVarByLabel(const char *szGameLabel,int32_t lDefault,int32_t iActor,int32_t iPlayer); int32_t Gv_NewArray(const char *pszLabel,void *arrayptr,intptr_t asize,uint32_t dwFlags); int32_t Gv_NewVar(const char *pszLabel,intptr_t lValue,uint32_t dwFlags); -static inline void A_ResetVars(int32_t iActor) -{ - int32_t i; - for (i=0; i MAXPLAYERS - 1)) \ - break; \ - aGameVars[id].val.plValues[vm.g_p] operator lValue; \ - break; \ - case GAMEVAR_PERACTOR: \ - if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_i > MAXSPRITES - 1)) \ - break; \ - aGameVars[id].val.plValues[vm.g_i] operator lValue; \ - break; \ - case GAMEVAR_INTPTR: *((int32_t *)aGameVars[id].val.lValue) operator(int32_t) lValue; break; \ - case GAMEVAR_SHORTPTR: *((int16_t *)aGameVars[id].val.lValue) operator(int16_t) lValue; break; \ - case GAMEVAR_CHARPTR: *((uint8_t *)aGameVars[id].val.lValue) operator(uint8_t) lValue; break; \ - } \ +#define VM_GAMEVAR_OPERATOR(func, operator) \ + static inline void __fastcall func(const int32_t id, const int32_t lValue) \ + { \ + switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK)) \ + { \ + default: aGameVars[id].val.lValue operator lValue; break; \ + case GAMEVAR_PERPLAYER: \ + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_p > MAXPLAYERS - 1)) \ + break; \ + aGameVars[id].val.plValues[vm.g_p] operator lValue; \ + break; \ + case GAMEVAR_PERACTOR: \ + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_i > MAXSPRITES - 1)) \ + break; \ + aGameVars[id].val.plValues[vm.g_i] operator lValue; \ + break; \ + case GAMEVAR_INTPTR: *((int32_t *)aGameVars[id].val.lValue) operator (int32_t) lValue; break; \ + case GAMEVAR_SHORTPTR: *((int16_t *)aGameVars[id].val.lValue) operator (int16_t) lValue; break; \ + case GAMEVAR_CHARPTR: *((uint8_t *)aGameVars[id].val.lValue) operator (uint8_t) lValue; break; \ + } \ } #if defined(__arm__) || defined(LIBDIVIDE_ALWAYS) -static inline void __fastcall Gv_DivVar(int32_t id, int32_t lValue) +static inline void __fastcall Gv_DivVar(const int32_t id, const int32_t lValue) { static libdivide_s32_t sdiv; static int32_t lastlValue; diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index c98acf108..68882e4cb 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -3186,7 +3186,7 @@ void M_ChangeMenu(MenuID_t cm) Menu_t *search; int32_t i; - cm = VM_OnEvent(EVENT_CHANGEMENU, g_player[myconnectindex].ps->i, myconnectindex, -1, cm); + cm = VM_OnEventWithReturn(EVENT_CHANGEMENU, g_player[myconnectindex].ps->i, myconnectindex, cm); if (cm == MENU_PREVIOUS) { @@ -4950,7 +4950,7 @@ void M_DisplayMenus(void) M_RunMenuInput(m_currentMenu); - VM_OnEvent(EVENT_DISPLAYMENU, g_player[screenpeek].ps->i, screenpeek, -1, 0); + VM_OnEvent(EVENT_DISPLAYMENU, g_player[screenpeek].ps->i, screenpeek); g_player[myconnectindex].ps->gm &= (0xff-MODE_TYPE); g_player[myconnectindex].ps->fta = 0; @@ -4986,7 +4986,7 @@ void M_DisplayMenus(void) #endif if (VM_HaveEvent(EVENT_DISPLAYMENUREST)) - VM_OnEvent(EVENT_DISPLAYMENUREST, g_player[screenpeek].ps->i, screenpeek, -1, 0); + VM_OnEvent(EVENT_DISPLAYMENUREST, g_player[screenpeek].ps->i, screenpeek); if (readmouseabsxy(&m_mousepos.x, &m_mousepos.y)) { diff --git a/polymer/eduke32/source/player.c b/polymer/eduke32/source/player.c index 7d2334dd5..ddafa8231 100644 --- a/polymer/eduke32/source/player.c +++ b/polymer/eduke32/source/player.c @@ -67,7 +67,7 @@ static void P_IncurDamage(DukePlayer_t *p) { int32_t damage; - if (VM_OnEvent(EVENT_INCURDAMAGE, p->i, P_Get(p->i), -1, 0) != 0) + if (VM_OnEvent(EVENT_INCURDAMAGE, p->i, P_Get(p->i)) != 0) return; sprite[p->i].extra -= p->extra_extra8>>8; @@ -350,7 +350,7 @@ static int32_t GetAutoAimAngle(int32_t i, int32_t p, int32_t atwith, Gv_SetVar(g_iAimAngleVarID, g_player[p].ps->auto_aim == 3 ? AUTO_AIM_ANGLE<<1 : AUTO_AIM_ANGLE, i, p); #endif - VM_OnEvent(EVENT_GETAUTOAIMANGLE, i, p, -1, 0); + VM_OnEvent(EVENT_GETAUTOAIMANGLE, i, p); { #ifdef LUNATIC @@ -472,7 +472,7 @@ static void P_PreFireHitscan(int32_t i, int32_t p, int32_t atwith, Gv_SetVar(g_iZRangeVarID,zRange,i,p); #endif - VM_OnEvent(EVENT_GETSHOTRANGE, i, p, -1, 0); + VM_OnEvent(EVENT_GETSHOTRANGE, i, p); #ifdef LUNATIC angRange = ps->angrange; @@ -595,7 +595,7 @@ static int32_t SectorContainsSE13(int32_t sectnum) // Maybe handle bit 2 (swap wall bottoms). // (in that case walltype *hitwal may be stale) -static void HandleHitWall(hitdata_t *hit) +static inline void HandleHitWall(hitdata_t *hit) { const walltype *const hitwal = &wall[hit->wall]; @@ -1925,7 +1925,7 @@ static void P_FireWeapon(int32_t snum) int32_t i; DukePlayer_t *const p = g_player[snum].ps; - if (VM_OnEvent(EVENT_DOFIRE, p->i, snum, -1, 0) || p->weapon_pos != 0) + if (VM_OnEvent(EVENT_DOFIRE, p->i, snum) || p->weapon_pos != 0) return; if (PWEAPON(snum, p->curr_weapon, WorksLike) != KNEE_WEAPON) @@ -2145,7 +2145,7 @@ void P_DisplayWeapon(int32_t snum) hudweap.count=*kb; hudweap.lookhalfang=p->look_ang>>1; - if (VM_OnEvent(EVENT_DISPLAYWEAPON, p->i, screenpeek, -1, 0) == 0) + if (VM_OnEvent(EVENT_DISPLAYWEAPON, p->i, screenpeek) == 0) { j = 14-p->quick_kick; if (j != 14 || p->last_quick_kick) @@ -2194,7 +2194,7 @@ void P_DisplayWeapon(int32_t snum) switch (cw) { case KNEE_WEAPON: - if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek, -1, 0) || *kb == 0) + if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek) || *kb == 0) break; if (pal == 0) @@ -2211,7 +2211,7 @@ void P_DisplayWeapon(int32_t snum) break; case TRIPBOMB_WEAPON: - if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek, -1, 0)) + if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek)) break; weapon_xoffset += 8; @@ -2234,7 +2234,7 @@ void P_DisplayWeapon(int32_t snum) break; case RPG_WEAPON: - if (VM_OnEvent(EVENT_DRAWWEAPON,g_player[screenpeek].ps->i,screenpeek, -1, 0)) + if (VM_OnEvent(EVENT_DRAWWEAPON,g_player[screenpeek].ps->i,screenpeek)) break; weapon_xoffset -= sintable[(768 + ((*kb) << 7)) & 2047] >> 11; @@ -2251,7 +2251,7 @@ void P_DisplayWeapon(int32_t snum) break; case SHOTGUN_WEAPON: - if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek, -1, 0)) + if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek)) break; weapon_xoffset -= 8; @@ -2324,7 +2324,7 @@ void P_DisplayWeapon(int32_t snum) break; case CHAINGUN_WEAPON: - if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek, -1, 0)) + if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek)) break; if (*kb > 0) @@ -2374,7 +2374,7 @@ void P_DisplayWeapon(int32_t snum) break; case PISTOL_WEAPON: - if (VM_OnEvent(EVENT_DRAWWEAPON,g_player[screenpeek].ps->i,screenpeek, -1, 0)) + if (VM_OnEvent(EVENT_DRAWWEAPON,g_player[screenpeek].ps->i,screenpeek)) break; if ((*kb) < PWEAPON(screenpeek, PISTOL_WEAPON, TotalTime)+1) @@ -2416,7 +2416,7 @@ void P_DisplayWeapon(int32_t snum) break; case HANDBOMB_WEAPON: - if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek, -1, 0)) + if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek)) break; else { @@ -2443,7 +2443,7 @@ void P_DisplayWeapon(int32_t snum) break; case HANDREMOTE_WEAPON: - if (VM_OnEvent(EVENT_DRAWWEAPON,g_player[screenpeek].ps->i,screenpeek, -1, 0)) + if (VM_OnEvent(EVENT_DRAWWEAPON,g_player[screenpeek].ps->i,screenpeek)) break; else { @@ -2459,7 +2459,7 @@ void P_DisplayWeapon(int32_t snum) break; case DEVISTATOR_WEAPON: - if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek, -1, 0)) + if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek)) break; if ((*kb) < (PWEAPON(screenpeek, DEVISTATOR_WEAPON, TotalTime) + 1) && (*kb) > 0) @@ -2498,7 +2498,7 @@ void P_DisplayWeapon(int32_t snum) break; case FREEZE_WEAPON: - if (VM_OnEvent(EVENT_DRAWWEAPON,g_player[screenpeek].ps->i,screenpeek, -1, 0)) + if (VM_OnEvent(EVENT_DRAWWEAPON,g_player[screenpeek].ps->i,screenpeek)) break; if ((*kb) < (PWEAPON(snum, p->curr_weapon, TotalTime)+1) && (*kb) > 0) @@ -2523,7 +2523,7 @@ void P_DisplayWeapon(int32_t snum) case GROW_WEAPON: case SHRINKER_WEAPON: - if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek, -1, 0)) + if (VM_OnEvent(EVENT_DRAWWEAPON, g_player[screenpeek].ps->i, screenpeek)) break; weapon_xoffset += 28; @@ -3087,7 +3087,7 @@ static void P_ChangeWeapon(DukePlayer_t *p, int32_t weapon) return; if (p->curr_weapon != weapon && VM_HaveEvent(EVENT_CHANGEWEAPON)) - i = VM_OnEvent(EVENT_CHANGEWEAPON,p->i, snum, -1, weapon); + i = VM_OnEventWithReturn(EVENT_CHANGEWEAPON,p->i, snum, weapon); if (i == -1) return; @@ -3216,7 +3216,7 @@ static void DoWallTouchDamage(const DukePlayer_t *p, int32_t obj) static void P_CheckTouchDamage(DukePlayer_t *p, int32_t obj) { - if ((obj = VM_OnEvent(EVENT_CHECKTOUCHDAMAGE, p->i, P_Get(p->i), -1, obj)) == -1) + if ((obj = VM_OnEventWithReturn(EVENT_CHECKTOUCHDAMAGE, p->i, P_Get(p->i), obj)) == -1) return; if ((obj&49152) == 49152) @@ -3277,7 +3277,7 @@ static int32_t P_CheckFloorDamage(DukePlayer_t *p, int32_t tex) { spritetype *s = &sprite[p->i]; - if ((unsigned)(tex = VM_OnEvent(EVENT_CHECKFLOORDAMAGE, p->i, P_Get(p->i), -1, tex)) >= MAXTILES) + if ((unsigned)(tex = VM_OnEventWithReturn(EVENT_CHECKFLOORDAMAGE, p->i, P_Get(p->i), tex)) >= MAXTILES) return 0; switch (DYNAMICTILEMAP(tex)) @@ -3506,7 +3506,7 @@ static void P_ProcessWeapon(int32_t snum) { P_SetWeaponGamevars(snum, p); - if (VM_OnEvent(EVENT_PRESSEDFIRE, p->i, snum, -1, 0) != 0) + if (VM_OnEvent(EVENT_PRESSEDFIRE, p->i, snum) != 0) sb_snum &= ~BIT(SK_FIRE); } @@ -3514,7 +3514,7 @@ static void P_ProcessWeapon(int32_t snum) { P_SetWeaponGamevars(snum, p); - if (VM_OnEvent(EVENT_HOLSTER, p->i, snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_HOLSTER, p->i, snum) == 0) { if (PWEAPON(snum, p->curr_weapon, WorksLike) != KNEE_WEAPON) { @@ -3616,10 +3616,10 @@ static void P_ProcessWeapon(int32_t snum) { P_SetWeaponGamevars(snum, p); - if (VM_OnEvent(EVENT_FIRE, p->i, snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_FIRE, p->i, snum) == 0) { // this event is deprecated - VM_OnEvent(EVENT_FIREWEAPON, p->i, snum, -1, 0); + VM_OnEvent(EVENT_FIREWEAPON, p->i, snum); switch (PWEAPON(snum, p->curr_weapon, WorksLike)) { @@ -4119,7 +4119,7 @@ void P_ProcessInput(int32_t snum) p->player_par++; - VM_OnEvent(EVENT_PROCESSINPUT, p->i, snum, -1, 0); + VM_OnEvent(EVENT_PROCESSINPUT, p->i, snum); if (p->cheat_phase > 0) sb_snum = 0; @@ -4371,7 +4371,7 @@ void P_ProcessInput(int32_t snum) if (TEST_SYNC_KEY(sb_snum, SK_LOOK_LEFT)) { // look_left - if (VM_OnEvent(EVENT_LOOKLEFT,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_LOOKLEFT,p->i,snum) == 0) { p->look_ang -= 152; p->rotscrnang += 24; @@ -4381,7 +4381,7 @@ void P_ProcessInput(int32_t snum) if (TEST_SYNC_KEY(sb_snum, SK_LOOK_RIGHT)) { // look_right - if (VM_OnEvent(EVENT_LOOKRIGHT,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_LOOKRIGHT,p->i,snum) == 0) { p->look_ang += 152; p->rotscrnang -= 24; @@ -4452,7 +4452,7 @@ void P_ProcessInput(int32_t snum) if (TEST_SYNC_KEY(sb_snum, SK_JUMP)) { - if (VM_OnEvent(EVENT_SWIMUP,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_SWIMUP,p->i,snum) == 0) { // jump if (p->vel.z > 0) p->vel.z = 0; @@ -4462,7 +4462,7 @@ void P_ProcessInput(int32_t snum) } else if (TEST_SYNC_KEY(sb_snum, SK_CROUCH)) { - if (VM_OnEvent(EVENT_SWIMDOWN,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_SWIMDOWN,p->i,snum) == 0) { // crouch if (p->vel.z < 0) p->vel.z = 0; @@ -4538,7 +4538,7 @@ void P_ProcessInput(int32_t snum) if (TEST_SYNC_KEY(sb_snum, SK_JUMP)) //A (soar high) { // jump - if (VM_OnEvent(EVENT_SOARUP,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_SOARUP,p->i,snum) == 0) { p->pos.z -= j; p->crack_time = 777; @@ -4548,7 +4548,7 @@ void P_ProcessInput(int32_t snum) if (TEST_SYNC_KEY(sb_snum, SK_CROUCH)) //Z (soar low) { // crouch - if (VM_OnEvent(EVENT_SOARDOWN,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_SOARDOWN,p->i,snum) == 0) { p->pos.z += j; p->crack_time = 777; @@ -4735,7 +4735,7 @@ void P_ProcessInput(int32_t snum) if (TEST_SYNC_KEY(sb_snum, SK_CROUCH)) { // crouching - if (VM_OnEvent(EVENT_CROUCH,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_CROUCH,p->i,snum) == 0) { p->pos.z += (2048+768); p->crack_time = 777; @@ -4750,7 +4750,7 @@ void P_ProcessInput(int32_t snum) if (p->jumping_counter == 0) if ((fz-cz) > (56<<8)) { - if (VM_OnEvent(EVENT_JUMP,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_JUMP,p->i,snum) == 0) { p->jumping_counter = 1; p->jumping_toggle = 1; @@ -4856,22 +4856,22 @@ void P_ProcessInput(int32_t snum) } if (g_player[snum].sync->extbits&(1)) - VM_OnEvent(EVENT_MOVEFORWARD,p->i,snum, -1, 0); + VM_OnEvent(EVENT_MOVEFORWARD,p->i,snum); if (g_player[snum].sync->extbits&(1<<1)) - VM_OnEvent(EVENT_MOVEBACKWARD,p->i,snum, -1, 0); + VM_OnEvent(EVENT_MOVEBACKWARD,p->i,snum); if (g_player[snum].sync->extbits&(1<<2)) - VM_OnEvent(EVENT_STRAFELEFT,p->i,snum, -1, 0); + VM_OnEvent(EVENT_STRAFELEFT,p->i,snum); if (g_player[snum].sync->extbits&(1<<3)) - VM_OnEvent(EVENT_STRAFERIGHT,p->i,snum, -1, 0); + VM_OnEvent(EVENT_STRAFERIGHT,p->i,snum); if (g_player[snum].sync->extbits&(1<<4) || g_player[snum].sync->avel < 0) - VM_OnEvent(EVENT_TURNLEFT,p->i,snum, -1, 0); + VM_OnEvent(EVENT_TURNLEFT,p->i,snum); if (g_player[snum].sync->extbits&(1<<5) || g_player[snum].sync->avel > 0) - VM_OnEvent(EVENT_TURNRIGHT,p->i,snum, -1, 0); + VM_OnEvent(EVENT_TURNRIGHT,p->i,snum); if (p->vel.x || p->vel.y || g_player[snum].sync->fvel || g_player[snum].sync->svel) { @@ -5056,12 +5056,12 @@ HORIZONLY: i = 0; if (TEST_SYNC_KEY(sb_snum, SK_CENTER_VIEW) || p->hard_landing) - if (VM_OnEvent(EVENT_RETURNTOCENTER,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_RETURNTOCENTER,p->i,snum) == 0) p->return_to_center = 9; if (TEST_SYNC_KEY(sb_snum, SK_LOOK_UP)) { - if (VM_OnEvent(EVENT_LOOKUP,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_LOOKUP,p->i,snum) == 0) { p->return_to_center = 9; if (TEST_SYNC_KEY(sb_snum, SK_RUN)) p->horiz += 12; @@ -5072,7 +5072,7 @@ HORIZONLY: if (TEST_SYNC_KEY(sb_snum, SK_LOOK_DOWN)) { - if (VM_OnEvent(EVENT_LOOKDOWN,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_LOOKDOWN,p->i,snum) == 0) { p->return_to_center = 9; if (TEST_SYNC_KEY(sb_snum, SK_RUN)) p->horiz -= 12; @@ -5083,7 +5083,7 @@ HORIZONLY: if (TEST_SYNC_KEY(sb_snum, SK_AIM_UP)) { - if (VM_OnEvent(EVENT_AIMUP,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_AIMUP,p->i,snum) == 0) { if (TEST_SYNC_KEY(sb_snum, SK_RUN)) p->horiz += 6; p->horiz += 6; @@ -5093,7 +5093,7 @@ HORIZONLY: if (TEST_SYNC_KEY(sb_snum, SK_AIM_DOWN)) { - if (VM_OnEvent(EVENT_AIMDOWN,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_AIMDOWN,p->i,snum) == 0) { if (TEST_SYNC_KEY(sb_snum, SK_RUN)) p->horiz -= 6; p->horiz -= 6; diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index 8fb6a514e..b79ea7883 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -334,7 +334,7 @@ static void G_DoLoadScreen(const char *statustext, int32_t percent) if (ud.recstat != 2) { - j = VM_OnEvent(EVENT_GETLOADTILE, -1, myconnectindex, -1, LOADSCREEN); + j = VM_OnEventWithReturn(EVENT_GETLOADTILE, -1, myconnectindex, LOADSCREEN); //g_player[myconnectindex].ps->palette = palette; P_SetGamePalette(g_player[myconnectindex].ps, BASEPAL, 1); // JBF 20040308 @@ -383,7 +383,7 @@ static void G_DoLoadScreen(const char *statustext, int32_t percent) rotatesprite(158<<16,144<<16,65536,0,929,0,0,2+8+16,0,0,ii,ydim-1); } - VM_OnEvent(EVENT_DISPLAYLOADINGSCREEN, g_player[screenpeek].ps->i, screenpeek, -1, 0); + VM_OnEvent(EVENT_DISPLAYLOADINGSCREEN, g_player[screenpeek].ps->i, screenpeek); nextpage(); if (!statustext) @@ -403,7 +403,7 @@ static void G_DoLoadScreen(const char *statustext, int32_t percent) } /*Gv_SetVar(g_iReturnVarID,LOADSCREEN, -1, -1);*/ - j = VM_OnEvent(EVENT_GETLOADTILE, -1, myconnectindex, -1, LOADSCREEN); + j = VM_OnEventWithReturn(EVENT_GETLOADTILE, -1, myconnectindex, LOADSCREEN); if ((uint32_t)j < 2*MAXTILES) { @@ -418,7 +418,7 @@ static void G_DoLoadScreen(const char *statustext, int32_t percent) menutext(160,105,0,0,"Loading..."); if (statustext) gametext(160,180,statustext,0,2+8+16); - VM_OnEvent(EVENT_DISPLAYLOADINGSCREEN, g_player[screenpeek].ps->i, screenpeek, -1, 0); + VM_OnEvent(EVENT_DISPLAYLOADINGSCREEN, g_player[screenpeek].ps->i, screenpeek); nextpage(); } } @@ -718,7 +718,7 @@ void P_ResetPlayer(int32_t snum) pl->movement_lock = 0; - VM_OnEvent(EVENT_RESETPLAYER, pl->i, snum, -1, 0); + VM_OnEvent(EVENT_RESETPLAYER, pl->i, snum); } void P_ResetStatus(int32_t snum) @@ -827,7 +827,7 @@ void P_ResetStatus(int32_t snum) p->frag_ps = snum; P_UpdateScreenPal(p); - VM_OnEvent(EVENT_RESETPLAYER, p->i, snum, -1, 0); + VM_OnEvent(EVENT_RESETPLAYER, p->i, snum); } void P_ResetWeapons(int32_t snum) @@ -848,7 +848,7 @@ void P_ResetWeapons(int32_t snum) p->show_empty_weapon= 0; p->last_pissed_time = 0; p->holster_weapon = 0; - VM_OnEvent(EVENT_RESETWEAPONS, p->i, snum, -1, 0); + VM_OnEvent(EVENT_RESETWEAPONS, p->i, snum); } void P_ResetInventory(int32_t snum) @@ -863,7 +863,7 @@ void P_ResetInventory(int32_t snum) p->holoduke_on = -1; p->inv_amount[GET_SHIELD] = g_startArmorAmount; p->inven_icon = ICON_NONE; - VM_OnEvent(EVENT_RESETINVENTORY, p->i, snum, -1, 0); + VM_OnEvent(EVENT_RESETINVENTORY, p->i, snum); } static void resetprestat(int32_t snum,int32_t g) @@ -1064,7 +1064,7 @@ static void prelevel(char g) #if !defined LUNATIC A_LoadActor(i); #endif - VM_OnEvent(EVENT_LOADACTOR, i, -1, -1, 0); + VM_OnEvent(EVENT_LOADACTOR, i, -1); if (G_CheckExitSprite(i)) { g_player[0].ps->exitx = SX; @@ -1447,7 +1447,7 @@ end_vol4a: El_CreateGameState(); G_PostCreateGameState(); #endif - VM_OnEvent(EVENT_NEWGAME, g_player[myconnectindex].ps->i, myconnectindex, -1, 0); + VM_OnEvent(EVENT_NEWGAME, g_player[myconnectindex].ps->i, myconnectindex); } static void resetpspritevars(char g) @@ -1978,7 +1978,7 @@ int32_t G_EnterLevel(int32_t g) // variables are set by pointer... Bmemcpy(currentboardfilename, boardfilename, BMAX_PATH); - VM_OnEvent(EVENT_ENTERLEVEL, -1, -1, -1, 0); + VM_OnEvent(EVENT_ENTERLEVEL, -1, -1); OSD_Printf(OSDTEXT_YELLOW "E%dL%d: %s\n", ud.volume_number+1, ud.level_number+1, MapInfo[mii].name); diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index 522b723d0..83bea0949 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -324,7 +324,7 @@ int32_t G_LoadPlayer(int32_t spot) } sv_postudload(); // ud.m_XXX = ud.XXX - VM_OnEvent(EVENT_LOADGAME, g_player[myconnectindex].ps->i, myconnectindex, -1, 0); + VM_OnEvent(EVENT_LOADGAME, g_player[myconnectindex].ps->i, myconnectindex); return 0; } @@ -398,7 +398,7 @@ int32_t G_SavePlayer(int32_t spot) polymer_resetlights(); #endif - VM_OnEvent(EVENT_SAVEGAME, g_player[myconnectindex].ps->i, myconnectindex, -1, 0); + VM_OnEvent(EVENT_SAVEGAME, g_player[myconnectindex].ps->i, myconnectindex); // SAVE! sv_saveandmakesnapshot(fil, spot, 0, 0, 0); diff --git a/polymer/eduke32/source/sector.c b/polymer/eduke32/source/sector.c index e73037bcf..084e33112 100644 --- a/polymer/eduke32/source/sector.c +++ b/polymer/eduke32/source/sector.c @@ -1802,7 +1802,7 @@ int32_t Sect_DamageCeilingOrFloor(int32_t floorp, int32_t sn) const int32_t RETURN_in = floorp ? 131072+sn : 65536+sn; // NOTE: pass RETURN in the dist argument, too. - int32_t ret = VM_OnEvent(EVENT_DAMAGEHPLANE, g_player[screenpeek].ps->i, screenpeek, + int32_t ret = VM_OnEventWithBoth(EVENT_DAMAGEHPLANE, g_player[screenpeek].ps->i, screenpeek, RETURN_in, RETURN_in); if (ret < 0) @@ -2424,7 +2424,7 @@ void P_HandleSharedKeys(int32_t snum) if (TEST_SYNC_KEY(sb_snum, SK_QUICK_KICK) && p->quick_kick == 0) if (PWEAPON(snum, p->curr_weapon, WorksLike) != KNEE_WEAPON || p->kickback_pic == 0) { - if (VM_OnEvent(EVENT_QUICKKICK,g_player[snum].ps->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_QUICKKICK,g_player[snum].ps->i,snum) == 0) { p->quick_kick = 14; if (p->fta == 0 || p->ftq == 80) @@ -2467,7 +2467,7 @@ void P_HandleSharedKeys(int32_t snum) if (TEST_SYNC_KEY(sb_snum, SK_INVENTORY) && p->newowner == -1) // inventory button generates event for selected item { - if (VM_OnEvent(EVENT_INVENTORY,g_player[snum].ps->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_INVENTORY,g_player[snum].ps->i,snum) == 0) { switch (p->inven_icon) { @@ -2492,7 +2492,7 @@ void P_HandleSharedKeys(int32_t snum) if (TEST_SYNC_KEY(sb_snum, SK_NIGHTVISION)) { - if (VM_OnEvent(EVENT_USENIGHTVISION,g_player[snum].ps->i,snum, -1, 0) == 0 + if (VM_OnEvent(EVENT_USENIGHTVISION,g_player[snum].ps->i,snum) == 0 && p->inv_amount[GET_HEATS] > 0) { p->heat_on = !p->heat_on; @@ -2505,7 +2505,7 @@ void P_HandleSharedKeys(int32_t snum) if (TEST_SYNC_KEY(sb_snum, SK_STEROIDS)) { - if (VM_OnEvent(EVENT_USESTEROIDS,g_player[snum].ps->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_USESTEROIDS,g_player[snum].ps->i,snum) == 0) { if (p->inv_amount[GET_STEROIDS] == 400) { @@ -2590,12 +2590,12 @@ CHECKINV1: if (TEST_SYNC_KEY(sb_snum, SK_INV_LEFT)) // Inventory_Left { /*Gv_SetVar(g_iReturnVarID,dainv,g_player[snum].ps->i,snum);*/ - dainv = VM_OnEvent(EVENT_INVENTORYLEFT,g_player[snum].ps->i,snum, -1, dainv); + dainv = VM_OnEventWithReturn(EVENT_INVENTORYLEFT,g_player[snum].ps->i,snum, dainv); } else if (TEST_SYNC_KEY(sb_snum, SK_INV_RIGHT)) // Inventory_Right { /*Gv_SetVar(g_iReturnVarID,dainv,g_player[snum].ps->i,snum);*/ - dainv = VM_OnEvent(EVENT_INVENTORYRIGHT,g_player[snum].ps->i,snum, -1, dainv); + dainv = VM_OnEventWithReturn(EVENT_INVENTORYRIGHT,g_player[snum].ps->i,snum, dainv); } if (dainv >= 1) @@ -2619,13 +2619,13 @@ CHECKINV1: case -1: break; default: - j = VM_OnEvent(EVENT_WEAPKEY1+j,p->i,snum, -1, j); + j = VM_OnEventWithReturn(EVENT_WEAPKEY1+j,p->i,snum, j); break; case 10: - j = VM_OnEvent(EVENT_PREVIOUSWEAPON,p->i,snum, -1, j); + j = VM_OnEventWithReturn(EVENT_PREVIOUSWEAPON,p->i,snum, j); break; case 11: - j = VM_OnEvent(EVENT_NEXTWEAPON,p->i,snum, -1, j); + j = VM_OnEventWithReturn(EVENT_NEXTWEAPON,p->i,snum, j); break; } @@ -2723,7 +2723,7 @@ CHECKINV1: P_SetWeaponGamevars(snum, p); - j = VM_OnEvent(EVENT_SELECTWEAPON,p->i,snum, -1, j); + j = VM_OnEventWithReturn(EVENT_SELECTWEAPON,p->i,snum, j); // XXX: any signifcance to "<= MAX_WEAPONS" instead of "<"? if ((int32_t)j != -1 && j <= MAX_WEAPONS) @@ -2817,7 +2817,7 @@ CHECKINV1: { if (p->holoduke_on == -1) { - if (VM_OnEvent(EVENT_HOLODUKEON,g_player[snum].ps->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_HOLODUKEON,g_player[snum].ps->i,snum) == 0) { if (p->inv_amount[GET_HOLODUKE] > 0) { @@ -2839,7 +2839,7 @@ CHECKINV1: } else { - if (VM_OnEvent(EVENT_HOLODUKEOFF,g_player[snum].ps->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_HOLODUKEOFF,g_player[snum].ps->i,snum) == 0) { A_PlaySound(TELEPORTER,p->holoduke_on); p->holoduke_on = -1; @@ -2850,7 +2850,7 @@ CHECKINV1: if (TEST_SYNC_KEY(sb_snum, SK_MEDKIT)) { - if (VM_OnEvent(EVENT_USEMEDKIT,g_player[snum].ps->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_USEMEDKIT,g_player[snum].ps->i,snum) == 0) { if (p->inv_amount[GET_FIRSTAID] > 0 && sprite[p->i].extra < p->max_player_health) { @@ -2875,7 +2875,7 @@ CHECKINV1: if (p->newowner == -1 && TEST_SYNC_KEY(sb_snum, SK_JETPACK)) { - if (VM_OnEvent(EVENT_USEJETPACK,g_player[snum].ps->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_USEJETPACK,g_player[snum].ps->i,snum) == 0) { if (p->inv_amount[GET_JETPACK] > 0) { @@ -2908,7 +2908,7 @@ CHECKINV1: } if (TEST_SYNC_KEY(sb_snum, SK_TURNAROUND) && p->one_eighty_count == 0) - if (VM_OnEvent(EVENT_TURNAROUND,p->i,snum, -1, 0) == 0) + if (VM_OnEvent(EVENT_TURNAROUND,p->i,snum) == 0) p->one_eighty_count = -1024; } } @@ -3025,7 +3025,7 @@ void P_CheckSectors(int32_t snum) if (TEST_SYNC_KEY(g_player[snum].sync->bits, SK_OPEN)) { - if (VM_OnEvent(EVENT_USE, p->i, snum, -1, 0) != 0) + if (VM_OnEvent(EVENT_USE, p->i, snum) != 0) g_player[snum].sync->bits &= ~BIT(SK_OPEN); } diff --git a/polymer/eduke32/source/sounds.c b/polymer/eduke32/source/sounds.c index f3a8ec57a..2950ddb7f 100644 --- a/polymer/eduke32/source/sounds.c +++ b/polymer/eduke32/source/sounds.c @@ -580,7 +580,7 @@ int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos) const DukePlayer_t *const myps = g_player[myconnectindex].ps; const DukePlayer_t *peekps; - j = VM_OnEvent(EVENT_SOUND, i, screenpeek, -1, num); + j = VM_OnEventWithReturn(EVENT_SOUND, i, screenpeek, num); if (j == -1 && num != -1) // check that the user returned -1, but only if -1 wasn't playing already (in which case, warn) return -1; @@ -736,7 +736,7 @@ int32_t S_PlaySound(int32_t num) int32_t pitch; int32_t voice, j; - j = VM_OnEvent(EVENT_SOUND, g_player[screenpeek].ps->i, screenpeek, -1, num); + j = VM_OnEventWithReturn(EVENT_SOUND, g_player[screenpeek].ps->i, screenpeek, num); if (j == -1 && num != -1) // check that the user returned -1, but only if -1 wasn't playing already (in which case, warn) return -1;