From 53382473b3ed8266a6355de0954f324efdc5192f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 2 May 2018 18:24:48 +0200 Subject: dinput: fix clang "non-constant-expression" error --- dinput/win32-joystick.cpp | 22 +++++++++++++++------- dinput/win32-joystick.hpp | 4 +++- 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'dinput') diff --git a/dinput/win32-joystick.cpp b/dinput/win32-joystick.cpp index c20aefce..d4ae0e8a 100644 --- a/dinput/win32-joystick.cpp +++ b/dinput/win32-joystick.cpp @@ -3,6 +3,8 @@ #undef NDEBUG #include "win32-joystick.hpp" #include "compat/sleep.hpp" + +#include #include #include #include @@ -180,18 +182,24 @@ bool win32_joy_ctx::joy::poll(fn f) bool is_pov = false; int i = -1; +#define POV_HAT_OFFSET(k) \ + (offsetof(DIJOYSTATE, rgdwPOV) + (k) * sizeof(DWORD)) + +#define BUTTON(k) \ + (offsetof(DIJOYSTATE, rgbButtons) + (k) * sizeof(BYTE)) + switch (event.dwOfs) { - case DIJOFS_POV(0): i = 0, is_pov = true; break; - case DIJOFS_POV(2): i = 1, is_pov = true; break; - case DIJOFS_POV(3): i = 2, is_pov = true; break; - case DIJOFS_POV(4): i = 3, is_pov = true; break; + case POV_HAT_OFFSET(0): i = 0; is_pov = true; break; + case POV_HAT_OFFSET(2): i = 1; is_pov = true; break; + case POV_HAT_OFFSET(3): i = 2; is_pov = true; break; + case POV_HAT_OFFSET(4): i = 3; is_pov = true; break; default: - if (event.dwOfs >= DIJOFS_BUTTON0 && event.dwOfs <= DIJOFS_BUTTON(127)) + if (event.dwOfs >= BUTTON(0) && event.dwOfs <= BUTTON(127)) { unsigned tmp = event.dwOfs; - tmp -= DIJOFS_BUTTON0; - tmp /= DIJOFS_BUTTON1 - DIJOFS_BUTTON0; + tmp -= BUTTON(0); + tmp /= BUTTON(1) - BUTTON(0); tmp &= 127; i = tmp; } diff --git a/dinput/win32-joystick.hpp b/dinput/win32-joystick.hpp index f7ea1302..8b71b8b7 100644 --- a/dinput/win32-joystick.hpp +++ b/dinput/win32-joystick.hpp @@ -35,7 +35,7 @@ struct hash }; } -struct OTR_DINPUT_EXPORT win32_joy_ctx +struct OTR_DINPUT_EXPORT win32_joy_ctx final { using fn = std::function; @@ -97,6 +97,8 @@ private: ~enum_state(); void refresh(); const joys_t& get_joys() const; + + enum_state(enum_state const&) = delete; }; static enum_state enumerator; -- cgit v1.2.3