mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-18 07:22:28 +00:00
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:
parent
58dd578b09
commit
a36920808b
5 changed files with 65 additions and 27 deletions
|
@ -9824,9 +9824,6 @@ struct {
|
||||||
{"TC_RAINBOW",TC_RAINBOW},
|
{"TC_RAINBOW",TC_RAINBOW},
|
||||||
{"TC_BLINK",TC_BLINK},
|
{"TC_BLINK",TC_BLINK},
|
||||||
{"TC_DASHMODE",TC_DASHMODE},
|
{"TC_DASHMODE",TC_DASHMODE},
|
||||||
|
|
||||||
{"OPT_LINES", 1},
|
|
||||||
{"OPT_MOBJS", 1<<1},
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{NULL,0}
|
{NULL,0}
|
||||||
|
|
|
@ -18,6 +18,11 @@
|
||||||
#include "lua_libs.h"
|
#include "lua_libs.h"
|
||||||
//#include "lua_hud.h" // hud_running errors
|
//#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...
|
// a quickly-made function pointer typedef used by lib_searchBlockmap...
|
||||||
// return values:
|
// return values:
|
||||||
// 0 - normal, no interruptions
|
// 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)
|
// false = searching of at least one block stopped mid-way (including if the whole search was stopped)
|
||||||
static int lib_searchBlockmap(lua_State *L)
|
static int lib_searchBlockmap(lua_State *L)
|
||||||
{
|
{
|
||||||
|
int searchtype = luaL_checkoption(L, 1, "objects", search_opt);
|
||||||
int n;
|
int n;
|
||||||
mobj_t *mobj;
|
mobj_t *mobj;
|
||||||
INT32 xl, xh, yl, yh, bx, by;
|
INT32 xl, xh, yl, yh, bx, by;
|
||||||
fixed_t x1, x2, y1, y2;
|
fixed_t x1, x2, y1, y2;
|
||||||
boolean retval = true;
|
boolean retval = true;
|
||||||
boolean repeat = false;
|
|
||||||
UINT8 funcret = 0;
|
UINT8 funcret = 0;
|
||||||
|
blockmap_func searchFunc;
|
||||||
|
|
||||||
UINT32 flags = luaL_checkinteger(L, 1);
|
lua_remove(L, 1); // remove searchtype, stack is now function, mobj, [x1, x2, y1, y2]
|
||||||
lua_remove(L, 1); // remove flags, stack is now function, mobj, [x1, x2, y1, y2]
|
|
||||||
luaL_checktype(L, 1, LUA_TFUNCTION);
|
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
|
// the mobj we are searching around, the "calling" mobj we could say
|
||||||
mobj = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ));
|
mobj = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ));
|
||||||
if (!mobj)
|
if (!mobj)
|
||||||
|
@ -225,13 +241,7 @@ static int lib_searchBlockmap(lua_State *L)
|
||||||
for (bx = xl; bx <= xh; bx++)
|
for (bx = xl; bx <= xh; bx++)
|
||||||
for (by = yl; by <= yh; by++)
|
for (by = yl; by <= yh; by++)
|
||||||
{
|
{
|
||||||
if (flags & (OPT_LINES|OPT_MOBJS))
|
funcret = searchFunc(L, bx, by, mobj);
|
||||||
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
|
// return value of searchFunc determines searchFunc's return value and/or when to stop
|
||||||
if (funcret == 2){ // stop whole search
|
if (funcret == 2){ // stop whole search
|
||||||
lua_pushboolean(L, false); // return false
|
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
|
lua_pushboolean(L, false); // in which case we have to stop now regardless
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (repeat)
|
|
||||||
{
|
|
||||||
funcret = lib_searchBlockmap_Objects(L, bx, by, mobj);
|
|
||||||
repeat = false;
|
|
||||||
goto doitagain;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
lua_pushboolean(L, retval);
|
lua_pushboolean(L, retval);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -21,6 +21,7 @@ enum hook {
|
||||||
hook_MapLoad,
|
hook_MapLoad,
|
||||||
hook_PlayerJoin,
|
hook_PlayerJoin,
|
||||||
hook_PreThinkFrame,
|
hook_PreThinkFrame,
|
||||||
|
hook_ThinkFrame,
|
||||||
hook_PostThinkFrame,
|
hook_PostThinkFrame,
|
||||||
hook_MobjSpawn,
|
hook_MobjSpawn,
|
||||||
hook_MobjCollide,
|
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_MapLoad(void); // Hook for map load
|
||||||
void LUAh_PlayerJoin(int playernum); // Hook for Got_AddPlayer
|
void LUAh_PlayerJoin(int playernum); // Hook for Got_AddPlayer
|
||||||
void LUAh_PreThinkFrame(void); // Hook for frame (before 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)
|
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_MobjHook(mobj_t *mo, enum hook which);
|
||||||
boolean LUAh_PlayerHook(player_t *plr, 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
|
#define LUAh_MobjSpawn(mo) LUAh_MobjHook(mo, hook_MobjSpawn) // Hook for P_SpawnMobj by mobj type
|
||||||
|
|
|
@ -32,6 +32,7 @@ const char *const hookNames[hook_MAX+1] = {
|
||||||
"MapLoad",
|
"MapLoad",
|
||||||
"PlayerJoin",
|
"PlayerJoin",
|
||||||
"PreThinkFrame",
|
"PreThinkFrame",
|
||||||
|
"ThinkFrame",
|
||||||
"PostThinkFrame",
|
"PostThinkFrame",
|
||||||
"MobjSpawn",
|
"MobjSpawn",
|
||||||
"MobjCollide",
|
"MobjCollide",
|
||||||
|
@ -436,6 +437,30 @@ void LUAh_PreThinkFrame(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook for frame (after mobj and player thinkers)
|
// 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)
|
void LUAh_PostThinkFrame(void)
|
||||||
{
|
{
|
||||||
hook_p hookp;
|
hook_p hookp;
|
||||||
|
|
16
src/p_tick.c
16
src/p_tick.c
|
@ -658,7 +658,7 @@ void P_Ticker(boolean run)
|
||||||
P_PlayerAfterThink(&players[i]);
|
P_PlayerAfterThink(&players[i]);
|
||||||
|
|
||||||
#ifdef HAVE_BLUA
|
#ifdef HAVE_BLUA
|
||||||
LUAh_PostThinkFrame();
|
LUAh_ThinkFrame();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,6 +730,10 @@ void P_Ticker(boolean run)
|
||||||
G_ConsGhostTic();
|
G_ConsGhostTic();
|
||||||
if (modeattacking)
|
if (modeattacking)
|
||||||
G_GhostTicker();
|
G_GhostTicker();
|
||||||
|
|
||||||
|
#ifdef HAVE_BLUA
|
||||||
|
LUAh_PostThinkFrame();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
P_MapEnd();
|
P_MapEnd();
|
||||||
|
@ -764,7 +768,9 @@ void P_PreTicker(INT32 frames)
|
||||||
|
|
||||||
memcpy(&players[i].cmd, &temptic, sizeof(ticcmd_t));
|
memcpy(&players[i].cmd, &temptic, sizeof(ticcmd_t));
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_BLUA
|
||||||
|
LUAh_PreThinkFrame();
|
||||||
|
#endif
|
||||||
P_RunThinkers();
|
P_RunThinkers();
|
||||||
|
|
||||||
// Run any "after all the other thinkers" stuff
|
// Run any "after all the other thinkers" stuff
|
||||||
|
@ -773,7 +779,7 @@ void P_PreTicker(INT32 frames)
|
||||||
P_PlayerAfterThink(&players[i]);
|
P_PlayerAfterThink(&players[i]);
|
||||||
|
|
||||||
#ifdef HAVE_BLUA
|
#ifdef HAVE_BLUA
|
||||||
LUAh_PostThinkFrame();
|
LUAh_ThinkFrame();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Run shield positioning
|
// Run shield positioning
|
||||||
|
@ -783,6 +789,10 @@ void P_PreTicker(INT32 frames)
|
||||||
P_UpdateSpecials();
|
P_UpdateSpecials();
|
||||||
P_RespawnSpecials();
|
P_RespawnSpecials();
|
||||||
|
|
||||||
|
#ifdef HAVE_BLUA
|
||||||
|
LUAh_PostThinkFrame();
|
||||||
|
#endif
|
||||||
|
|
||||||
P_MapEnd();
|
P_MapEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue