diff --git a/src/Backends/GLFW3/Controller.cpp b/src/Backends/GLFW3/Controller.cpp index 71e83122..bc378cdc 100644 --- a/src/Backends/GLFW3/Controller.cpp +++ b/src/Backends/GLFW3/Controller.cpp @@ -102,9 +102,11 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) if (total_buttons > 32) total_buttons = 32; + // Read whatever buttons actually exist for (int i = 0; i < total_buttons; ++i) status->bButton[i] = buttons[i] == GLFW_PRESS; + // Blank the buttons that do not for (int i = total_buttons; i < 32; ++i) status->bButton[i] = FALSE; diff --git a/src/Backends/SDL2/Controller.cpp b/src/Backends/SDL2/Controller.cpp index ace9d913..bedc56d5 100644 --- a/src/Backends/SDL2/Controller.cpp +++ b/src/Backends/SDL2/Controller.cpp @@ -8,12 +8,12 @@ #include "../../WindowsWrapper.h" +#define DEADZONE 10000; + static SDL_Joystick *joystick; static int joystick_neutral_x; static int joystick_neutral_y; -void ControllerBackend_JoystickCallback(int joystick_id, BOOL connected); - BOOL ControllerBackend_Init(void) { SDL_InitSubSystem(SDL_INIT_JOYSTICK); @@ -37,6 +37,15 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) if (joystick == NULL) return FALSE; + // Read axis + const Sint16 joystick_x = SDL_JoystickGetAxis(joystick, 0); + const Sint16 joystick_y = SDL_JoystickGetAxis(joystick, 1); + + status->bLeft = joystick_x < joystick_neutral_x - DEADZONE; + status->bRight = joystick_x > joystick_neutral_x + DEADZONE; + status->bUp = joystick_y < joystick_neutral_y - DEADZONE; + status->bDown = joystick_y > joystick_neutral_y + DEADZONE; + // The original `Input.cpp` assumed there were 32 buttons (because of DirectInput's `DIJOYSTATE` struct) int numButtons = SDL_JoystickNumButtons(joystick); if (numButtons > 32) @@ -50,14 +59,6 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) for (int i = numButtons; i < 32; ++i) status->bButton[i] = FALSE; - const Sint16 joystick_x = SDL_JoystickGetAxis(joystick, 0); - const Sint16 joystick_y = SDL_JoystickGetAxis(joystick, 1); - - status->bLeft = joystick_x < joystick_neutral_x - 10000; - status->bRight = joystick_x > joystick_neutral_x + 10000; - status->bUp = joystick_y < joystick_neutral_y - 10000; - status->bDown = joystick_y > joystick_neutral_y + 10000; - return TRUE; }