From cd57ebd763712a9d473256f5aa177d72d0f86178 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 7 Feb 2025 15:57:13 +0100 Subject: [PATCH] keep track of joystick index in struct --- src/sdl/i_system.c | 7 ++++--- src/sdl/sdlmain.h | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 0b80e8f3f..b543e6cb5 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1113,7 +1113,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 { @@ -1303,6 +1303,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) { @@ -1385,13 +1386,13 @@ void I_InitJoystick(UINT8 index) 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; joystick_started[index] = 1; } else diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index 0ba8da762..001da6b69 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 @@ -54,7 +56,6 @@ typedef struct SDLJoyInfo_s int hats; /// number of balls int balls; - } SDLJoyInfo_t; /** \brief SDL info about controller 1