From 6bcf51868548e4ca5e1638fd0546d3820095e4a9 Mon Sep 17 00:00:00 2001 From: Snowiiii <71594357+Snowiiii@users.noreply.github.com> Date: Wed, 29 Dec 2021 23:09:38 +0100 Subject: [PATCH] Added some switches --- src/input.c | 58 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/input.c b/src/input.c index 11716bd5..25fd71c5 100644 --- a/src/input.c +++ b/src/input.c @@ -202,14 +202,21 @@ static GLFWbool parseMapping(_GLFWmapping* mapping, const char* string) c += 1; } - if (*c == 'a') + switch (*c) + { + case 'a': e->type = _GLFW_JOYSTICK_AXIS; - else if (*c == 'b') - e->type = _GLFW_JOYSTICK_BUTTON; - else if (*c == 'h') - e->type = _GLFW_JOYSTICK_HATBIT; - else break; + case 'b': + e->type = _GLFW_JOYSTICK_BUTTON; + break; + case 'h': + e->type = _GLFW_JOYSTICK_HATBIT; + break; + default: + break; + } + if (e->type == _GLFW_JOYSTICK_HATBIT) { @@ -1067,8 +1074,7 @@ GLFWAPI const unsigned char* glfwGetJoystickHats(int jid, int* count) if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_BUTTONS)) return NULL; - *count = js->hatCount; - return js->hats; + return *count = js->hats; } GLFWAPI const char* glfwGetJoystickName(int jid) @@ -1324,7 +1330,9 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state) for (i = 0; i <= GLFW_GAMEPAD_BUTTON_LAST; i++) { const _GLFWmapelement* e = js->mapping->buttons + i; - if (e->type == _GLFW_JOYSTICK_AXIS) + switch (e->type) + { + case _GLFW_JOYSTICK_AXIS: { const float value = js->axes[e->index] * e->axisScale + e->axisOffset; // HACK: This should be baked into the value transform @@ -1340,26 +1348,33 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state) state->buttons[i] = GLFW_PRESS; } } - else if (e->type == _GLFW_JOYSTICK_HATBIT) + break; + case _GLFW_JOYSTICK_HATBIT: { - const unsigned int hat = e->index >> 4; - const unsigned int bit = e->index & 0xf; - if (js->hats[hat] & bit) - state->buttons[i] = GLFW_PRESS; + const unsigned int hat = e->index >> 4; + const unsigned int bit = e->index & 0xf; + if (js->hats[hat] & bit) + state->buttons[i] = GLFW_PRESS; + break; + } + case _GLFW_JOYSTICK_BUTTON: + state->buttons[i] = js->buttons[e->index]; + break; } - else if (e->type == _GLFW_JOYSTICK_BUTTON) - state->buttons[i] = js->buttons[e->index]; } - for (i = 0; i <= GLFW_GAMEPAD_AXIS_LAST; i++) + for (i = 0; i <= GLFW_GAMEPAD_AXIS_LAST; i++) { const _GLFWmapelement* e = js->mapping->axes + i; - if (e->type == _GLFW_JOYSTICK_AXIS) + switch (e->type) + { + case _GLFW_JOYSTICK_AXIS: { const float value = js->axes[e->index] * e->axisScale + e->axisOffset; state->axes[i] = _glfw_fminf(_glfw_fmaxf(value, -1.f), 1.f); } - else if (e->type == _GLFW_JOYSTICK_HATBIT) + break; + case _GLFW_JOYSTICK_HATBIT: { const unsigned int hat = e->index >> 4; const unsigned int bit = e->index & 0xf; @@ -1368,8 +1383,11 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state) else state->axes[i] = -1.f; } - else if (e->type == _GLFW_JOYSTICK_BUTTON) + break; + case _GLFW_JOYSTICK_BUTTON: state->axes[i] = js->buttons[e->index] * 2.f - 1.f; + break; + } } return GLFW_TRUE;