From d860c14267e55217891b6b0ccbd397d7e6946e8c Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Thu, 7 Jan 2021 18:30:43 -0800 Subject: [PATCH] CommonHostInterface: Update rumble every frame regardless of change Fixes SDL rumble cutting off early when a game sends the same motor strength values every frame over a long duration. --- src/frontend-common/common_host_interface.cpp | 17 +++-------------- .../sdl_controller_interface.cpp | 2 +- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 88005e265..1666ff926 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -1055,16 +1055,10 @@ void CommonHostInterface::UpdateControllerRumble() if (!controller) continue; - bool changed = false; for (u32 i = 0; i < rumble.num_motors; i++) - { - const float strength = controller->GetVibrationMotorStrength(i); - changed |= (strength != rumble.last_strength[i]); - rumble.last_strength[i] = strength; - } + rumble.last_strength[i] = controller->GetVibrationMotorStrength(i); - if (changed) - rumble.update_callback(rumble.last_strength.data(), rumble.num_motors); + rumble.update_callback(rumble.last_strength.data(), rumble.num_motors); } } @@ -1072,15 +1066,10 @@ void CommonHostInterface::StopControllerRumble() { for (ControllerRumbleState& rumble : m_controller_vibration_motors) { - bool changed = false; for (u32 i = 0; i < rumble.num_motors; i++) - { - changed |= (rumble.last_strength[i] != 0.0f); rumble.last_strength[i] = 0.0f; - } - if (changed) - rumble.update_callback(rumble.last_strength.data(), rumble.num_motors); + rumble.update_callback(rumble.last_strength.data(), rumble.num_motors); } } diff --git a/src/frontend-common/sdl_controller_interface.cpp b/src/frontend-common/sdl_controller_interface.cpp index 9e257345b..fea1f3581 100644 --- a/src/frontend-common/sdl_controller_interface.cpp +++ b/src/frontend-common/sdl_controller_interface.cpp @@ -710,7 +710,7 @@ void SDLControllerInterface::SetControllerRumbleStrength(int controller_index, c return; // we'll update before this duration is elapsed - static constexpr u32 DURATION = 1000; + static constexpr u32 DURATION = 65535; // SDL_MAX_RUMBLE_DURATION_MS #if SDL_VERSION_ATLEAST(2, 0, 9) if (it->use_game_controller_rumble)