From 72be2f54598159771bf10934989bbb35b175d7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 11 Sep 2023 11:10:00 +0200 Subject: [PATCH] Restore the D-Pad behavior (see #18028) --- Core/ControlMapper.cpp | 1 + UI/GamepadEmu.cpp | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Core/ControlMapper.cpp b/Core/ControlMapper.cpp index c3808150ecc5..5fd5c50ee0fe 100644 --- a/Core/ControlMapper.cpp +++ b/Core/ControlMapper.cpp @@ -251,6 +251,7 @@ void ControlMapper::SwapMappingIfEnabled(uint32_t *vkey) { } // Can only be called from Key or Axis. +// mutex_ should be locked. // TODO: We should probably make a batched version of this. bool ControlMapper::UpdatePSPState(const InputMapping &changedMapping, double now) { // Instead of taking an input key and finding what it outputs, we loop through the OUTPUTS and diff --git a/UI/GamepadEmu.cpp b/UI/GamepadEmu.cpp index 0651792b06da..30dda6760905 100644 --- a/UI/GamepadEmu.cpp +++ b/UI/GamepadEmu.cpp @@ -351,22 +351,23 @@ void PSPDpad::ProcessTouch(float x, float y, bool down) { } int lastDown = down_; + int pressed = ctrlMask & ~lastDown; + int released = (~ctrlMask) & lastDown; down_ = ctrlMask; - __CtrlUpdateButtons(ctrlMask, CTRL_LEFT | CTRL_RIGHT | CTRL_UP | CTRL_DOWN); - - if (g_Config.bHapticFeedback) { - int pressed = down_ & ~lastDown; - static const int dir[4] = { CTRL_RIGHT, CTRL_DOWN, CTRL_LEFT, CTRL_UP }; - bool vibrate = false; - for (int i = 0; i < 4; i++) { - if (pressed & dir[i]) { - vibrate = true; - } + bool vibrate = false; + static const int dir[4] = { CTRL_RIGHT, CTRL_DOWN, CTRL_LEFT, CTRL_UP }; + for (int i = 0; i < 4; i++) { + if (pressed & dir[i]) { + vibrate = true; + __CtrlUpdateButtons(dir[i], 0); } - if (vibrate) { - System_Vibrate(HAPTIC_VIRTUAL_KEY); + if (released & dir[i]) { + __CtrlUpdateButtons(0, dir[i]); } } + if (vibrate && g_Config.bHapticFeedback) { + System_Vibrate(HAPTIC_VIRTUAL_KEY); + } } void PSPDpad::Draw(UIContext &dc) {