Skip to content
Permalink
Browse files

Reworked XInput and DirectInput joystick code.

Now multiple XInput controllers map correctly to device indexes instead of grabbing
the first available userid, and are completely separated out from DirectInput.

Also, the hardcoded limitation on number of DirectInput devices is gone. I don't
expect there to really ever be more than eight joysticks plugged into a machine, but
it was a leftover limitation for a static array we didn't actually use anymore.

Fixes Bugzilla #1984. (etc?)
  • Loading branch information
icculus committed Aug 28, 2013
1 parent c89e046 commit 4b255c63f1e0846111ce51f6dddb06f4d2ae9791
Showing with 152 additions and 194 deletions.
  1. +0 −21 src/joystick/SDL_gamecontroller.c
  2. +152 −173 src/joystick/windows/SDL_dxjoystick.c
@@ -851,9 +851,6 @@ SDL_GameControllerOpen(int device_index)
SDL_GameController *gamecontroller;
SDL_GameController *gamecontrollerlist;
ControllerMapping_t *pSupportedController = NULL;
#ifdef SDL_JOYSTICK_DINPUT
SDL_bool bIsXinputDevice;
#endif

if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
@@ -886,31 +883,13 @@ SDL_GameControllerOpen(int device_index)
return NULL;
}

#ifdef SDL_JOYSTICK_DINPUT
/* check if we think we should open this device in XInput mode */
bIsXinputDevice = SDL_SYS_IsXInputDeviceIndex(device_index);
#endif

SDL_memset(gamecontroller, 0, (sizeof *gamecontroller));
gamecontroller->joystick = SDL_JoystickOpen(device_index);
if ( !gamecontroller->joystick ) {
SDL_free(gamecontroller);
return NULL;
}

#ifdef SDL_JOYSTICK_DINPUT
if ( !SDL_SYS_IsXInputJoystick( gamecontroller->joystick ) && bIsXinputDevice )
{
/* we tried to open the controller in XInput mode and failed, so get the mapping again for the direct input variant if possible */
SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
pSupportedController = SDL_PrivateGetControllerMappingForGUID(&jGUID);
if ( !pSupportedController ) {
SDL_SetError("Failed to open device in XInput mode (%d)", device_index );
return (NULL);
}
}
#endif

SDL_PrivateLoadButtonMapping( &gamecontroller->mapping, pSupportedController->guid, pSupportedController->name, pSupportedController->mapping );

/* Add joystick to list */

0 comments on commit 4b255c6

Please sign in to comment.