N3DS: Use macro to correct axis. Using `(value * SDL max) / 3DS max` allows for marginally better accuracy compared to `value * (SDL max / 3DS max)`.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
diff --git a/src/joystick/n3ds/SDL_sysjoystick.c b/src/joystick/n3ds/SDL_sysjoystick.c
index 6525d51..ea00a6d 100644
--- a/src/joystick/n3ds/SDL_sysjoystick.c
+++ b/src/joystick/n3ds/SDL_sysjoystick.c
@@ -34,16 +34,16 @@
/*
N3DS sticks values are roughly within +/-160
which is too small to pass the jitter tolerance.
- This correction factor is applied to axis values
+ This correction is applied to axis values
so they fit better in SDL's value range.
*/
-#define CORRECTION_FACTOR_X SDL_JOYSTICK_AXIS_MAX / 160
+#define CORRECT_AXIS_X(X) ((X * SDL_JOYSTICK_AXIS_MAX) / 160)
/*
The Y axis needs to be flipped because SDL's "up"
is reversed compared to libctru's "up"
*/
-#define CORRECTION_FACTOR_Y -CORRECTION_FACTOR_X
+#define CORRECT_AXIS_Y(Y) CORRECT_AXIS_X(-Y)
SDL_FORCE_INLINE void UpdateN3DSPressedButtons(SDL_Joystick *joystick);
SDL_FORCE_INLINE void UpdateN3DSReleasedButtons(SDL_Joystick *joystick);
@@ -151,12 +151,12 @@ UpdateN3DSCircle(SDL_Joystick *joystick)
if (previous_state.dx != current_state.dx) {
SDL_PrivateJoystickAxis(joystick,
0,
- current_state.dx * CORRECTION_FACTOR_X);
+ CORRECT_AXIS_X(current_state.dx));
}
if (previous_state.dy != current_state.dy) {
SDL_PrivateJoystickAxis(joystick,
1,
- current_state.dy * CORRECTION_FACTOR_Y);
+ CORRECT_AXIS_Y(current_state.dy));
}
previous_state = current_state;
}
@@ -170,12 +170,12 @@ UpdateN3DSCStick(SDL_Joystick *joystick)
if (previous_state.dx != current_state.dx) {
SDL_PrivateJoystickAxis(joystick,
2,
- current_state.dx * CORRECTION_FACTOR_X);
+ CORRECT_AXIS_X(current_state.dx));
}
if (previous_state.dy != current_state.dy) {
SDL_PrivateJoystickAxis(joystick,
3,
- current_state.dy * CORRECTION_FACTOR_Y);
+ CORRECT_AXIS_Y(current_state.dy));
}
previous_state = current_state;
}