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