mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-25 22:01:01 +00:00
Allow KeyDown to check gamepad buttons
This commit is contained in:
parent
207053a023
commit
c69442c9b7
3 changed files with 20 additions and 19 deletions
|
@ -89,26 +89,26 @@ static boolean CheckInputDown(UINT8 which, gamecontrols_e gc, boolean checkaxes)
|
|||
{
|
||||
INT32 (*controls)[2] = which == 0 ? gamecontrol : gamecontrolbis;
|
||||
|
||||
for (unsigned i = 0; i < 2; i++)
|
||||
return G_CheckKeyDown(which, controls[gc][0], checkaxes) || G_CheckKeyDown(which, controls[gc][1], checkaxes);
|
||||
}
|
||||
|
||||
boolean G_CheckKeyDown(UINT8 which, INT32 key, boolean checkaxes)
|
||||
{
|
||||
if (key >= KEY_GAMEPAD && key < KEY_AXES)
|
||||
{
|
||||
INT32 key = controls[gc][i];
|
||||
|
||||
if (key >= KEY_GAMEPAD && key < KEY_AXES)
|
||||
{
|
||||
if (gamepads[which].buttons[key - KEY_GAMEPAD])
|
||||
return true;
|
||||
}
|
||||
else if (checkaxes && (key >= KEY_AXES && key < KEY_INV_AXES + NUM_GAMEPAD_AXES))
|
||||
{
|
||||
const UINT16 jdeadzone = G_GetGamepadDigitalDeadZone(which);
|
||||
const INT16 value = G_GetGamepadAxisValue(which, (key - KEY_AXES) % NUM_GAMEPAD_AXES);
|
||||
|
||||
if (abs(value) > jdeadzone)
|
||||
return true;
|
||||
}
|
||||
else if (gamekeydown[key])
|
||||
if (gamepads[which].buttons[key - KEY_GAMEPAD])
|
||||
return true;
|
||||
}
|
||||
else if (checkaxes && (key >= KEY_AXES && key < KEY_INV_AXES + NUM_GAMEPAD_AXES))
|
||||
{
|
||||
const UINT16 jdeadzone = G_GetGamepadDigitalDeadZone(which);
|
||||
const INT16 value = G_GetGamepadAxisValue(which, (key - KEY_AXES) % NUM_GAMEPAD_AXES);
|
||||
|
||||
if (abs(value) > jdeadzone)
|
||||
return true;
|
||||
}
|
||||
else if (gamekeydown[key])
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -285,6 +285,7 @@ extern INT32 gamecontrolbis[NUM_GAMECONTROLS][2]; // secondary splitscreen playe
|
|||
extern INT32 gamecontroldefault[num_gamecontrolschemes][NUM_GAMECONTROLS][2];
|
||||
extern INT32 gamecontrolbisdefault[num_gamecontrolschemes][NUM_GAMECONTROLS][2];
|
||||
|
||||
boolean G_CheckKeyDown(UINT8 which, INT32 key, boolean checkaxes);
|
||||
boolean G_PlayerInputDown(UINT8 which, gamecontrols_e gc);
|
||||
boolean G_CheckDigitalPlayerInput(UINT8 which, gamecontrols_e gc);
|
||||
|
||||
|
|
|
@ -170,8 +170,8 @@ static int lib_getGameKeyDown(lua_State *L)
|
|||
{
|
||||
int i = luaL_checkinteger(L, 2);
|
||||
if (i < 0 || i >= NUMINPUTS)
|
||||
return luaL_error(L, "gamekeydown[] index %d out of range (0 - %d)", i, NUMINPUTS-1);
|
||||
lua_pushboolean(L, gamekeydown[i]);
|
||||
return luaL_error(L, "Key index %d out of range (0 - %d)", i, NUMINPUTS-1);
|
||||
lua_pushboolean(L, G_CheckKeyDown(0, i, false) || G_CheckKeyDown(1, i, false));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue