ref: 4568d58c777c3a7f72463bea3d019b2617ef1287
parent: 65325e2b34f68be94398df393e6156183a797590
author: Clownacy <Clownacy@users.noreply.github.com>
date: Sat Apr 4 15:53:16 EDT 2020
Cleanup
--- a/src/Backends/GLFW3/Controller.cpp
+++ b/src/Backends/GLFW3/Controller.cpp
@@ -102,9 +102,11 @@
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;
--- 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 @@
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)
@@ -49,14 +58,6 @@
// Blank the buttons that do not
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;
}