From 0dfd7fc41ef17a4c6aef14a433a3c768547938cd Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Sun, 24 Dec 2017 08:20:58 -0500 Subject: [PATCH] some joystick fixes Turns out P3/P4 controllers are broken (and still are) --- src/d_netcmd.c | 4 +-- src/g_game.c | 58 +++++++++++++++++++-------------------- src/g_input.c | 2 +- src/i_system.h | 8 ++++++ src/m_menu.c | 25 ++++++++--------- src/sdl/i_system.c | 2 +- src/sdl/i_video.c | 68 ++++++++++++++++++++++++++++++++++++++++++++-- src/sdl/sdlmain.h | 8 ++++++ 8 files changed, 127 insertions(+), 48 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index b42cc745..62367b6f 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -276,9 +276,9 @@ consvar_t cv_usejoystick = {"use_joystick", "0", CV_SAVE|CV_CALL, usejoystick_co consvar_t cv_usejoystick2 = {"use_joystick2", "0", CV_SAVE|CV_CALL, usejoystick_cons_t, I_InitJoystick2, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_usejoystick3 = {"use_joystick3", "0", CV_SAVE|CV_CALL, usejoystick_cons_t, -I_InitJoystick3, 0, NULL, NULL, 0, 0, NULL}; + I_InitJoystick3, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_usejoystick4 = {"use_joystick4", "0", CV_SAVE|CV_CALL, usejoystick_cons_t, -I_InitJoystick4, 0, NULL, NULL, 0, 0, NULL}; + I_InitJoystick4, 0, NULL, NULL, 0, 0, NULL}; #endif #if (defined (LJOYSTICK) || defined (HAVE_SDL)) #ifdef LJOYSTICK diff --git a/src/g_game.c b/src/g_game.c index cf1e0a21..9bb59b20 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1006,8 +1006,8 @@ static INT32 Joy3Axis(axis_input_e axissel) } else #endif - if (axisval > JOYAXISSET*2 || axisval == 0) //not there in array or None - return 0; + if (axisval > JOYAXISSET*2 || axisval == 0) //not there in array or None + return 0; if (axisval%2) { @@ -1025,18 +1025,18 @@ static INT32 Joy3Axis(axis_input_e axissel) skipDC: #endif - if (retaxis < (-JOYAXISRANGE)) - retaxis = -JOYAXISRANGE; - if (retaxis > (+JOYAXISRANGE)) - retaxis = +JOYAXISRANGE; - if (!Joystick3.bGamepadStyle && axissel < AXISDEAD) - { - const INT32 jdeadzone = JOYAXISRANGE/4; - if (-jdeadzone < retaxis && retaxis < jdeadzone) - return 0; - } - if (flp) retaxis = -retaxis; //flip it around - return retaxis; + if (retaxis < (-JOYAXISRANGE)) + retaxis = -JOYAXISRANGE; + if (retaxis > (+JOYAXISRANGE)) + retaxis = +JOYAXISRANGE; + if (!Joystick3.bGamepadStyle && axissel < AXISDEAD) + { + const INT32 jdeadzone = JOYAXISRANGE/4; + if (-jdeadzone < retaxis && retaxis < jdeadzone) + return 0; + } + if (flp) retaxis = -retaxis; //flip it around + return retaxis; } static INT32 Joy4Axis(axis_input_e axissel) @@ -1079,13 +1079,13 @@ static INT32 Joy4Axis(axis_input_e axissel) #ifdef _arch_dreamcast if (axisval == 7) // special case { - retaxis = joy4xmove[1] - joy4ymove[1]; + retaxis = joy2xmove[1] - joy2ymove[1]; goto skipDC; } else #endif - if (axisval > JOYAXISSET*2 || axisval == 0) //not there in array or None - return 0; + if (axisval > JOYAXISSET*2 || axisval == 0) //not there in array or None + return 0; if (axisval%2) { @@ -1103,18 +1103,18 @@ static INT32 Joy4Axis(axis_input_e axissel) skipDC: #endif - if (retaxis < (-JOYAXISRANGE)) - retaxis = -JOYAXISRANGE; - if (retaxis > (+JOYAXISRANGE)) - retaxis = +JOYAXISRANGE; - if (!Joystick4.bGamepadStyle && axissel < AXISDEAD) - { - const INT32 jdeadzone = JOYAXISRANGE/4; - if (-jdeadzone < retaxis && retaxis < jdeadzone) - return 0; - } - if (flp) retaxis = -retaxis; //flip it around - return retaxis; + if (retaxis < (-JOYAXISRANGE)) + retaxis = -JOYAXISRANGE; + if (retaxis > (+JOYAXISRANGE)) + retaxis = +JOYAXISRANGE; + if (!Joystick4.bGamepadStyle && axissel < AXISDEAD) + { + const INT32 jdeadzone = JOYAXISRANGE/4; + if (-jdeadzone < retaxis && retaxis < jdeadzone) + return 0; + } + if (flp) retaxis = -retaxis; //flip it around + return retaxis; } static boolean InputDown(INT32 gc, UINT8 p) diff --git a/src/g_input.c b/src/g_input.c index fca940cb..79c9e9f6 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -2036,7 +2036,7 @@ void Command_Setcontrol3_f(void) if (na != 3 && na != 4) { - CONS_Printf(M_GetText("setcontrol23 [<2nd keyname>]: set controls for player 3\n")); + CONS_Printf(M_GetText("setcontrol3 [<2nd keyname>]: set controls for player 3\n")); return; } diff --git a/src/i_system.h b/src/i_system.h index 1887d2b9..447e5934 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -330,6 +330,14 @@ void I_GetJoystickEvents(void); */ void I_GetJoystick2Events(void); +/** \brief Third Joystick's events +*/ +void I_GetJoystick3Events(void); + +/** \brief Fourth Joystick's events +*/ +void I_GetJoystick4Events(void); + /** \brief Mouses events */ void I_GetMouseEvents(void); diff --git a/src/m_menu.c b/src/m_menu.c index 2d9ed8d5..32101726 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7138,9 +7138,7 @@ static void M_SetupJoystickMenu(INT32 choice) static void M_Setup1PJoystickMenu(INT32 choice) { - setupcontrols_secondaryplayer = false; - setupcontrols_thirdplayer = false; - setupcontrols_fourthplayer = false; + setupcontrols_secondaryplayer = setupcontrols_thirdplayer = setupcontrols_fourthplayer = false; OP_JoystickSetDef.prevMenu = &OP_Joystick1Def; M_SetupJoystickMenu(choice); } @@ -7148,8 +7146,7 @@ static void M_Setup1PJoystickMenu(INT32 choice) static void M_Setup2PJoystickMenu(INT32 choice) { setupcontrols_secondaryplayer = true; - setupcontrols_thirdplayer = false; - setupcontrols_fourthplayer = false; + setupcontrols_thirdplayer = setupcontrols_fourthplayer = false; OP_JoystickSetDef.prevMenu = &OP_Joystick2Def; M_SetupJoystickMenu(choice); } @@ -7157,8 +7154,7 @@ static void M_Setup2PJoystickMenu(INT32 choice) static void M_Setup3PJoystickMenu(INT32 choice) { setupcontrols_thirdplayer = true; - setupcontrols_secondaryplayer = false; - setupcontrols_fourthplayer = false; + setupcontrols_secondaryplayer = setupcontrols_fourthplayer = false; OP_JoystickSetDef.prevMenu = &OP_Joystick3Def; M_SetupJoystickMenu(choice); } @@ -7166,15 +7162,18 @@ static void M_Setup3PJoystickMenu(INT32 choice) static void M_Setup4PJoystickMenu(INT32 choice) { setupcontrols_fourthplayer = true; - setupcontrols_secondaryplayer = false; - setupcontrols_thirdplayer = false; + setupcontrols_secondaryplayer = setupcontrols_thirdplayer = false; OP_JoystickSetDef.prevMenu = &OP_Joystick4Def; M_SetupJoystickMenu(choice); } static void M_AssignJoystick(INT32 choice) { - if (setupcontrols_secondaryplayer) + if (setupcontrols_fourthplayer) + CV_SetValue(&cv_usejoystick4, choice); + else if (setupcontrols_thirdplayer) + CV_SetValue(&cv_usejoystick3, choice); + else if (setupcontrols_secondaryplayer) CV_SetValue(&cv_usejoystick2, choice); else CV_SetValue(&cv_usejoystick, choice); @@ -7187,9 +7186,7 @@ static void M_AssignJoystick(INT32 choice) static void M_Setup1PControlsMenu(INT32 choice) { (void)choice; - setupcontrols_secondaryplayer = false; - setupcontrols_thirdplayer = false; - setupcontrols_fourthplayer = false; + setupcontrols_secondaryplayer = setupcontrols_thirdplayer = setupcontrols_fourthplayer = false; setupcontrols = gamecontrol; // was called from main Options (for console player, then) currentMenu->lastOn = itemOn; @@ -7339,6 +7336,8 @@ static void M_ChangecontrolResponse(event_t *ev) case ev_mouse2: case ev_joystick: case ev_joystick2: + case ev_joystick3: + case ev_joystick4: ch = KEY_NULL; // no key break; diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 11da6674..79bf222f 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2036,7 +2036,7 @@ void I_InitJoystick4(void) { I_ShutdownJoystick4(); SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); - if (!strcmp(cv_usejoystick3.string, "0") || M_CheckParm("-nojoy")) + if (!strcmp(cv_usejoystick4.string, "0") || M_CheckParm("-nojoy")) return; if (joy_open4(cv_usejoystick4.string) != -1) JoyInfo4.oldjoy = atoi(cv_usejoystick4.string); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 3a919437..12103349 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -522,6 +522,48 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) { raxis = JoyInfo2.scale!=1?((raxis/JoyInfo2.scale)*JoyInfo2.scale):raxis; +#ifdef SDL_JDEADZONE + if (-SDL_JDEADZONE <= raxis && raxis <= SDL_JDEADZONE) + raxis = 0; +#endif + } + } + else if (which == ev_joystick3) + { + if (Joystick3.bGamepadStyle) + { + // gamepad control type, on or off, live or die + if (raxis < -(JOYAXISRANGE/2)) + raxis = -1; + else if (raxis > (JOYAXISRANGE/2)) + raxis = 1; + else raxis = 0; + } + else + { + raxis = JoyInfo3.scale!=1?((raxis/JoyInfo3.scale)*JoyInfo3.scale):raxis; + +#ifdef SDL_JDEADZONE + if (-SDL_JDEADZONE <= raxis && raxis <= SDL_JDEADZONE) + raxis = 0; +#endif + } + } + else if (which == ev_joystick4) + { + if (Joystick4.bGamepadStyle) + { + // gamepad control type, on or off, live or die + if (raxis < -(JOYAXISRANGE/2)) + raxis = -1; + else if (raxis > (JOYAXISRANGE/2)) + raxis = 1; + else raxis = 0; + } + else + { + raxis = JoyInfo4.scale!=1?((raxis/JoyInfo4.scale)*JoyInfo4.scale):raxis; + #ifdef SDL_JDEADZONE if (-SDL_JDEADZONE <= raxis && raxis <= SDL_JDEADZONE) raxis = 0; @@ -717,11 +759,13 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt) static void Impl_HandleJoystickAxisEvent(SDL_JoyAxisEvent evt) { event_t event; - SDL_JoystickID joyid[2]; + SDL_JoystickID joyid[4]; // Determine the Joystick IDs for each current open joystick joyid[0] = SDL_JoystickInstanceID(JoyInfo.dev); joyid[1] = SDL_JoystickInstanceID(JoyInfo2.dev); + joyid[2] = SDL_JoystickInstanceID(JoyInfo3.dev); + joyid[3] = SDL_JoystickInstanceID(JoyInfo4.dev); evt.axis++; event.data1 = event.data2 = event.data3 = INT32_MAX; @@ -734,6 +778,14 @@ static void Impl_HandleJoystickAxisEvent(SDL_JoyAxisEvent evt) { event.type = ev_joystick2; } + else if (evt.which == joyid[2]) + { + event.type = ev_joystick3; + } + else if (evt.which == joyid[3]) + { + event.type = ev_joystick4; + } else return; //axis if (evt.axis > JOYAXISSET*2) @@ -756,11 +808,13 @@ static void Impl_HandleJoystickAxisEvent(SDL_JoyAxisEvent evt) static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type) { event_t event; - SDL_JoystickID joyid[2]; + SDL_JoystickID joyid[4]; // Determine the Joystick IDs for each current open joystick joyid[0] = SDL_JoystickInstanceID(JoyInfo.dev); joyid[1] = SDL_JoystickInstanceID(JoyInfo2.dev); + joyid[2] = SDL_JoystickInstanceID(JoyInfo3.dev); + joyid[3] = SDL_JoystickInstanceID(JoyInfo4.dev); if (evt.which == joyid[0]) { @@ -770,6 +824,14 @@ static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type) { event.data1 = KEY_2JOY1; } + else if (evt.which == joyid[2]) + { + event.data1 = KEY_3JOY1; + } + else if (evt.which == joyid[3]) + { + event.data1 = KEY_4JOY1; + } else return; if (type == SDL_JOYBUTTONUP) { @@ -891,6 +953,8 @@ void I_OsPolling(void) SDL_JoystickUpdate(); I_GetJoystickEvents(); I_GetJoystick2Events(); + I_GetJoystick3Events(); + I_GetJoystick4Events(); } I_GetMouseEvents(); diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index fea1e164..110b03fd 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -67,6 +67,14 @@ extern SDLJoyInfo_t JoyInfo; */ extern SDLJoyInfo_t JoyInfo2; +/** \brief SDL inof about joystick 3 +*/ +extern SDLJoyInfo_t JoyInfo3; + +/** \brief SDL inof about joystick 4 +*/ +extern SDLJoyInfo_t JoyInfo4; + void I_GetConsoleEvents(void); void SDLforceUngrabMouse(void);