Cleanup
This commit is contained in:
parent
2040309d0c
commit
3c9011030f
26
src/input.c
26
src/input.c
@ -62,11 +62,11 @@ static _GLFWmapping* findMapping(const char* guid)
|
|||||||
static GLFWbool isValidElementForJoystick(const _GLFWmapelement* e,
|
static GLFWbool isValidElementForJoystick(const _GLFWmapelement* e,
|
||||||
const _GLFWjoystick* js)
|
const _GLFWjoystick* js)
|
||||||
{
|
{
|
||||||
if (e->type == _GLFW_JOYSTICK_HATBIT && (e->value >> 4) >= js->hatCount)
|
if (e->type == _GLFW_JOYSTICK_HATBIT && (e->index >> 4) >= js->hatCount)
|
||||||
return GLFW_FALSE;
|
return GLFW_FALSE;
|
||||||
else if (e->type == _GLFW_JOYSTICK_BUTTON && e->value >= js->buttonCount)
|
else if (e->type == _GLFW_JOYSTICK_BUTTON && e->index >= js->buttonCount)
|
||||||
return GLFW_FALSE;
|
return GLFW_FALSE;
|
||||||
else if (e->type == _GLFW_JOYSTICK_AXIS && e->value >= js->axisCount)
|
else if (e->type == _GLFW_JOYSTICK_AXIS && e->index >= js->axisCount)
|
||||||
return GLFW_FALSE;
|
return GLFW_FALSE;
|
||||||
|
|
||||||
return GLFW_TRUE;
|
return GLFW_TRUE;
|
||||||
@ -209,10 +209,10 @@ static GLFWbool parseMapping(_GLFWmapping* mapping, const char* string)
|
|||||||
{
|
{
|
||||||
const unsigned long hat = strtoul(c + 1, (char**) &c, 10);
|
const unsigned long hat = strtoul(c + 1, (char**) &c, 10);
|
||||||
const unsigned long bit = strtoul(c + 1, (char**) &c, 10);
|
const unsigned long bit = strtoul(c + 1, (char**) &c, 10);
|
||||||
e->value = (uint8_t) ((hat << 4) | bit);
|
e->index = (uint8_t) ((hat << 4) | bit);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
e->value = (uint8_t) strtoul(c + 1, (char**) &c, 10);
|
e->index = (uint8_t) strtoul(c + 1, (char**) &c, 10);
|
||||||
|
|
||||||
if (e->type == _GLFW_JOYSTICK_AXIS)
|
if (e->type == _GLFW_JOYSTICK_AXIS)
|
||||||
{
|
{
|
||||||
@ -1222,19 +1222,19 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state)
|
|||||||
const _GLFWmapelement* e = js->mapping->buttons + i;
|
const _GLFWmapelement* e = js->mapping->buttons + i;
|
||||||
if (e->type == _GLFW_JOYSTICK_AXIS)
|
if (e->type == _GLFW_JOYSTICK_AXIS)
|
||||||
{
|
{
|
||||||
const float value = js->axes[e->value] * e->axisScale + e->axisOffset;
|
const float value = js->axes[e->index] * e->axisScale + e->axisOffset;
|
||||||
if (value > 0.f)
|
if (value > 0.f)
|
||||||
state->buttons[i] = GLFW_PRESS;
|
state->buttons[i] = GLFW_PRESS;
|
||||||
}
|
}
|
||||||
else if (e->type == _GLFW_JOYSTICK_HATBIT)
|
else if (e->type == _GLFW_JOYSTICK_HATBIT)
|
||||||
{
|
{
|
||||||
const unsigned int hat = e->value >> 4;
|
const unsigned int hat = e->index >> 4;
|
||||||
const unsigned int bit = e->value & 0xf;
|
const unsigned int bit = e->index & 0xf;
|
||||||
if (js->hats[hat] & bit)
|
if (js->hats[hat] & bit)
|
||||||
state->buttons[i] = GLFW_PRESS;
|
state->buttons[i] = GLFW_PRESS;
|
||||||
}
|
}
|
||||||
else if (e->type == _GLFW_JOYSTICK_BUTTON)
|
else if (e->type == _GLFW_JOYSTICK_BUTTON)
|
||||||
state->buttons[i] = js->buttons[e->value];
|
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++)
|
||||||
@ -1242,18 +1242,18 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state)
|
|||||||
const _GLFWmapelement* e = js->mapping->axes + i;
|
const _GLFWmapelement* e = js->mapping->axes + i;
|
||||||
if (e->type == _GLFW_JOYSTICK_AXIS)
|
if (e->type == _GLFW_JOYSTICK_AXIS)
|
||||||
{
|
{
|
||||||
const float value = js->axes[e->value] * e->axisScale + e->axisOffset;
|
const float value = js->axes[e->index] * e->axisScale + e->axisOffset;
|
||||||
state->axes[i] = fminf(fmaxf(value, -1.f), 1.f);
|
state->axes[i] = fminf(fmaxf(value, -1.f), 1.f);
|
||||||
}
|
}
|
||||||
else if (e->type == _GLFW_JOYSTICK_HATBIT)
|
else if (e->type == _GLFW_JOYSTICK_HATBIT)
|
||||||
{
|
{
|
||||||
const unsigned int hat = e->value >> 4;
|
const unsigned int hat = e->index >> 4;
|
||||||
const unsigned int bit = e->value & 0xf;
|
const unsigned int bit = e->index & 0xf;
|
||||||
if (js->hats[hat] & bit)
|
if (js->hats[hat] & bit)
|
||||||
state->axes[i] = 1.f;
|
state->axes[i] = 1.f;
|
||||||
}
|
}
|
||||||
else if (e->type == _GLFW_JOYSTICK_BUTTON)
|
else if (e->type == _GLFW_JOYSTICK_BUTTON)
|
||||||
state->axes[i] = (float) js->buttons[e->value];
|
state->axes[i] = (float) js->buttons[e->index];
|
||||||
}
|
}
|
||||||
|
|
||||||
return GLFW_TRUE;
|
return GLFW_TRUE;
|
||||||
|
@ -456,7 +456,7 @@ struct _GLFWcursor
|
|||||||
struct _GLFWmapelement
|
struct _GLFWmapelement
|
||||||
{
|
{
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint8_t value;
|
uint8_t index;
|
||||||
int8_t axisScale;
|
int8_t axisScale;
|
||||||
int8_t axisOffset;
|
int8_t axisOffset;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user