Implement input.ignoregameinputs

This commit is contained in:
LJ Sonic 2023-10-27 17:34:29 +02:00
parent 23268bf3e5
commit 4fa4d6e076
4 changed files with 36 additions and 4 deletions

View file

@ -51,6 +51,7 @@
#include "r_fps.h" // frame interpolation/uncapped #include "r_fps.h" // frame interpolation/uncapped
#include "lua_hud.h" #include "lua_hud.h"
#include "lua_libs.h"
gameaction_t gameaction; gameaction_t gameaction;
gamestate_t gamestate = GS_NULL; gamestate_t gamestate = GS_NULL;
@ -1170,7 +1171,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer)
// why build a ticcmd if we're paused? // why build a ticcmd if we're paused?
// Or, for that matter, if we're being reborn. // Or, for that matter, if we're being reborn.
// ...OR if we're blindfolded. No looking into the floor. // ...OR if we're blindfolded. No looking into the floor.
if (paused || P_AutoPause() || (gamestate == GS_LEVEL && (player->playerstate == PST_REBORN || ((gametyperules & GTR_TAG) if (ignoregameinputs || paused || P_AutoPause() || (gamestate == GS_LEVEL && (player->playerstate == PST_REBORN || ((gametyperules & GTR_TAG)
&& (leveltime < hidetime * TICRATE) && (player->pflags & PF_TAGIT))))) && (leveltime < hidetime * TICRATE) && (player->pflags & PF_TAGIT)))))
{//@TODO splitscreen player {//@TODO splitscreen player
cmd->angleturn = ticcmd_oldangleturn[forplayer]; cmd->angleturn = ticcmd_oldangleturn[forplayer];

View file

@ -18,6 +18,8 @@
#include "hu_stuff.h" // need HUFONT start & end #include "hu_stuff.h" // need HUFONT start & end
#include "netcode/d_net.h" #include "netcode/d_net.h"
#include "console.h" #include "console.h"
#include "lua_script.h"
#include "lua_libs.h"
#define MAXMOUSESENSITIVITY 100 // sensitivity steps #define MAXMOUSESENSITIVITY 100 // sensitivity steps
@ -116,7 +118,10 @@ void G_MapEventsToControls(event_t *ev)
{ {
case ev_keydown: case ev_keydown:
if (ev->key < NUMINPUTS) if (ev->key < NUMINPUTS)
{
if (!ignoregameinputs)
gamekeydown[ev->key] = 1; gamekeydown[ev->key] = 1;
}
#ifdef PARANOIA #ifdef PARANOIA
else else
{ {
@ -144,7 +149,7 @@ void G_MapEventsToControls(event_t *ev)
case ev_joystick: // buttons are virtual keys case ev_joystick: // buttons are virtual keys
i = ev->key; i = ev->key;
if (i >= JOYAXISSET || menuactive || CON_Ready() || chat_on) if (i >= JOYAXISSET || menuactive || CON_Ready() || chat_on || ignoregameinputs)
break; break;
if (ev->x != INT32_MAX) joyxmove[i] = ev->x; if (ev->x != INT32_MAX) joyxmove[i] = ev->x;
if (ev->y != INT32_MAX) joyymove[i] = ev->y; if (ev->y != INT32_MAX) joyymove[i] = ev->y;
@ -152,7 +157,7 @@ void G_MapEventsToControls(event_t *ev)
case ev_joystick2: // buttons are virtual keys case ev_joystick2: // buttons are virtual keys
i = ev->key; i = ev->key;
if (i >= JOYAXISSET || menuactive || CON_Ready() || chat_on) if (i >= JOYAXISSET || menuactive || CON_Ready() || chat_on || ignoregameinputs)
break; break;
if (ev->x != INT32_MAX) joy2xmove[i] = ev->x; if (ev->x != INT32_MAX) joy2xmove[i] = ev->x;
if (ev->y != INT32_MAX) joy2ymove[i] = ev->y; if (ev->y != INT32_MAX) joy2ymove[i] = ev->y;

View file

@ -20,6 +20,7 @@
#include "lua_libs.h" #include "lua_libs.h"
boolean mousegrabbedbylua = true; boolean mousegrabbedbylua = true;
boolean ignoregameinputs = false;
/////////////// ///////////////
// FUNCTIONS // // FUNCTIONS //
@ -163,12 +164,33 @@ static int lib_get(lua_State *L)
LUA_PushUserdata(L, &mouse2, META_MOUSE); LUA_PushUserdata(L, &mouse2, META_MOUSE);
return 1; return 1;
} }
else if (fastcmp(field, "ignoregameinputs"))
{
lua_pushboolean(L, ignoregameinputs);
return 1;
}
else else
{ {
return 0; return 0;
} }
} }
static int lib_set(lua_State *L)
{
const char *field = luaL_checkstring(L, 2);
if (fastcmp(field, "ignoregameinputs"))
{
ignoregameinputs = luaL_checkboolean(L, 3);
}
else
{
lua_rawset(L, 1);
}
return 0;
}
/////////////////// ///////////////////
// gamekeydown[] // // gamekeydown[] //
/////////////////// ///////////////////
@ -282,6 +304,9 @@ int LUA_InputLib(lua_State *L)
lua_createtable(L, 0, 2); lua_createtable(L, 0, 2);
lua_pushcfunction(L, lib_get); lua_pushcfunction(L, lib_get);
lua_setfield(L, -2, "__index"); lua_setfield(L, -2, "__index");
lua_pushcfunction(L, lib_set);
lua_setfield(L, -2, "__newindex");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
lua_newuserdata(L, 0); lua_newuserdata(L, 0);

View file

@ -13,6 +13,7 @@
extern lua_State *gL; extern lua_State *gL;
extern boolean mousegrabbedbylua; extern boolean mousegrabbedbylua;
extern boolean ignoregameinputs;
#define MUTABLE_TAGS #define MUTABLE_TAGS