mirror of
https://github.com/encounter/SDL.git
synced 2025-12-13 07:06:10 +00:00
Generalized the XInput user index into a player index
This commit is contained in:
@@ -407,6 +407,18 @@ WINDOWS_JoystickGetDeviceName(int device_index)
|
||||
return device->joystickname;
|
||||
}
|
||||
|
||||
static int
|
||||
WINDOWS_JoystickGetDevicePlayerIndex(int device_index)
|
||||
{
|
||||
JoyStick_DeviceData *device = SYS_Joystick;
|
||||
int index;
|
||||
|
||||
for (index = device_index; index > 0; index--)
|
||||
device = device->pNext;
|
||||
|
||||
return device->bXInputDevice ? (int)device->XInputUserId : -1;
|
||||
}
|
||||
|
||||
/* return the stable device guid for this device index */
|
||||
static SDL_JoystickGUID
|
||||
WINDOWS_JoystickGetDeviceGUID(int device_index)
|
||||
@@ -544,6 +556,7 @@ SDL_JoystickDriver SDL_WINDOWS_JoystickDriver =
|
||||
WINDOWS_JoystickGetCount,
|
||||
WINDOWS_JoystickDetect,
|
||||
WINDOWS_JoystickGetDeviceName,
|
||||
WINDOWS_JoystickGetDevicePlayerIndex,
|
||||
WINDOWS_JoystickGetDeviceGUID,
|
||||
WINDOWS_JoystickGetDeviceInstanceID,
|
||||
WINDOWS_JoystickOpen,
|
||||
|
||||
@@ -312,6 +312,8 @@ SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickde
|
||||
SDL_assert(XINPUTSETSTATE);
|
||||
SDL_assert(userId < XUSER_MAX_COUNT);
|
||||
|
||||
joystick->player_index = userId;
|
||||
|
||||
joystick->hwdata->bXInputDevice = SDL_TRUE;
|
||||
|
||||
if (XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities) != ERROR_SUCCESS) {
|
||||
@@ -322,7 +324,6 @@ SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickde
|
||||
SDL_zero(state);
|
||||
joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &state) == ERROR_SUCCESS);
|
||||
joystick->hwdata->userid = userId;
|
||||
joystick->userid = userId;
|
||||
|
||||
/* The XInput API has a hard coded button/axis mapping, so we just match it */
|
||||
if (SDL_XInputUseOldJoystickMapping()) {
|
||||
|
||||
Reference in New Issue
Block a user