add deadzone + storing of previous joyx/y values etc to attempt to make joysticks less sensitive in menus

This commit is contained in:
Monster Iestyn 2018-12-02 21:52:30 +00:00 committed by mazmazz
parent 9ea0df0986
commit 71eaabea75

View file

@ -54,6 +54,8 @@
#include "st_stuff.h" #include "st_stuff.h"
#include "i_sound.h" #include "i_sound.h"
#include "i_joy.h" // for joystick menu controls
// Condition Sets // Condition Sets
#include "m_cond.h" #include "m_cond.h"
@ -2064,6 +2066,7 @@ boolean M_Responder(event_t *ev)
INT32 ch = -1; INT32 ch = -1;
// INT32 i; // INT32 i;
static tic_t joywait = 0, mousewait = 0; static tic_t joywait = 0, mousewait = 0;
static INT32 pjoyx = 0, pjoyy = 0;
static INT32 pmousex = 0, pmousey = 0; static INT32 pmousex = 0, pmousey = 0;
static INT32 lastx = 0, lasty = 0; static INT32 lastx = 0, lasty = 0;
void (*routine)(INT32 choice); // for some casting problem void (*routine)(INT32 choice); // for some casting problem
@ -2116,32 +2119,45 @@ boolean M_Responder(event_t *ev)
{ {
if (ev->type == ev_joystick && ev->data1 == 0 && joywait < I_GetTime()) if (ev->type == ev_joystick && ev->data1 == 0 && joywait < I_GetTime())
{ {
const INT32 jdeadzone = JOYAXISRANGE/4;
if (ev->data3 != INT32_MAX) if (ev->data3 != INT32_MAX)
{ {
if (ev->data3 < 0) if (Joystick.bGamepadStyle || abs(ev->data3) > jdeadzone)
{
if (ev->data3 < 0 && pjoyy >= 0)
{ {
ch = KEY_UPARROW; ch = KEY_UPARROW;
joywait = I_GetTime() + NEWTICRATE/7; joywait = I_GetTime() + NEWTICRATE/7;
} }
else if (ev->data3 > 0) else if (ev->data3 > 0 && pjoyy <= 0)
{ {
ch = KEY_DOWNARROW; ch = KEY_DOWNARROW;
joywait = I_GetTime() + NEWTICRATE/7; joywait = I_GetTime() + NEWTICRATE/7;
} }
pjoyy = ev->data3;
}
else
pjoyy = 0;
} }
if (ev->data2 != INT32_MAX) if (ev->data2 != INT32_MAX)
{ {
if (ev->data2 < 0) if (Joystick.bGamepadStyle || abs(ev->data2) > jdeadzone)
{
if (ev->data2 < 0 && pjoyx >= 0)
{ {
ch = KEY_LEFTARROW; ch = KEY_LEFTARROW;
joywait = I_GetTime() + NEWTICRATE/17; joywait = I_GetTime() + NEWTICRATE/17;
} }
else if (ev->data2 > 0) else if (ev->data2 > 0 && pjoyx <= 0)
{ {
ch = KEY_RIGHTARROW; ch = KEY_RIGHTARROW;
joywait = I_GetTime() + NEWTICRATE/17; joywait = I_GetTime() + NEWTICRATE/17;
} }
pjoyx = ev->data2;
}
else
pjoyx = 0;
} }
} }
else if (ev->type == ev_mouse && mousewait < I_GetTime()) else if (ev->type == ev_mouse && mousewait < I_GetTime())