Implemented trigger rumble for raw input controllers

Sam Lantinga 2020-11-25 16:46:42 -08:00
parent 517be80822
commit 845b903324
2 changed files with 35 additions and 6 deletions

View File

@ -191,6 +191,20 @@ typedef unsigned int uintptr_t;
#define HAVE_STDDEF_H 1
#endif
/* Check to see if we have Windows 10 build environment */
#if _MSC_VER >= 1911 /* Visual Studio 15.3 */
#include <sdkddkver.h>
#if _WIN32_WINNT >= 0x0601 /* Windows 7 */
#define SDL_WINDOWS7_SDK
#endif
#if _WIN32_WINNT >= 0x0602 /* Windows 8 */
#define SDL_WINDOWS8_SDK
#endif
#if _WIN32_WINNT >= 0x0A00 /* Windows 10 */
#define SDL_WINDOWS10_SDK
#endif
#endif /* _MSC_VER >= 1911 */
/* Enable various audio drivers */
#define SDL_AUDIO_DRIVER_WASAPI 1
#define SDL_AUDIO_DRIVER_DSOUND 1
@ -203,8 +217,8 @@ typedef unsigned int uintptr_t;
#define SDL_JOYSTICK_HIDAPI 1
#define SDL_JOYSTICK_RAWINPUT 1
#define SDL_JOYSTICK_VIRTUAL 1
#if _MSC_VER >= 1911
#define SDL_JOYSTICK_WGI 1 /* This requires Windows SDK 10.0.16299.0 or newer */
#ifdef SDL_WINDOWS10_SDK
#define SDL_JOYSTICK_WGI 1
#endif
#define SDL_JOYSTICK_XINPUT 1
#define SDL_HAPTIC_DINPUT 1
@ -229,7 +243,7 @@ typedef unsigned int uintptr_t;
#ifndef SDL_VIDEO_RENDER_D3D
#define SDL_VIDEO_RENDER_D3D 1
#endif
#if _MSC_VER >= 1911
#ifdef SDL_WINDOWS7_SDK
#define SDL_VIDEO_RENDER_D3D11 1
#endif

View File

@ -44,10 +44,9 @@
#include "../../core/windows/SDL_hid.h"
#include "../hidapi/SDL_hidapijoystick_c.h"
#ifdef __WIN32__
#define SDL_JOYSTICK_RAWINPUT_XINPUT
/* This requires the Windows 10 SDK to build */
/*#define SDL_JOYSTICK_RAWINPUT_GAMING_INPUT*/
#ifdef SDL_WINDOWS10_SDK
#define SDL_JOYSTICK_RAWINPUT_GAMING_INPUT
#endif
#ifdef SDL_JOYSTICK_RAWINPUT_XINPUT
@ -1232,7 +1231,23 @@ RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uin
static int
RAWINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
{
#if defined(SDL_JOYSTICK_RAWINPUT_GAMING_INPUT)
RAWINPUT_DeviceContext *ctx = joystick->hwdata;
if (ctx->wgi_correlated) {
WindowsGamingInputGamepadState *gamepad_state = ctx->wgi_slot;
HRESULT hr;
gamepad_state->vibration.LeftTrigger = (DOUBLE)left_rumble / SDL_MAX_UINT16;
gamepad_state->vibration.RightTrigger = (DOUBLE)right_rumble / SDL_MAX_UINT16;
hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(gamepad_state->gamepad, gamepad_state->vibration);
if (!SUCCEEDED(hr)) {
return SDL_SetError("Setting vibration failed: 0x%x\n", hr);
}
}
return 0;
#else
return SDL_Unsupported();
#endif
}
static SDL_bool