Fix 3DS Analog Values (#8581)

main
zoeyjodon 2023-11-22 13:34:01 -05:00 committed by GitHub
parent dbf14df80f
commit 059e550e98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 7 deletions

View File

@ -31,18 +31,28 @@
#define NB_BUTTONS 23
/*
N3DS sticks values are roughly within +/-160
N3DS sticks values are roughly within +/-170
which is too small to pass the jitter tolerance.
This correction is applied to axis values
so they fit better in SDL's value range.
*/
#define CORRECT_AXIS_X(X) ((X * SDL_JOYSTICK_AXIS_MAX) / 160)
static inline int Correct_Axis_X(int X) {
if (X > 160) {
return SDL_JOYSTICK_AXIS_MAX;
}
else if (X < -160) {
return -SDL_JOYSTICK_AXIS_MAX;
}
return (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 CORRECT_AXIS_Y(Y) CORRECT_AXIS_X(-Y)
static inline int Correct_Axis_Y(int Y) {
return Correct_Axis_X(-Y);
}
static void UpdateN3DSPressedButtons(Uint64 timestamp, SDL_Joystick *joystick);
static void UpdateN3DSReleasedButtons(Uint64 timestamp, SDL_Joystick *joystick);
@ -141,12 +151,12 @@ static void UpdateN3DSCircle(Uint64 timestamp, SDL_Joystick *joystick)
if (previous_state.dx != current_state.dx) {
SDL_SendJoystickAxis(timestamp, joystick,
0,
CORRECT_AXIS_X(current_state.dx));
Correct_Axis_X(current_state.dx));
}
if (previous_state.dy != current_state.dy) {
SDL_SendJoystickAxis(timestamp, joystick,
1,
CORRECT_AXIS_Y(current_state.dy));
Correct_Axis_Y(current_state.dy));
}
previous_state = current_state;
}
@ -159,12 +169,12 @@ static void UpdateN3DSCStick(Uint64 timestamp, SDL_Joystick *joystick)
if (previous_state.dx != current_state.dx) {
SDL_SendJoystickAxis(timestamp, joystick,
2,
CORRECT_AXIS_X(current_state.dx));
Correct_Axis_X(current_state.dx));
}
if (previous_state.dy != current_state.dy) {
SDL_SendJoystickAxis(timestamp, joystick,
3,
CORRECT_AXIS_Y(current_state.dy));
Correct_Axis_Y(current_state.dy));
}
previous_state = current_state;
}