src/joystick/windows/SDL_windowsjoystick.c
changeset 13873 5bb6be4f2425
parent 13872 75c33f89d791
child 13944 b8c8ce11efc7
equal deleted inserted replaced
13872:75c33f89d791 13873:5bb6be4f2425
   398 /* Function to get the device-dependent name of a joystick */
   398 /* Function to get the device-dependent name of a joystick */
   399 static const char *
   399 static const char *
   400 WINDOWS_JoystickGetDeviceName(int device_index)
   400 WINDOWS_JoystickGetDeviceName(int device_index)
   401 {
   401 {
   402     JoyStick_DeviceData *device = SYS_Joystick;
   402     JoyStick_DeviceData *device = SYS_Joystick;
   403 
   403     int index;
   404     for (; device_index > 0; device_index--)
   404 
       
   405     for (index = device_index; index > 0; index--)
   405         device = device->pNext;
   406         device = device->pNext;
   406 
   407 
   407     return device->joystickname;
   408     return device->joystickname;
   408 }
   409 }
   409 
   410 
   456    It returns 0, or -1 if there is an error.
   457    It returns 0, or -1 if there is an error.
   457  */
   458  */
   458 static int
   459 static int
   459 WINDOWS_JoystickOpen(SDL_Joystick * joystick, int device_index)
   460 WINDOWS_JoystickOpen(SDL_Joystick * joystick, int device_index)
   460 {
   461 {
   461     JoyStick_DeviceData *joystickdevice = SYS_Joystick;
   462     JoyStick_DeviceData *device = SYS_Joystick;
   462 
   463     int index;
   463     for (; device_index > 0; device_index--)
   464 
   464         joystickdevice = joystickdevice->pNext;
   465     for (index = device_index; index > 0; index--)
       
   466         device = device->pNext;
   465 
   467 
   466     /* allocate memory for system specific hardware data */
   468     /* allocate memory for system specific hardware data */
   467     joystick->instance_id = joystickdevice->nInstanceID;
   469     joystick->instance_id = device->nInstanceID;
   468     joystick->hwdata =
   470     joystick->hwdata =
   469         (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata));
   471         (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata));
   470     if (joystick->hwdata == NULL) {
   472     if (joystick->hwdata == NULL) {
   471         return SDL_OutOfMemory();
   473         return SDL_OutOfMemory();
   472     }
   474     }
   473     SDL_zerop(joystick->hwdata);
   475     SDL_zerop(joystick->hwdata);
   474     joystick->hwdata->guid = joystickdevice->guid;
   476     joystick->hwdata->guid = device->guid;
   475 
   477 
   476     if (joystickdevice->bXInputDevice) {
   478     if (device->bXInputDevice) {
   477         return SDL_XINPUT_JoystickOpen(joystick, joystickdevice);
   479         return SDL_XINPUT_JoystickOpen(joystick, device);
   478     } else {
   480     } else {
   479         return SDL_DINPUT_JoystickOpen(joystick, joystickdevice);
   481         return SDL_DINPUT_JoystickOpen(joystick, device);
   480     }
   482     }
   481 }
   483 }
   482 
   484 
   483 static int
   485 static int
   484 WINDOWS_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
   486 WINDOWS_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)