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(); } }