Don't use SDL_GameControllerGetPlayerIndex() because the indexes may be non-contiguous (and wrong) on XInput

This commit is contained in:
Cameron Gutman
2019-02-12 22:04:05 -08:00
parent 46bd8ad83d
commit 5397e8ae1a
+5 -11
View File
@@ -682,17 +682,12 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
return; return;
} }
#if SDL_VERSION_ATLEAST(2, 0, 9) // We used to use SDL_GameControllerGetPlayerIndex() here but that
// Determine this player's preferred index // can lead to strange issues due to bugs in Windows where an Xbox
i = SDL_GameControllerGetPlayerIndex(controller); // controller will join as player 2, even though no player 1 controller
if (i < 0 || i >= MAX_GAMEPADS || m_GamepadState[i].controller != NULL) { // is connected at all. This pretty much screws any attempt to use
// If the player index is unavailable or invalid, start searching from 0 // the gamepad in single player games, so just assign them in order from 0.
i = 0;
}
#else
// SDL 2.0.8 and earlier has no player number hints
i = 0; i = 0;
#endif
for (; i < MAX_GAMEPADS; i++) { for (; i < MAX_GAMEPADS; i++) {
if (m_GamepadState[i].controller == NULL) { if (m_GamepadState[i].controller == NULL) {
@@ -996,7 +991,6 @@ int SdlInputHandler::getAttachedGamepadMask()
return 0x1; return 0x1;
} }
// TODO: Use SDL_GameControllerGetPlayerIndex() for accurate indexes?
count = mask = 0; count = mask = 0;
for (int i = 0; i < SDL_NumJoysticks(); i++) { for (int i = 0; i < SDL_NumJoysticks(); i++) {
if (SDL_IsGameController(i)) { if (SDL_IsGameController(i)) {