From b6eeea4b92d6c3b6b9a5d210edfaf11053ebc8fb Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 10 Mar 2013 13:28:39 -0400 Subject: [PATCH] Attempt to get XInput haptics building on Cygwin (or rather, avoid building). --- src/core/windows/SDL_windows.c | 63 ------------------------- src/core/windows/SDL_windows.h | 59 ----------------------- src/joystick/windows/SDL_dxjoystick.c | 63 +++++++++++++++++++++++++ src/joystick/windows/SDL_dxjoystick_c.h | 59 +++++++++++++++++++++++ 4 files changed, 122 insertions(+), 122 deletions(-) diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c index 49f2f04fd..0927832f0 100644 --- a/src/core/windows/SDL_windows.c +++ b/src/core/windows/SDL_windows.c @@ -28,69 +28,6 @@ #include /* for CoInitialize/CoUninitialize */ - -XInputGetState_t SDL_XInputGetState = NULL; -XInputSetState_t SDL_XInputSetState = NULL; -XInputGetCapabilities_t SDL_XInputGetCapabilities = NULL; -DWORD SDL_XInputVersion = 0; - -static HANDLE s_pXInputDLL = 0; -static int s_XInputDLLRefCount = 0; - -int -WIN_LoadXInputDLL(void) -{ - DWORD version = 0; - - if (s_pXInputDLL) { - SDL_assert(s_XInputDLLRefCount > 0); - s_XInputDLLRefCount++; - return 0; /* already loaded */ - } - - version = (1 << 16) | 4; - s_pXInputDLL = LoadLibrary( L"XInput1_4.dll" ); // 1.4 Ships with Windows 8. - if (!s_pXInputDLL) { - version = (1 << 16) | 3; - s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" ); // 1.3 Ships with Vista and Win7, can be installed as a restributable component. - } - if (!s_pXInputDLL) { - s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" ); - } - if (!s_pXInputDLL) { - return -1; - } - - SDL_assert(s_XInputDLLRefCount == 0); - SDL_XInputVersion = version; - s_XInputDLLRefCount = 1; - - /* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */ - SDL_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 ); - SDL_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" ); - SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" ); - if ( !SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities ) { - WIN_UnloadXInputDLL(); - return -1; - } - - return 0; -} - -void -WIN_UnloadXInputDLL(void) -{ - if ( s_pXInputDLL ) { - SDL_assert(s_XInputDLLRefCount > 0); - if (--s_XInputDLLRefCount == 0) { - FreeLibrary( s_pXInputDLL ); - s_pXInputDLL = NULL; - } - } else { - SDL_assert(s_XInputDLLRefCount == 0); - } -} - /* Sets an error message based on GetLastError() */ void WIN_SetError(const char *prefix) diff --git a/src/core/windows/SDL_windows.h b/src/core/windows/SDL_windows.h index a68182777..c30fa9be6 100644 --- a/src/core/windows/SDL_windows.h +++ b/src/core/windows/SDL_windows.h @@ -33,7 +33,6 @@ #define _WIN32_WINNT 0x501 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input */ #include -#include /* Routines to convert from UTF8 to native Windows text */ #if UNICODE @@ -51,64 +50,6 @@ extern void WIN_SetError(const char *prefix); extern HRESULT WIN_CoInitialize(void); extern void WIN_CoUninitialize(void); -/* typedef's for XInput structs we use */ -typedef struct -{ - WORD wButtons; - BYTE bLeftTrigger; - BYTE bRightTrigger; - SHORT sThumbLX; - SHORT sThumbLY; - SHORT sThumbRX; - SHORT sThumbRY; - DWORD dwPaddingReserved; -} XINPUT_GAMEPAD_EX; - -typedef struct -{ - DWORD dwPacketNumber; - XINPUT_GAMEPAD_EX Gamepad; -} XINPUT_STATE_EX; - - -/* Forward decl's for XInput API's we load dynamically and use if available */ -typedef DWORD (WINAPI *XInputGetState_t) - ( - DWORD dwUserIndex, // [in] Index of the gamer associated with the device - XINPUT_STATE_EX* pState // [out] Receives the current state - ); - -typedef DWORD (WINAPI *XInputSetState_t) - ( - DWORD dwUserIndex, // [in] Index of the gamer associated with the device - XINPUT_VIBRATION* pVibration // [in, out] The vibration information to send to the controller - ); - -typedef DWORD (WINAPI *XInputGetCapabilities_t) - ( - DWORD dwUserIndex, // [in] Index of the gamer associated with the device - DWORD dwFlags, // [in] Input flags that identify the device type - XINPUT_CAPABILITIES* pCapabilities // [out] Receives the capabilities - ); - -extern int WIN_LoadXInputDLL(void); -extern void WIN_UnloadXInputDLL(void); - -extern XInputGetState_t SDL_XInputGetState; -extern XInputSetState_t SDL_XInputSetState; -extern XInputGetCapabilities_t SDL_XInputGetCapabilities; -extern DWORD SDL_XInputVersion; // ((major << 16) & 0xFF00) | (minor & 0xFF) - -#define XINPUTGETSTATE SDL_XInputGetState -#define XINPUTSETSTATE SDL_XInputSetState -#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities -#define INVALID_XINPUT_USERID 255 -#define SDL_XINPUT_MAX_DEVICES 4 - -#ifndef XINPUT_CAPS_FFB_SUPPORTED -#define XINPUT_CAPS_FFB_SUPPORTED 0x0001 -#endif - #endif /* _INCLUDED_WINDOWS_H */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index 69f7da3aa..e67e66e68 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -75,6 +75,69 @@ static SDL_Thread *s_threadJoystick = NULL; static SDL_bool s_bJoystickThreadQuit = SDL_FALSE; static SDL_bool s_bXInputEnabled = SDL_TRUE; +XInputGetState_t SDL_XInputGetState = NULL; +XInputSetState_t SDL_XInputSetState = NULL; +XInputGetCapabilities_t SDL_XInputGetCapabilities = NULL; +DWORD SDL_XInputVersion = 0; + +static HANDLE s_pXInputDLL = 0; +static int s_XInputDLLRefCount = 0; + +int +WIN_LoadXInputDLL(void) +{ + DWORD version = 0; + + if (s_pXInputDLL) { + SDL_assert(s_XInputDLLRefCount > 0); + s_XInputDLLRefCount++; + return 0; /* already loaded */ + } + + version = (1 << 16) | 4; + s_pXInputDLL = LoadLibrary( L"XInput1_4.dll" ); // 1.4 Ships with Windows 8. + if (!s_pXInputDLL) { + version = (1 << 16) | 3; + s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" ); // 1.3 Ships with Vista and Win7, can be installed as a restributable component. + } + if (!s_pXInputDLL) { + s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" ); + } + if (!s_pXInputDLL) { + return -1; + } + + SDL_assert(s_XInputDLLRefCount == 0); + SDL_XInputVersion = version; + s_XInputDLLRefCount = 1; + + /* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */ + SDL_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 ); + SDL_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" ); + SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" ); + if ( !SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities ) { + WIN_UnloadXInputDLL(); + return -1; + } + + return 0; +} + +void +WIN_UnloadXInputDLL(void) +{ + if ( s_pXInputDLL ) { + SDL_assert(s_XInputDLLRefCount > 0); + if (--s_XInputDLLRefCount == 0) { + FreeLibrary( s_pXInputDLL ); + s_pXInputDLL = NULL; + } + } else { + SDL_assert(s_XInputDLLRefCount == 0); + } +} + + extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT * ppDI, LPUNKNOWN punkOuter); diff --git a/src/joystick/windows/SDL_dxjoystick_c.h b/src/joystick/windows/SDL_dxjoystick_c.h index 6d4957815..13d0d451a 100644 --- a/src/joystick/windows/SDL_dxjoystick_c.h +++ b/src/joystick/windows/SDL_dxjoystick_c.h @@ -42,6 +42,65 @@ #include #include #include +#include + +/* typedef's for XInput structs we use */ +typedef struct +{ + WORD wButtons; + BYTE bLeftTrigger; + BYTE bRightTrigger; + SHORT sThumbLX; + SHORT sThumbLY; + SHORT sThumbRX; + SHORT sThumbRY; + DWORD dwPaddingReserved; +} XINPUT_GAMEPAD_EX; + +typedef struct +{ + DWORD dwPacketNumber; + XINPUT_GAMEPAD_EX Gamepad; +} XINPUT_STATE_EX; + +/* Forward decl's for XInput API's we load dynamically and use if available */ +typedef DWORD (WINAPI *XInputGetState_t) + ( + DWORD dwUserIndex, // [in] Index of the gamer associated with the device + XINPUT_STATE_EX* pState // [out] Receives the current state + ); + +typedef DWORD (WINAPI *XInputSetState_t) + ( + DWORD dwUserIndex, // [in] Index of the gamer associated with the device + XINPUT_VIBRATION* pVibration // [in, out] The vibration information to send to the controller + ); + +typedef DWORD (WINAPI *XInputGetCapabilities_t) + ( + DWORD dwUserIndex, // [in] Index of the gamer associated with the device + DWORD dwFlags, // [in] Input flags that identify the device type + XINPUT_CAPABILITIES* pCapabilities // [out] Receives the capabilities + ); + +extern int WIN_LoadXInputDLL(void); +extern void WIN_UnloadXInputDLL(void); + +extern XInputGetState_t SDL_XInputGetState; +extern XInputSetState_t SDL_XInputSetState; +extern XInputGetCapabilities_t SDL_XInputGetCapabilities; +extern DWORD SDL_XInputVersion; // ((major << 16) & 0xFF00) | (minor & 0xFF) + +#define XINPUTGETSTATE SDL_XInputGetState +#define XINPUTSETSTATE SDL_XInputSetState +#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities +#define INVALID_XINPUT_USERID 255 +#define SDL_XINPUT_MAX_DEVICES 4 + +#ifndef XINPUT_CAPS_FFB_SUPPORTED +#define XINPUT_CAPS_FFB_SUPPORTED 0x0001 +#endif + #define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */