Remove menu defaults/backup code from G_PlayerInputAnalog

Nothing except the extra event loop in CL_ServerConnectionTicker uses this,
because we still use old menus with events rather than inputs,
and that has its own system for default controls.

The third argument is now 'digital' to get rid of that pesky global boolean
This commit is contained in:
GenericHeroGuy 2025-03-11 21:50:05 +01:00
parent f547af9992
commit bfcee5d6c2
5 changed files with 41 additions and 81 deletions

View file

@ -1950,12 +1950,21 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic
}
else if (netgame)
{
event_t *ev;
INT32 key;
for (; eventtail != eventhead; eventtail = (eventtail+1) & (MAXEVENTS-1))
G_MapEventsToControls(&events[eventtail]);
{
ev = &events[eventtail];
if (ev->type == ev_joystick && G_GetDevicePlayer(ev->device) == 0 && !G_AxisInDeadzone(0, ev))
key = G_AxisToKey(ev);
else if (ev->type == ev_keydown)
key = ev->data1;
else
continue;
if (gamekeydown[0][KEY_ESCAPE]
|| G_PlayerInputDown(0, gc_brake, true))
cl_mode = CL_ABORTED;
if (key == KEY_ESCAPE || G_ControlBoundToKey(0, gc_brake, key, true))
cl_mode = CL_ABORTED;
}
}
if (cl_mode == CL_ABORTED)

View file

@ -770,8 +770,8 @@ boolean G_AxisInDeadzone(UINT8 p, event_t *ev)
}
// check if the given key is bound to the given gamecontrol
// if menu is true, also check defaults if the gamecontrol has no binds
boolean G_ControlBoundToKey(UINT8 p, INT32 gc, INT32 key, boolean menu)
// if defaults is true, also check default controls if the gamecontrol has no binds
boolean G_ControlBoundToKey(UINT8 p, INT32 gc, INT32 key, boolean defaults)
{
INT32 i;
INT32 (*map)[MAXINPUTMAPPING] = &gamecontrol[p][gc];
@ -779,10 +779,10 @@ boolean G_ControlBoundToKey(UINT8 p, INT32 gc, INT32 key, boolean menu)
if (key <= 0 || key >= NUMINPUTS)
return false;
if (menu)
if (defaults)
{
for (i = 0; i < MAXINPUTMAPPING; i++)
if (G_KeyIsAvailable((*map)[i], cv_usejoystick[p].value))
if (G_KeyIsAvailable((*map)[i], cv_usejoystick[p].value, false))
goto bound;
map = &gamecontroldefault[gc];
}
@ -795,14 +795,11 @@ bound:
return false;
}
INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean menu)
INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean digital)
{
INT32 deviceID;
INT32 i;
INT32 deadzone = 0;
boolean trydefaults = true;
boolean tryingotherID = false;
INT32 *controltable = &(gamecontrol[p][gc][0]);
if (p >= MAXSPLITSCREENPLAYERS)
{
@ -819,18 +816,15 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean menu)
retrygetcontrol:
for (i = 0; i < MAXINPUTMAPPING; i++)
{
INT32 key = controltable[i];
INT32 key = gamecontrol[p][gc][i];
INT32 value = 0;
// Invalid key number.
if (!G_KeyIsAvailable(key, deviceID))
if (!G_KeyIsAvailable(key, deviceID, digital))
{
continue;
}
// It's possible to access this control right now, so let's disable the default control backup for later.
trydefaults = false;
value = gamekeydown[deviceID][key];
if (value >= deadzone)
@ -840,58 +834,18 @@ retrygetcontrol:
}
// If you're on controller, try your keyboard-based binds as an immediate backup.
if (deviceID > 0 && !tryingotherID)
if (deviceID > 0)
{
deviceID = 0;
goto retrygetcontrol;
}
if (menu == false)
{
return 0;
}
// We don't want menus to become unnavigable if people unbind
// all of their controls, so we do several things in this scenario.
// First: try other controllers.
if (!tryingotherID)
{
deviceID = MAXDEVICES;
tryingotherID = true;
}
loweringid:
deviceID--;
if (deviceID > 0)
{
for (i = 0; i < cv_splitplayers.value-1; i++)
{
if (deviceID != cv_usejoystick[i].value)
continue;
// Controller taken? Try again...
goto loweringid;
}
goto retrygetcontrol;
}
if (trydefaults && G_KeyBindIsNecessary(gc))
{
// If we still haven't found anything and the keybind is necessary,
// try it all again but with default binds.
trydefaults = false;
controltable = &(gamecontroldefault[gc][0]);
tryingotherID = false;
deviceID = cv_usejoystick[p].value;
goto retrygetcontrol;
}
return 0;
}
boolean G_PlayerInputDown(UINT8 p, INT32 gc, boolean menu)
boolean G_PlayerInputDown(UINT8 p, INT32 gc, boolean digital)
{
return (G_PlayerInputAnalog(p, gc, menu) != 0);
return (G_PlayerInputAnalog(p, gc, digital) != 0);
}
// Take a magnitude of two axes, and adjust it to take out the deadzone
@ -1050,15 +1004,16 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer)
if (joystickvector.xaxis != 0)
{
turnheld[forplayer] += realtics;
if (turnheld[forplayer] < cv_turnsmooth.value * 3)
{
boolean digital;
inputcheckdigital = true;
digital = G_PlayerInputDown(forplayer, gc_turnleft, false) || G_PlayerInputDown(forplayer, gc_turnright, false);
inputcheckdigital = false;
if (digital)
// check turn input again, but this time digital only
// if it's false, an analog stick is inputting the turn; no smoothing!
if (G_PlayerInputDown(forplayer, gc_turnleft, true) || G_PlayerInputDown(forplayer, gc_turnright, true))
{
I_Assert(cv_turnsmooth.value);
joystickvector.xaxis /= cv_turnsmooth.value * 2;
}
}
}
else

View file

@ -117,9 +117,9 @@ INT16 G_SoftwareClipAimingPitch(INT32 *aiming);
extern angle_t localangle[MAXSPLITSCREENPLAYERS];
extern INT32 localaiming[MAXSPLITSCREENPLAYERS]; // should be an angle_t but signed
INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean menu);
boolean G_PlayerInputDown(UINT8 p, INT32 gc, boolean menu);
boolean G_ControlBoundToKey(UINT8 p, INT32 gc, INT32 key, boolean menu);
INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean digital);
boolean G_PlayerInputDown(UINT8 p, INT32 gc, boolean digital);
boolean G_ControlBoundToKey(UINT8 p, INT32 gc, INT32 key, boolean defaults);
boolean G_AxisInDeadzone(UINT8 p, event_t *ev);
//

View file

@ -401,10 +401,8 @@ boolean G_KeyBindIsNecessary(INT32 gc)
return false;
}
boolean inputcheckdigital = false;
// Returns false if a key is deemed unreachable for this device.
boolean G_KeyIsAvailable(INT32 key, INT32 deviceID)
boolean G_KeyIsAvailable(INT32 key, INT32 deviceID, boolean digital)
{
// Invalid key number.
if (key <= 0 || key >= NUMINPUTS)
@ -412,6 +410,12 @@ boolean G_KeyIsAvailable(INT32 key, INT32 deviceID)
return false;
}
// analog input only
if (digital && key >= KEY_AXIS1 && key < JOYINPUTEND)
{
return false;
}
// Valid keyboard-specific virtual key, but no keyboard attached for player.
if (key < NUMKEYS && deviceID > 0)
{
@ -432,12 +436,6 @@ boolean G_KeyIsAvailable(INT32 key, INT32 deviceID)
}
*/
// this is ugly as fuck, but it's also better than copy-pasting half of G_PlayerInputAnalog just for turn smoothing
if (inputcheckdigital && key >= KEY_AXIS1 && key < JOYINPUTEND)
{
return false;
}
return true;
}

View file

@ -134,9 +134,7 @@ const char *G_KeynumToString(INT32 keynum);
INT32 G_KeyStringtoNum(const char *keystr);
boolean G_KeyBindIsNecessary(INT32 gc);
boolean G_KeyIsAvailable(INT32 key, INT32 deviceID);
extern boolean inputcheckdigital;
boolean G_KeyIsAvailable(INT32 key, INT32 deviceID, boolean digital);
// detach any keys associated to the given game control
void G_ClearControlKeys(INT32 (*setupcontrols)[MAXINPUTMAPPING], INT32 control);