diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 8f720cfa1..dd197cd1b 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -721,6 +721,7 @@ static void JoyReset(SDLJoyInfo_t *JoySet) } JoySet->dev = NULL; + JoySet->id = -1; JoySet->oldjoy = -1; JoySet->axises = JoySet->buttons = JoySet->hats = JoySet->balls = 0; } @@ -779,7 +780,7 @@ void I_UpdateJoystickDeviceIndex(UINT8 player) /////////////////////////////////////////////// if (JoyInfo[player].dev) { - cv_usejoystick[player].value = I_GetJoystickDeviceIndex(JoyInfo[player].dev) + 1; + cv_usejoystick[player].value = JoyInfo[player].id + 1; } else { @@ -794,6 +795,7 @@ void I_UpdateJoystickDeviceIndex(UINT8 player) { if (compareJoystick == player) continue; + if (value == JoyInfo[compareJoystick].oldjoy || value == cv_usejoystick[compareJoystick].value) break; } @@ -925,6 +927,7 @@ static int joy_open(int playerIndex, int joyIndex) } JoyInfo[playerIndex].dev = newdev; + JoyInfo[playerIndex].id = I_GetJoystickDeviceIndex(JoyInfo[playerIndex].dev); if (JoyInfo[playerIndex].dev == NULL) { @@ -1003,15 +1006,17 @@ void I_InitJoystick(UINT8 index) break; } + JoyInfo[index].id = I_GetJoystickDeviceIndex(JoyInfo[index].dev); + if (newcontroller && i < MAXSPLITSCREENPLAYERS) // don't override an active device { - cv_usejoystick[index].value = I_GetJoystickDeviceIndex(JoyInfo[index].dev) + 1; + cv_usejoystick[index].value = JoyInfo[index].id + 1; } else if (newcontroller && joy_open(index, cv_usejoystick[index].value) != -1) { // SDL's device indexes are unstable, so cv_usejoystick may not match // the actual device index. So let's cheat a bit and find the device's current index. - JoyInfo[index].oldjoy = I_GetJoystickDeviceIndex(JoyInfo[index].dev) + 1; + JoyInfo[index].oldjoy = JoyInfo[index].id + 1; } else { diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 6a8145b0a..6b2cbec7b 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -728,7 +728,7 @@ static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt) // Determine the Joystick IDs for each current open joystick for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (evt.which == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev))) + if (evt.which == JoyInfo[i].id) { event.type = ev_joystick + i; break; @@ -788,7 +788,7 @@ static void Impl_HandleControllerHatEvent(SDL_ControllerButtonEvent evt, Uint32 // Determine the Joystick IDs for each current open joystick for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (evt.which == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev))) + if (evt.which == JoyInfo[i].id) { event.data1 = hat_buttons_base[i]; break; @@ -850,7 +850,7 @@ static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint // Determine the Joystick IDs for each current open joystick for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (evt.which == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev))) + if (evt.which == JoyInfo[i].id) { event.data1 = buttons_base[i]; break; diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index 2caafc729..0fe93953a 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -42,6 +42,8 @@ typedef struct SDLJoyInfo_s { /// Controller handle SDL_GameController *dev; + /// Controller index + INT32 id; /// number of old joystick int oldjoy; /// number of axies