diff options
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/drivers/sdl_driver.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index d56351815..53e282ef3 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp | |||
| @@ -94,7 +94,6 @@ public: | |||
| 94 | 94 | ||
| 95 | bool RumblePlay(const Input::VibrationStatus vibration) { | 95 | bool RumblePlay(const Input::VibrationStatus vibration) { |
| 96 | constexpr u32 rumble_max_duration_ms = 1000; | 96 | constexpr u32 rumble_max_duration_ms = 1000; |
| 97 | |||
| 98 | if (sdl_controller) { | 97 | if (sdl_controller) { |
| 99 | return SDL_GameControllerRumble( | 98 | return SDL_GameControllerRumble( |
| 100 | sdl_controller.get(), static_cast<u16>(vibration.low_amplitude), | 99 | sdl_controller.get(), static_cast<u16>(vibration.low_amplitude), |
| @@ -520,25 +519,31 @@ Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifier, | |||
| 520 | const Input::VibrationStatus vibration) { | 519 | const Input::VibrationStatus vibration) { |
| 521 | const auto joystick = | 520 | const auto joystick = |
| 522 | GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port)); | 521 | GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port)); |
| 523 | const auto process_amplitude = [](f32 amplitude) { | 522 | const auto process_amplitude_exp = [](f32 amplitude, f32 factor) { |
| 524 | return (amplitude + std::pow(amplitude, 0.3f)) * 0.5f * 0xFFFF; | 523 | return (amplitude + std::pow(amplitude, factor)) * 0.5f * 0xFFFF; |
| 525 | }; | 524 | }; |
| 526 | const Input::VibrationStatus exponential_vibration{ | 525 | |
| 527 | .low_amplitude = process_amplitude(vibration.low_amplitude), | 526 | // Default exponential curve for rumble |
| 527 | f32 factor = 0.35f; | ||
| 528 | |||
| 529 | // If vibration is set as a linear output use a flatter value | ||
| 530 | if (vibration.type == Input::VibrationAmplificationType::Linear) { | ||
| 531 | factor = 0.5f; | ||
| 532 | } | ||
| 533 | |||
| 534 | // Amplitude for HD rumble needs no modification | ||
| 535 | if (joystick->HasHDRumble()) { | ||
| 536 | factor = 1.0f; | ||
| 537 | } | ||
| 538 | |||
| 539 | const Input::VibrationStatus new_vibration{ | ||
| 540 | .low_amplitude = process_amplitude_exp(vibration.low_amplitude, factor), | ||
| 528 | .low_frequency = vibration.low_frequency, | 541 | .low_frequency = vibration.low_frequency, |
| 529 | .high_amplitude = process_amplitude(vibration.high_amplitude), | 542 | .high_amplitude = process_amplitude_exp(vibration.high_amplitude, factor), |
| 530 | .high_frequency = vibration.high_frequency, | 543 | .high_frequency = vibration.high_frequency, |
| 531 | .type = Input::VibrationAmplificationType::Exponential, | 544 | .type = Input::VibrationAmplificationType::Exponential, |
| 532 | }; | 545 | }; |
| 533 | 546 | ||
| 534 | Input::VibrationStatus new_vibration{}; | ||
| 535 | |||
| 536 | if (vibration.type == Input::VibrationAmplificationType::Linear || joystick->HasHDRumble()) { | ||
| 537 | new_vibration = vibration; | ||
| 538 | } else { | ||
| 539 | new_vibration = exponential_vibration; | ||
| 540 | } | ||
| 541 | |||
| 542 | if (!joystick->RumblePlay(new_vibration)) { | 547 | if (!joystick->RumblePlay(new_vibration)) { |
| 543 | return Input::VibrationError::Unknown; | 548 | return Input::VibrationError::Unknown; |
| 544 | } | 549 | } |