mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-04 02:47:39 +00:00
Added HIDAPI joystick drivers for more consistent support for Xbox, PS4 and Nintendo Switch Pro controller support across platforms.
Added SDL_GameControllerRumble() and SDL_JoystickRumble() for simple force feedback outside of the SDL haptics API
This commit is contained in:
parent
ba90412cda
commit
d2042e1ed4
53 changed files with 6827 additions and 1367 deletions
|
@ -102,6 +102,7 @@ typedef struct _ControllerMapping_t
|
|||
static SDL_JoystickGUID s_zeroGUID;
|
||||
static ControllerMapping_t *s_pSupportedControllers = NULL;
|
||||
static ControllerMapping_t *s_pDefaultMapping = NULL;
|
||||
static ControllerMapping_t *s_pHIDAPIMapping = NULL;
|
||||
static ControllerMapping_t *s_pXInputMapping = NULL;
|
||||
|
||||
/* The SDL game controller structure */
|
||||
|
@ -430,6 +431,10 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG
|
|||
}
|
||||
pSupportedController = pSupportedController->next;
|
||||
}
|
||||
if (guid->data[14] == 'h') {
|
||||
/* This is a HIDAPI device */
|
||||
return s_pHIDAPIMapping;
|
||||
}
|
||||
#if SDL_JOYSTICK_XINPUT
|
||||
if (guid->data[14] == 'x') {
|
||||
/* This is an XInput device */
|
||||
|
@ -1130,6 +1135,7 @@ SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMap
|
|||
char *pchGUID;
|
||||
SDL_JoystickGUID jGUID;
|
||||
SDL_bool is_default_mapping = SDL_FALSE;
|
||||
SDL_bool is_hidapi_mapping = SDL_FALSE;
|
||||
SDL_bool is_xinput_mapping = SDL_FALSE;
|
||||
SDL_bool existing = SDL_FALSE;
|
||||
ControllerMapping_t *pControllerMapping;
|
||||
|
@ -1144,6 +1150,8 @@ SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMap
|
|||
}
|
||||
if (!SDL_strcasecmp(pchGUID, "default")) {
|
||||
is_default_mapping = SDL_TRUE;
|
||||
} else if (!SDL_strcasecmp(pchGUID, "hidapi")) {
|
||||
is_hidapi_mapping = SDL_TRUE;
|
||||
} else if (!SDL_strcasecmp(pchGUID, "xinput")) {
|
||||
is_xinput_mapping = SDL_TRUE;
|
||||
}
|
||||
|
@ -1160,6 +1168,8 @@ SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMap
|
|||
} else {
|
||||
if (is_default_mapping) {
|
||||
s_pDefaultMapping = pControllerMapping;
|
||||
} else if (is_hidapi_mapping) {
|
||||
s_pHIDAPIMapping = pControllerMapping;
|
||||
} else if (is_xinput_mapping) {
|
||||
s_pXInputMapping = pControllerMapping;
|
||||
}
|
||||
|
@ -1458,7 +1468,6 @@ SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid)
|
|||
}
|
||||
|
||||
SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL);
|
||||
vidpid = MAKE_VIDPID(vendor, product);
|
||||
|
||||
if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", SDL_FALSE)) {
|
||||
/* We shouldn't ignore Steam's virtual gamepad since it's using the hints to filter out the real controllers so it can remap input for the virtual controller */
|
||||
|
@ -1476,6 +1485,8 @@ SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid)
|
|||
}
|
||||
}
|
||||
|
||||
vidpid = MAKE_VIDPID(vendor, product);
|
||||
|
||||
if (SDL_allowed_controllers.num_entries > 0) {
|
||||
for (i = 0; i < SDL_allowed_controllers.num_entries; ++i) {
|
||||
if (vidpid == SDL_allowed_controllers.entries[i]) {
|
||||
|
@ -1503,22 +1514,18 @@ SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid)
|
|||
SDL_GameController *
|
||||
SDL_GameControllerOpen(int device_index)
|
||||
{
|
||||
SDL_JoystickID instance_id;
|
||||
SDL_GameController *gamecontroller;
|
||||
SDL_GameController *gamecontrollerlist;
|
||||
ControllerMapping_t *pSupportedController = NULL;
|
||||
|
||||
SDL_LockJoysticks();
|
||||
|
||||
if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
|
||||
SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
|
||||
SDL_UnlockJoysticks();
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
gamecontrollerlist = SDL_gamecontrollers;
|
||||
/* If the controller is already open, return it */
|
||||
instance_id = SDL_JoystickGetDeviceInstanceID(device_index);
|
||||
while (gamecontrollerlist) {
|
||||
if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id) {
|
||||
if (instance_id == gamecontrollerlist->joystick->instance_id) {
|
||||
gamecontroller = gamecontrollerlist;
|
||||
++gamecontroller->ref_count;
|
||||
SDL_UnlockJoysticks();
|
||||
|
@ -1834,6 +1841,12 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameControll
|
|||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
|
||||
{
|
||||
return SDL_JoystickRumble(SDL_GameControllerGetJoystick(gamecontroller), low_frequency_rumble, high_frequency_rumble, duration_ms);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_GameControllerClose(SDL_GameController * gamecontroller)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue