mirror of https://github.com/encounter/SDL.git
Fix SDL xinput code to work at all when xinput has devices at high indexes but no device connected at lower index, for instance 0->disconnected, 1->wireles, 2->wired. Previously the SDL code assumed the indexes were always used up in order which is not true at all and lead to a bunch of failure cases where controllers would go unrecognized.
This entire function is kind of a mess and more complicated than needed, but I don't want to refactor it too heavily tonight. May look at improving how the indexes are assigned more significanly later. The way it handles not finding a valid "gamepad" type device is also super broken, it leaves in place the xinput bindings but opens the controller with dinput and ends up with completely wrong mappings, not solving that now, but fixing the bug where we'd very frequently not find a controller due to gaps in assigned player numbers should mostly avoid it.
This commit is contained in:
parent
3d217ed7b5
commit
05d8c2dcd2
|
@ -1013,6 +1013,8 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
|
|||
}
|
||||
|
||||
if ( s_bXInputEnabled && XINPUTGETCAPABILITIES )
|
||||
{
|
||||
while ( 1 )
|
||||
{
|
||||
result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities );
|
||||
if ( result == ERROR_SUCCESS )
|
||||
|
@ -1043,10 +1045,34 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
|
|||
joystick->nballs = 0;
|
||||
joystick->nhats = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( userId < XUSER_MAX_COUNT && result == ERROR_DEVICE_NOT_CONNECTED )
|
||||
{
|
||||
/* scan the opened joysticks and pick the next free xinput userid for this one */
|
||||
++userId;
|
||||
|
||||
joysticklist = SYS_Joystick;
|
||||
for( ; joysticklist; joysticklist = joysticklist->pNext)
|
||||
{
|
||||
if ( joysticklist->bXInputDevice && joysticklist->XInputUserId == userId )
|
||||
userId++;
|
||||
}
|
||||
|
||||
if ( userId >= XUSER_MAX_COUNT )
|
||||
{
|
||||
joystickdevice->bXInputDevice = SDL_FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
joystickdevice->bXInputDevice = SDL_FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue