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 1/4] 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; From 9fd90689697cd74e38ba48df2a20982cef8a7204 Mon Sep 17 00:00:00 2001 From: Snowiiii <71594357+Snowiiii@users.noreply.github.com> Date: Wed, 29 Dec 2021 23:16:12 +0100 Subject: [PATCH 2/4] Fixed Hats --- src/input.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/input.c b/src/input.c index 25fd71c5..f82e4bb1 100644 --- a/src/input.c +++ b/src/input.c @@ -1074,7 +1074,8 @@ GLFWAPI const unsigned char* glfwGetJoystickHats(int jid, int* count) if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_BUTTONS)) return NULL; - return *count = js->hats; + *count = js->hatCount; + return js->hats; } GLFWAPI const char* glfwGetJoystickName(int jid) From 5562aa575bf0c7f4a3b1c49dfb72a6cfa587ba86 Mon Sep 17 00:00:00 2001 From: Snowiiii <71594357+Snowiiii@users.noreply.github.com> Date: Thu, 30 Dec 2021 10:49:14 +0100 Subject: [PATCH 3/4] Added switch --- src/init.c | 67 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/src/init.c b/src/init.c index b5c5da9c..cfb815e4 100644 --- a/src/init.c +++ b/src/init.c @@ -150,26 +150,18 @@ char* _glfw_strdup(const char* source) float _glfw_fminf(float a, float b) { - if (a != a) - return b; - else if (b != b) + if (b != b || a < b) return a; - else if (a < b) - return a; - else - return b; + + return b; } float _glfw_fmaxf(float a, float b) { - if (a != a) - return b; - else if (b != b) + if (b != b || a > b) return a; - else if (a > b) - return a; - else - return b; + + return b; } void* _glfw_calloc(size_t count, size_t size) @@ -249,36 +241,53 @@ void _glfwInputError(int code, const char* format, ...) } else { - if (code == GLFW_NOT_INITIALIZED) + switch (code) + { + case GLFW_NOT_INITIALIZED: strcpy(description, "The GLFW library is not initialized"); - else if (code == GLFW_NO_CURRENT_CONTEXT) + break; + case GLFW_NO_CURRENT_CONTEXT: strcpy(description, "There is no current context"); - else if (code == GLFW_INVALID_ENUM) + break; + case GLFW_INVALID_ENUM: strcpy(description, "Invalid argument for enum parameter"); - else if (code == GLFW_INVALID_VALUE) + break; + case GLFW_INVALID_VALUE: strcpy(description, "Invalid value for parameter"); - else if (code == GLFW_OUT_OF_MEMORY) + break; + case GLFW_OUT_OF_MEMORY: strcpy(description, "Out of memory"); - else if (code == GLFW_API_UNAVAILABLE) + break; + case GLFW_API_UNAVAILABLE: strcpy(description, "The requested API is unavailable"); - else if (code == GLFW_VERSION_UNAVAILABLE) + break; + case GLFW_VERSION_UNAVAILABLE: strcpy(description, "The requested API version is unavailable"); - else if (code == GLFW_PLATFORM_ERROR) + break; + case GLFW_PLATFORM_ERROR: strcpy(description, "A platform-specific error occurred"); - else if (code == GLFW_FORMAT_UNAVAILABLE) + break; + case GLFW_FORMAT_UNAVAILABLE: strcpy(description, "The requested format is unavailable"); - else if (code == GLFW_NO_WINDOW_CONTEXT) + break; + case GLFW_NO_WINDOW_CONTEXT: strcpy(description, "The specified window has no context"); - else if (code == GLFW_CURSOR_UNAVAILABLE) + break; + case GLFW_CURSOR_UNAVAILABLE: strcpy(description, "The specified cursor shape is unavailable"); - else if (code == GLFW_FEATURE_UNAVAILABLE) + break; + case GLFW_FEATURE_UNAVAILABLE: strcpy(description, "The requested feature cannot be implemented for this platform"); - else if (code == GLFW_FEATURE_UNIMPLEMENTED) + break; + case GLFW_FEATURE_UNIMPLEMENTED: strcpy(description, "The requested feature has not yet been implemented for this platform"); - else if (code == GLFW_PLATFORM_UNAVAILABLE) + break; + case GLFW_PLATFORM_UNAVAILABLE: strcpy(description, "The requested platform is unavailable"); - else + break; + default: strcpy(description, "ERROR: UNKNOWN GLFW ERROR"); + } } if (_glfw.initialized) From 4353b622517ff55f3b4e85cef8654613efeff003 Mon Sep 17 00:00:00 2001 From: Snowiiii <71594357+Snowiiii@users.noreply.github.com> Date: Sat, 1 Jan 2022 22:13:22 +0100 Subject: [PATCH 4/4] Update xinput.h --- deps/mingw/xinput.h | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/deps/mingw/xinput.h b/deps/mingw/xinput.h index d3ca726c..46f2d335 100644 --- a/deps/mingw/xinput.h +++ b/deps/mingw/xinput.h @@ -110,14 +110,17 @@ * which are being used. */ -#define XINPUT_DEVTYPE_GAMEPAD 0x01 -#define XINPUT_DEVSUBTYPE_GAMEPAD 0x01 -#define XINPUT_DEVSUBTYPE_WHEEL 0x02 -#define XINPUT_DEVSUBTYPE_ARCADE_STICK 0x03 -#define XINPUT_DEVSUBTYPE_FLIGHT_SICK 0x04 -#define XINPUT_DEVSUBTYPE_DANCE_PAD 0x05 -#define XINPUT_DEVSUBTYPE_GUITAR 0x06 -#define XINPUT_DEVSUBTYPE_DRUM_KIT 0x08 +#define XINPUT_DEVTYPE_GAMEPAD 0x01 +#define XINPUT_DEVSUBTYPE_GAMEPAD 0x01 +#define XINPUT_DEVSUBTYPE_WHEEL 0x02 +#define XINPUT_DEVSUBTYPE_ARCADE_STICK 0x03 +#define XINPUT_DEVSUBTYPE_FLIGHT_SICK 0x04 +#define XINPUT_DEVSUBTYPE_DANCE_PAD 0x05 +#define XINPUT_DEVSUBTYPE_GUITAR 0x06 +#define XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE 0x07 +#define XINPUT_DEVSUBTYPE_DRUM_KIT 0x08 +#define XINPUT_DEVSUBTYPE_GUITAR_BASS 0x0b +#define XINPUT_DEVSUBTYPE_ARCADE_PAD 0x13 /* * These are used with the XInputGetCapabilities function to @@ -156,6 +159,11 @@ #define XUSER_MAX_COUNT 4 #define XUSER_INDEX_ANY 0x000000FF +#define XINPUT_CAPS_FFB_SUPPORTED 0x0001 +#define XINPUT_CAPS_WIRELESS 0x0002 +#define XINPUT_CAPS_PMD_SUPPORTED 0x0008 +#define XINPUT_CAPS_NO_NAVIGATION 0x0010 + /* * Defines the structure of an xbox 360 joystick. */ @@ -232,6 +240,8 @@ DWORD WINAPI XInputGetCapabilities(DWORD, DWORD, XINPUT_CAPABILITIES*); DWORD WINAPI XInputGetDSoundAudioDeviceGuids(DWORD, GUID*, GUID*); DWORD WINAPI XInputGetBatteryInformation(DWORD, BYTE, XINPUT_BATTERY_INFORMATION*); +DWORD WINAPI XInputGetStateEx(DWORD, XINPUT_STATE*); + #ifdef __cplusplus } #endif