Added some switches

This commit is contained in:
Snowiiii 2021-12-29 23:09:38 +01:00 committed by GitHub
parent 6281f498c8
commit 6bcf518685
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
break;
}
else if (e->type == _GLFW_JOYSTICK_BUTTON)
case _GLFW_JOYSTICK_BUTTON:
state->buttons[i] = js->buttons[e->index];
break;
}
}
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;