diff options
| author | GideonSerf <[email protected]> | 2024-02-24 17:47:27 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-02-24 16:47:27 +0100 |
| commit | 371d25c8c99f6db487c938f8b7f391d45e26d3a4 (patch) | |
| tree | bc4600ada3abc9f74420e3d00b36a3b38ccd22f5 /src/platforms | |
| parent | bda919033dfdd2d0d75b606f3fa29d21f0408ffb (diff) | |
| download | raylib-371d25c8c99f6db487c938f8b7f391d45e26d3a4.tar.gz raylib-371d25c8c99f6db487c938f8b7f391d45e26d3a4.zip | |
Gamepad rumble support with SDL2 (#3819)
* Added gamepad rumble to rcore_desktop.c and rcore_desktop_sdl.c
Still need to add to the rest of the platforms.
* Add SetGamepadVibration warnings to unimplemented platforms.
* Added MAX_GAMEPAD_VIBRATION_TIME
The rumble in SDL2 will continue for MAX_GAMEPAD_VIBRATION_TIME unless the user cancels it with a call to SetGamepadVibration(0.0f,0.0f,0.0f)
* Cast float duration value to Uint 32
* Changed defines from int to float and fixed typo
---------
Co-authored-by: Gideon Serfontein <[email protected]>
Diffstat (limited to 'src/platforms')
| -rw-r--r-- | src/platforms/rcore_android.c | 6 | ||||
| -rw-r--r-- | src/platforms/rcore_desktop.c | 6 | ||||
| -rw-r--r-- | src/platforms/rcore_desktop_sdl.c | 15 | ||||
| -rw-r--r-- | src/platforms/rcore_drm.c | 6 | ||||
| -rw-r--r-- | src/platforms/rcore_web.c | 6 |
5 files changed, 39 insertions, 0 deletions
diff --git a/src/platforms/rcore_android.c b/src/platforms/rcore_android.c index cc124d95..23b8f436 100644 --- a/src/platforms/rcore_android.c +++ b/src/platforms/rcore_android.c @@ -613,6 +613,12 @@ int SetGamepadMappings(const char *mappings) return 0; } +// Set gamepad vibration +void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor) +{ + TRACELOG(LOG_WARNING, "GamepadSetVibration() not implemented on target platform"); +} + // Set mouse position XY void SetMousePosition(int x, int y) { diff --git a/src/platforms/rcore_desktop.c b/src/platforms/rcore_desktop.c index 4c98fcdf..dbfc29e0 100644 --- a/src/platforms/rcore_desktop.c +++ b/src/platforms/rcore_desktop.c @@ -1050,6 +1050,12 @@ int SetGamepadMappings(const char *mappings) return glfwUpdateGamepadMappings(mappings); } +// Set gamepad vibration +void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor) +{ + TRACELOG(LOG_WARNING, "GamepadSetVibration() not available on target platform"); +} + // Set mouse position XY void SetMousePosition(int x, int y) { diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index 2e2d190c..f567119e 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -938,6 +938,21 @@ int SetGamepadMappings(const char *mappings) return SDL_GameControllerAddMapping(mappings); } +// Set gamepad vibration +void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor) +{ + //Limit input values to between 0.0f and 1.0f + leftMotor = (0.0f > leftMotor) ? 0.0f : leftMotor; + rightMotor = (0.0f > rightMotor) ? 0.0f : rightMotor; + leftMotor = (1.0f < leftMotor) ? 1.0f : leftMotor; + rightMotor = (1.0f < rightMotor) ? 1.0f : rightMotor; + + if (IsGamepadAvailable(gamepad)) + { + SDL_JoystickRumble(platform.gamepad[gamepad], (Uint16)(leftMotor*65535.0f), (Uint16)(rightMotor*65535.0f), (Uint32)(MAX_GAMEPAD_VIBRATION_TIME*1000.0f)); + } +} + // Set mouse position XY void SetMousePosition(int x, int y) { diff --git a/src/platforms/rcore_drm.c b/src/platforms/rcore_drm.c index 12e749a0..d303ab1d 100644 --- a/src/platforms/rcore_drm.c +++ b/src/platforms/rcore_drm.c @@ -519,6 +519,12 @@ int SetGamepadMappings(const char *mappings) return 0; } +// Set gamepad vibration +void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor) +{ + TRACELOG(LOG_WARNING, "GamepadSetVibration() not implemented on target platform"); +} + // Set mouse position XY void SetMousePosition(int x, int y) { diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index a13f6990..9328b8c9 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -850,6 +850,12 @@ int SetGamepadMappings(const char *mappings) return 0; } +// Set gamepad vibration +void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor) +{ + TRACELOG(LOG_WARNING, "GamepadSetVibration() not implemented on target platform"); +} + // Set mouse position XY void SetMousePosition(int x, int y) { |
