Split acinclude.m4 into its component parts for easy updating
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402532
This commit is contained in:
parent
01b58163f3
commit
cfcb0787d2
1 changed files with 381 additions and 309 deletions
|
@ -44,33 +44,61 @@
|
||||||
|
|
||||||
#define DIRECTINPUT_VERSION 0x0500
|
#define DIRECTINPUT_VERSION 0x0500
|
||||||
#include <dinput.h>
|
#include <dinput.h>
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
/* Used for the c_dfDIJoystick2 symbol (no imports are used) */
|
||||||
|
# pragma comment (lib, "dinput.lib")
|
||||||
|
#endif
|
||||||
|
#include <dxerr9.h> /* From DirectX SDK 9c */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# pragma comment (lib, "dxerr9.lib")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* an ISO hack for VisualC++ */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define snprintf _snprintf
|
||||||
|
#endif
|
||||||
|
|
||||||
#define INPUT_QSIZE 32 /* Buffer up to 32 input messages */
|
#define INPUT_QSIZE 32 /* Buffer up to 32 input messages */
|
||||||
|
|
||||||
extern HINSTANCE SDL_Instance;
|
|
||||||
extern int DX5_Load();
|
|
||||||
extern void DX5_Unload();
|
|
||||||
extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion,
|
|
||||||
LPDIRECTINPUT * ppDI,
|
|
||||||
LPUNKNOWN punkOuter);
|
|
||||||
|
|
||||||
static LPDIRECTINPUT dinput = NULL;
|
|
||||||
|
|
||||||
#define MAX_JOYSTICKS 8
|
#define MAX_JOYSTICKS 8
|
||||||
#define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */
|
#define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */
|
||||||
#define AXIS_MIN -32768 /* minimum value for axis coordinate */
|
#define AXIS_MIN -32768 /* minimum value for axis coordinate */
|
||||||
#define AXIS_MAX 32767 /* maximum value for axis coordinate */
|
#define AXIS_MAX 32767 /* maximum value for axis coordinate */
|
||||||
#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/100) /* 1% motion */
|
#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/100) /* 1% motion */
|
||||||
|
|
||||||
|
/* external variables referenced. */
|
||||||
|
extern HINSTANCE SDL_Instance;
|
||||||
|
extern HWND SDL_Window;
|
||||||
|
|
||||||
|
|
||||||
|
/* local variables */
|
||||||
|
static LPDIRECTINPUT dinput = NULL;
|
||||||
|
extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion,
|
||||||
|
LPDIRECTINPUT * ppDI,
|
||||||
|
LPUNKNOWN punkOuter);
|
||||||
|
static DIDEVICEINSTANCE SYS_Joystick[MAX_JOYSTICKS]; /* array to hold joystick ID values */
|
||||||
|
static int SYS_NumJoysticks;
|
||||||
|
static HINSTANCE DInputDLL = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
/* local prototypes */
|
||||||
|
static void SetDIerror(const char *function, HRESULT code);
|
||||||
|
static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE *
|
||||||
|
pdidInstance, VOID * pContext);
|
||||||
|
static BOOL CALLBACK EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev,
|
||||||
|
LPVOID pvRef);
|
||||||
|
static Uint8 TranslatePOV(DWORD value);
|
||||||
|
static int SDL_PrivateJoystickAxis_Int(SDL_Joystick * joystick, Uint8 axis,
|
||||||
|
Sint16 value);
|
||||||
|
static int SDL_PrivateJoystickHat_Int(SDL_Joystick * joystick, Uint8 hat,
|
||||||
|
Uint8 value);
|
||||||
|
static int SDL_PrivateJoystickButton_Int(SDL_Joystick * joystick,
|
||||||
|
Uint8 button, Uint8 state);
|
||||||
|
|
||||||
|
|
||||||
|
/* local types */
|
||||||
typedef enum Type
|
typedef enum Type
|
||||||
{ BUTTON, AXIS, HAT } Type;
|
{ BUTTON, AXIS, HAT } Type;
|
||||||
|
|
||||||
/* array to hold joystick ID values */
|
|
||||||
static DIDEVICEINSTANCE SYS_Joystick[MAX_JOYSTICKS];
|
|
||||||
static int SYS_NumJoysticks;
|
|
||||||
|
|
||||||
extern HWND SDL_Window;
|
|
||||||
|
|
||||||
typedef struct input_t
|
typedef struct input_t
|
||||||
{
|
{
|
||||||
/* DirectInput offset for this input type: */
|
/* DirectInput offset for this input type: */
|
||||||
|
@ -87,6 +115,7 @@ typedef struct input_t
|
||||||
struct joystick_hwdata
|
struct joystick_hwdata
|
||||||
{
|
{
|
||||||
LPDIRECTINPUTDEVICE2 InputDevice;
|
LPDIRECTINPUTDEVICE2 InputDevice;
|
||||||
|
DIDEVCAPS Capabilities;
|
||||||
int buffered;
|
int buffered;
|
||||||
|
|
||||||
input_t Inputs[MAX_INPUTS];
|
input_t Inputs[MAX_INPUTS];
|
||||||
|
@ -95,123 +124,13 @@ struct joystick_hwdata
|
||||||
|
|
||||||
/* Convert a DirectInput return code to a text message */
|
/* Convert a DirectInput return code to a text message */
|
||||||
static void
|
static void
|
||||||
SetDIerror(char *function, int code)
|
SetDIerror(const char *function, HRESULT code)
|
||||||
{
|
{
|
||||||
static char *error;
|
SDL_SetError("%s() [%s]: %s", function,
|
||||||
static char errbuf[1024];
|
DXGetErrorString9(code), DXGetErrorDescription9(code));
|
||||||
|
|
||||||
errbuf[0] = 0;
|
|
||||||
switch (code) {
|
|
||||||
case DIERR_GENERIC:
|
|
||||||
error = "Undefined error!";
|
|
||||||
break;
|
|
||||||
case DIERR_OLDDIRECTINPUTVERSION:
|
|
||||||
error = "Your version of DirectInput needs upgrading";
|
|
||||||
break;
|
|
||||||
case DIERR_INVALIDPARAM:
|
|
||||||
error = "Invalid parameters";
|
|
||||||
break;
|
|
||||||
case DIERR_OUTOFMEMORY:
|
|
||||||
error = "Out of memory";
|
|
||||||
break;
|
|
||||||
case DIERR_DEVICENOTREG:
|
|
||||||
error = "Device not registered";
|
|
||||||
break;
|
|
||||||
case DIERR_NOINTERFACE:
|
|
||||||
error = "Interface not supported";
|
|
||||||
break;
|
|
||||||
case DIERR_NOTINITIALIZED:
|
|
||||||
error = "Device not initialized";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
sprintf(errbuf, "%s: Unknown DirectInput error: 0x%x",
|
|
||||||
function, code);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!errbuf[0]) {
|
|
||||||
sprintf(errbuf, "%s: %s", function, error);
|
|
||||||
}
|
|
||||||
SDL_SetError("%s", errbuf);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOL CALLBACK
|
|
||||||
EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
|
|
||||||
{
|
|
||||||
memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance,
|
|
||||||
sizeof(DIDEVICEINSTANCE));
|
|
||||||
SYS_NumJoysticks++;
|
|
||||||
|
|
||||||
if (SYS_NumJoysticks >= MAX_JOYSTICKS)
|
|
||||||
return DIENUM_STOP;
|
|
||||||
|
|
||||||
return DIENUM_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL CALLBACK
|
|
||||||
DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
|
|
||||||
{
|
|
||||||
SDL_Joystick *joystick = (SDL_Joystick *) pvRef;
|
|
||||||
HRESULT result;
|
|
||||||
input_t *in = &joystick->hwdata->Inputs[joystick->hwdata->NumInputs];
|
|
||||||
const int SupportedMask = DIDFT_BUTTON | DIDFT_POV | DIDFT_AXIS;
|
|
||||||
if (!(dev->dwType & SupportedMask))
|
|
||||||
return DIENUM_CONTINUE; /* unsupported */
|
|
||||||
|
|
||||||
in->ofs = dev->dwOfs;
|
|
||||||
|
|
||||||
if (dev->dwType & DIDFT_BUTTON) {
|
|
||||||
in->type = BUTTON;
|
|
||||||
in->num = joystick->nbuttons;
|
|
||||||
joystick->nbuttons++;
|
|
||||||
} else if (dev->dwType & DIDFT_POV) {
|
|
||||||
in->type = HAT;
|
|
||||||
in->num = joystick->nhats;
|
|
||||||
joystick->nhats++;
|
|
||||||
} else { /* dev->dwType & DIDFT_AXIS */
|
|
||||||
DIPROPRANGE diprg;
|
|
||||||
DIPROPDWORD dilong;
|
|
||||||
|
|
||||||
in->type = AXIS;
|
|
||||||
in->num = joystick->naxes;
|
|
||||||
|
|
||||||
diprg.diph.dwSize = sizeof(diprg);
|
|
||||||
diprg.diph.dwHeaderSize = sizeof(diprg.diph);
|
|
||||||
diprg.diph.dwObj = dev->dwOfs;
|
|
||||||
diprg.diph.dwHow = DIPH_BYOFFSET;
|
|
||||||
diprg.lMin = AXIS_MIN;
|
|
||||||
diprg.lMax = AXIS_MAX;
|
|
||||||
|
|
||||||
result =
|
|
||||||
IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
|
|
||||||
DIPROP_RANGE, &diprg.diph);
|
|
||||||
if (result != DI_OK)
|
|
||||||
return DIENUM_CONTINUE; /* don't use this axis */
|
|
||||||
|
|
||||||
/* Set dead zone to 0. */
|
|
||||||
dilong.diph.dwSize = sizeof(dilong);
|
|
||||||
dilong.diph.dwHeaderSize = sizeof(dilong.diph);
|
|
||||||
dilong.diph.dwObj = dev->dwOfs;
|
|
||||||
dilong.diph.dwHow = DIPH_BYOFFSET;
|
|
||||||
dilong.dwData = 0;
|
|
||||||
result =
|
|
||||||
IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
|
|
||||||
DIPROP_DEADZONE, &dilong.diph);
|
|
||||||
if (result != DI_OK)
|
|
||||||
return DIENUM_CONTINUE; /* don't use this axis */
|
|
||||||
|
|
||||||
joystick->naxes++;
|
|
||||||
}
|
|
||||||
|
|
||||||
joystick->hwdata->NumInputs++;
|
|
||||||
|
|
||||||
if (joystick->hwdata->NumInputs == MAX_INPUTS)
|
|
||||||
return DIENUM_STOP; /* too many */
|
|
||||||
|
|
||||||
return DIENUM_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Function to scan the system for joysticks.
|
/* Function to scan the system for joysticks.
|
||||||
* This function should set SDL_numjoysticks to the number of available
|
* This function should set SDL_numjoysticks to the number of available
|
||||||
* joysticks. Joystick 0 should be the system default joystick.
|
* joysticks. Joystick 0 should be the system default joystick.
|
||||||
|
@ -224,18 +143,30 @@ SDL_SYS_JoystickInit(void)
|
||||||
|
|
||||||
SYS_NumJoysticks = 0;
|
SYS_NumJoysticks = 0;
|
||||||
|
|
||||||
/* Create the DirectInput object */
|
result = CoInitialize(NULL);
|
||||||
if (DX5_Load() < 0) {
|
if (FAILED(result)) {
|
||||||
SDL_SetError("Couldn't load DirectInput");
|
SetDIerror("CoInitialize", result);
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
result = DInputCreate(SDL_Instance, DIRECTINPUT_VERSION, &dinput, NULL);
|
|
||||||
if (result != DI_OK) {
|
|
||||||
DX5_Unload();
|
|
||||||
SetDIerror("DirectInputCreate", result);
|
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER,
|
||||||
|
&IID_IDirectInput, &dinput);
|
||||||
|
|
||||||
|
if (FAILED(result)) {
|
||||||
|
SetDIerror("CoCreateInstance", result);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Because we used CoCreateInstance, we need to Initialize it, first. */
|
||||||
|
result =
|
||||||
|
IDirectInput_Initialize(dinput, SDL_Instance, DIRECTINPUT_VERSION);
|
||||||
|
|
||||||
|
if (FAILED(result)) {
|
||||||
|
SetDIerror("IDirectInput::Initialize", result);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Look for joysticks, wheels, head trackers, gamepads, etc.. */
|
||||||
result = IDirectInput_EnumDevices(dinput,
|
result = IDirectInput_EnumDevices(dinput,
|
||||||
DIDEVTYPE_JOYSTICK,
|
DIDEVTYPE_JOYSTICK,
|
||||||
EnumJoysticksCallback,
|
EnumJoysticksCallback,
|
||||||
|
@ -244,6 +175,19 @@ SDL_SYS_JoystickInit(void)
|
||||||
return SYS_NumJoysticks;
|
return SYS_NumJoysticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL CALLBACK
|
||||||
|
EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
|
||||||
|
{
|
||||||
|
memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance,
|
||||||
|
sizeof(DIDEVICEINSTANCE));
|
||||||
|
SYS_NumJoysticks++;
|
||||||
|
|
||||||
|
if (SYS_NumJoysticks >= MAX_JOYSTICKS)
|
||||||
|
return DIENUM_STOP;
|
||||||
|
|
||||||
|
return DIENUM_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Function to get the device-dependent name of a joystick */
|
/* Function to get the device-dependent name of a joystick */
|
||||||
const char *
|
const char *
|
||||||
SDL_SYS_JoystickName(int index)
|
SDL_SYS_JoystickName(int index)
|
||||||
|
@ -262,84 +206,354 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
|
||||||
{
|
{
|
||||||
HRESULT result;
|
HRESULT result;
|
||||||
LPDIRECTINPUTDEVICE device;
|
LPDIRECTINPUTDEVICE device;
|
||||||
|
DIPROPDWORD dipdw;
|
||||||
|
|
||||||
|
ZeroMemory(&dipdw, sizeof(DIPROPDWORD));
|
||||||
|
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
|
||||||
|
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||||
|
|
||||||
|
|
||||||
/* allocate memory for system specific hardware data */
|
/* allocate memory for system specific hardware data */
|
||||||
joystick->hwdata =
|
joystick->hwdata =
|
||||||
(struct joystick_hwdata *) malloc(sizeof(*joystick->hwdata));
|
(struct joystick_hwdata *) malloc(sizeof(struct joystick_hwdata));
|
||||||
if (joystick->hwdata == NULL) {
|
if (joystick->hwdata == NULL) {
|
||||||
SDL_OutOfMemory();
|
SDL_OutOfMemory();
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
|
ZeroMemory(joystick->hwdata, sizeof(struct joystick_hwdata));
|
||||||
joystick->hwdata->buffered = 1;
|
joystick->hwdata->buffered = 1;
|
||||||
|
joystick->hwdata->Capabilities.dwSize = sizeof(DIDEVCAPS);
|
||||||
|
|
||||||
result =
|
result =
|
||||||
IDirectInput_CreateDevice(dinput,
|
IDirectInput_CreateDevice(dinput,
|
||||||
&SYS_Joystick[joystick->index].
|
&SYS_Joystick[joystick->index].
|
||||||
guidInstance, &device, NULL);
|
guidInstance, &device, NULL);
|
||||||
if (result != DI_OK) {
|
if (FAILED(result)) {
|
||||||
SetDIerror("DirectInput::CreateDevice", result);
|
SetDIerror("IDirectInput::CreateDevice", result);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Now get the IDirectInputDevice2 interface, instead. */
|
||||||
result = IDirectInputDevice_QueryInterface(device,
|
result = IDirectInputDevice_QueryInterface(device,
|
||||||
&IID_IDirectInputDevice2,
|
&IID_IDirectInputDevice2,
|
||||||
(LPVOID *) & joystick->
|
(LPVOID *) & joystick->
|
||||||
hwdata->InputDevice);
|
hwdata->InputDevice);
|
||||||
|
/* We are done with this object. Use the stored one from now on. */
|
||||||
IDirectInputDevice_Release(device);
|
IDirectInputDevice_Release(device);
|
||||||
if (result != DI_OK) {
|
|
||||||
SetDIerror("DirectInputDevice::QueryInterface", result);
|
if (FAILED(result)) {
|
||||||
|
SetDIerror("IDirectInputDevice::QueryInterface", result);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Aquire shared access. Exclusive access is required for forces,
|
||||||
|
* though. */
|
||||||
result =
|
result =
|
||||||
IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata->
|
IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata->
|
||||||
InputDevice, SDL_Window,
|
InputDevice, SDL_Window,
|
||||||
DISCL_NONEXCLUSIVE |
|
DISCL_EXCLUSIVE |
|
||||||
DISCL_BACKGROUND);
|
DISCL_BACKGROUND);
|
||||||
if (result != DI_OK) {
|
if (FAILED(result)) {
|
||||||
SetDIerror("DirectInputDevice::SetCooperativeLevel", result);
|
SetDIerror("IDirectInputDevice2::SetCooperativeLevel", result);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Use the extended data structure: DIJOYSTATE2. */
|
||||||
result =
|
result =
|
||||||
IDirectInputDevice2_SetDataFormat(joystick->hwdata->InputDevice,
|
IDirectInputDevice2_SetDataFormat(joystick->hwdata->InputDevice,
|
||||||
&c_dfDIJoystick);
|
&c_dfDIJoystick2);
|
||||||
if (result != DI_OK) {
|
if (FAILED(result)) {
|
||||||
SetDIerror("DirectInputDevice::SetDataFormat", result);
|
SetDIerror("IDirectInputDevice2::SetDataFormat", result);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
IDirectInputDevice2_EnumObjects(joystick->hwdata->InputDevice,
|
/* Get device capabilities */
|
||||||
DIJoystick_EnumDevObjectsProc,
|
result =
|
||||||
joystick,
|
IDirectInputDevice2_GetCapabilities(joystick->hwdata->InputDevice,
|
||||||
DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV);
|
&joystick->hwdata->Capabilities);
|
||||||
|
|
||||||
{
|
if (FAILED(result)) {
|
||||||
DIPROPDWORD dipdw;
|
SetDIerror("IDirectInputDevice2::GetCapabilities", result);
|
||||||
memset(&dipdw, 0, sizeof(dipdw));
|
return (-1);
|
||||||
dipdw.diph.dwSize = sizeof(dipdw);
|
}
|
||||||
dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
|
|
||||||
|
/* Force capable? */
|
||||||
|
if (joystick->hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) {
|
||||||
|
|
||||||
|
result = IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
|
||||||
|
|
||||||
|
if (FAILED(result)) {
|
||||||
|
SetDIerror("IDirectInputDevice2::Acquire", result);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* reset all accuators. */
|
||||||
|
result =
|
||||||
|
IDirectInputDevice2_SendForceFeedbackCommand(joystick->hwdata->
|
||||||
|
InputDevice,
|
||||||
|
DISFFC_RESET);
|
||||||
|
|
||||||
|
if (FAILED(result)) {
|
||||||
|
SetDIerror("IDirectInputDevice2::SendForceFeedbackCommand",
|
||||||
|
result);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = IDirectInputDevice2_Unacquire(joystick->hwdata->InputDevice);
|
||||||
|
|
||||||
|
if (FAILED(result)) {
|
||||||
|
SetDIerror("IDirectInputDevice2::Unacquire", result);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Turn on auto-centering for a ForceFeedback device (until told
|
||||||
|
* otherwise). */
|
||||||
dipdw.diph.dwObj = 0;
|
dipdw.diph.dwObj = 0;
|
||||||
dipdw.diph.dwHow = DIPH_DEVICE;
|
dipdw.diph.dwHow = DIPH_DEVICE;
|
||||||
dipdw.dwData = INPUT_QSIZE;
|
dipdw.dwData = DIPROPAUTOCENTER_ON;
|
||||||
|
|
||||||
result =
|
result =
|
||||||
IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
|
IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
|
||||||
DIPROP_BUFFERSIZE, &dipdw.diph);
|
DIPROP_AUTOCENTER, &dipdw.diph);
|
||||||
|
|
||||||
if (result == DI_POLLEDDEVICE) {
|
if (FAILED(result)) {
|
||||||
/* This device doesn't support buffering, so we're forced
|
SetDIerror("IDirectInputDevice2::SetProperty", result);
|
||||||
* to use less reliable polling. */
|
|
||||||
joystick->hwdata->buffered = 0;
|
|
||||||
} else if (result != DI_OK) {
|
|
||||||
SetDIerror("DirectInputDevice::SetProperty", result);
|
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* What buttons and axes does it have? */
|
||||||
|
IDirectInputDevice2_EnumObjects(joystick->hwdata->InputDevice,
|
||||||
|
EnumDevObjectsCallback, joystick,
|
||||||
|
DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV);
|
||||||
|
|
||||||
|
dipdw.diph.dwObj = 0;
|
||||||
|
dipdw.diph.dwHow = DIPH_DEVICE;
|
||||||
|
dipdw.dwData = INPUT_QSIZE;
|
||||||
|
|
||||||
|
/* Set the buffer size */
|
||||||
|
result =
|
||||||
|
IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
|
||||||
|
DIPROP_BUFFERSIZE, &dipdw.diph);
|
||||||
|
|
||||||
|
if (result == DI_POLLEDDEVICE) {
|
||||||
|
/* This device doesn't support buffering, so we're forced
|
||||||
|
* to use less reliable polling. */
|
||||||
|
joystick->hwdata->buffered = 0;
|
||||||
|
} else if (FAILED(result)) {
|
||||||
|
SetDIerror("IDirectInputDevice2::SetProperty", result);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL CALLBACK
|
||||||
|
EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
|
||||||
|
{
|
||||||
|
SDL_Joystick *joystick = (SDL_Joystick *) pvRef;
|
||||||
|
HRESULT result;
|
||||||
|
input_t *in = &joystick->hwdata->Inputs[joystick->hwdata->NumInputs];
|
||||||
|
|
||||||
|
in->ofs = dev->dwOfs;
|
||||||
|
|
||||||
|
if (dev->dwType & DIDFT_BUTTON) {
|
||||||
|
in->type = BUTTON;
|
||||||
|
in->num = joystick->nbuttons;
|
||||||
|
joystick->nbuttons++;
|
||||||
|
} else if (dev->dwType & DIDFT_POV) {
|
||||||
|
in->type = HAT;
|
||||||
|
in->num = joystick->nhats;
|
||||||
|
joystick->nhats++;
|
||||||
|
} else if (dev->dwType & DIDFT_AXIS) {
|
||||||
|
DIPROPRANGE diprg;
|
||||||
|
DIPROPDWORD dilong;
|
||||||
|
|
||||||
|
in->type = AXIS;
|
||||||
|
in->num = joystick->naxes;
|
||||||
|
|
||||||
|
diprg.diph.dwSize = sizeof(diprg);
|
||||||
|
diprg.diph.dwHeaderSize = sizeof(diprg.diph);
|
||||||
|
diprg.diph.dwObj = dev->dwOfs;
|
||||||
|
diprg.diph.dwHow = DIPH_BYOFFSET;
|
||||||
|
diprg.lMin = AXIS_MIN;
|
||||||
|
diprg.lMax = AXIS_MAX;
|
||||||
|
|
||||||
|
result =
|
||||||
|
IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
|
||||||
|
DIPROP_RANGE, &diprg.diph);
|
||||||
|
if (FAILED(result)) {
|
||||||
|
return DIENUM_CONTINUE; /* don't use this axis */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set dead zone to 0. */
|
||||||
|
dilong.diph.dwSize = sizeof(dilong);
|
||||||
|
dilong.diph.dwHeaderSize = sizeof(dilong.diph);
|
||||||
|
dilong.diph.dwObj = dev->dwOfs;
|
||||||
|
dilong.diph.dwHow = DIPH_BYOFFSET;
|
||||||
|
dilong.dwData = 0;
|
||||||
|
result =
|
||||||
|
IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
|
||||||
|
DIPROP_DEADZONE, &dilong.diph);
|
||||||
|
if (FAILED(result)) {
|
||||||
|
return DIENUM_CONTINUE; /* don't use this axis */
|
||||||
|
}
|
||||||
|
|
||||||
|
joystick->naxes++;
|
||||||
|
} else {
|
||||||
|
/* not supported at this time */
|
||||||
|
return DIENUM_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
joystick->hwdata->NumInputs++;
|
||||||
|
|
||||||
|
if (joystick->hwdata->NumInputs == MAX_INPUTS) {
|
||||||
|
return DIENUM_STOP; /* too many */
|
||||||
|
}
|
||||||
|
|
||||||
|
return DIENUM_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Function to update the state of a joystick - called as a device poll.
|
||||||
|
* This function shouldn't update the joystick structure directly,
|
||||||
|
* but instead should call SDL_PrivateJoystick*() to deliver events
|
||||||
|
* and update joystick device state.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
SDL_SYS_JoystickUpdate_Polled(SDL_Joystick * joystick)
|
||||||
|
{
|
||||||
|
DIJOYSTATE2 state;
|
||||||
|
HRESULT result;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
result =
|
||||||
|
IDirectInputDevice2_GetDeviceState(joystick->hwdata->InputDevice,
|
||||||
|
sizeof(DIJOYSTATE2), &state);
|
||||||
|
if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
|
||||||
|
IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
|
||||||
|
result =
|
||||||
|
IDirectInputDevice2_GetDeviceState(joystick->hwdata->InputDevice,
|
||||||
|
sizeof(DIJOYSTATE2), &state);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set each known axis, button and POV. */
|
||||||
|
for (i = 0; i < joystick->hwdata->NumInputs; ++i) {
|
||||||
|
const input_t *in = &joystick->hwdata->Inputs[i];
|
||||||
|
|
||||||
|
switch (in->type) {
|
||||||
|
case AXIS:
|
||||||
|
switch (in->ofs) {
|
||||||
|
case DIJOFS_X:
|
||||||
|
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
||||||
|
(Sint16) state.lX);
|
||||||
|
break;
|
||||||
|
case DIJOFS_Y:
|
||||||
|
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
||||||
|
(Sint16) state.lY);
|
||||||
|
break;
|
||||||
|
case DIJOFS_Z:
|
||||||
|
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
||||||
|
(Sint16) state.lZ);
|
||||||
|
break;
|
||||||
|
case DIJOFS_RX:
|
||||||
|
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
||||||
|
(Sint16) state.lRx);
|
||||||
|
break;
|
||||||
|
case DIJOFS_RY:
|
||||||
|
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
||||||
|
(Sint16) state.lRy);
|
||||||
|
break;
|
||||||
|
case DIJOFS_RZ:
|
||||||
|
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
||||||
|
(Sint16) state.lRz);
|
||||||
|
break;
|
||||||
|
case DIJOFS_SLIDER(0):
|
||||||
|
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
||||||
|
(Sint16) state.rglSlider[0]);
|
||||||
|
break;
|
||||||
|
case DIJOFS_SLIDER(1):
|
||||||
|
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
||||||
|
(Sint16) state.rglSlider[1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BUTTON:
|
||||||
|
SDL_PrivateJoystickButton_Int(joystick, in->num,
|
||||||
|
(Uint8) (state.
|
||||||
|
rgbButtons[in->ofs -
|
||||||
|
DIJOFS_BUTTON0]
|
||||||
|
? SDL_PRESSED :
|
||||||
|
SDL_RELEASED));
|
||||||
|
break;
|
||||||
|
case HAT:
|
||||||
|
{
|
||||||
|
Uint8 pos = TranslatePOV(state.rgdwPOV[in->ofs -
|
||||||
|
DIJOFS_POV(0)]);
|
||||||
|
SDL_PrivateJoystickHat_Int(joystick, in->num, pos);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SDL_SYS_JoystickUpdate_Buffered(SDL_Joystick * joystick)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
HRESULT result;
|
||||||
|
DWORD numevents;
|
||||||
|
DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE];
|
||||||
|
|
||||||
|
numevents = INPUT_QSIZE;
|
||||||
|
result =
|
||||||
|
IDirectInputDevice2_GetDeviceData(joystick->hwdata->InputDevice,
|
||||||
|
sizeof(DIDEVICEOBJECTDATA), evtbuf,
|
||||||
|
&numevents, 0);
|
||||||
|
if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
|
||||||
|
IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
|
||||||
|
result =
|
||||||
|
IDirectInputDevice2_GetDeviceData(joystick->hwdata->InputDevice,
|
||||||
|
sizeof(DIDEVICEOBJECTDATA),
|
||||||
|
evtbuf, &numevents, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Handle the events or punt */
|
||||||
|
if (FAILED(result))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i = 0; i < (int) numevents; ++i) {
|
||||||
|
int j;
|
||||||
|
|
||||||
|
for (j = 0; j < joystick->hwdata->NumInputs; ++j) {
|
||||||
|
const input_t *in = &joystick->hwdata->Inputs[j];
|
||||||
|
|
||||||
|
if (evtbuf[i].dwOfs != in->ofs)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
switch (in->type) {
|
||||||
|
case AXIS:
|
||||||
|
SDL_PrivateJoystickAxis(joystick, in->num,
|
||||||
|
(Sint16) evtbuf[i].dwData);
|
||||||
|
break;
|
||||||
|
case BUTTON:
|
||||||
|
SDL_PrivateJoystickButton(joystick, in->num,
|
||||||
|
(Uint8) (evtbuf[i].
|
||||||
|
dwData ? SDL_PRESSED :
|
||||||
|
SDL_RELEASED));
|
||||||
|
break;
|
||||||
|
case HAT:
|
||||||
|
{
|
||||||
|
Uint8 pos = TranslatePOV(evtbuf[i].dwData);
|
||||||
|
SDL_PrivateJoystickHat(joystick, in->num, pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static Uint8
|
static Uint8
|
||||||
TranslatePOV(DWORD value)
|
TranslatePOV(DWORD value)
|
||||||
{
|
{
|
||||||
|
@ -395,147 +609,6 @@ SDL_PrivateJoystickButton_Int(SDL_Joystick * joystick, Uint8 button,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Function to update the state of a joystick - called as a device poll.
|
|
||||||
* This function shouldn't update the joystick structure directly,
|
|
||||||
* but instead should call SDL_PrivateJoystick*() to deliver events
|
|
||||||
* and update joystick device state.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
SDL_SYS_JoystickUpdate_Polled(SDL_Joystick * joystick)
|
|
||||||
{
|
|
||||||
DIJOYSTATE state;
|
|
||||||
HRESULT result;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
result =
|
|
||||||
IDirectInputDevice2_GetDeviceState(joystick->hwdata->InputDevice,
|
|
||||||
sizeof(state), &state);
|
|
||||||
if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
|
|
||||||
IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
|
|
||||||
result =
|
|
||||||
IDirectInputDevice2_GetDeviceState(joystick->hwdata->
|
|
||||||
InputDevice, sizeof(state),
|
|
||||||
&state);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set each known axis, button and POV. */
|
|
||||||
for (i = 0; i < joystick->hwdata->NumInputs; ++i) {
|
|
||||||
const input_t *in = &joystick->hwdata->Inputs[i];
|
|
||||||
|
|
||||||
switch (in->type) {
|
|
||||||
case AXIS:
|
|
||||||
switch (in->ofs) {
|
|
||||||
case DIJOFS_X:
|
|
||||||
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
|
||||||
(Sint16) state.lX);
|
|
||||||
break;
|
|
||||||
case DIJOFS_Y:
|
|
||||||
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
|
||||||
(Sint16) state.lY);
|
|
||||||
break;
|
|
||||||
case DIJOFS_Z:
|
|
||||||
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
|
||||||
(Sint16) state.lZ);
|
|
||||||
break;
|
|
||||||
case DIJOFS_RX:
|
|
||||||
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
|
||||||
(Sint16) state.lRx);
|
|
||||||
break;
|
|
||||||
case DIJOFS_RY:
|
|
||||||
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
|
||||||
(Sint16) state.lRy);
|
|
||||||
break;
|
|
||||||
case DIJOFS_RZ:
|
|
||||||
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
|
||||||
(Sint16) state.lRz);
|
|
||||||
break;
|
|
||||||
case DIJOFS_SLIDER(0):
|
|
||||||
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
|
||||||
(Sint16) state.rglSlider[0]);
|
|
||||||
break;
|
|
||||||
case DIJOFS_SLIDER(1):
|
|
||||||
SDL_PrivateJoystickAxis_Int(joystick, in->num,
|
|
||||||
(Sint16) state.rglSlider[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BUTTON:
|
|
||||||
SDL_PrivateJoystickButton_Int(joystick, in->num,
|
|
||||||
(Uint8) (state.
|
|
||||||
rgbButtons[in->ofs -
|
|
||||||
DIJOFS_BUTTON0]
|
|
||||||
? SDL_PRESSED :
|
|
||||||
SDL_RELEASED));
|
|
||||||
break;
|
|
||||||
case HAT:
|
|
||||||
{
|
|
||||||
Uint8 pos =
|
|
||||||
TranslatePOV(state.rgdwPOV[in->ofs - DIJOFS_POV(0)]);
|
|
||||||
SDL_PrivateJoystickHat_Int(joystick, in->num, pos);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
SDL_SYS_JoystickUpdate_Buffered(SDL_Joystick * joystick)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
HRESULT result;
|
|
||||||
DWORD numevents;
|
|
||||||
DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE];
|
|
||||||
|
|
||||||
numevents = INPUT_QSIZE;
|
|
||||||
result =
|
|
||||||
IDirectInputDevice2_GetDeviceData(joystick->hwdata->InputDevice,
|
|
||||||
sizeof(DIDEVICEOBJECTDATA),
|
|
||||||
evtbuf, &numevents, 0);
|
|
||||||
if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
|
|
||||||
IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
|
|
||||||
result =
|
|
||||||
IDirectInputDevice2_GetDeviceData(joystick->hwdata->
|
|
||||||
InputDevice,
|
|
||||||
sizeof(DIDEVICEOBJECTDATA),
|
|
||||||
evtbuf, &numevents, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Handle the events */
|
|
||||||
if (result != DI_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (i = 0; i < (int) numevents; ++i) {
|
|
||||||
int j;
|
|
||||||
|
|
||||||
for (j = 0; j < joystick->hwdata->NumInputs; ++j) {
|
|
||||||
const input_t *in = &joystick->hwdata->Inputs[j];
|
|
||||||
|
|
||||||
if (evtbuf[i].dwOfs != in->ofs)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
switch (in->type) {
|
|
||||||
case AXIS:
|
|
||||||
SDL_PrivateJoystickAxis(joystick, in->num,
|
|
||||||
(Sint16) evtbuf[i].dwData);
|
|
||||||
break;
|
|
||||||
case BUTTON:
|
|
||||||
SDL_PrivateJoystickButton(joystick, in->num,
|
|
||||||
(Uint8) (evtbuf[i].
|
|
||||||
dwData ? SDL_PRESSED
|
|
||||||
: SDL_RELEASED));
|
|
||||||
break;
|
|
||||||
case HAT:
|
|
||||||
{
|
|
||||||
Uint8 pos = TranslatePOV(evtbuf[i].dwData);
|
|
||||||
SDL_PrivateJoystickHat(joystick, in->num, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
|
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
|
||||||
{
|
{
|
||||||
|
@ -572,7 +645,6 @@ SDL_SYS_JoystickQuit(void)
|
||||||
{
|
{
|
||||||
IDirectInput_Release(dinput);
|
IDirectInput_Release(dinput);
|
||||||
dinput = NULL;
|
dinput = NULL;
|
||||||
DX5_Unload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* SDL_JOYSTICK_DINPUT */
|
#endif /* SDL_JOYSTICK_DINPUT */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue