Procházet zdrojové kódy

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.

(cherry picked from commit e5b0f86260063d64d6a5e446426e60aa32339485)
Sam Lantinga před 3 roky
rodič
revize
3c752893c5
1 změnil soubory, kde provedl 4 přidání a 1 odebrání
  1. 4 1
      main/input_default.cpp

+ 4 - 1
main/input_default.cpp

@@ -811,7 +811,10 @@ void InputDefault::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
 
 	Joypad &joy = joy_names[p_device];
 
-	if (joy.last_axis[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[p_axis] - p_value.value) < MIN_AXIS_CHANGE) {
 		return;
 	}