21 #include "../../SDL_internal.h" 25 #include "../SDL_syshaptic.h" 34 #include "../../core/windows/SDL_xinput.h" 35 #include "../../joystick/windows/SDL_windowsjoystick_c.h" 48 loaded_xinput = (WIN_LoadXInputDLL() == 0);
53 for (i = 0; i < XUSER_MAX_COUNT; i++) {
65 XINPUT_VIBRATION
state;
67 if ((!loaded_xinput) || (dwUserid >= XUSER_MAX_COUNT)) {
79 if (XINPUTSETSTATE(dwUserid, &state) != ERROR_SUCCESS) {
93 SDL_snprintf(buf,
sizeof(buf),
"XInput Controller #%u", (
unsigned int)(userid + 1));
116 if ((!loaded_xinput) || (dwUserid >= XUSER_MAX_COUNT)) {
145 SDL_RunXInputHaptic(
void *arg)
155 XINPUT_VIBRATION vibration = { 0, 0 };
157 XINPUTSETSTATE(hwdata->
userid, &vibration);
167 SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *
haptic,
const Uint8 userid)
170 XINPUT_VIBRATION vibration = { 0, 0 };
171 XINPUTSETSTATE(userid, &vibration);
175 haptic->neffects = 1;
176 haptic->nplaying = 1;
181 if (haptic->effects ==
NULL) {
189 if (haptic->hwdata ==
NULL) {
191 haptic->effects =
NULL;
194 SDL_memset(haptic->hwdata, 0,
sizeof(*haptic->hwdata));
196 haptic->hwdata->bXInputHaptic = 1;
197 haptic->hwdata->userid =
userid;
200 if (haptic->hwdata->mutex ==
NULL) {
203 haptic->effects =
NULL;
204 return SDL_SetError(
"Couldn't create XInput haptic mutex");
207 SDL_snprintf(threadName,
sizeof(threadName),
"SDLXInputDev%d", (
int)userid);
209 #if defined(__WIN32__) && !defined(HAVE_LIBC) 210 #undef SDL_CreateThread 212 haptic->hwdata->thread = SDL_CreateThread_REAL(SDL_RunXInputHaptic, threadName, haptic->hwdata,
NULL,
NULL);
217 haptic->hwdata->thread =
SDL_CreateThread(SDL_RunXInputHaptic, threadName, haptic->hwdata);
219 if (haptic->hwdata->thread ==
NULL) {
223 haptic->effects =
NULL;
224 return SDL_SetError(
"Couldn't create XInput haptic thread");
233 return SDL_XINPUT_HapticOpenFromUserIndex(haptic, item->
userid);
239 return (haptic->hwdata->userid == joystick->hwdata->userid);
251 haptic->index =
index;
252 return SDL_XINPUT_HapticOpenFromUserIndex(haptic, joystick->hwdata->userid);
257 SDL_SetError(
"Couldn't find joystick in haptic device list");
264 haptic->hwdata->stopThread = 1;
273 WIN_UnloadXInputDLL();
288 XINPUT_VIBRATION *vib = &effect->
hweffect->vibration;
293 if (haptic->hwdata->stopTicks) {
294 XINPUTSETSTATE(haptic->hwdata->userid, vib);
303 XINPUT_VIBRATION *vib = &effect->
hweffect->vibration;
312 if ((haptic->hwdata->stopTicks ==
SDL_HAPTIC_INFINITY) || (haptic->hwdata->stopTicks == 0)) {
313 haptic->hwdata->stopTicks = 1;
317 return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1;
323 XINPUT_VIBRATION vibration = { 0, 0 };
325 haptic->hwdata->stopTicks = 0;
327 return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS) ? 0 : -1;
369 XINPUT_VIBRATION vibration = { 0, 0 };
371 haptic->hwdata->stopTicks = 0;
373 return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS) ? 0 : -1;
378 #include "../../core/windows/SDL_windows.h"
uint32_t Uint32
An unsigned 32-bit integer type.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
The SDL Haptic subsystem allows you to control haptic (force feedback) devices.
int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item)
#define SDL_HINT_XINPUT_ENABLED
A variable that lets you disable the detection and use of Xinput gamepad devices. ...
#define SDL_HAPTIC_INFINITY
Used to play a device an infinite number of times.
SDL_hapticlist_item * SDL_hapticlist
struct SDL_hapticlist_item * next
volatile Uint32 stopTicks
The generic template for any haptic effect.
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
uint8_t Uint8
An unsigned 8-bit integer type.
GLenum GLuint GLenum GLsizei const GLchar * buf
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
#define SDL_assert(condition)
#define SDL_OutOfMemory()
static SDL_Haptic * haptic
struct haptic_hweffect * hweffect
SDL_HapticLeftRight leftright
#define SDL_TICKS_PASSED(A, B)
Compare SDL ticks values, and return true if A has passed B.
#define SDL_HAPTIC_LEFTRIGHT
Left/Right effect supported.
#define SDL_Unsupported()
int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item)