Cleanup
This commit is contained in:
parent
65325e2b34
commit
4568d58c77
2 changed files with 13 additions and 10 deletions
|
@ -102,9 +102,11 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status)
|
||||||
if (total_buttons > 32)
|
if (total_buttons > 32)
|
||||||
total_buttons = 32;
|
total_buttons = 32;
|
||||||
|
|
||||||
|
// Read whatever buttons actually exist
|
||||||
for (int i = 0; i < total_buttons; ++i)
|
for (int i = 0; i < total_buttons; ++i)
|
||||||
status->bButton[i] = buttons[i] == GLFW_PRESS;
|
status->bButton[i] = buttons[i] == GLFW_PRESS;
|
||||||
|
|
||||||
|
// Blank the buttons that do not
|
||||||
for (int i = total_buttons; i < 32; ++i)
|
for (int i = total_buttons; i < 32; ++i)
|
||||||
status->bButton[i] = FALSE;
|
status->bButton[i] = FALSE;
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,12 @@
|
||||||
|
|
||||||
#include "../../WindowsWrapper.h"
|
#include "../../WindowsWrapper.h"
|
||||||
|
|
||||||
|
#define DEADZONE 10000;
|
||||||
|
|
||||||
static SDL_Joystick *joystick;
|
static SDL_Joystick *joystick;
|
||||||
static int joystick_neutral_x;
|
static int joystick_neutral_x;
|
||||||
static int joystick_neutral_y;
|
static int joystick_neutral_y;
|
||||||
|
|
||||||
void ControllerBackend_JoystickCallback(int joystick_id, BOOL connected);
|
|
||||||
|
|
||||||
BOOL ControllerBackend_Init(void)
|
BOOL ControllerBackend_Init(void)
|
||||||
{
|
{
|
||||||
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
|
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
|
||||||
|
@ -37,6 +37,15 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status)
|
||||||
if (joystick == NULL)
|
if (joystick == NULL)
|
||||||
return FALSE;
|
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)
|
// The original `Input.cpp` assumed there were 32 buttons (because of DirectInput's `DIJOYSTATE` struct)
|
||||||
int numButtons = SDL_JoystickNumButtons(joystick);
|
int numButtons = SDL_JoystickNumButtons(joystick);
|
||||||
if (numButtons > 32)
|
if (numButtons > 32)
|
||||||
|
@ -50,14 +59,6 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status)
|
||||||
for (int i = numButtons; i < 32; ++i)
|
for (int i = numButtons; i < 32; ++i)
|
||||||
status->bButton[i] = FALSE;
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue