From ce4e63a3669c38ffb43c5dfef363db81d583259a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 2 Dec 2018 17:12:05 +0000 Subject: [PATCH 1/4] Miserable half-attempt to support hats in I_GetEvent, I've disabled it for now since I couldn't really figure out how to pull this off ...yet --- src/sdl/i_video.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 3cc29dbb..2c199c2d 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -767,6 +767,33 @@ static void Impl_HandleJoystickAxisEvent(SDL_JoyAxisEvent evt) D_PostEvent(&event); } +#if 0 +static void Impl_HandleJoystickHatEvent(SDL_JoyHatEvent evt) +{ + event_t event; + SDL_JoystickID joyid[2]; + + // Determine the Joystick IDs for each current open joystick + joyid[0] = SDL_JoystickInstanceID(JoyInfo.dev); + joyid[1] = SDL_JoystickInstanceID(JoyInfo2.dev); + + if (evt.hat >= JOYHATS) + return; // ignore hats with too high an index + + if (evt.which == joyid[0]) + { + event.data1 = KEY_HAT1 + (evt.hat*4); + } + else if (evt.which == joyid[1]) + { + event.data1 = KEY_2HAT1 + (evt.hat*4); + } + else return; + + // NOTE: UNFINISHED +} +#endif + static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type) { event_t event; @@ -804,6 +831,8 @@ static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type) if (event.type != ev_console) D_PostEvent(&event); } + + void I_GetEvent(void) { SDL_Event evt; @@ -844,6 +873,11 @@ void I_GetEvent(void) case SDL_JOYAXISMOTION: Impl_HandleJoystickAxisEvent(evt.jaxis); break; +#if 0 + case SDL_JOYHATMOTION: + Impl_HandleJoystickHatEvent(evt.jhat) + break; +#endif case SDL_JOYBUTTONUP: case SDL_JOYBUTTONDOWN: Impl_HandleJoystickButtonEvent(evt.jbutton, evt.type); From a63ba7084a7176a8d48620470c8f6ce8c330d20d Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 2 Dec 2018 17:42:51 +0000 Subject: [PATCH 2/4] Disable the axis parts of I_GetJoystickEvents and its player2 counterpart. (This is what I should have done in the first place) --- src/sdl/i_system.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 2b35ce8b..3bb4d08b 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -894,8 +894,8 @@ void I_GetJoystickEvents(void) UINT64 joyhats = 0; #if 0 UINT64 joybuttons = 0; -#endif Sint16 axisx, axisy; +#endif if (!joystick_started) return; @@ -963,6 +963,7 @@ void I_GetJoystickEvents(void) } } +#if 0 // send joystick axis positions event.type = ev_joystick; @@ -1013,6 +1014,7 @@ void I_GetJoystickEvents(void) } D_PostEvent(&event); } +#endif } /** \brief Open joystick handle @@ -1176,8 +1178,8 @@ void I_GetJoystick2Events(void) UINT64 joyhats = 0; #if 0 INT64 joybuttons = 0; -#endif INT32 axisx, axisy; +#endif if (!joystick2_started) return; @@ -1247,6 +1249,7 @@ void I_GetJoystick2Events(void) } } +#if 0 // send joystick axis positions event.type = ev_joystick2; @@ -1297,7 +1300,7 @@ void I_GetJoystick2Events(void) } D_PostEvent(&event); } - +#endif } /** \brief Open joystick handle From 13b0e9c3c59f203ba5596dd8f2e23c42fc33debb Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 2 Dec 2018 21:18:28 +0000 Subject: [PATCH 3/4] make menu respond to joystick axis events without joyscale having to be 0 --- src/m_menu.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index dfe8bbec..2d7f5eed 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2117,26 +2117,32 @@ boolean M_Responder(event_t *ev) { if (ev->type == ev_joystick && ev->data1 == 0 && joywait < I_GetTime()) { - if (ev->data3 == -1) + if (ev->data3 != INT32_MAX) { - ch = KEY_UPARROW; - joywait = I_GetTime() + NEWTICRATE/7; - } - else if (ev->data3 == 1) - { - ch = KEY_DOWNARROW; - joywait = I_GetTime() + NEWTICRATE/7; + if (ev->data3 < 0) + { + ch = KEY_UPARROW; + joywait = I_GetTime() + NEWTICRATE/7; + } + else if (ev->data3 > 0) + { + ch = KEY_DOWNARROW; + joywait = I_GetTime() + NEWTICRATE/7; + } } - if (ev->data2 == -1) + if (ev->data2 != INT32_MAX) { - ch = KEY_LEFTARROW; - joywait = I_GetTime() + NEWTICRATE/17; - } - else if (ev->data2 == 1) - { - ch = KEY_RIGHTARROW; - joywait = I_GetTime() + NEWTICRATE/17; + if (ev->data2 < 0) + { + ch = KEY_LEFTARROW; + joywait = I_GetTime() + NEWTICRATE/17; + } + else if (ev->data2 > 0) + { + ch = KEY_RIGHTARROW; + joywait = I_GetTime() + NEWTICRATE/17; + } } } else if (ev->type == ev_mouse && mousewait < I_GetTime()) From 978a28004df8e210fe139ee610828a3f8c385386 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 2 Dec 2018 21:52:30 +0000 Subject: [PATCH 4/4] add deadzone + storing of previous joyx/y values etc to attempt to make joysticks less sensitive in menus --- src/m_menu.c | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 2d7f5eed..f3f698af 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -54,6 +54,8 @@ #include "st_stuff.h" #include "i_sound.h" +#include "i_joy.h" // for joystick menu controls + // Condition Sets #include "m_cond.h" @@ -2065,6 +2067,7 @@ boolean M_Responder(event_t *ev) INT32 ch = -1; // INT32 i; static tic_t joywait = 0, mousewait = 0; + static INT32 pjoyx = 0, pjoyy = 0; static INT32 pmousex = 0, pmousey = 0; static INT32 lastx = 0, lasty = 0; void (*routine)(INT32 choice); // for some casting problem @@ -2117,32 +2120,45 @@ boolean M_Responder(event_t *ev) { if (ev->type == ev_joystick && ev->data1 == 0 && joywait < I_GetTime()) { + const INT32 jdeadzone = JOYAXISRANGE/4; if (ev->data3 != INT32_MAX) { - if (ev->data3 < 0) + if (Joystick.bGamepadStyle || abs(ev->data3) > jdeadzone) { - ch = KEY_UPARROW; - joywait = I_GetTime() + NEWTICRATE/7; - } - else if (ev->data3 > 0) - { - ch = KEY_DOWNARROW; - joywait = I_GetTime() + NEWTICRATE/7; + if (ev->data3 < 0 && pjoyy >= 0) + { + ch = KEY_UPARROW; + joywait = I_GetTime() + NEWTICRATE/7; + } + else if (ev->data3 > 0 && pjoyy <= 0) + { + ch = KEY_DOWNARROW; + joywait = I_GetTime() + NEWTICRATE/7; + } + pjoyy = ev->data3; } + else + pjoyy = 0; } if (ev->data2 != INT32_MAX) { - if (ev->data2 < 0) + if (Joystick.bGamepadStyle || abs(ev->data2) > jdeadzone) { - ch = KEY_LEFTARROW; - joywait = I_GetTime() + NEWTICRATE/17; - } - else if (ev->data2 > 0) - { - ch = KEY_RIGHTARROW; - joywait = I_GetTime() + NEWTICRATE/17; + if (ev->data2 < 0 && pjoyx >= 0) + { + ch = KEY_LEFTARROW; + joywait = I_GetTime() + NEWTICRATE/17; + } + else if (ev->data2 > 0 && pjoyx <= 0) + { + ch = KEY_RIGHTARROW; + joywait = I_GetTime() + NEWTICRATE/17; + } + pjoyx = ev->data2; } + else + pjoyx = 0; } } else if (ev->type == ev_mouse && mousewait < I_GetTime())