mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-26 20:31:30 +00:00
Merge branch 'lua-ports' into 'next'
Some Lua ports from 2.2 See merge request KartKrew/Kart-Public!241
This commit is contained in:
commit
4c2b6de02c
7 changed files with 169 additions and 13 deletions
|
@ -20,6 +20,14 @@
|
|||
// Command buffer & command execution
|
||||
//===================================
|
||||
|
||||
/* Lua command registration flags. */
|
||||
enum
|
||||
{
|
||||
COM_ADMIN = 1,
|
||||
COM_SPLITSCREEN = 2,
|
||||
COM_LOCAL = 4,
|
||||
};
|
||||
|
||||
typedef void (*com_func_t)(void);
|
||||
|
||||
void COM_AddCommand(const char *name, com_func_t func);
|
||||
|
|
|
@ -8685,6 +8685,11 @@ struct {
|
|||
{"BT_CUSTOM2",BT_CUSTOM2}, // Lua customizable
|
||||
{"BT_CUSTOM3",BT_CUSTOM3}, // Lua customizable
|
||||
|
||||
// Lua command registration flags
|
||||
{"COM_ADMIN",COM_ADMIN},
|
||||
{"COM_SPLITSCREEN",COM_SPLITSCREEN},
|
||||
{"COM_LOCAL",COM_LOCAL},
|
||||
|
||||
// cvflags_t
|
||||
{"CV_SAVE",CV_SAVE},
|
||||
{"CV_CALL",CV_CALL},
|
||||
|
@ -9713,12 +9718,12 @@ static inline int lib_getenum(lua_State *L)
|
|||
return 0;
|
||||
LUA_PushUserdata(L, &players[consoleplayer], META_PLAYER);
|
||||
return 1;
|
||||
/*} else if (fastcmp(word,"admin")) {
|
||||
LUA_Deprecated(L, "admin", "IsPlayerAdmin(player)");
|
||||
if (!playeringame[adminplayers[0]] || IsPlayerAdmin(serverplayer))
|
||||
return 0;
|
||||
LUA_PushUserdata(L, &players[adminplayers[0]], META_PLAYER);
|
||||
return 1;*/
|
||||
} else if (fastcmp(word,"isserver")) {
|
||||
lua_pushboolean(L, server);
|
||||
return 1;
|
||||
} else if (fastcmp(word, "isdedicatedserver")) {
|
||||
lua_pushboolean(L, dedicated);
|
||||
return 1;
|
||||
} else if (fastcmp(word,"gravity")) {
|
||||
lua_pushinteger(L, gravity);
|
||||
return 1;
|
||||
|
|
|
@ -113,12 +113,12 @@ void COM_Lua_f(void)
|
|||
|
||||
lua_rawgeti(gL, -1, 2); // push flags from command info table
|
||||
if (lua_isboolean(gL, -1))
|
||||
flags = (lua_toboolean(gL, -1) ? 1 : 0);
|
||||
flags = (lua_toboolean(gL, -1) ? COM_ADMIN : 0);
|
||||
else
|
||||
flags = (UINT8)lua_tointeger(gL, -1);
|
||||
lua_pop(gL, 1); // pop flags
|
||||
|
||||
if (flags & 2) // flag 2: splitscreen player command. TODO: support 4P
|
||||
if (flags & COM_SPLITSCREEN) // flag 2: splitscreen player command. TODO: support 4P
|
||||
{
|
||||
if (!splitscreen)
|
||||
{
|
||||
|
@ -128,12 +128,12 @@ void COM_Lua_f(void)
|
|||
playernum = displayplayers[1];
|
||||
}
|
||||
|
||||
if (netgame)
|
||||
if (netgame && !( flags & COM_LOCAL ))/* don't send local commands */
|
||||
{ // Send the command through the network
|
||||
UINT8 argc;
|
||||
lua_pop(gL, 1); // pop command info table
|
||||
|
||||
if (flags & 1 && !server && !IsPlayerAdmin(playernum)) // flag 1: only server/admin can use this command.
|
||||
if (flags & COM_ADMIN && !server && !IsPlayerAdmin(playernum)) // flag 1: only server/admin can use this command.
|
||||
{
|
||||
CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n"));
|
||||
return;
|
||||
|
@ -187,7 +187,15 @@ static int lib_comAddCommand(lua_State *L)
|
|||
if (lua_gettop(L) >= 3)
|
||||
{ // For the third argument, only take a boolean or a number.
|
||||
lua_settop(L, 3);
|
||||
if (lua_type(L, 3) != LUA_TBOOLEAN)
|
||||
if (lua_type(L, 3) == LUA_TBOOLEAN)
|
||||
{
|
||||
CONS_Alert(CONS_WARNING,
|
||||
"Using a boolean for admin commands is "
|
||||
"deprecated and will be removed.\n"
|
||||
"Use \"COM_ADMIN\" instead.\n"
|
||||
);
|
||||
}
|
||||
else
|
||||
luaL_checktype(L, 3, LUA_TNUMBER);
|
||||
}
|
||||
else
|
||||
|
@ -436,6 +444,45 @@ static int lib_cvFindVar(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int CVarSetFunction
|
||||
(
|
||||
lua_State *L,
|
||||
void (*Set)(consvar_t *, const char *),
|
||||
void (*SetValue)(consvar_t *, INT32)
|
||||
){
|
||||
consvar_t *cvar = (consvar_t *)luaL_checkudata(L, 1, META_CVAR);
|
||||
|
||||
switch (lua_type(L, 2))
|
||||
{
|
||||
case LUA_TSTRING:
|
||||
(*Set)(cvar, lua_tostring(L, 2));
|
||||
break;
|
||||
case LUA_TNUMBER:
|
||||
(*SetValue)(cvar, (INT32)lua_tonumber(L, 2));
|
||||
break;
|
||||
default:
|
||||
return luaL_typerror(L, 1, "string or number");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lib_cvSet(lua_State *L)
|
||||
{
|
||||
return CVarSetFunction(L, CV_Set, CV_SetValue);
|
||||
}
|
||||
|
||||
static int lib_cvStealthSet(lua_State *L)
|
||||
{
|
||||
return CVarSetFunction(L, CV_StealthSet, CV_StealthSetValue);
|
||||
}
|
||||
|
||||
static int lib_cvAddValue(lua_State *L)
|
||||
{
|
||||
consvar_t *cvar = (consvar_t *)luaL_checkudata(L, 1, META_CVAR);
|
||||
CV_AddValue(cvar, (INT32)luaL_checknumber(L, 2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// CONS_Printf for a single player
|
||||
// Use 'print' in baselib for a global message.
|
||||
|
@ -475,8 +522,11 @@ static luaL_Reg lib[] = {
|
|||
{"COM_BufAddText", lib_comBufAddText},
|
||||
{"COM_BufInsertText", lib_comBufInsertText},
|
||||
{"CV_RegisterVar", lib_cvRegisterVar},
|
||||
{"CONS_Printf", lib_consPrintf},
|
||||
{"CV_FindVar", lib_cvFindVar},
|
||||
{"CV_Set", lib_cvSet},
|
||||
{"CV_StealthSet", lib_cvStealthSet},
|
||||
{"CV_AddValue", lib_cvAddValue},
|
||||
{"CONS_Printf", lib_consPrintf},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
|
@ -20,7 +20,9 @@ enum hook {
|
|||
hook_MapChange,
|
||||
hook_MapLoad,
|
||||
hook_PlayerJoin,
|
||||
hook_PreThinkFrame,
|
||||
hook_ThinkFrame,
|
||||
hook_PostThinkFrame,
|
||||
hook_MobjSpawn,
|
||||
hook_MobjCollide,
|
||||
hook_MobjMoveCollide,
|
||||
|
@ -44,6 +46,7 @@ enum hook {
|
|||
hook_HurtMsg,
|
||||
hook_PlayerSpawn,
|
||||
hook_PlayerQuit,
|
||||
hook_PlayerThink,
|
||||
hook_MusicChange,
|
||||
hook_ShouldSpin, //SRB2KART
|
||||
hook_ShouldExplode, //SRB2KART
|
||||
|
@ -64,7 +67,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
|
||||
|
@ -106,5 +111,6 @@ boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd); // Allows to write to p
|
|||
|
||||
void LUAh_IntermissionThinker(void); // Hook for Y_Ticker
|
||||
void LUAh_VoteThinker(void); // Hook for Y_VoteTicker
|
||||
#define LUAh_PlayerThink(player) LUAh_PlayerHook(player, hook_PlayerThink) // Hook for P_PlayerThink
|
||||
|
||||
#endif
|
||||
|
|
|
@ -31,7 +31,9 @@ const char *const hookNames[hook_MAX+1] = {
|
|||
"MapChange",
|
||||
"MapLoad",
|
||||
"PlayerJoin",
|
||||
"PreThinkFrame",
|
||||
"ThinkFrame",
|
||||
"PostThinkFrame",
|
||||
"MobjSpawn",
|
||||
"MobjCollide",
|
||||
"MobjMoveCollide",
|
||||
|
@ -55,6 +57,7 @@ const char *const hookNames[hook_MAX+1] = {
|
|||
"HurtMsg",
|
||||
"PlayerSpawn",
|
||||
"PlayerQuit",
|
||||
"PlayerThink",
|
||||
"MusicChange",
|
||||
"ShouldSpin",
|
||||
"ShouldExplode",
|
||||
|
@ -206,6 +209,7 @@ static int lib_addHook(lua_State *L)
|
|||
case hook_SpinSpecial:
|
||||
case hook_JumpSpinSpecial:
|
||||
case hook_PlayerSpawn:
|
||||
case hook_PlayerThink:
|
||||
lastp = &playerhooks;
|
||||
break;
|
||||
case hook_LinedefExecute:
|
||||
|
@ -402,6 +406,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 +450,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();
|
||||
}
|
||||
}
|
||||
|
|
23
src/p_user.c
23
src/p_user.c
|
@ -8244,7 +8244,12 @@ void P_PlayerThink(player_t *player)
|
|||
player->playerstate = PST_REBORN;
|
||||
}
|
||||
if (player->playerstate == PST_REBORN)
|
||||
{
|
||||
#ifdef HAVE_BLUA
|
||||
LUAh_PlayerThink(player);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SEENAMES
|
||||
|
@ -8368,7 +8373,12 @@ void P_PlayerThink(player_t *player)
|
|||
P_DoTimeOver(player);
|
||||
|
||||
if (player->playerstate == PST_DEAD)
|
||||
{
|
||||
#ifdef HAVE_BLUA
|
||||
LUAh_PlayerThink(player);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8432,7 +8442,9 @@ void P_PlayerThink(player_t *player)
|
|||
else
|
||||
player->mo->flags2 &= ~MF2_SHADOW;
|
||||
P_DeathThink(player);
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
LUAh_PlayerThink(player);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -8568,7 +8580,12 @@ void P_PlayerThink(player_t *player)
|
|||
P_MovePlayer(player);
|
||||
|
||||
if (!player->mo)
|
||||
{
|
||||
#ifdef HAVE_BLUA
|
||||
LUAh_PlayerThink(player);
|
||||
#endif
|
||||
return; // P_MovePlayer removed player->mo.
|
||||
}
|
||||
|
||||
// Unset statis flags after moving.
|
||||
// In other words, if you manually set stasis via code,
|
||||
|
@ -8764,6 +8781,10 @@ void P_PlayerThink(player_t *player)
|
|||
|
||||
K_KartPlayerThink(player, cmd); // SRB2kart
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
LUAh_PlayerThink(player);
|
||||
#endif
|
||||
|
||||
/*
|
||||
// Colormap verification
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue