From b264c19c8353b80ec4f40d0d7d62c533b9fb07ae Mon Sep 17 00:00:00 2001 From: Sanjay Govind Date: Fri, 3 Apr 2026 13:10:42 +1300 Subject: [PATCH] Update to GameInput V3 (#15302) (cherry picked from commit c58a61fdd4c70530a4d155996f58b012fa5f814d) --- src/core/windows/SDL_gameinput.h | 4 +++- src/joystick/gdk/SDL_gameinputjoystick.cpp | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/core/windows/SDL_gameinput.h b/src/core/windows/SDL_gameinput.h index a046489900..0d7b6f85e7 100644 --- a/src/core/windows/SDL_gameinput.h +++ b/src/core/windows/SDL_gameinput.h @@ -31,7 +31,9 @@ #define GAMEINPUT_API_VERSION 0 #endif -#if GAMEINPUT_API_VERSION == 2 +#if GAMEINPUT_API_VERSION == 3 +using namespace GameInput::v3; +#elif GAMEINPUT_API_VERSION == 2 using namespace GameInput::v2; #elif GAMEINPUT_API_VERSION == 1 using namespace GameInput::v1; diff --git a/src/joystick/gdk/SDL_gameinputjoystick.cpp b/src/joystick/gdk/SDL_gameinputjoystick.cpp index 0e3d50a2b4..d60251a71e 100644 --- a/src/joystick/gdk/SDL_gameinputjoystick.cpp +++ b/src/joystick/gdk/SDL_gameinputjoystick.cpp @@ -542,9 +542,15 @@ static bool GAMEINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) } #endif // GAMEINPUT_API_VERSION >= 1 } else { +#if GAMEINPUT_API_VERSION >= 3 + joystick->naxes = info->controllerInfo->controllerAxisCount; + joystick->nbuttons = info->controllerInfo->controllerButtonCount; + joystick->nhats = info->controllerInfo->controllerSwitchCount; +#else joystick->naxes = info->controllerAxisCount; joystick->nbuttons = info->controllerButtonCount; joystick->nhats = info->controllerSwitchCount; +#endif // GAMEINPUT_API_VERSION >= 3 } if (info->supportedRumbleMotors & (GameInputRumbleLowFrequency | GameInputRumbleHighFrequency)) { @@ -676,13 +682,13 @@ static void GAMEINPUT_JoystickUpdate(SDL_Joystick *joystick) #undef CONVERT_TRIGGER } } else { - bool *button_state = SDL_stack_alloc(bool, info->controllerButtonCount); - float *axis_state = SDL_stack_alloc(float, info->controllerAxisCount); - GameInputSwitchPosition *switch_state = SDL_stack_alloc(GameInputSwitchPosition, info->controllerSwitchCount); + bool *button_state = SDL_stack_alloc(bool, joystick->nbuttons); + float *axis_state = SDL_stack_alloc(float, joystick->naxes); + GameInputSwitchPosition *switch_state = SDL_stack_alloc(GameInputSwitchPosition, joystick->nhats); if (button_state) { uint32_t i; - uint32_t button_count = reading->GetControllerButtonState(info->controllerButtonCount, button_state); + uint32_t button_count = reading->GetControllerButtonState(joystick->nbuttons, button_state); for (i = 0; i < button_count; ++i) { SDL_SendJoystickButton(timestamp, joystick, (Uint8)i, button_state[i]); } @@ -692,7 +698,7 @@ static void GAMEINPUT_JoystickUpdate(SDL_Joystick *joystick) #define CONVERT_AXIS(v) (Sint16)((v)*65535.0f - 32768.0f) if (axis_state) { uint32_t i; - uint32_t axis_count = reading->GetControllerAxisState(info->controllerAxisCount, axis_state); + uint32_t axis_count = reading->GetControllerAxisState(joystick->naxes, axis_state); for (i = 0; i < axis_count; ++i) { SDL_SendJoystickAxis(timestamp, joystick, (Uint8)i, CONVERT_AXIS(axis_state[i])); } @@ -702,7 +708,7 @@ static void GAMEINPUT_JoystickUpdate(SDL_Joystick *joystick) if (switch_state) { uint32_t i; - uint32_t switch_count = reading->GetControllerSwitchState(info->controllerSwitchCount, switch_state); + uint32_t switch_count = reading->GetControllerSwitchState(joystick->nhats, switch_state); for (i = 0; i < switch_count; ++i) { Uint8 hat; switch (switch_state[i]) {