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
This commit is contained in:
Nami 2019-12-30 19:04:27 -08:00
parent 58dd578b09
commit a36920808b
5 changed files with 65 additions and 27 deletions

View File

@ -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}

View File

@ -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
#endif

View File

@ -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

View File

@ -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;

View File

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