mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-26 04:11:18 +00:00
PreThinkFrame and PostThinkFrame hooks
Changes from 58dd578b094639405d452593562e0f8cb2b482ce, a36920808b74e068d582dda5a3b75bdf64246463, 41c902b819ac8fdef173c4ba76a8c50ad8107190, 60928db0e0b08fee7ceddd5515adf2246bb655c3.
This commit is contained in:
parent
3e31bc9e45
commit
a5db4ca572
3 changed files with 68 additions and 0 deletions
|
@ -20,7 +20,9 @@ enum hook {
|
|||
hook_MapChange,
|
||||
hook_MapLoad,
|
||||
hook_PlayerJoin,
|
||||
hook_PreThinkFrame,
|
||||
hook_ThinkFrame,
|
||||
hook_PostThinkFrame,
|
||||
hook_MobjSpawn,
|
||||
hook_MobjCollide,
|
||||
hook_MobjMoveCollide,
|
||||
|
@ -64,7 +66,9 @@ extern boolean hook_cmd_running; // This is used by PlayerCmd and lua_playerlib
|
|||
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_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
|
||||
|
|
|
@ -31,7 +31,9 @@ const char *const hookNames[hook_MAX+1] = {
|
|||
"MapChange",
|
||||
"MapLoad",
|
||||
"PlayerJoin",
|
||||
"PreThinkFrame",
|
||||
"ThinkFrame",
|
||||
"PostThinkFrame",
|
||||
"MobjSpawn",
|
||||
"MobjCollide",
|
||||
"MobjMoveCollide",
|
||||
|
@ -402,6 +404,29 @@ void LUAh_PlayerJoin(int playernum)
|
|||
lua_settop(gL, 0);
|
||||
}
|
||||
|
||||
// Hook for frame (before mobj and player thinkers)
|
||||
void LUAh_PreThinkFrame(void)
|
||||
{
|
||||
hook_p hookp;
|
||||
if (!gL || !(hooksAvailable[hook_PreThinkFrame/8] & (1<<(hook_PreThinkFrame%8))))
|
||||
return;
|
||||
|
||||
for (hookp = roothook; hookp; hookp = hookp->next)
|
||||
{
|
||||
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_ThinkFrame(void)
|
||||
{
|
||||
|
@ -423,6 +448,29 @@ void LUAh_ThinkFrame(void)
|
|||
}
|
||||
}
|
||||
|
||||
// Hook for frame (at end of tick, ie after overlays, precipitation, specials)
|
||||
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);
|
||||
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 Y_Ticker
|
||||
void LUAh_IntermissionThinker(void)
|
||||
{
|
||||
|
|
16
src/p_tick.c
16
src/p_tick.c
|
@ -648,6 +648,10 @@ void P_Ticker(boolean run)
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
LUAh_PreThinkFrame();
|
||||
#endif
|
||||
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo))
|
||||
P_PlayerThink(&players[i]);
|
||||
|
@ -779,6 +783,10 @@ void P_Ticker(boolean run)
|
|||
&& --mapreset <= 1
|
||||
&& server) // Remember: server uses it for mapchange, but EVERYONE ticks down for the animation
|
||||
D_MapChange(gamemap, gametype, encoremode, true, 0, false, false);
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
LUAh_PostThinkFrame();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Always move the camera.
|
||||
|
@ -809,6 +817,10 @@ void P_PreTicker(INT32 frames)
|
|||
{
|
||||
P_MapStart();
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
LUAh_PreThinkFrame();
|
||||
#endif
|
||||
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo))
|
||||
{
|
||||
|
@ -843,6 +855,10 @@ void P_PreTicker(INT32 frames)
|
|||
P_UpdateSpecials();
|
||||
P_RespawnSpecials();
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
LUAh_PostThinkFrame();
|
||||
#endif
|
||||
|
||||
P_MapEnd();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue