mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-25 10:22:33 -05:00
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 <gse@newspacesystems.com>
This commit is contained in:
@ -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)
|
||||
{
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user