From 0fb318c8e9573f60227827ef63d6caf613d83cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 18 Oct 2023 22:48:23 +0200 Subject: [PATCH] Revert "Control: Remove the axis event dupe filtering from ScreenManager" This reverts commit 265a9021fd87b530970e4be093b5c29ae0b6f17e. --- Common/UI/Screen.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Common/UI/Screen.cpp b/Common/UI/Screen.cpp index 0851469985..1707b1a566 100644 --- a/Common/UI/Screen.cpp +++ b/Common/UI/Screen.cpp @@ -119,9 +119,28 @@ bool ScreenManager::key(const KeyInput &key) { void ScreenManager::axis(const AxisInput *axes, size_t count) { std::lock_guard guard(inputLock_); - if (stack_.empty()) - return; - stack_.back().screen->UnsyncAxis(axes, count); + + for (size_t i = 0; i < count; i++) { + const AxisInput &axis = axes[i]; + // Ignore duplicate values to prevent axis values overwriting each other. + uint64_t key = ((uint64_t)axis.axisId << 32) | axis.deviceId; + // Center value far from zero just to ensure we send the first zero. + // PSP games can't see higher resolution than this. + int value = 128 + ceilf(axis.value * 127.5f + 127.5f); + if (lastAxis_[key] == value) { + return; + } + lastAxis_[key] = value; + + // Send center axis to every screen layer. + if (axis.value == 0) { + for (auto &layer : stack_) { + layer.screen->UnsyncAxis(&axis, 1); + } + } else if (!stack_.empty()) { + stack_.back().screen->UnsyncAxis(&axis, 1); + } + } } void ScreenManager::deviceLost() {