Mercurial > sdl-ios-xcode
comparison src/joystick/win32/SDL_dxjoystick.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
46 #include <dinput.h> | 46 #include <dinput.h> |
47 | 47 |
48 #define INPUT_QSIZE 32 /* Buffer up to 32 input messages */ | 48 #define INPUT_QSIZE 32 /* Buffer up to 32 input messages */ |
49 | 49 |
50 extern HINSTANCE SDL_Instance; | 50 extern HINSTANCE SDL_Instance; |
51 extern int DX5_Load (); | 51 extern int DX5_Load(); |
52 extern void DX5_Unload (); | 52 extern void DX5_Unload(); |
53 extern HRESULT (WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, | 53 extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, |
54 LPDIRECTINPUT * ppDI, | 54 LPDIRECTINPUT * ppDI, |
55 LPUNKNOWN punkOuter); | 55 LPUNKNOWN punkOuter); |
56 | 56 |
57 static LPDIRECTINPUT dinput = NULL; | 57 static LPDIRECTINPUT dinput = NULL; |
58 | 58 |
59 #define MAX_JOYSTICKS 8 | 59 #define MAX_JOYSTICKS 8 |
60 #define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */ | 60 #define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */ |
93 int NumInputs; | 93 int NumInputs; |
94 }; | 94 }; |
95 | 95 |
96 /* Convert a DirectInput return code to a text message */ | 96 /* Convert a DirectInput return code to a text message */ |
97 static void | 97 static void |
98 SetDIerror (char *function, int code) | 98 SetDIerror(char *function, int code) |
99 { | 99 { |
100 static char *error; | 100 static char *error; |
101 static char errbuf[1024]; | 101 static char errbuf[1024]; |
102 | 102 |
103 errbuf[0] = 0; | 103 errbuf[0] = 0; |
122 break; | 122 break; |
123 case DIERR_NOTINITIALIZED: | 123 case DIERR_NOTINITIALIZED: |
124 error = "Device not initialized"; | 124 error = "Device not initialized"; |
125 break; | 125 break; |
126 default: | 126 default: |
127 sprintf (errbuf, "%s: Unknown DirectInput error: 0x%x", | 127 sprintf(errbuf, "%s: Unknown DirectInput error: 0x%x", |
128 function, code); | 128 function, code); |
129 break; | 129 break; |
130 } | 130 } |
131 if (!errbuf[0]) { | 131 if (!errbuf[0]) { |
132 sprintf (errbuf, "%s: %s", function, error); | 132 sprintf(errbuf, "%s: %s", function, error); |
133 } | 133 } |
134 SDL_SetError ("%s", errbuf); | 134 SDL_SetError("%s", errbuf); |
135 return; | 135 return; |
136 } | 136 } |
137 | 137 |
138 | 138 |
139 BOOL CALLBACK | 139 BOOL CALLBACK |
140 EnumJoysticksCallback (const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) | 140 EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) |
141 { | 141 { |
142 memcpy (&SYS_Joystick[SYS_NumJoysticks], pdidInstance, | 142 memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance, |
143 sizeof (DIDEVICEINSTANCE)); | 143 sizeof(DIDEVICEINSTANCE)); |
144 SYS_NumJoysticks++; | 144 SYS_NumJoysticks++; |
145 | 145 |
146 if (SYS_NumJoysticks >= MAX_JOYSTICKS) | 146 if (SYS_NumJoysticks >= MAX_JOYSTICKS) |
147 return DIENUM_STOP; | 147 return DIENUM_STOP; |
148 | 148 |
149 return DIENUM_CONTINUE; | 149 return DIENUM_CONTINUE; |
150 } | 150 } |
151 | 151 |
152 static BOOL CALLBACK | 152 static BOOL CALLBACK |
153 DIJoystick_EnumDevObjectsProc (LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef) | 153 DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef) |
154 { | 154 { |
155 SDL_Joystick *joystick = (SDL_Joystick *) pvRef; | 155 SDL_Joystick *joystick = (SDL_Joystick *) pvRef; |
156 HRESULT result; | 156 HRESULT result; |
157 input_t *in = &joystick->hwdata->Inputs[joystick->hwdata->NumInputs]; | 157 input_t *in = &joystick->hwdata->Inputs[joystick->hwdata->NumInputs]; |
158 const int SupportedMask = DIDFT_BUTTON | DIDFT_POV | DIDFT_AXIS; | 158 const int SupportedMask = DIDFT_BUTTON | DIDFT_POV | DIDFT_AXIS; |
174 DIPROPDWORD dilong; | 174 DIPROPDWORD dilong; |
175 | 175 |
176 in->type = AXIS; | 176 in->type = AXIS; |
177 in->num = joystick->naxes; | 177 in->num = joystick->naxes; |
178 | 178 |
179 diprg.diph.dwSize = sizeof (diprg); | 179 diprg.diph.dwSize = sizeof(diprg); |
180 diprg.diph.dwHeaderSize = sizeof (diprg.diph); | 180 diprg.diph.dwHeaderSize = sizeof(diprg.diph); |
181 diprg.diph.dwObj = dev->dwOfs; | 181 diprg.diph.dwObj = dev->dwOfs; |
182 diprg.diph.dwHow = DIPH_BYOFFSET; | 182 diprg.diph.dwHow = DIPH_BYOFFSET; |
183 diprg.lMin = AXIS_MIN; | 183 diprg.lMin = AXIS_MIN; |
184 diprg.lMax = AXIS_MAX; | 184 diprg.lMax = AXIS_MAX; |
185 | 185 |
186 result = | 186 result = |
187 IDirectInputDevice2_SetProperty (joystick->hwdata->InputDevice, | 187 IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice, |
188 DIPROP_RANGE, &diprg.diph); | 188 DIPROP_RANGE, &diprg.diph); |
189 if (result != DI_OK) | 189 if (result != DI_OK) |
190 return DIENUM_CONTINUE; /* don't use this axis */ | 190 return DIENUM_CONTINUE; /* don't use this axis */ |
191 | 191 |
192 /* Set dead zone to 0. */ | 192 /* Set dead zone to 0. */ |
193 dilong.diph.dwSize = sizeof (dilong); | 193 dilong.diph.dwSize = sizeof(dilong); |
194 dilong.diph.dwHeaderSize = sizeof (dilong.diph); | 194 dilong.diph.dwHeaderSize = sizeof(dilong.diph); |
195 dilong.diph.dwObj = dev->dwOfs; | 195 dilong.diph.dwObj = dev->dwOfs; |
196 dilong.diph.dwHow = DIPH_BYOFFSET; | 196 dilong.diph.dwHow = DIPH_BYOFFSET; |
197 dilong.dwData = 0; | 197 dilong.dwData = 0; |
198 result = | 198 result = |
199 IDirectInputDevice2_SetProperty (joystick->hwdata->InputDevice, | 199 IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice, |
200 DIPROP_DEADZONE, &dilong.diph); | 200 DIPROP_DEADZONE, &dilong.diph); |
201 if (result != DI_OK) | 201 if (result != DI_OK) |
202 return DIENUM_CONTINUE; /* don't use this axis */ | 202 return DIENUM_CONTINUE; /* don't use this axis */ |
203 | 203 |
204 joystick->naxes++; | 204 joystick->naxes++; |
205 } | 205 } |
216 * This function should set SDL_numjoysticks to the number of available | 216 * This function should set SDL_numjoysticks to the number of available |
217 * joysticks. Joystick 0 should be the system default joystick. | 217 * joysticks. Joystick 0 should be the system default joystick. |
218 * It should return 0, or -1 on an unrecoverable fatal error. | 218 * It should return 0, or -1 on an unrecoverable fatal error. |
219 */ | 219 */ |
220 int | 220 int |
221 SDL_SYS_JoystickInit (void) | 221 SDL_SYS_JoystickInit(void) |
222 { | 222 { |
223 HRESULT result; | 223 HRESULT result; |
224 | 224 |
225 SYS_NumJoysticks = 0; | 225 SYS_NumJoysticks = 0; |
226 | 226 |
227 /* Create the DirectInput object */ | 227 /* Create the DirectInput object */ |
228 if (DX5_Load () < 0) { | 228 if (DX5_Load() < 0) { |
229 SDL_SetError ("Couldn't load DirectInput"); | 229 SDL_SetError("Couldn't load DirectInput"); |
230 return (-1); | 230 return (-1); |
231 } | 231 } |
232 result = DInputCreate (SDL_Instance, DIRECTINPUT_VERSION, &dinput, NULL); | 232 result = DInputCreate(SDL_Instance, DIRECTINPUT_VERSION, &dinput, NULL); |
233 if (result != DI_OK) { | 233 if (result != DI_OK) { |
234 DX5_Unload (); | 234 DX5_Unload(); |
235 SetDIerror ("DirectInputCreate", result); | 235 SetDIerror("DirectInputCreate", result); |
236 return (-1); | 236 return (-1); |
237 } | 237 } |
238 | 238 |
239 result = IDirectInput_EnumDevices (dinput, | 239 result = IDirectInput_EnumDevices(dinput, |
240 DIDEVTYPE_JOYSTICK, | 240 DIDEVTYPE_JOYSTICK, |
241 EnumJoysticksCallback, | 241 EnumJoysticksCallback, |
242 NULL, DIEDFL_ATTACHEDONLY); | 242 NULL, DIEDFL_ATTACHEDONLY); |
243 | 243 |
244 return SYS_NumJoysticks; | 244 return SYS_NumJoysticks; |
245 } | 245 } |
246 | 246 |
247 /* Function to get the device-dependent name of a joystick */ | 247 /* Function to get the device-dependent name of a joystick */ |
248 const char * | 248 const char * |
249 SDL_SYS_JoystickName (int index) | 249 SDL_SYS_JoystickName(int index) |
250 { | 250 { |
251 /***-> test for invalid index ? */ | 251 /***-> test for invalid index ? */ |
252 return (SYS_Joystick[index].tszProductName); | 252 return (SYS_Joystick[index].tszProductName); |
253 } | 253 } |
254 | 254 |
256 The joystick to open is specified by the index field of the joystick. | 256 The joystick to open is specified by the index field of the joystick. |
257 This should fill the nbuttons and naxes fields of the joystick structure. | 257 This should fill the nbuttons and naxes fields of the joystick structure. |
258 It returns 0, or -1 if there is an error. | 258 It returns 0, or -1 if there is an error. |
259 */ | 259 */ |
260 int | 260 int |
261 SDL_SYS_JoystickOpen (SDL_Joystick * joystick) | 261 SDL_SYS_JoystickOpen(SDL_Joystick * joystick) |
262 { | 262 { |
263 HRESULT result; | 263 HRESULT result; |
264 LPDIRECTINPUTDEVICE device; | 264 LPDIRECTINPUTDEVICE device; |
265 | 265 |
266 /* allocate memory for system specific hardware data */ | 266 /* allocate memory for system specific hardware data */ |
267 joystick->hwdata = | 267 joystick->hwdata = |
268 (struct joystick_hwdata *) malloc (sizeof (*joystick->hwdata)); | 268 (struct joystick_hwdata *) malloc(sizeof(*joystick->hwdata)); |
269 if (joystick->hwdata == NULL) { | 269 if (joystick->hwdata == NULL) { |
270 SDL_OutOfMemory (); | 270 SDL_OutOfMemory(); |
271 return (-1); | 271 return (-1); |
272 } | 272 } |
273 memset (joystick->hwdata, 0, sizeof (*joystick->hwdata)); | 273 memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); |
274 joystick->hwdata->buffered = 1; | 274 joystick->hwdata->buffered = 1; |
275 | 275 |
276 result = | 276 result = |
277 IDirectInput_CreateDevice (dinput, | 277 IDirectInput_CreateDevice(dinput, |
278 &SYS_Joystick[joystick->index]. | 278 &SYS_Joystick[joystick->index]. |
279 guidInstance, &device, NULL); | 279 guidInstance, &device, NULL); |
280 if (result != DI_OK) { | 280 if (result != DI_OK) { |
281 SetDIerror ("DirectInput::CreateDevice", result); | 281 SetDIerror("DirectInput::CreateDevice", result); |
282 return (-1); | 282 return (-1); |
283 } | 283 } |
284 | 284 |
285 result = IDirectInputDevice_QueryInterface (device, | 285 result = IDirectInputDevice_QueryInterface(device, |
286 &IID_IDirectInputDevice2, | 286 &IID_IDirectInputDevice2, |
287 (LPVOID *) & joystick-> | 287 (LPVOID *) & joystick-> |
288 hwdata->InputDevice); | 288 hwdata->InputDevice); |
289 IDirectInputDevice_Release (device); | 289 IDirectInputDevice_Release(device); |
290 if (result != DI_OK) { | 290 if (result != DI_OK) { |
291 SetDIerror ("DirectInputDevice::QueryInterface", result); | 291 SetDIerror("DirectInputDevice::QueryInterface", result); |
292 return (-1); | 292 return (-1); |
293 } | 293 } |
294 | 294 |
295 result = | 295 result = |
296 IDirectInputDevice2_SetCooperativeLevel (joystick->hwdata-> | 296 IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata-> |
297 InputDevice, SDL_Window, | 297 InputDevice, SDL_Window, |
298 DISCL_NONEXCLUSIVE | | 298 DISCL_NONEXCLUSIVE | |
299 DISCL_BACKGROUND); | 299 DISCL_BACKGROUND); |
300 if (result != DI_OK) { | 300 if (result != DI_OK) { |
301 SetDIerror ("DirectInputDevice::SetCooperativeLevel", result); | 301 SetDIerror("DirectInputDevice::SetCooperativeLevel", result); |
302 return (-1); | 302 return (-1); |
303 } | 303 } |
304 | 304 |
305 result = | 305 result = |
306 IDirectInputDevice2_SetDataFormat (joystick->hwdata->InputDevice, | 306 IDirectInputDevice2_SetDataFormat(joystick->hwdata->InputDevice, |
307 &c_dfDIJoystick); | 307 &c_dfDIJoystick); |
308 if (result != DI_OK) { | 308 if (result != DI_OK) { |
309 SetDIerror ("DirectInputDevice::SetDataFormat", result); | 309 SetDIerror("DirectInputDevice::SetDataFormat", result); |
310 return (-1); | 310 return (-1); |
311 } | 311 } |
312 | 312 |
313 IDirectInputDevice2_EnumObjects (joystick->hwdata->InputDevice, | 313 IDirectInputDevice2_EnumObjects(joystick->hwdata->InputDevice, |
314 DIJoystick_EnumDevObjectsProc, | 314 DIJoystick_EnumDevObjectsProc, |
315 joystick, | 315 joystick, |
316 DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV); | 316 DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV); |
317 | 317 |
318 { | 318 { |
319 DIPROPDWORD dipdw; | 319 DIPROPDWORD dipdw; |
320 memset (&dipdw, 0, sizeof (dipdw)); | 320 memset(&dipdw, 0, sizeof(dipdw)); |
321 dipdw.diph.dwSize = sizeof (dipdw); | 321 dipdw.diph.dwSize = sizeof(dipdw); |
322 dipdw.diph.dwHeaderSize = sizeof (dipdw.diph); | 322 dipdw.diph.dwHeaderSize = sizeof(dipdw.diph); |
323 dipdw.diph.dwObj = 0; | 323 dipdw.diph.dwObj = 0; |
324 dipdw.diph.dwHow = DIPH_DEVICE; | 324 dipdw.diph.dwHow = DIPH_DEVICE; |
325 dipdw.dwData = INPUT_QSIZE; | 325 dipdw.dwData = INPUT_QSIZE; |
326 result = | 326 result = |
327 IDirectInputDevice2_SetProperty (joystick->hwdata->InputDevice, | 327 IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice, |
328 DIPROP_BUFFERSIZE, &dipdw.diph); | 328 DIPROP_BUFFERSIZE, &dipdw.diph); |
329 | 329 |
330 if (result == DI_POLLEDDEVICE) { | 330 if (result == DI_POLLEDDEVICE) { |
331 /* This device doesn't support buffering, so we're forced | 331 /* This device doesn't support buffering, so we're forced |
332 * to use less reliable polling. */ | 332 * to use less reliable polling. */ |
333 joystick->hwdata->buffered = 0; | 333 joystick->hwdata->buffered = 0; |
334 } else if (result != DI_OK) { | 334 } else if (result != DI_OK) { |
335 SetDIerror ("DirectInputDevice::SetProperty", result); | 335 SetDIerror("DirectInputDevice::SetProperty", result); |
336 return (-1); | 336 return (-1); |
337 } | 337 } |
338 } | 338 } |
339 | 339 |
340 return (0); | 340 return (0); |
341 } | 341 } |
342 | 342 |
343 static Uint8 | 343 static Uint8 |
344 TranslatePOV (DWORD value) | 344 TranslatePOV(DWORD value) |
345 { | 345 { |
346 const int HAT_VALS[] = { | 346 const int HAT_VALS[] = { |
347 SDL_HAT_UP, | 347 SDL_HAT_UP, |
348 SDL_HAT_UP | SDL_HAT_RIGHT, | 348 SDL_HAT_UP | SDL_HAT_RIGHT, |
349 SDL_HAT_RIGHT, | 349 SDL_HAT_RIGHT, |
352 SDL_HAT_DOWN | SDL_HAT_LEFT, | 352 SDL_HAT_DOWN | SDL_HAT_LEFT, |
353 SDL_HAT_LEFT, | 353 SDL_HAT_LEFT, |
354 SDL_HAT_UP | SDL_HAT_LEFT | 354 SDL_HAT_UP | SDL_HAT_LEFT |
355 }; | 355 }; |
356 | 356 |
357 if (LOWORD (value) == 0xFFFF) | 357 if (LOWORD(value) == 0xFFFF) |
358 return SDL_HAT_CENTERED; | 358 return SDL_HAT_CENTERED; |
359 | 359 |
360 /* Round the value up: */ | 360 /* Round the value up: */ |
361 value += 4500 / 2; | 361 value += 4500 / 2; |
362 value %= 36000; | 362 value %= 36000; |
369 } | 369 } |
370 | 370 |
371 /* SDL_PrivateJoystick* doesn't discard duplicate events, so we need to | 371 /* SDL_PrivateJoystick* doesn't discard duplicate events, so we need to |
372 * do it. */ | 372 * do it. */ |
373 static int | 373 static int |
374 SDL_PrivateJoystickAxis_Int (SDL_Joystick * joystick, Uint8 axis, | 374 SDL_PrivateJoystickAxis_Int(SDL_Joystick * joystick, Uint8 axis, Sint16 value) |
375 Sint16 value) | |
376 { | 375 { |
377 if (joystick->axes[axis] != value) | 376 if (joystick->axes[axis] != value) |
378 return SDL_PrivateJoystickAxis (joystick, axis, value); | 377 return SDL_PrivateJoystickAxis(joystick, axis, value); |
379 return 0; | 378 return 0; |
380 } | 379 } |
381 | 380 |
382 static int | 381 static int |
383 SDL_PrivateJoystickHat_Int (SDL_Joystick * joystick, Uint8 hat, Uint8 value) | 382 SDL_PrivateJoystickHat_Int(SDL_Joystick * joystick, Uint8 hat, Uint8 value) |
384 { | 383 { |
385 if (joystick->hats[hat] != value) | 384 if (joystick->hats[hat] != value) |
386 return SDL_PrivateJoystickHat (joystick, hat, value); | 385 return SDL_PrivateJoystickHat(joystick, hat, value); |
387 return 0; | 386 return 0; |
388 } | 387 } |
389 | 388 |
390 static int | 389 static int |
391 SDL_PrivateJoystickButton_Int (SDL_Joystick * joystick, Uint8 button, | 390 SDL_PrivateJoystickButton_Int(SDL_Joystick * joystick, Uint8 button, |
392 Uint8 state) | 391 Uint8 state) |
393 { | 392 { |
394 if (joystick->buttons[button] != state) | 393 if (joystick->buttons[button] != state) |
395 return SDL_PrivateJoystickButton (joystick, button, state); | 394 return SDL_PrivateJoystickButton(joystick, button, state); |
396 return 0; | 395 return 0; |
397 } | 396 } |
398 | 397 |
399 /* Function to update the state of a joystick - called as a device poll. | 398 /* Function to update the state of a joystick - called as a device poll. |
400 * This function shouldn't update the joystick structure directly, | 399 * This function shouldn't update the joystick structure directly, |
401 * but instead should call SDL_PrivateJoystick*() to deliver events | 400 * but instead should call SDL_PrivateJoystick*() to deliver events |
402 * and update joystick device state. | 401 * and update joystick device state. |
403 */ | 402 */ |
404 void | 403 void |
405 SDL_SYS_JoystickUpdate_Polled (SDL_Joystick * joystick) | 404 SDL_SYS_JoystickUpdate_Polled(SDL_Joystick * joystick) |
406 { | 405 { |
407 DIJOYSTATE state; | 406 DIJOYSTATE state; |
408 HRESULT result; | 407 HRESULT result; |
409 int i; | 408 int i; |
410 | 409 |
411 result = | 410 result = |
412 IDirectInputDevice2_GetDeviceState (joystick->hwdata->InputDevice, | 411 IDirectInputDevice2_GetDeviceState(joystick->hwdata->InputDevice, |
413 sizeof (state), &state); | 412 sizeof(state), &state); |
414 if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { | 413 if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { |
415 IDirectInputDevice2_Acquire (joystick->hwdata->InputDevice); | 414 IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice); |
416 result = | 415 result = |
417 IDirectInputDevice2_GetDeviceState (joystick->hwdata-> | 416 IDirectInputDevice2_GetDeviceState(joystick->hwdata-> |
418 InputDevice, sizeof (state), | 417 InputDevice, sizeof(state), |
419 &state); | 418 &state); |
420 } | 419 } |
421 | 420 |
422 /* Set each known axis, button and POV. */ | 421 /* Set each known axis, button and POV. */ |
423 for (i = 0; i < joystick->hwdata->NumInputs; ++i) { | 422 for (i = 0; i < joystick->hwdata->NumInputs; ++i) { |
424 const input_t *in = &joystick->hwdata->Inputs[i]; | 423 const input_t *in = &joystick->hwdata->Inputs[i]; |
425 | 424 |
426 switch (in->type) { | 425 switch (in->type) { |
427 case AXIS: | 426 case AXIS: |
428 switch (in->ofs) { | 427 switch (in->ofs) { |
429 case DIJOFS_X: | 428 case DIJOFS_X: |
430 SDL_PrivateJoystickAxis_Int (joystick, in->num, | 429 SDL_PrivateJoystickAxis_Int(joystick, in->num, |
431 (Sint16) state.lX); | 430 (Sint16) state.lX); |
432 break; | 431 break; |
433 case DIJOFS_Y: | 432 case DIJOFS_Y: |
434 SDL_PrivateJoystickAxis_Int (joystick, in->num, | 433 SDL_PrivateJoystickAxis_Int(joystick, in->num, |
435 (Sint16) state.lY); | 434 (Sint16) state.lY); |
436 break; | 435 break; |
437 case DIJOFS_Z: | 436 case DIJOFS_Z: |
438 SDL_PrivateJoystickAxis_Int (joystick, in->num, | 437 SDL_PrivateJoystickAxis_Int(joystick, in->num, |
439 (Sint16) state.lZ); | 438 (Sint16) state.lZ); |
440 break; | 439 break; |
441 case DIJOFS_RX: | 440 case DIJOFS_RX: |
442 SDL_PrivateJoystickAxis_Int (joystick, in->num, | 441 SDL_PrivateJoystickAxis_Int(joystick, in->num, |
443 (Sint16) state.lRx); | 442 (Sint16) state.lRx); |
444 break; | 443 break; |
445 case DIJOFS_RY: | 444 case DIJOFS_RY: |
446 SDL_PrivateJoystickAxis_Int (joystick, in->num, | 445 SDL_PrivateJoystickAxis_Int(joystick, in->num, |
447 (Sint16) state.lRy); | 446 (Sint16) state.lRy); |
448 break; | 447 break; |
449 case DIJOFS_RZ: | 448 case DIJOFS_RZ: |
450 SDL_PrivateJoystickAxis_Int (joystick, in->num, | 449 SDL_PrivateJoystickAxis_Int(joystick, in->num, |
451 (Sint16) state.lRz); | 450 (Sint16) state.lRz); |
452 break; | 451 break; |
453 case DIJOFS_SLIDER (0): | 452 case DIJOFS_SLIDER(0): |
454 SDL_PrivateJoystickAxis_Int (joystick, in->num, | 453 SDL_PrivateJoystickAxis_Int(joystick, in->num, |
455 (Sint16) state.rglSlider[0]); | 454 (Sint16) state.rglSlider[0]); |
456 break; | 455 break; |
457 case DIJOFS_SLIDER (1): | 456 case DIJOFS_SLIDER(1): |
458 SDL_PrivateJoystickAxis_Int (joystick, in->num, | 457 SDL_PrivateJoystickAxis_Int(joystick, in->num, |
459 (Sint16) state.rglSlider[0]); | 458 (Sint16) state.rglSlider[0]); |
460 break; | 459 break; |
461 } | 460 } |
462 | 461 |
463 break; | 462 break; |
464 | 463 |
465 case BUTTON: | 464 case BUTTON: |
466 SDL_PrivateJoystickButton_Int (joystick, in->num, | 465 SDL_PrivateJoystickButton_Int(joystick, in->num, |
467 (Uint8) (state. | 466 (Uint8) (state. |
468 rgbButtons[in->ofs - | 467 rgbButtons[in->ofs - |
469 DIJOFS_BUTTON0] | 468 DIJOFS_BUTTON0] |
470 ? SDL_PRESSED : | 469 ? SDL_PRESSED : |
471 SDL_RELEASED)); | 470 SDL_RELEASED)); |
472 break; | 471 break; |
473 case HAT: | 472 case HAT: |
474 { | 473 { |
475 Uint8 pos = | 474 Uint8 pos = |
476 TranslatePOV (state.rgdwPOV[in->ofs - DIJOFS_POV (0)]); | 475 TranslatePOV(state.rgdwPOV[in->ofs - DIJOFS_POV(0)]); |
477 SDL_PrivateJoystickHat_Int (joystick, in->num, pos); | 476 SDL_PrivateJoystickHat_Int(joystick, in->num, pos); |
478 break; | 477 break; |
479 } | 478 } |
480 } | 479 } |
481 } | 480 } |
482 } | 481 } |
483 | 482 |
484 void | 483 void |
485 SDL_SYS_JoystickUpdate_Buffered (SDL_Joystick * joystick) | 484 SDL_SYS_JoystickUpdate_Buffered(SDL_Joystick * joystick) |
486 { | 485 { |
487 int i; | 486 int i; |
488 HRESULT result; | 487 HRESULT result; |
489 DWORD numevents; | 488 DWORD numevents; |
490 DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE]; | 489 DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE]; |
491 | 490 |
492 numevents = INPUT_QSIZE; | 491 numevents = INPUT_QSIZE; |
493 result = | 492 result = |
494 IDirectInputDevice2_GetDeviceData (joystick->hwdata->InputDevice, | 493 IDirectInputDevice2_GetDeviceData(joystick->hwdata->InputDevice, |
495 sizeof (DIDEVICEOBJECTDATA), | 494 sizeof(DIDEVICEOBJECTDATA), |
496 evtbuf, &numevents, 0); | 495 evtbuf, &numevents, 0); |
497 if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { | 496 if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { |
498 IDirectInputDevice2_Acquire (joystick->hwdata->InputDevice); | 497 IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice); |
499 result = | 498 result = |
500 IDirectInputDevice2_GetDeviceData (joystick->hwdata-> | 499 IDirectInputDevice2_GetDeviceData(joystick->hwdata-> |
501 InputDevice, | 500 InputDevice, |
502 sizeof (DIDEVICEOBJECTDATA), | 501 sizeof(DIDEVICEOBJECTDATA), |
503 evtbuf, &numevents, 0); | 502 evtbuf, &numevents, 0); |
504 } | 503 } |
505 | 504 |
506 /* Handle the events */ | 505 /* Handle the events */ |
507 if (result != DI_OK) | 506 if (result != DI_OK) |
508 return; | 507 return; |
516 if (evtbuf[i].dwOfs != in->ofs) | 515 if (evtbuf[i].dwOfs != in->ofs) |
517 continue; | 516 continue; |
518 | 517 |
519 switch (in->type) { | 518 switch (in->type) { |
520 case AXIS: | 519 case AXIS: |
521 SDL_PrivateJoystickAxis (joystick, in->num, | 520 SDL_PrivateJoystickAxis(joystick, in->num, |
522 (Sint16) evtbuf[i].dwData); | 521 (Sint16) evtbuf[i].dwData); |
523 break; | 522 break; |
524 case BUTTON: | 523 case BUTTON: |
525 SDL_PrivateJoystickButton (joystick, in->num, | 524 SDL_PrivateJoystickButton(joystick, in->num, |
526 (Uint8) (evtbuf[i]. | 525 (Uint8) (evtbuf[i]. |
527 dwData ? SDL_PRESSED | 526 dwData ? SDL_PRESSED |
528 : SDL_RELEASED)); | 527 : SDL_RELEASED)); |
529 break; | 528 break; |
530 case HAT: | 529 case HAT: |
531 { | 530 { |
532 Uint8 pos = TranslatePOV (evtbuf[i].dwData); | 531 Uint8 pos = TranslatePOV(evtbuf[i].dwData); |
533 SDL_PrivateJoystickHat (joystick, in->num, pos); | 532 SDL_PrivateJoystickHat(joystick, in->num, pos); |
534 } | 533 } |
535 } | 534 } |
536 } | 535 } |
537 } | 536 } |
538 } | 537 } |
539 | 538 |
540 void | 539 void |
541 SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) | 540 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) |
542 { | 541 { |
543 HRESULT result; | 542 HRESULT result; |
544 | 543 |
545 result = IDirectInputDevice2_Poll (joystick->hwdata->InputDevice); | 544 result = IDirectInputDevice2_Poll(joystick->hwdata->InputDevice); |
546 if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { | 545 if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) { |
547 IDirectInputDevice2_Acquire (joystick->hwdata->InputDevice); | 546 IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice); |
548 IDirectInputDevice2_Poll (joystick->hwdata->InputDevice); | 547 IDirectInputDevice2_Poll(joystick->hwdata->InputDevice); |
549 } | 548 } |
550 | 549 |
551 if (joystick->hwdata->buffered) | 550 if (joystick->hwdata->buffered) |
552 SDL_SYS_JoystickUpdate_Buffered (joystick); | 551 SDL_SYS_JoystickUpdate_Buffered(joystick); |
553 else | 552 else |
554 SDL_SYS_JoystickUpdate_Polled (joystick); | 553 SDL_SYS_JoystickUpdate_Polled(joystick); |
555 } | 554 } |
556 | 555 |
557 /* Function to close a joystick after use */ | 556 /* Function to close a joystick after use */ |
558 void | 557 void |
559 SDL_SYS_JoystickClose (SDL_Joystick * joystick) | 558 SDL_SYS_JoystickClose(SDL_Joystick * joystick) |
560 { | 559 { |
561 IDirectInputDevice2_Unacquire (joystick->hwdata->InputDevice); | 560 IDirectInputDevice2_Unacquire(joystick->hwdata->InputDevice); |
562 IDirectInputDevice2_Release (joystick->hwdata->InputDevice); | 561 IDirectInputDevice2_Release(joystick->hwdata->InputDevice); |
563 | 562 |
564 if (joystick->hwdata != NULL) { | 563 if (joystick->hwdata != NULL) { |
565 /* free system specific hardware data */ | 564 /* free system specific hardware data */ |
566 free (joystick->hwdata); | 565 free(joystick->hwdata); |
567 } | 566 } |
568 } | 567 } |
569 | 568 |
570 /* Function to perform any system-specific joystick related cleanup */ | 569 /* Function to perform any system-specific joystick related cleanup */ |
571 void | 570 void |
572 SDL_SYS_JoystickQuit (void) | 571 SDL_SYS_JoystickQuit(void) |
573 { | 572 { |
574 IDirectInput_Release (dinput); | 573 IDirectInput_Release(dinput); |
575 dinput = NULL; | 574 dinput = NULL; |
576 DX5_Unload (); | 575 DX5_Unload(); |
577 } | 576 } |
578 | 577 |
579 #endif /* SDL_JOYSTICK_DINPUT */ | 578 #endif /* SDL_JOYSTICK_DINPUT */ |
580 /* vi: set ts=4 sw=4 expandtab: */ | 579 /* vi: set ts=4 sw=4 expandtab: */ |