diff --git a/src/i_joy.h b/src/i_joy.h index 925e69bcf..53824d391 100644 --- a/src/i_joy.h +++ b/src/i_joy.h @@ -62,6 +62,8 @@ void I_SetGamepadPlayerIndex(INT32 device_id, INT32 index); void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue); void I_GetGamepadGuid(INT32 device_id, char *out, int out_len); void I_GetGamepadName(INT32 device_id, char *out, int out_len); +void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength); +void I_GamepadRumbleTriggers(INT32 device_id, UINT16 left_strength, UINT16 right_strength); #ifdef __cplusplus } // extern "C" diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index b0598a05b..76cafa09a 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1019,6 +1019,46 @@ void I_GetGamepadName(INT32 device_id, char *out, int out_len) out[out_len - 1] = 0; } +void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength) +{ +#if !(SDL_VERSION_ATLEAST(2,0,9)) + (void)device_id; + (void)low_strength; + (void)high_strength; + (void)length_ms; +#else + I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher + + SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1); + if (controller == NULL) + { + return; + } + + SDL_GameControllerRumble(controller, low_strength, high_strength, 0); +#endif +} + +void I_GamepadRumbleTriggers(INT32 device_id, UINT16 left_strength, UINT16 right_strength) +{ +#if !(SDL_VERSION_ATLEAST(2,0,14)) + (void)device_id; + (void)low_strength; + (void)high_strength; + (void)length_ms; +#else + I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher + + SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1); + if (controller == NULL) + { + return; + } + + SDL_GameControllerRumbleTriggers(controller, left_strength, right_strength, 0); +#endif +} + // // I_StartupInput //