mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-29 20:50:58 +00:00
Let's try this again!
This commit is contained in:
parent
98313a8216
commit
58dd578b09
5 changed files with 60 additions and 31 deletions
|
@ -9824,6 +9824,9 @@ 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,11 +18,6 @@
|
||||||
#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
|
||||||
|
@ -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)
|
// 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;
|
|
||||||
|
|
||||||
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);
|
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)
|
||||||
|
@ -240,8 +224,14 @@ static int lib_searchBlockmap(lua_State *L)
|
||||||
validcount++;
|
validcount++;
|
||||||
for (bx = xl; bx <= xh; bx++)
|
for (bx = xl; bx <= xh; bx++)
|
||||||
for (by = yl; by <= yh; by++)
|
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
|
// 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
|
||||||
|
@ -254,6 +244,12 @@ 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;
|
||||||
|
@ -265,4 +261,4 @@ int LUA_BlockmapLib(lua_State *L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -20,7 +20,8 @@ enum hook {
|
||||||
hook_MapChange,
|
hook_MapChange,
|
||||||
hook_MapLoad,
|
hook_MapLoad,
|
||||||
hook_PlayerJoin,
|
hook_PlayerJoin,
|
||||||
hook_ThinkFrame,
|
hook_PreThinkFrame,
|
||||||
|
hook_PostThinkFrame,
|
||||||
hook_MobjSpawn,
|
hook_MobjSpawn,
|
||||||
hook_MobjCollide,
|
hook_MobjCollide,
|
||||||
hook_MobjMoveCollide,
|
hook_MobjMoveCollide,
|
||||||
|
@ -61,7 +62,8 @@ extern const char *const hookNames[];
|
||||||
void LUAh_MapChange(INT16 mapnumber); // Hook for map change (before load)
|
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_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_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
|
||||||
|
|
|
@ -31,7 +31,8 @@ const char *const hookNames[hook_MAX+1] = {
|
||||||
"MapChange",
|
"MapChange",
|
||||||
"MapLoad",
|
"MapLoad",
|
||||||
"PlayerJoin",
|
"PlayerJoin",
|
||||||
"ThinkFrame",
|
"PreThinkFrame",
|
||||||
|
"PostThinkFrame",
|
||||||
"MobjSpawn",
|
"MobjSpawn",
|
||||||
"MobjCollide",
|
"MobjCollide",
|
||||||
"MobjMoveCollide",
|
"MobjMoveCollide",
|
||||||
|
@ -411,16 +412,39 @@ void LUAh_PlayerJoin(int playernum)
|
||||||
lua_settop(gL, 0);
|
lua_settop(gL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook for frame (after mobj and player thinkers)
|
// Hook for frame (before mobj and player thinkers)
|
||||||
void LUAh_ThinkFrame(void)
|
void LUAh_PreThinkFrame(void)
|
||||||
{
|
{
|
||||||
hook_p hookp;
|
hook_p hookp;
|
||||||
if (!gL || !(hooksAvailable[hook_ThinkFrame/8] & (1<<(hook_ThinkFrame%8))))
|
if (!gL || !(hooksAvailable[hook_PreThinkFrame/8] & (1<<(hook_PreThinkFrame%8))))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (hookp = roothook; hookp; hookp = hookp->next)
|
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;
|
continue;
|
||||||
|
|
||||||
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
||||||
|
|
|
@ -646,6 +646,10 @@ void P_Ticker(boolean run)
|
||||||
|
|
||||||
if (run)
|
if (run)
|
||||||
{
|
{
|
||||||
|
#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
|
||||||
|
@ -654,7 +658,7 @@ void P_Ticker(boolean run)
|
||||||
P_PlayerAfterThink(&players[i]);
|
P_PlayerAfterThink(&players[i]);
|
||||||
|
|
||||||
#ifdef HAVE_BLUA
|
#ifdef HAVE_BLUA
|
||||||
LUAh_ThinkFrame();
|
LUAh_PostThinkFrame();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,7 +773,7 @@ void P_PreTicker(INT32 frames)
|
||||||
P_PlayerAfterThink(&players[i]);
|
P_PlayerAfterThink(&players[i]);
|
||||||
|
|
||||||
#ifdef HAVE_BLUA
|
#ifdef HAVE_BLUA
|
||||||
LUAh_ThinkFrame();
|
LUAh_PostThinkFrame();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Run shield positioning
|
// Run shield positioning
|
||||||
|
|
Loading…
Reference in a new issue