From 88e89653b13bd590f58e57a82d07b398134a4afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 30 Mar 2023 15:15:33 +0200 Subject: [PATCH] Bring back zeroing of the opposite direction. --- Core/ControlMapper.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Core/ControlMapper.cpp b/Core/ControlMapper.cpp index 4f4a2064c9..1c6c4f925a 100644 --- a/Core/ControlMapper.cpp +++ b/Core/ControlMapper.cpp @@ -11,7 +11,7 @@ #include "Core/CoreParameter.h" #include "Core/System.h" -// TODO: Possibly make these configurable? +// TODO: Possibly make these thresholds configurable? static float GetDeviceAxisThreshold(int device) { return device == DEVICE_ID_MOUSE ? AXIS_BIND_THRESHOLD_MOUSE : AXIS_BIND_THRESHOLD; } @@ -190,6 +190,7 @@ bool ControlMapper::UpdatePSPState(const InputMapping &changedMapping) { // mapping which gets a little hacky. float threshold = 1.0f; bool touchedByMapping = false; + bool zeroOpposite = false; float value = 0.0f; for (auto &mapping : inputMappings) { if (mapping == changedMapping) { @@ -200,6 +201,7 @@ bool ControlMapper::UpdatePSPState(const InputMapping &changedMapping) { if (iter != curInput_.end()) { if (mapping.IsAxis()) { threshold = GetDeviceAxisThreshold(iter->first.deviceId); + zeroOpposite = true; } value += iter->second; } @@ -219,6 +221,14 @@ bool ControlMapper::UpdatePSPState(const InputMapping &changedMapping) { onVKeyAnalog(changedMapping.deviceId, vkId, value); virtKeys_[i] = value; } + if (zeroOpposite) { + // For analog stick events, always zero the "opposite" when we get a valid value. + // Otherwise, lingering small values can create strange offsets when summing up later. + int opposite = GetOppositeVKey(vkId); + if (opposite) { + virtKeys_[i] = 0.0f; + } + } if (!bPrevValue && bValue) { // INFO_LOG(G3D, "vkeyon %s", KeyMap::GetVirtKeyName(vkId)); onVKey(vkId, true);