From 58dd578b094639405d452593562e0f8cb2b482ce Mon Sep 17 00:00:00 2001 From: Nami <50415197+namishere@users.noreply.github.com> Date: Sun, 29 Dec 2019 20:36:24 -0800 Subject: [PATCH 1/6] Let's try this again! --- src/dehacked.c | 3 +++ src/lua_blockmaplib.c | 40 ++++++++++++++++++---------------------- src/lua_hook.h | 6 ++++-- src/lua_hooklib.c | 34 +++++++++++++++++++++++++++++----- src/p_tick.c | 8 ++++++-- 5 files changed, 60 insertions(+), 31 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 4c90211cc..450e33c16 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -9824,6 +9824,9 @@ struct { {"TC_RAINBOW",TC_RAINBOW}, {"TC_BLINK",TC_BLINK}, {"TC_DASHMODE",TC_DASHMODE}, + + {"OPT_LINES", 1}, + {"OPT_MOBJS", 1<<1}, #endif {NULL,0} diff --git a/src/lua_blockmaplib.c b/src/lua_blockmaplib.c index 7f7dc9560..2130e9333 100644 --- a/src/lua_blockmaplib.c +++ b/src/lua_blockmaplib.c @@ -18,11 +18,6 @@ #include "lua_libs.h" //#include "lua_hud.h" // hud_running errors -static const char *const search_opt[] = { - "objects", - "lines", - NULL}; - // a quickly-made function pointer typedef used by lib_searchBlockmap... // return values: // 0 - normal, no interruptions @@ -179,29 +174,18 @@ static UINT8 lib_searchBlockmap_Lines(lua_State *L, INT32 x, INT32 y, mobj_t *th // false = searching of at least one block stopped mid-way (including if the whole search was stopped) static int lib_searchBlockmap(lua_State *L) { - int searchtype = luaL_checkoption(L, 1, "objects", search_opt); int n; mobj_t *mobj; INT32 xl, xh, yl, yh, bx, by; fixed_t x1, x2, y1, y2; boolean retval = true; + boolean repeat = false; UINT8 funcret = 0; - blockmap_func searchFunc; - lua_remove(L, 1); // remove searchtype, stack is now function, mobj, [x1, x2, y1, y2] + UINT32 flags = luaL_checkinteger(L, 1); + lua_remove(L, 1); // remove flags, stack is now function, mobj, [x1, x2, y1, y2] luaL_checktype(L, 1, LUA_TFUNCTION); - switch (searchtype) - { - case 0: // "objects" - default: - searchFunc = lib_searchBlockmap_Objects; - break; - case 1: // "lines" - searchFunc = lib_searchBlockmap_Lines; - break; - } - // the mobj we are searching around, the "calling" mobj we could say mobj = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); if (!mobj) @@ -240,8 +224,14 @@ static int lib_searchBlockmap(lua_State *L) validcount++; for (bx = xl; bx <= xh; bx++) for (by = yl; by <= yh; by++) - { - funcret = searchFunc(L, bx, by, mobj); + { + if (flags & (OPT_LINES|OPT_MOBJS)) + repeat = true; + if (flags & OPT_LINES) + funcret = lib_searchBlockmap_Lines(L, bx, by, mobj); + else + funcret = lib_searchBlockmap_Objects(L, bx, by, mobj); + doitagain: // return value of searchFunc determines searchFunc's return value and/or when to stop if (funcret == 2){ // stop whole search lua_pushboolean(L, false); // return false @@ -254,6 +244,12 @@ static int lib_searchBlockmap(lua_State *L) lua_pushboolean(L, false); // in which case we have to stop now regardless return 1; } + if (repeat) + { + funcret = lib_searchBlockmap_Objects(L, bx, by, mobj); + repeat = false; + goto doitagain; + } } lua_pushboolean(L, retval); return 1; @@ -265,4 +261,4 @@ int LUA_BlockmapLib(lua_State *L) return 0; } -#endif +#endif \ No newline at end of file diff --git a/src/lua_hook.h b/src/lua_hook.h index 68efbce93..620a7b307 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -20,7 +20,8 @@ enum hook { hook_MapChange, hook_MapLoad, hook_PlayerJoin, - hook_ThinkFrame, + hook_PreThinkFrame, + hook_PostThinkFrame, hook_MobjSpawn, hook_MobjCollide, hook_MobjMoveCollide, @@ -61,7 +62,8 @@ extern const char *const hookNames[]; void LUAh_MapChange(INT16 mapnumber); // Hook for map change (before load) void LUAh_MapLoad(void); // Hook for map load void LUAh_PlayerJoin(int playernum); // Hook for Got_AddPlayer -void LUAh_ThinkFrame(void); // Hook for frame (after mobj and player thinkers) +void LUAh_PreThinkFrame(void); // Hook for frame (before mobj and player thinkers) +void LUAh_PostThinkFrame(void); // Hook for frame (after mobj and player thinkers) boolean LUAh_MobjHook(mobj_t *mo, enum hook which); boolean LUAh_PlayerHook(player_t *plr, enum hook which); #define LUAh_MobjSpawn(mo) LUAh_MobjHook(mo, hook_MobjSpawn) // Hook for P_SpawnMobj by mobj type diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 91b4c6992..ace0f14d5 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -31,7 +31,8 @@ const char *const hookNames[hook_MAX+1] = { "MapChange", "MapLoad", "PlayerJoin", - "ThinkFrame", + "PreThinkFrame", + "PostThinkFrame", "MobjSpawn", "MobjCollide", "MobjMoveCollide", @@ -411,16 +412,39 @@ void LUAh_PlayerJoin(int playernum) lua_settop(gL, 0); } -// Hook for frame (after mobj and player thinkers) -void LUAh_ThinkFrame(void) +// Hook for frame (before mobj and player thinkers) +void LUAh_PreThinkFrame(void) { hook_p hookp; - if (!gL || !(hooksAvailable[hook_ThinkFrame/8] & (1<<(hook_ThinkFrame%8)))) + if (!gL || !(hooksAvailable[hook_PreThinkFrame/8] & (1<<(hook_PreThinkFrame%8)))) return; for (hookp = roothook; hookp; hookp = hookp->next) { - if (hookp->type != hook_ThinkFrame) + if (hookp->type != hook_PreThinkFrame) + continue; + + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + if (lua_pcall(gL, 0, 0, 0)) { + if (!hookp->error || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + hookp->error = true; + } + } +} + +// Hook for frame (after mobj and player thinkers) +void LUAh_PostThinkFrame(void) +{ + hook_p hookp; + if (!gL || !(hooksAvailable[hook_PostThinkFrame/8] & (1<<(hook_PostThinkFrame%8)))) + return; + + for (hookp = roothook; hookp; hookp = hookp->next) + { + if (hookp->type != hook_PostThinkFrame) continue; lua_pushfstring(gL, FMT_HOOKID, hookp->id); diff --git a/src/p_tick.c b/src/p_tick.c index e0f60bd22..b92465fe4 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -646,6 +646,10 @@ void P_Ticker(boolean run) if (run) { + #ifdef HAVE_BLUA + LUAh_PreThinkFrame(); + #endif + P_RunThinkers(); // Run any "after all the other thinkers" stuff @@ -654,7 +658,7 @@ void P_Ticker(boolean run) P_PlayerAfterThink(&players[i]); #ifdef HAVE_BLUA - LUAh_ThinkFrame(); + LUAh_PostThinkFrame(); #endif } @@ -769,7 +773,7 @@ void P_PreTicker(INT32 frames) P_PlayerAfterThink(&players[i]); #ifdef HAVE_BLUA - LUAh_ThinkFrame(); + LUAh_PostThinkFrame(); #endif // Run shield positioning From a36920808b74e068d582dda5a3b75bdf64246463 Mon Sep 17 00:00:00 2001 From: Nami <50415197+namishere@users.noreply.github.com> Date: Mon, 30 Dec 2019 19:04:27 -0800 Subject: [PATCH 2/6] Revert changes to searchBlockmap because on reflection, the benefits didn't outweigh breaking every current usage of it Readd ThinkFrame in its original position PostThinkFrame now runs at the end of P_Ticker, only MapEnd runs after it --- src/dehacked.c | 3 --- src/lua_blockmaplib.c | 40 ++++++++++++++++++++++------------------ src/lua_hook.h | 4 +++- src/lua_hooklib.c | 25 +++++++++++++++++++++++++ src/p_tick.c | 20 +++++++++++++++----- 5 files changed, 65 insertions(+), 27 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 450e33c16..4c90211cc 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -9824,9 +9824,6 @@ struct { {"TC_RAINBOW",TC_RAINBOW}, {"TC_BLINK",TC_BLINK}, {"TC_DASHMODE",TC_DASHMODE}, - - {"OPT_LINES", 1}, - {"OPT_MOBJS", 1<<1}, #endif {NULL,0} diff --git a/src/lua_blockmaplib.c b/src/lua_blockmaplib.c index 2130e9333..7f7dc9560 100644 --- a/src/lua_blockmaplib.c +++ b/src/lua_blockmaplib.c @@ -18,6 +18,11 @@ #include "lua_libs.h" //#include "lua_hud.h" // hud_running errors +static const char *const search_opt[] = { + "objects", + "lines", + NULL}; + // a quickly-made function pointer typedef used by lib_searchBlockmap... // return values: // 0 - normal, no interruptions @@ -174,18 +179,29 @@ static UINT8 lib_searchBlockmap_Lines(lua_State *L, INT32 x, INT32 y, mobj_t *th // false = searching of at least one block stopped mid-way (including if the whole search was stopped) static int lib_searchBlockmap(lua_State *L) { + int searchtype = luaL_checkoption(L, 1, "objects", search_opt); int n; mobj_t *mobj; INT32 xl, xh, yl, yh, bx, by; fixed_t x1, x2, y1, y2; boolean retval = true; - boolean repeat = false; UINT8 funcret = 0; + blockmap_func searchFunc; - UINT32 flags = luaL_checkinteger(L, 1); - lua_remove(L, 1); // remove flags, stack is now function, mobj, [x1, x2, y1, y2] + lua_remove(L, 1); // remove searchtype, stack is now function, mobj, [x1, x2, y1, y2] luaL_checktype(L, 1, LUA_TFUNCTION); + switch (searchtype) + { + case 0: // "objects" + default: + searchFunc = lib_searchBlockmap_Objects; + break; + case 1: // "lines" + searchFunc = lib_searchBlockmap_Lines; + break; + } + // the mobj we are searching around, the "calling" mobj we could say mobj = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); if (!mobj) @@ -224,14 +240,8 @@ static int lib_searchBlockmap(lua_State *L) validcount++; for (bx = xl; bx <= xh; bx++) for (by = yl; by <= yh; by++) - { - if (flags & (OPT_LINES|OPT_MOBJS)) - repeat = true; - if (flags & OPT_LINES) - funcret = lib_searchBlockmap_Lines(L, bx, by, mobj); - else - funcret = lib_searchBlockmap_Objects(L, bx, by, mobj); - doitagain: + { + funcret = searchFunc(L, bx, by, mobj); // return value of searchFunc determines searchFunc's return value and/or when to stop if (funcret == 2){ // stop whole search lua_pushboolean(L, false); // return false @@ -244,12 +254,6 @@ static int lib_searchBlockmap(lua_State *L) lua_pushboolean(L, false); // in which case we have to stop now regardless return 1; } - if (repeat) - { - funcret = lib_searchBlockmap_Objects(L, bx, by, mobj); - repeat = false; - goto doitagain; - } } lua_pushboolean(L, retval); return 1; @@ -261,4 +265,4 @@ int LUA_BlockmapLib(lua_State *L) return 0; } -#endif \ No newline at end of file +#endif diff --git a/src/lua_hook.h b/src/lua_hook.h index 620a7b307..d035be097 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -21,6 +21,7 @@ enum hook { hook_MapLoad, hook_PlayerJoin, hook_PreThinkFrame, + hook_ThinkFrame, hook_PostThinkFrame, hook_MobjSpawn, hook_MobjCollide, @@ -63,7 +64,8 @@ void LUAh_MapChange(INT16 mapnumber); // Hook for map change (before load) void LUAh_MapLoad(void); // Hook for map load void LUAh_PlayerJoin(int playernum); // Hook for Got_AddPlayer void LUAh_PreThinkFrame(void); // Hook for frame (before mobj and player thinkers) -void LUAh_PostThinkFrame(void); // Hook for frame (after mobj and player thinkers) +void LUAh_ThinkFrame(void); // Hook for frame (after mobj and player thinkers) +void LUAh_PostThinkFrame(void); // Hook for frame (at end of tick, ie after overlays, precipitation, specials) boolean LUAh_MobjHook(mobj_t *mo, enum hook which); boolean LUAh_PlayerHook(player_t *plr, enum hook which); #define LUAh_MobjSpawn(mo) LUAh_MobjHook(mo, hook_MobjSpawn) // Hook for P_SpawnMobj by mobj type diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index ace0f14d5..d548f6a65 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -32,6 +32,7 @@ const char *const hookNames[hook_MAX+1] = { "MapLoad", "PlayerJoin", "PreThinkFrame", + "ThinkFrame", "PostThinkFrame", "MobjSpawn", "MobjCollide", @@ -436,6 +437,30 @@ void LUAh_PreThinkFrame(void) } // Hook for frame (after mobj and player thinkers) +void LUAh_ThinkFrame(void) +{ + hook_p hookp; + if (!gL || !(hooksAvailable[hook_ThinkFrame/8] & (1<<(hook_ThinkFrame%8)))) + return; + + for (hookp = roothook; hookp; hookp = hookp->next) + { + if (hookp->type != hook_ThinkFrame) + continue; + + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + if (lua_pcall(gL, 0, 0, 0)) { + if (!hookp->error || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + hookp->error = true; + } + } +} + + +// Hook for frame (at end of tick, ie after overlays, precipitation, specials) void LUAh_PostThinkFrame(void) { hook_p hookp; diff --git a/src/p_tick.c b/src/p_tick.c index b92465fe4..e266f7013 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -646,9 +646,9 @@ void P_Ticker(boolean run) if (run) { - #ifdef HAVE_BLUA +#ifdef HAVE_BLUA LUAh_PreThinkFrame(); - #endif +#endif P_RunThinkers(); @@ -658,7 +658,7 @@ void P_Ticker(boolean run) P_PlayerAfterThink(&players[i]); #ifdef HAVE_BLUA - LUAh_PostThinkFrame(); + LUAh_ThinkFrame(); #endif } @@ -730,6 +730,10 @@ void P_Ticker(boolean run) G_ConsGhostTic(); if (modeattacking) G_GhostTicker(); + +#ifdef HAVE_BLUA + LUAh_PostThinkFrame(); +#endif } P_MapEnd(); @@ -764,7 +768,9 @@ void P_PreTicker(INT32 frames) memcpy(&players[i].cmd, &temptic, sizeof(ticcmd_t)); } - +#ifdef HAVE_BLUA + LUAh_PreThinkFrame(); +#endif P_RunThinkers(); // Run any "after all the other thinkers" stuff @@ -773,7 +779,7 @@ void P_PreTicker(INT32 frames) P_PlayerAfterThink(&players[i]); #ifdef HAVE_BLUA - LUAh_PostThinkFrame(); + LUAh_ThinkFrame(); #endif // Run shield positioning @@ -783,6 +789,10 @@ void P_PreTicker(INT32 frames) P_UpdateSpecials(); P_RespawnSpecials(); +#ifdef HAVE_BLUA + LUAh_PostThinkFrame(); +#endif + P_MapEnd(); } } From 41c902b819ac8fdef173c4ba76a8c50ad8107190 Mon Sep 17 00:00:00 2001 From: Nami <50415197+namishere@users.noreply.github.com> Date: Mon, 30 Dec 2019 19:11:49 -0800 Subject: [PATCH 3/6] Move PreThinkFrame hook back a bit, now runs before PlayerThink --- src/p_tick.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index e266f7013..13209c3f9 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -629,6 +629,10 @@ void P_Ticker(boolean run) if (demoplayback) G_ReadDemoTiccmd(&players[consoleplayer].cmd, 0); + #ifdef HAVE_BLUA + LUAh_PreThinkFrame(); + #endif + for (i = 0; i < MAXPLAYERS; i++) if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo)) P_PlayerThink(&players[i]); @@ -753,6 +757,9 @@ void P_PreTicker(INT32 frames) { P_MapStart(); +#ifdef HAVE_BLUA + LUAh_PreThinkFrame(); +#endif for (i = 0; i < MAXPLAYERS; i++) if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo)) { @@ -768,9 +775,7 @@ void P_PreTicker(INT32 frames) memcpy(&players[i].cmd, &temptic, sizeof(ticcmd_t)); } -#ifdef HAVE_BLUA - LUAh_PreThinkFrame(); -#endif + P_RunThinkers(); // Run any "after all the other thinkers" stuff From 60928db0e0b08fee7ceddd5515adf2246bb655c3 Mon Sep 17 00:00:00 2001 From: Nami <50415197+namishere@users.noreply.github.com> Date: Mon, 30 Dec 2019 19:22:12 -0800 Subject: [PATCH 4/6] I removed a hook I left behind and forgot to save the change before committing :upside_down: --- src/p_tick.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index 13209c3f9..9b56ee1c2 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -650,10 +650,6 @@ void P_Ticker(boolean run) if (run) { -#ifdef HAVE_BLUA - LUAh_PreThinkFrame(); -#endif - P_RunThinkers(); // Run any "after all the other thinkers" stuff From ef4840555e2c52a781e69ade5c56a88f70963af9 Mon Sep 17 00:00:00 2001 From: Nami <50415197+namishere@users.noreply.github.com> Date: Tue, 31 Dec 2019 15:17:02 -0800 Subject: [PATCH 5/6] Add MobjLineCollide hook --- src/lua_hook.h | 3 ++ src/lua_hooklib.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++ src/p_map.c | 11 +++++++ 3 files changed, 95 insertions(+) diff --git a/src/lua_hook.h b/src/lua_hook.h index d035be097..6f8805708 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -25,6 +25,7 @@ enum hook { hook_PostThinkFrame, hook_MobjSpawn, hook_MobjCollide, + hook_MobjLineCollide, hook_MobjMoveCollide, hook_TouchSpecial, hook_MobjFuse, @@ -70,7 +71,9 @@ boolean LUAh_MobjHook(mobj_t *mo, enum hook which); boolean LUAh_PlayerHook(player_t *plr, enum hook which); #define LUAh_MobjSpawn(mo) LUAh_MobjHook(mo, hook_MobjSpawn) // Hook for P_SpawnMobj by mobj type UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which); +UINT8 LUAh_MobjLineCollideHook(mobj_t *thing, line_t *line, enum hook which); #define LUAh_MobjCollide(thing1, thing2) LUAh_MobjCollideHook(thing1, thing2, hook_MobjCollide) // Hook for PIT_CheckThing by (thing) mobj type +#define LUAh_MobjLineCollide(thing, line) LUAh_MobjLineCollideHook(thing, line, hook_MobjLineCollide) // Hook for PIT_CheckThing by (thing) mobj type #define LUAh_MobjMoveCollide(thing1, thing2) LUAh_MobjCollideHook(thing1, thing2, hook_MobjMoveCollide) // Hook for PIT_CheckThing by (tmthing) mobj type boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher); // Hook for P_TouchSpecialThing by mobj type #define LUAh_MobjFuse(mo) LUAh_MobjHook(mo, hook_MobjFuse) // Hook for mobj->fuse == 0 by mobj type diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index d548f6a65..2d9a98c4b 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -36,6 +36,7 @@ const char *const hookNames[hook_MAX+1] = { "PostThinkFrame", "MobjSpawn", "MobjCollide", + "MobjLineCollide", "MobjMoveCollide", "TouchSpecial", "MobjFuse", @@ -125,6 +126,7 @@ static int lib_addHook(lua_State *L) // Take a mobjtype enum which this hook is specifically for. case hook_MobjSpawn: case hook_MobjCollide: + case hook_MobjLineCollide: case hook_MobjMoveCollide: case hook_TouchSpecial: case hook_MobjFuse: @@ -184,6 +186,7 @@ static int lib_addHook(lua_State *L) lastp = &mobjthinkerhooks[hook.s.mt]; break; case hook_MobjCollide: + case hook_MobjLineCollide: case hook_MobjMoveCollide: lastp = &mobjcollidehooks[hook.s.mt]; break; @@ -562,6 +565,84 @@ UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which) return shouldCollide; } +UINT8 LUAh_MobjLineCollideHook(mobj_t *thing, line_t *line, enum hook which) +{ + hook_p hookp; + UINT8 shouldCollide = 0; // 0 = default, 1 = force yes, 2 = force no. + if (!gL || !(hooksAvailable[which/8] & (1<<(which%8)))) + return 0; + + I_Assert(thing->type < NUMMOBJTYPES); + + lua_settop(gL, 0); + + // Look for all generic mobj collision hooks + for (hookp = mobjcollidehooks[MT_NULL]; hookp; hookp = hookp->next) + { + if (hookp->type != which) + continue; + + if (lua_gettop(gL) == 0) + { + LUA_PushUserdata(gL, thing, META_MOBJ); + LUA_PushUserdata(gL, line, META_LINE); + } + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + lua_pushvalue(gL, -3); + lua_pushvalue(gL, -3); + if (lua_pcall(gL, 2, 1, 0)) { + if (!hookp->error || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + hookp->error = true; + continue; + } + if (!lua_isnil(gL, -1)) + { // if nil, leave shouldCollide = 0. + if (lua_toboolean(gL, -1)) + shouldCollide = 1; // Force yes + else + shouldCollide = 2; // Force no + } + lua_pop(gL, 1); + } + + for (hookp = mobjcollidehooks[thing->type]; hookp; hookp = hookp->next) + { + if (hookp->type != which) + continue; + + if (lua_gettop(gL) == 0) + { + LUA_PushUserdata(gL, thing, META_MOBJ); + LUA_PushUserdata(gL, line, META_LINE); + } + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + lua_pushvalue(gL, -3); + lua_pushvalue(gL, -3); + if (lua_pcall(gL, 2, 1, 0)) { + if (!hookp->error || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + hookp->error = true; + continue; + } + if (!lua_isnil(gL, -1)) + { // if nil, leave shouldCollide = 0. + if (lua_toboolean(gL, -1)) + shouldCollide = 1; // Force yes + else + shouldCollide = 2; // Force no + } + lua_pop(gL, 1); + } + + lua_settop(gL, 0); + return shouldCollide; +} + // Hook for mobj thinkers boolean LUAh_MobjThinker(mobj_t *mo) { diff --git a/src/p_map.c b/src/p_map.c index 1b6f23cde..628268bff 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1988,6 +1988,17 @@ static boolean PIT_CheckLine(line_t *ld) if (lowfloor < tmdropoffz) tmdropoffz = lowfloor; +#ifdef HAVE_BLUA + { + UINT8 shouldCollide = LUAh_MobjLineCollide(tmthing, ld); // checks hook for thing's type + if (P_MobjWasRemoved(tmthing)) + return true; // one of them was removed??? + if (shouldCollide == 1) + return false; // force collide + else if (shouldCollide == 2) + return true; // force no collide + } +#endif return true; } From ad610ba4aa65ead17d1a9696bbc76077ea3dd830 Mon Sep 17 00:00:00 2001 From: Nami <50415197+namishere@users.noreply.github.com> Date: Wed, 1 Jan 2020 19:38:48 -0800 Subject: [PATCH 6/6] Move MobjLineCollide up a bit to where we first know for sure that we hit a line --- src/p_map.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index 628268bff..4cc591330 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1943,6 +1943,19 @@ static boolean PIT_CheckLine(line_t *ld) // this line is out of the if so upper and lower textures can be hit by a splat blockingline = ld; + +#ifdef HAVE_BLUA + { + UINT8 shouldCollide = LUAh_MobjLineCollide(tmthing, blockingline); // checks hook for thing's type + if (P_MobjWasRemoved(tmthing)) + return true; // one of them was removed??? + if (shouldCollide == 1) + return false; // force collide + else if (shouldCollide == 2) + return true; // force no collide + } +#endif + if (!ld->backsector) // one sided line { if (P_PointOnLineSide(tmthing->x, tmthing->y, ld)) @@ -1987,18 +2000,7 @@ static boolean PIT_CheckLine(line_t *ld) if (lowfloor < tmdropoffz) tmdropoffz = lowfloor; - -#ifdef HAVE_BLUA - { - UINT8 shouldCollide = LUAh_MobjLineCollide(tmthing, ld); // checks hook for thing's type - if (P_MobjWasRemoved(tmthing)) - return true; // one of them was removed??? - if (shouldCollide == 1) - return false; // force collide - else if (shouldCollide == 2) - return true; // force no collide - } -#endif + return true; }