Properly implement joystick axes

NOW it's fully navigable with controller
This commit is contained in:
Sally Coolatta 2021-12-28 08:44:20 -05:00 committed by GenericHeroGuy
parent 9b3067a7a2
commit a934e09b0c
3 changed files with 31 additions and 32 deletions

View file

@ -438,10 +438,10 @@ consvar_t cv_shrinkme[MAXSPLITSCREENPLAYERS] = {
static CV_PossibleValue_t zerotoone_cons_t[] = {{0, "MIN"}, {FRACUNIT, "MAX"}, {0, NULL}};
consvar_t cv_deadzone[MAXSPLITSCREENPLAYERS] = {
CVAR_INIT ("joy_deadzone", "0.125", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL),
CVAR_INIT ("joy2_deadzone", "0.125", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL),
CVAR_INIT ("joy3_deadzone", "0.125", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL),
CVAR_INIT ("joy4_deadzone", "0.125", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL)
CVAR_INIT ("deadzone", "0.25", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL),
CVAR_INIT ("deadzone2", "0.25", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL),
CVAR_INIT ("deadzone3", "0.25", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL),
CVAR_INIT ("deadzone4", "0.25", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL)
};
// now automatically allocated in D_RegisterClientCommands

View file

@ -1177,7 +1177,7 @@ static UINT64 lastjoyhats[MAXSPLITSCREENPLAYERS] = {0,0,0,0};
*/
void I_ShutdownJoystick(UINT8 index)
{
INT32 i;
INT32 i, j;
event_t event;
event.type=ev_keyup;
event.data2 = 0;
@ -1186,22 +1186,25 @@ void I_ShutdownJoystick(UINT8 index)
lastjoybuttons[index] = lastjoyhats[index] = 0;
// emulate the up of all joystick buttons
for (i=0;i<JOYBUTTONS;i++)
for (i = 0; i < JOYBUTTONS; i++)
{
event.data1=KEY_JOY1+i;
D_PostEvent(&event);
}
// emulate the up of all joystick hats
for (i=0;i<JOYHATS*4;i++)
for (i = 0; i < JOYHATS*4; i++)
{
event.data1=KEY_HAT1+i;
for (j = 0; j < 4; j++)
{
event.data1 = KEY_HAT1 + (i * 4) + j;
D_PostEvent(&event);
}
}
// reset joystick position
event.type = ev_joystick;
for (i=0;i<JOYAXISSET; i++)
for (i = 0; i < JOYAXISSET; i++)
{
event.data1 = i;
D_PostEvent(&event);

View file

@ -541,13 +541,11 @@ static inline void SDLJoyRemap(event_t *event)
(void)event;
}
static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which, UINT8 pid)
static INT32 SDLJoyAxis(const Sint16 axis, UINT8 pid)
{
// -32768 to 32767
INT32 raxis = axis/32;
INT32 raxis = axis / 32;
if (which == ev_joystick)
{
if (Joystick[pid].bGamepadStyle)
{
// gamepad control type, on or off, live or die
@ -560,14 +558,13 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which, UINT8 pid)
}
else
{
raxis = JoyInfo[pid].scale!=1?((raxis/JoyInfo[pid].scale)*JoyInfo[pid].scale):raxis;
raxis = (JoyInfo[pid].scale != 1) ? ((raxis / JoyInfo[pid].scale) * JoyInfo[pid].scale) : raxis;
#ifdef SDL_JDEADZONE
if (-SDL_JDEADZONE <= raxis && raxis <= SDL_JDEADZONE)
raxis = 0;
#endif
}
}
return raxis;
}
@ -802,15 +799,14 @@ static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt)
event.type = ev_joystick;
event.data1 = event.data2 = event.data3 = INT32_MAX;
event.device = 1 + evt.which;
if (event.device == INT32_MAX)
{
return;
}
event.data1 = event.data2 = event.data3 = INT32_MAX;
//axis
switch (evt.axis)
{
@ -837,7 +833,7 @@ static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt)
}
//value
event.data2 = SDLJoyAxis(evt.value, event.type, event.device);
event.data2 = SDLJoyAxis(evt.value, 0); // TODO: replace 0 with pid
D_PostEvent(&event);
}