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" 36 #include "../../thread/SDL_systhread.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);
210 if (haptic->hwdata->thread ==
NULL) {
214 haptic->effects =
NULL;
215 return SDL_SetError(
"Couldn't create XInput haptic thread");
224 return SDL_XINPUT_HapticOpenFromUserIndex(haptic, item->
userid);
230 return (haptic->hwdata->userid == joystick->hwdata->userid);
242 haptic->index =
index;
243 return SDL_XINPUT_HapticOpenFromUserIndex(haptic, joystick->hwdata->userid);
248 SDL_SetError(
"Couldn't find joystick in haptic device list");
264 WIN_UnloadXInputDLL();
279 XINPUT_VIBRATION *vib = &effect->
hweffect->vibration;
285 if (haptic->hwdata->stopTicks) {
286 XINPUTSETSTATE(haptic->hwdata->userid, vib);
295 XINPUT_VIBRATION *vib = &effect->
hweffect->vibration;
304 if ((haptic->hwdata->stopTicks ==
SDL_HAPTIC_INFINITY) || (haptic->hwdata->stopTicks == 0)) {
305 haptic->hwdata->stopTicks = 1;
309 return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1;
315 XINPUT_VIBRATION vibration = { 0, 0 };
317 haptic->hwdata->stopTicks = 0;
319 return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS) ? 0 : -1;
361 XINPUT_VIBRATION vibration = { 0, 0 };
363 haptic->hwdata->stopTicks = 0;
365 return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS) ? 0 : -1;
370 #include "../../core/windows/SDL_windows.h"
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_GetHintBoolean
#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
SDL_Thread * SDL_CreateThreadInternal(int(*fn)(void *), const char *name, const size_t stacksize, void *data)
The generic template for any haptic effect.
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
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)