From 073c221b950b6601e601d2db3ac6261303386fa2 Mon Sep 17 00:00:00 2001 From: asdqwe Date: Mon, 21 Oct 2024 13:58:40 -0300 Subject: [PATCH] Updates SetGamepadVibration() --- src/platforms/rcore_android.c | 2 +- src/platforms/rcore_desktop_glfw.c | 2 +- src/platforms/rcore_desktop_sdl.c | 17 ++++++++--------- src/platforms/rcore_drm.c | 4 ++-- src/platforms/rcore_web.c | 2 +- src/raylib.h | 2 +- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/platforms/rcore_android.c b/src/platforms/rcore_android.c index 88438c9b0..099719a29 100644 --- a/src/platforms/rcore_android.c +++ b/src/platforms/rcore_android.c @@ -615,7 +615,7 @@ int SetGamepadMappings(const char *mappings) } // Set gamepad vibration -void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor) +void SetGamepadVibration(int gamepad, float low, float high, int duration) { TRACELOG(LOG_WARNING, "GamepadSetVibration() not implemented on target platform"); } diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 0bc52ac9e..222a7245a 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -1060,7 +1060,7 @@ int SetGamepadMappings(const char *mappings) } // Set gamepad vibration -void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor) +void SetGamepadVibration(int gamepad, float low, float high, int duration) { TRACELOG(LOG_WARNING, "GamepadSetVibration() not available on target platform"); } diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index b4ceb78eb..cbd5c3e60 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -953,17 +953,16 @@ int SetGamepadMappings(const char *mappings) } // Set gamepad vibration -void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor) +void SetGamepadVibration(int gamepad, float low, float high, int duration) { - // 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)) + if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (duration > 0)) { - SDL_GameControllerRumble(platform.gamepad[gamepad], (Uint16)(leftMotor*65535.0f), (Uint16)(rightMotor*65535.0f), (Uint32)(MAX_GAMEPAD_VIBRATION_TIME*1000.0f)); + if (low < 0.0f) low = 0.0f; + if (low > 1.0f) low = 1.0f; + if (high < 0.0f) high = 0.0f; + if (high > 1.0f) high = 1.0f; + + SDL_GameControllerRumble(platform.gamepad[gamepad], (Uint16)(low*65535.0f), (Uint16)(high*65535.0f), (Uint32)duration); } } diff --git a/src/platforms/rcore_drm.c b/src/platforms/rcore_drm.c index e77457b1b..910d22c22 100644 --- a/src/platforms/rcore_drm.c +++ b/src/platforms/rcore_drm.c @@ -610,7 +610,7 @@ int SetGamepadMappings(const char *mappings) } // Set gamepad vibration -void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor) +void SetGamepadVibration(int gamepad, float low, float high, int duration) { TRACELOG(LOG_WARNING, "GamepadSetVibration() not implemented on target platform"); } @@ -763,7 +763,7 @@ int InitPlatform(void) drmModeConnector *con = drmModeGetConnector(platform.fd, res->connectors[i]); TRACELOG(LOG_TRACE, "DISPLAY: Connector modes detected: %i", con->count_modes); - + // In certain cases the status of the conneciton is reported as UKNOWN, but it is still connected. // This might be a hardware or software limitation like on Raspberry Pi Zero with composite output. if (((con->connection == DRM_MODE_CONNECTED) || (con->connection == DRM_MODE_UNKNOWNCONNECTION)) && (con->encoder_id)) diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index 36af66a47..e94492764 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -892,7 +892,7 @@ int SetGamepadMappings(const char *mappings) } // Set gamepad vibration -void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor) +void SetGamepadVibration(int gamepad, float low, float high, int duration) { TRACELOG(LOG_WARNING, "GamepadSetVibration() not implemented on target platform"); } diff --git a/src/raylib.h b/src/raylib.h index 5ae45fa9d..ea2416950 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1184,7 +1184,7 @@ RLAPI int GetGamepadButtonPressed(void); RLAPI int GetGamepadAxisCount(int gamepad); // Get gamepad axis count for a gamepad RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Get axis movement value for a gamepad axis RLAPI int SetGamepadMappings(const char *mappings); // Set internal gamepad mappings (SDL_GameControllerDB) -RLAPI void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor); // Set gamepad vibration for both motors +RLAPI void SetGamepadVibration(int gamepad, float low, float high, int duration); // Set gamepad vibration for both motors (duration in ms) // Input-related functions: mouse RLAPI bool IsMouseButtonPressed(int button); // Check if a mouse button has been pressed once