mirror of
https://github.com/encounter/SDL.git
synced 2025-12-14 23:56:19 +00:00
Added SDL_JoystickRumbleTriggers() and SDL_GameControllerRumbleTriggers()
This commit is contained in:
@@ -614,6 +614,15 @@ RAWINPUT_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Ui
|
||||
return device->driver->RumbleJoystick(&device->hiddevice, joystick, low_frequency_rumble, high_frequency_rumble);
|
||||
}
|
||||
|
||||
static int
|
||||
RAWINPUT_JoystickRumbleTriggers(SDL_Joystick * joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
{
|
||||
struct joystick_hwdata *hwdata = joystick->hwdata;
|
||||
SDL_RAWINPUT_Device *device = hwdata->device;
|
||||
|
||||
return device->driver->RumbleJoystickTriggers(&device->hiddevice, joystick, low_frequency_rumble, high_frequency_rumble);
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
RAWINPUT_JoystickHasLED(SDL_Joystick * joystick)
|
||||
{
|
||||
@@ -756,6 +765,7 @@ SDL_JoystickDriver SDL_RAWINPUT_JoystickDriver =
|
||||
RAWINPUT_JoystickGetDeviceInstanceID,
|
||||
RAWINPUT_JoystickOpen,
|
||||
RAWINPUT_JoystickRumble,
|
||||
RAWINPUT_JoystickRumbleTriggers,
|
||||
RAWINPUT_JoystickHasLED,
|
||||
RAWINPUT_JoystickSetLED,
|
||||
RAWINPUT_JoystickUpdate,
|
||||
|
||||
@@ -38,6 +38,7 @@ struct joystick_hwdata
|
||||
__x_ABI_CWindows_CGaming_CInput_CIGameController *gamecontroller;
|
||||
__x_ABI_CWindows_CGaming_CInput_CIGameControllerBatteryInfo *battery;
|
||||
__x_ABI_CWindows_CGaming_CInput_CIGamepad *gamepad;
|
||||
__x_ABI_CWindows_CGaming_CInput_CGamepadVibration vibration;
|
||||
UINT64 timestamp;
|
||||
};
|
||||
|
||||
@@ -559,12 +560,31 @@ WGI_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16
|
||||
|
||||
if (hwdata->gamepad) {
|
||||
HRESULT hr;
|
||||
struct __x_ABI_CWindows_CGaming_CInput_CGamepadVibration vibration;
|
||||
|
||||
SDL_zero(vibration);
|
||||
vibration.LeftMotor = (DOUBLE)low_frequency_rumble / SDL_MAX_UINT16;
|
||||
vibration.RightMotor = (DOUBLE)high_frequency_rumble / SDL_MAX_UINT16;
|
||||
hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(hwdata->gamepad, vibration);
|
||||
hwdata->vibration.LeftMotor = (DOUBLE)low_frequency_rumble / SDL_MAX_UINT16;
|
||||
hwdata->vibration.RightMotor = (DOUBLE)high_frequency_rumble / SDL_MAX_UINT16;
|
||||
hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(hwdata->gamepad, hwdata->vibration);
|
||||
if (SUCCEEDED(hr)) {
|
||||
return 0;
|
||||
} else {
|
||||
return SDL_SetError("Setting vibration failed: 0x%x\n", hr);
|
||||
}
|
||||
} else {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
WGI_JoystickRumbleTriggers(SDL_Joystick * joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
{
|
||||
struct joystick_hwdata *hwdata = joystick->hwdata;
|
||||
|
||||
if (hwdata->gamepad) {
|
||||
HRESULT hr;
|
||||
|
||||
hwdata->vibration.LeftTrigger = (DOUBLE)left_rumble / SDL_MAX_UINT16;
|
||||
hwdata->vibration.RightTrigger = (DOUBLE)right_rumble / SDL_MAX_UINT16;
|
||||
hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(hwdata->gamepad, hwdata->vibration);
|
||||
if (SUCCEEDED(hr)) {
|
||||
return 0;
|
||||
} else {
|
||||
@@ -729,6 +749,7 @@ SDL_JoystickDriver SDL_WGI_JoystickDriver =
|
||||
WGI_JoystickGetDeviceInstanceID,
|
||||
WGI_JoystickOpen,
|
||||
WGI_JoystickRumble,
|
||||
WGI_JoystickRumbleTriggers,
|
||||
WGI_JoystickHasLED,
|
||||
WGI_JoystickSetLED,
|
||||
WGI_JoystickUpdate,
|
||||
|
||||
@@ -500,6 +500,12 @@ WINDOWS_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uin
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
WINDOWS_JoystickRumbleTriggers(SDL_Joystick * joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
WINDOWS_JoystickHasLED(SDL_Joystick * joystick)
|
||||
{
|
||||
@@ -595,6 +601,7 @@ SDL_JoystickDriver SDL_WINDOWS_JoystickDriver =
|
||||
WINDOWS_JoystickGetDeviceInstanceID,
|
||||
WINDOWS_JoystickOpen,
|
||||
WINDOWS_JoystickRumble,
|
||||
WINDOWS_JoystickRumbleTriggers,
|
||||
WINDOWS_JoystickHasLED,
|
||||
WINDOWS_JoystickSetLED,
|
||||
WINDOWS_JoystickUpdate,
|
||||
|
||||
Reference in New Issue
Block a user