summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2021-12-15 22:49:19 -0800
committerSam Lantinga <slouken@libsdl.org>2021-12-16 09:04:58 -0800
commit313815f8184278dd2eabe1fbe05488dc527e4a0a (patch)
treeee991d659e0ba4bedcdfa512e099c75e25020b59
parent765032ae956b51c85435e7619774f31211843af4 (diff)
Fixed event spam when using the Nintendo Switch controller
There is no filtering on the Nintendo Switch Pro controller thumbstick, so there will frequently be events with very slight change. These are turned into "not pressed" events, which cancel "pressed" events from keys and buttons. This change filters out up to 5% jitter, but it might be worth revisiting whether "not pressed" events should cancel "pressed" events.
-rw-r--r--core/input/input.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 3dfe73ab8e..9a6a2a2e15 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -922,7 +922,10 @@ void Input::joy_axis(int p_device, JoyAxis p_axis, const JoyAxisValue &p_value)
Joypad &joy = joy_names[p_device];
- if (joy.last_axis[(size_t)p_axis] == p_value.value) {
+ // Make sure that we don't generate events for up to 5% jitter
+ // This is needed for Nintendo Switch Pro controllers, which jitter at rest
+ const float MIN_AXIS_CHANGE = 0.05f;
+ if (fabs(joy.last_axis[(size_t)p_axis] - p_value.value) < MIN_AXIS_CHANGE) {
return;
}