Merge pull request #1152 from headshot2017/switch

add left analog stick movement for Switch
This commit is contained in:
UnknownShadow200 2024-03-17 10:31:22 +11:00 committed by GitHub
commit 34d2e868fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -120,7 +120,17 @@ static void HandleButtons(u64 mods) {
Input_SetNonRepeatable(CCPAD_DOWN, mods & HidNpadButton_Down);
}
static void ProcessJoystickInput(HidAnalogStickState* pos) {
static void ProcessJoystickInput_L(HidAnalogStickState* pos) {
// May not be exactly 0 on actual hardware
if (Math_AbsI(pos->x) <= 16) pos->x = 0;
if (Math_AbsI(pos->y) <= 16) pos->y = 0;
Input.JoystickMovement = (pos->x != 0 || pos->y != 0);
if (!Input.JoystickMovement) return;
Input.JoystickAngle = Math_Atan2(pos->x, -pos->y);
}
static void ProcessJoystickInput_R(HidAnalogStickState* pos) {
// May not be exactly 0 on actual hardware
if (Math_AbsI(pos->x) <= 16) pos->x = 0;
if (Math_AbsI(pos->y) <= 16) pos->y = 0;
@ -166,8 +176,8 @@ void Window_ProcessEvents(double delta) {
// Read the sticks' position
HidAnalogStickState analog_stick_l = padGetStickPos(&pad, 0);
HidAnalogStickState analog_stick_r = padGetStickPos(&pad, 1);
ProcessJoystickInput(&analog_stick_l);
ProcessJoystickInput(&analog_stick_r);
ProcessJoystickInput_L(&analog_stick_l);
ProcessJoystickInput_R(&analog_stick_r);
ProcessTouchInput();
}