Merge commit '852f2a6343518919e5ca8d3c1bbcab9f493e3cd8'

This commit is contained in:
2024-01-17 17:02:59 +01:00
1244 changed files with 50102 additions and 28146 deletions

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -36,13 +36,23 @@
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);
@ -73,7 +83,7 @@ static SDL_JoystickGUID N3DS_JoystickGetDeviceGUID(int device_index)
static SDL_JoystickID N3DS_JoystickGetDeviceInstanceID(int device_index)
{
return device_index;
return device_index + 1;
}
static int N3DS_JoystickOpen(SDL_Joystick *joystick, int device_index)
@ -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;
}
@ -221,6 +231,11 @@ static const char *N3DS_JoystickGetDevicePath(int device_index)
return NULL;
}
static int N3DS_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
{
return -1;
}
static int N3DS_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
@ -261,6 +276,7 @@ SDL_JoystickDriver SDL_N3DS_JoystickDriver = {
.Detect = N3DS_JoystickDetect,
.GetDeviceName = N3DS_JoystickGetDeviceName,
.GetDevicePath = N3DS_JoystickGetDevicePath,
.GetDeviceSteamVirtualGamepadSlot = N3DS_JoystickGetDeviceSteamVirtualGamepadSlot,
.GetDevicePlayerIndex = N3DS_JoystickGetDevicePlayerIndex,
.SetDevicePlayerIndex = N3DS_JoystickSetDevicePlayerIndex,
.GetDeviceGUID = N3DS_JoystickGetDeviceGUID,