This commit is contained in:
Clownacy 2020-04-05 00:11:52 +01:00
parent e0674d8f54
commit 6bb240d335

View file

@ -25,10 +25,10 @@ static void JoystickCallback(int joystick_id, int event)
if (!joystick_connected) if (!joystick_connected)
{ {
int total_axis; int total_axes;
const float *axis = glfwGetJoystickAxes(joystick_id, &total_axis); const float *axes = glfwGetJoystickAxes(joystick_id, &total_axes);
if (total_axis >= 2) if (total_axes >= 2)
{ {
#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3) #if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3)
if (glfwJoystickIsGamepad(joystick_id) == GLFW_TRUE) // Avoid selecting things like laptop touchpads if (glfwJoystickIsGamepad(joystick_id) == GLFW_TRUE) // Avoid selecting things like laptop touchpads
@ -39,9 +39,6 @@ static void JoystickCallback(int joystick_id, int event)
connected_joystick_id = joystick_id; connected_joystick_id = joystick_id;
// Set up neutral axes // Set up neutral axes
int total_axes;
const float *axes = glfwGetJoystickAxes(connected_joystick_id, &total_axes);
axis_neutrals = (float*)malloc(sizeof(float) * total_axes); axis_neutrals = (float*)malloc(sizeof(float) * total_axes);
for (int i = 0; i < total_axes; ++i) for (int i = 0; i < total_axes; ++i)
@ -104,13 +101,13 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status)
const unsigned char *hats = glfwGetJoystickHats(connected_joystick_id, &total_hats); const unsigned char *hats = glfwGetJoystickHats(connected_joystick_id, &total_hats);
// Handle direction inputs // Handle direction inputs
if (axes >= 1) if (total_axes >= 1)
{ {
status->bLeft = axes[0] < -DEADZONE; status->bLeft = axes[0] < -DEADZONE;
status->bRight = axes[0] > DEADZONE; status->bRight = axes[0] > DEADZONE;
} }
if (axes >= 2) if (total_axes >= 2)
{ {
status->bUp = axes[1] < -DEADZONE; status->bUp = axes[1] < -DEADZONE;
status->bDown = axes[1] > DEADZONE; status->bDown = axes[1] > DEADZONE;