mirror of
https://github.com/raysan5/raylib.git
synced 2026-07-05 08:55:14 +00:00
[rcore] Fix SDL3 backend using wrong joystick functions (#5948)
* [rcore] Fix gamepad code using outdated functions * [rcore] Remove printing available joysticks
This commit is contained in:
@@ -2164,11 +2164,20 @@ int InitPlatform(void)
|
||||
platform.gamepadId[i] = -1; // Set all gamepad initial instance ids as invalid to not conflict with instance id zero
|
||||
}
|
||||
|
||||
#if defined(USING_VERSION_SDL3)
|
||||
int numJoysticks;
|
||||
SDL_JoystickID *joysticks = SDL_GetJoysticks(&numJoysticks);
|
||||
#else
|
||||
int numJoysticks = SDL_NumJoysticks();
|
||||
#endif
|
||||
|
||||
for (int i = 0; (i < numJoysticks) && (i < MAX_GAMEPADS); i++)
|
||||
{
|
||||
#if defined(USING_VERSION_SDL3)
|
||||
platform.gamepad[i] = SDL_OpenGamepad(joysticks[i]);
|
||||
#else
|
||||
platform.gamepad[i] = SDL_GameControllerOpen(i);
|
||||
#endif
|
||||
platform.gamepadId[i] = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(platform.gamepad[i]));
|
||||
|
||||
if (platform.gamepad[i])
|
||||
@@ -2177,7 +2186,12 @@ int InitPlatform(void)
|
||||
CORE.Input.Gamepad.axisCount[i] = SDL_JoystickNumAxes(SDL_GameControllerGetJoystick(platform.gamepad[i]));
|
||||
CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f;
|
||||
CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f;
|
||||
strncpy(CORE.Input.Gamepad.name[i], SDL_GameControllerNameForIndex(i), MAX_GAMEPAD_NAME_LENGTH - 1);
|
||||
#if defined(USING_VERSION_SDL3)
|
||||
const char *joystickName = SDL_GetJoystickNameForID(joysticks[i]);
|
||||
#else
|
||||
const char *joystickName = SDL_GameControllerNameForIndex(i);
|
||||
#endif
|
||||
strncpy(CORE.Input.Gamepad.name[i], joystickName, MAX_GAMEPAD_NAME_LENGTH - 1);
|
||||
CORE.Input.Gamepad.name[i][MAX_GAMEPAD_NAME_LENGTH - 1] = '\0';
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "PLATFORM: Unable to open game controller [ERROR: %s]", SDL_GetError());
|
||||
|
||||
Reference in New Issue
Block a user