Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
authorRyan C. Gordon <icculus@icculus.org>
Sun, 10 Mar 2013 13:28:39 -0400
changeset 6991ff49588e3ddb
parent 6990 2514368c2aaf
child 6992 e7c2c85bcf69
Attempt to get XInput haptics building on Cygwin (or rather, avoid building).
src/core/windows/SDL_windows.c
src/core/windows/SDL_windows.h
src/joystick/windows/SDL_dxjoystick.c
src/joystick/windows/SDL_dxjoystick_c.h
     1.1 --- a/src/core/windows/SDL_windows.c	Sun Mar 10 13:05:47 2013 -0400
     1.2 +++ b/src/core/windows/SDL_windows.c	Sun Mar 10 13:28:39 2013 -0400
     1.3 @@ -28,69 +28,6 @@
     1.4  
     1.5  #include <objbase.h>  /* for CoInitialize/CoUninitialize */
     1.6  
     1.7 -
     1.8 -XInputGetState_t SDL_XInputGetState = NULL;
     1.9 -XInputSetState_t SDL_XInputSetState = NULL;
    1.10 -XInputGetCapabilities_t SDL_XInputGetCapabilities = NULL;
    1.11 -DWORD SDL_XInputVersion = 0;
    1.12 -
    1.13 -static HANDLE s_pXInputDLL = 0;
    1.14 -static int s_XInputDLLRefCount = 0;
    1.15 -
    1.16 -int
    1.17 -WIN_LoadXInputDLL(void)
    1.18 -{
    1.19 -    DWORD version = 0;
    1.20 -
    1.21 -    if (s_pXInputDLL) {
    1.22 -        SDL_assert(s_XInputDLLRefCount > 0);
    1.23 -        s_XInputDLLRefCount++;
    1.24 -        return 0;  /* already loaded */
    1.25 -    }
    1.26 -
    1.27 -    version = (1 << 16) | 4;
    1.28 -    s_pXInputDLL = LoadLibrary( L"XInput1_4.dll" );  // 1.4 Ships with Windows 8.
    1.29 -    if (!s_pXInputDLL) {
    1.30 -        version = (1 << 16) | 3;
    1.31 -        s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" );  // 1.3 Ships with Vista and Win7, can be installed as a restributable component.
    1.32 -    }
    1.33 -    if (!s_pXInputDLL) {
    1.34 -        s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" );
    1.35 -    }
    1.36 -    if (!s_pXInputDLL) {
    1.37 -        return -1;
    1.38 -    }
    1.39 -
    1.40 -    SDL_assert(s_XInputDLLRefCount == 0);
    1.41 -    SDL_XInputVersion = version;
    1.42 -    s_XInputDLLRefCount = 1;
    1.43 -
    1.44 -    /* 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... */
    1.45 -    SDL_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 );
    1.46 -    SDL_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" );
    1.47 -    SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" );
    1.48 -    if ( !SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities ) {
    1.49 -        WIN_UnloadXInputDLL();
    1.50 -        return -1;
    1.51 -    }
    1.52 -
    1.53 -    return 0;
    1.54 -}
    1.55 -
    1.56 -void
    1.57 -WIN_UnloadXInputDLL(void)
    1.58 -{
    1.59 -    if ( s_pXInputDLL ) {
    1.60 -        SDL_assert(s_XInputDLLRefCount > 0);
    1.61 -        if (--s_XInputDLLRefCount == 0) {
    1.62 -            FreeLibrary( s_pXInputDLL );
    1.63 -            s_pXInputDLL = NULL;
    1.64 -        }
    1.65 -    } else {
    1.66 -        SDL_assert(s_XInputDLLRefCount == 0);
    1.67 -    }
    1.68 -}
    1.69 -
    1.70  /* Sets an error message based on GetLastError() */
    1.71  void
    1.72  WIN_SetError(const char *prefix)
     2.1 --- a/src/core/windows/SDL_windows.h	Sun Mar 10 13:05:47 2013 -0400
     2.2 +++ b/src/core/windows/SDL_windows.h	Sun Mar 10 13:28:39 2013 -0400
     2.3 @@ -33,7 +33,6 @@
     2.4  #define _WIN32_WINNT  0x501   /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input */
     2.5  
     2.6  #include <windows.h>
     2.7 -#include <xinput.h>
     2.8  
     2.9  /* Routines to convert from UTF8 to native Windows text */
    2.10  #if UNICODE
    2.11 @@ -51,64 +50,6 @@
    2.12  extern HRESULT WIN_CoInitialize(void);
    2.13  extern void WIN_CoUninitialize(void);
    2.14  
    2.15 -/* typedef's for XInput structs we use */
    2.16 -typedef struct
    2.17 -{
    2.18 -    WORD wButtons;
    2.19 -    BYTE bLeftTrigger;
    2.20 -    BYTE bRightTrigger;
    2.21 -    SHORT sThumbLX;
    2.22 -    SHORT sThumbLY;
    2.23 -    SHORT sThumbRX;
    2.24 -    SHORT sThumbRY;
    2.25 -    DWORD dwPaddingReserved;
    2.26 -} XINPUT_GAMEPAD_EX;
    2.27 -
    2.28 -typedef struct 
    2.29 -{
    2.30 -    DWORD dwPacketNumber;
    2.31 -    XINPUT_GAMEPAD_EX Gamepad;
    2.32 -} XINPUT_STATE_EX;
    2.33 -
    2.34 -
    2.35 -/* Forward decl's for XInput API's we load dynamically and use if available */
    2.36 -typedef DWORD (WINAPI *XInputGetState_t)
    2.37 -	(
    2.38 -	DWORD         dwUserIndex,  // [in] Index of the gamer associated with the device
    2.39 -	XINPUT_STATE_EX* pState        // [out] Receives the current state
    2.40 -	);
    2.41 -
    2.42 -typedef DWORD (WINAPI *XInputSetState_t)
    2.43 -	(
    2.44 -	DWORD             dwUserIndex,  // [in] Index of the gamer associated with the device
    2.45 -	XINPUT_VIBRATION* pVibration    // [in, out] The vibration information to send to the controller
    2.46 -	);
    2.47 -
    2.48 -typedef DWORD (WINAPI *XInputGetCapabilities_t)
    2.49 -	(
    2.50 -	DWORD                dwUserIndex,   // [in] Index of the gamer associated with the device
    2.51 -	DWORD                dwFlags,       // [in] Input flags that identify the device type
    2.52 -	XINPUT_CAPABILITIES* pCapabilities  // [out] Receives the capabilities
    2.53 -	);
    2.54 -
    2.55 -extern int WIN_LoadXInputDLL(void);
    2.56 -extern void WIN_UnloadXInputDLL(void);
    2.57 -
    2.58 -extern XInputGetState_t SDL_XInputGetState;
    2.59 -extern XInputSetState_t SDL_XInputSetState;
    2.60 -extern XInputGetCapabilities_t SDL_XInputGetCapabilities;
    2.61 -extern DWORD SDL_XInputVersion;  // ((major << 16) & 0xFF00) | (minor & 0xFF)
    2.62 -
    2.63 -#define XINPUTGETSTATE			SDL_XInputGetState
    2.64 -#define XINPUTSETSTATE			SDL_XInputSetState
    2.65 -#define XINPUTGETCAPABILITIES	SDL_XInputGetCapabilities
    2.66 -#define INVALID_XINPUT_USERID 255
    2.67 -#define SDL_XINPUT_MAX_DEVICES 4
    2.68 -
    2.69 -#ifndef XINPUT_CAPS_FFB_SUPPORTED
    2.70 -#define XINPUT_CAPS_FFB_SUPPORTED 0x0001
    2.71 -#endif
    2.72 -
    2.73  #endif /* _INCLUDED_WINDOWS_H */
    2.74  
    2.75  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Sun Mar 10 13:05:47 2013 -0400
     3.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Sun Mar 10 13:28:39 2013 -0400
     3.3 @@ -75,6 +75,69 @@
     3.4  static SDL_bool s_bJoystickThreadQuit = SDL_FALSE;
     3.5  static SDL_bool s_bXInputEnabled = SDL_TRUE;
     3.6  
     3.7 +XInputGetState_t SDL_XInputGetState = NULL;
     3.8 +XInputSetState_t SDL_XInputSetState = NULL;
     3.9 +XInputGetCapabilities_t SDL_XInputGetCapabilities = NULL;
    3.10 +DWORD SDL_XInputVersion = 0;
    3.11 +
    3.12 +static HANDLE s_pXInputDLL = 0;
    3.13 +static int s_XInputDLLRefCount = 0;
    3.14 +
    3.15 +int
    3.16 +WIN_LoadXInputDLL(void)
    3.17 +{
    3.18 +    DWORD version = 0;
    3.19 +
    3.20 +    if (s_pXInputDLL) {
    3.21 +        SDL_assert(s_XInputDLLRefCount > 0);
    3.22 +        s_XInputDLLRefCount++;
    3.23 +        return 0;  /* already loaded */
    3.24 +    }
    3.25 +
    3.26 +    version = (1 << 16) | 4;
    3.27 +    s_pXInputDLL = LoadLibrary( L"XInput1_4.dll" );  // 1.4 Ships with Windows 8.
    3.28 +    if (!s_pXInputDLL) {
    3.29 +        version = (1 << 16) | 3;
    3.30 +        s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" );  // 1.3 Ships with Vista and Win7, can be installed as a restributable component.
    3.31 +    }
    3.32 +    if (!s_pXInputDLL) {
    3.33 +        s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" );
    3.34 +    }
    3.35 +    if (!s_pXInputDLL) {
    3.36 +        return -1;
    3.37 +    }
    3.38 +
    3.39 +    SDL_assert(s_XInputDLLRefCount == 0);
    3.40 +    SDL_XInputVersion = version;
    3.41 +    s_XInputDLLRefCount = 1;
    3.42 +
    3.43 +    /* 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... */
    3.44 +    SDL_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 );
    3.45 +    SDL_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" );
    3.46 +    SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" );
    3.47 +    if ( !SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities ) {
    3.48 +        WIN_UnloadXInputDLL();
    3.49 +        return -1;
    3.50 +    }
    3.51 +
    3.52 +    return 0;
    3.53 +}
    3.54 +
    3.55 +void
    3.56 +WIN_UnloadXInputDLL(void)
    3.57 +{
    3.58 +    if ( s_pXInputDLL ) {
    3.59 +        SDL_assert(s_XInputDLLRefCount > 0);
    3.60 +        if (--s_XInputDLLRefCount == 0) {
    3.61 +            FreeLibrary( s_pXInputDLL );
    3.62 +            s_pXInputDLL = NULL;
    3.63 +        }
    3.64 +    } else {
    3.65 +        SDL_assert(s_XInputDLLRefCount == 0);
    3.66 +    }
    3.67 +}
    3.68 +
    3.69 +
    3.70  extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion,
    3.71                                         LPDIRECTINPUT * ppDI,
    3.72                                         LPUNKNOWN punkOuter);
     4.1 --- a/src/joystick/windows/SDL_dxjoystick_c.h	Sun Mar 10 13:05:47 2013 -0400
     4.2 +++ b/src/joystick/windows/SDL_dxjoystick_c.h	Sun Mar 10 13:28:39 2013 -0400
     4.3 @@ -42,6 +42,65 @@
     4.4  #include <xinput.h>
     4.5  #include <devguid.h>
     4.6  #include <dbt.h>
     4.7 +#include <xinput.h>
     4.8 +
     4.9 +/* typedef's for XInput structs we use */
    4.10 +typedef struct
    4.11 +{
    4.12 +    WORD wButtons;
    4.13 +    BYTE bLeftTrigger;
    4.14 +    BYTE bRightTrigger;
    4.15 +    SHORT sThumbLX;
    4.16 +    SHORT sThumbLY;
    4.17 +    SHORT sThumbRX;
    4.18 +    SHORT sThumbRY;
    4.19 +    DWORD dwPaddingReserved;
    4.20 +} XINPUT_GAMEPAD_EX;
    4.21 +
    4.22 +typedef struct 
    4.23 +{
    4.24 +    DWORD dwPacketNumber;
    4.25 +    XINPUT_GAMEPAD_EX Gamepad;
    4.26 +} XINPUT_STATE_EX;
    4.27 +
    4.28 +/* Forward decl's for XInput API's we load dynamically and use if available */
    4.29 +typedef DWORD (WINAPI *XInputGetState_t)
    4.30 +	(
    4.31 +	DWORD         dwUserIndex,  // [in] Index of the gamer associated with the device
    4.32 +	XINPUT_STATE_EX* pState        // [out] Receives the current state
    4.33 +	);
    4.34 +
    4.35 +typedef DWORD (WINAPI *XInputSetState_t)
    4.36 +	(
    4.37 +	DWORD             dwUserIndex,  // [in] Index of the gamer associated with the device
    4.38 +	XINPUT_VIBRATION* pVibration    // [in, out] The vibration information to send to the controller
    4.39 +	);
    4.40 +
    4.41 +typedef DWORD (WINAPI *XInputGetCapabilities_t)
    4.42 +	(
    4.43 +	DWORD                dwUserIndex,   // [in] Index of the gamer associated with the device
    4.44 +	DWORD                dwFlags,       // [in] Input flags that identify the device type
    4.45 +	XINPUT_CAPABILITIES* pCapabilities  // [out] Receives the capabilities
    4.46 +	);
    4.47 +
    4.48 +extern int WIN_LoadXInputDLL(void);
    4.49 +extern void WIN_UnloadXInputDLL(void);
    4.50 +
    4.51 +extern XInputGetState_t SDL_XInputGetState;
    4.52 +extern XInputSetState_t SDL_XInputSetState;
    4.53 +extern XInputGetCapabilities_t SDL_XInputGetCapabilities;
    4.54 +extern DWORD SDL_XInputVersion;  // ((major << 16) & 0xFF00) | (minor & 0xFF)
    4.55 +
    4.56 +#define XINPUTGETSTATE			SDL_XInputGetState
    4.57 +#define XINPUTSETSTATE			SDL_XInputSetState
    4.58 +#define XINPUTGETCAPABILITIES	SDL_XInputGetCapabilities
    4.59 +#define INVALID_XINPUT_USERID 255
    4.60 +#define SDL_XINPUT_MAX_DEVICES 4
    4.61 +
    4.62 +#ifndef XINPUT_CAPS_FFB_SUPPORTED
    4.63 +#define XINPUT_CAPS_FFB_SUPPORTED 0x0001
    4.64 +#endif
    4.65 +
    4.66  
    4.67  #define MAX_INPUTS	256     /* each joystick can have up to 256 inputs */
    4.68