From 2f66d61f30a1a73da889b1443117da8c5293ad34 Mon Sep 17 00:00:00 2001 From: Kekker_ Date: Tue, 13 Mar 2018 21:43:37 -0400 Subject: [PATCH] Fix rumble on emulation pause Resets rumble on emulation pause and rumble for XInput/DInput controllers --- Source/Core/Core/Core.cpp | 24 +++++++++++++++--------- Source/Core/Core/HW/GCPad.cpp | 5 +++++ Source/Core/Core/HW/GCPad.h | 1 + 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 5f740c489f95..45e3b2ed6da5 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -275,9 +275,8 @@ void Stop() // - Hammertime! g_video_backend->Video_ExitLoop(); } -#if defined(__LIBUSB__) - GCAdapter::ResetRumble(); -#endif + + ResetRumble(); #ifdef USE_MEMORYWATCHER MemoryWatcher::Shutdown(); @@ -667,9 +666,7 @@ void SetState(State state) // stopped (including the CPU). CPU::EnableStepping(true); // Break Wiimote::Pause(); -#if defined(__LIBUSB__) - GCAdapter::ResetRumble(); -#endif + ResetRumble(); break; case State::Running: CPU::EnableStepping(false); @@ -788,9 +785,7 @@ static bool PauseAndLock(bool do_lock, bool unpause_on_unlock) // (s_efbAccessRequested). Fifo::PauseAndLock(do_lock, false); -#if defined(__LIBUSB__) - GCAdapter::ResetRumble(); -#endif + ResetRumble(); // CPU is unlocked last because CPU::PauseAndLock contains the synchronization // mechanism that prevents CPU::Break from racing. @@ -806,6 +801,17 @@ static bool PauseAndLock(bool do_lock, bool unpause_on_unlock) return was_unpaused; } +static void ResetRumble() +{ +#if defined(__LIBUSB__) + GCAdapter::ResetRumble(); +#endif +#if defined(CIFACE_USE_XINPUT) || defined(CIFACE_USE_DINPUT) + for (int i = 0; i != 4; ++i) + Pad::ResetRumble(i); +#endif +} + void RunAsCPUThread(std::function function) { const bool is_cpu_thread = IsCPUThread(); diff --git a/Source/Core/Core/HW/GCPad.cpp b/Source/Core/Core/HW/GCPad.cpp index 9cefbb4db12d..170e2b4f0e54 100644 --- a/Source/Core/Core/HW/GCPad.cpp +++ b/Source/Core/Core/HW/GCPad.cpp @@ -60,6 +60,11 @@ void Rumble(const int pad_num, const ControlState strength) static_cast(s_config.GetController(pad_num))->SetOutput(strength); } +void ResetRumble(const int pad_num) +{ + static_cast(s_config.GetController(pad_num))->SetOutput(0.0); +} + bool GetMicButton(const int pad_num) { return static_cast(s_config.GetController(pad_num))->GetMicButton(); diff --git a/Source/Core/Core/HW/GCPad.h b/Source/Core/Core/HW/GCPad.h index 728f68e7f99e..d3a9572d8c9a 100644 --- a/Source/Core/Core/HW/GCPad.h +++ b/Source/Core/Core/HW/GCPad.h @@ -27,6 +27,7 @@ InputConfig* GetConfig(); GCPadStatus GetStatus(int pad_num); ControllerEmu::ControlGroup* GetGroup(int pad_num, PadGroup group); void Rumble(int pad_num, ControlState strength); +void ResetRumble(int pad_num); bool GetMicButton(int pad_num); }