21 #include "../SDL_internal.h" 25 #include "../joystick/SDL_joystick_c.h" 29 #if (defined(SDL_HAPTIC_DINPUT) && SDL_HAPTIC_DINPUT) || (defined(SDL_HAPTIC_XINPUT) && SDL_HAPTIC_XINPUT) 59 SDL_Haptic *hapticlist;
66 if (hapticlist == haptic) {
70 hapticlist = hapticlist->next;
76 SDL_SetError(
"Haptic: Invalid haptic device identifier");
100 SDL_SetError(
"Haptic: There are %d haptic devices available",
115 SDL_Haptic *hapticlist;
118 SDL_SetError(
"Haptic: There are %d haptic devices available",
129 if (device_index == hapticlist->index) {
134 hapticlist = hapticlist->next;
138 haptic = (SDL_Haptic *)
SDL_malloc((
sizeof *haptic));
139 if (haptic ==
NULL) {
146 haptic->rumble_id = -1;
147 haptic->index = device_index;
176 SDL_Haptic *hapticlist;
180 SDL_SetError(
"Haptic: There are %d haptic devices available",
190 if (hapticlist->index == (
Uint8) device_index) {
194 hapticlist = hapticlist->next;
210 return haptic->index;
236 if (device_index < 0) {
276 SDL_Haptic *hapticlist;
280 SDL_SetError(
"Haptic: There are %d haptic devices available",
293 SDL_SetError(
"Haptic: Joystick isn't a haptic device.");
306 hapticlist = hapticlist->next;
310 haptic = (SDL_Haptic *)
SDL_malloc((
sizeof *haptic));
311 if (haptic ==
NULL) {
318 haptic->rumble_id = -1;
320 SDL_SetError(
"Haptic: SDL_SYS_HapticOpenFromJoystick failed.");
342 SDL_Haptic *hapticlist;
343 SDL_Haptic *hapticlistprev;
351 if (--haptic->ref_count > 0) {
356 for (i = 0; i < haptic->neffects; i++) {
357 if (haptic->effects[i].hweffect !=
NULL) {
365 hapticlistprev =
NULL;
368 if (haptic == hapticlist)
370 if ( hapticlistprev )
373 hapticlistprev->next = hapticlist->next;
382 hapticlistprev = hapticlist;
383 hapticlist = hapticlist->next;
413 return haptic->neffects;
427 return haptic->nplaying;
441 return haptic->supported;
455 return haptic->naxes;
468 if ((haptic->supported & effect->
type) != 0)
488 return SDL_SetError(
"Haptic: Effect not supported by haptic device.");
492 for (i = 0; i < haptic->neffects; i++) {
493 if (haptic->effects[i].hweffect ==
NULL) {
501 SDL_memcpy(&haptic->effects[i].effect, effect,
507 return SDL_SetError(
"Haptic: Device has no free space left.");
516 if ((effect < 0) || (effect >= haptic->neffects)) {
535 if (data->
type != haptic->effects[effect].effect.type) {
536 return SDL_SetError(
"Haptic: Updating effect type is illegal.");
545 SDL_memcpy(&haptic->effects[effect].effect, data,
599 if (haptic->effects[effect].hweffect ==
NULL) {
617 return SDL_SetError(
"Haptic: Device does not support status queries.");
630 int real_gain, max_gain;
637 return SDL_SetError(
"Haptic: Device does not support setting gain.");
640 if ((gain < 0) || (gain > 100)) {
641 return SDL_SetError(
"Haptic: Gain must be between 0 and 100.");
652 else if (max_gain > 100)
656 real_gain = (gain * max_gain) / 100;
679 return SDL_SetError(
"Haptic: Device does not support setting autocenter.");
682 if ((autocenter < 0) || (autocenter > 100)) {
683 return SDL_SetError(
"Haptic: Autocenter must be between 0 and 100.");
704 return SDL_SetError(
"Haptic: Device does not support setting pausing.");
767 if (haptic->rumble_id >= 0) {
790 if (haptic->rumble_id >= 0) {
809 if (haptic->rumble_id < 0) {
810 return SDL_SetError(
"Haptic: Rumble effect not initialized on haptic device");
814 if (strength > 1.0
f) {
816 }
else if (strength < 0.0
f) {
819 magnitude = (
Sint16)(32767.0
f*strength);
821 efx = &haptic->rumble_effect;
829 SDL_assert(0 &&
"This should have been caught elsewhere");
849 if (haptic->rumble_id < 0) {
850 return SDL_SetError(
"Haptic: Rumble effect not initialized on haptic device");
int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
int SDL_HapticRumbleStop(SDL_Haptic *haptic)
Stops the simple rumble on a haptic device.
int SDL_HapticStopAll(SDL_Haptic *haptic)
Stops all the currently playing effects on a haptic device.
int SDL_HapticUnpause(SDL_Haptic *haptic)
Unpauses a haptic device.
const char * SDL_HapticName(int device_index)
Get the implementation dependent name of a haptic device.
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
int SDL_HapticRumbleInit(SDL_Haptic *haptic)
Initializes the haptic device for simple rumble playback.
void SDL_HapticQuit(void)
#define SDL_HAPTIC_AUTOCENTER
Device can set autocenter.
#define SDL_HAPTIC_GAIN
Device can set global gain.
int SDL_HapticRumbleSupported(SDL_Haptic *haptic)
Checks to see if rumble is supported on a haptic device.
int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
Gets the status of the current effect on the haptic device.
int SDL_SYS_HapticMouse(void)
int SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
const char * SDL_SYS_HapticName(int index)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int SDL_HapticPause(SDL_Haptic *haptic)
Pauses a haptic device.
int SDL_HapticNewEffect(SDL_Haptic *haptic, SDL_HapticEffect *effect)
Creates a new haptic effect on the device.
int SDL_SYS_HapticUnpause(SDL_Haptic *haptic)
SDL_Haptic * SDL_HapticOpen(int device_index)
Opens a haptic device for use.
int SDL_SYS_NumHaptics(void)
#define SDL_HAPTIC_SINE
Sine wave effect supported.
int SDL_HapticNumEffectsPlaying(SDL_Haptic *haptic)
Returns the number of effects a haptic device can play at the same time.
int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect)
#define SDL_HAPTIC_CARTESIAN
Uses cartesian coordinates for the direction.
int SDL_HapticIndex(SDL_Haptic *haptic)
Gets the index of a haptic device.
int SDL_HapticEffectSupported(SDL_Haptic *haptic, SDL_HapticEffect *effect)
Checks to see if effect is supported by haptic.
The generic template for any haptic effect.
int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
int SDL_JoystickIsHaptic(SDL_Joystick *joystick)
Checks to see if a joystick has haptic features.
int SDL_HapticSetGain(SDL_Haptic *haptic, int gain)
Sets the global gain of the device.
int SDL_HapticRumblePlay(SDL_Haptic *haptic, float strength, Uint32 length)
Runs simple rumble on a haptic device.
int SDL_HapticRunEffect(SDL_Haptic *haptic, int effect, Uint32 iterations)
Runs the haptic effect on its associated haptic device.
int SDL_NumHaptics(void)
Count the number of haptic devices attached to the system.
static int ValidHaptic(SDL_Haptic *haptic)
#define SDL_HAPTIC_PAUSE
Device can be paused.
int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *data)
int SDL_MouseIsHaptic(void)
Gets whether or not the current mouse has haptic capabilities.
int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
int SDL_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
Sets the global autocenter of the device.
void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
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
int SDL_SYS_HapticInit(void)
void SDL_SYS_HapticQuit(void)
#define SDL_HAPTIC_STATUS
Device can be queried for effect status.
void SDL_SYS_HapticClose(SDL_Haptic *haptic)
int SDL_SYS_HapticPause(SDL_Haptic *haptic)
SDL_HapticDirection direction
SDL_HapticLeftRight leftright
int SDL_HapticNumAxes(SDL_Haptic *haptic)
Gets the number of haptic axes the device has.
int SDL_HapticNumEffects(SDL_Haptic *haptic)
Returns the number of effects a haptic device can store.
static int ValidEffect(SDL_Haptic *haptic, int effect)
void SDL_HapticDestroyEffect(SDL_Haptic *haptic, int effect)
Destroys a haptic effect on the device.
int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
int SDL_HapticUpdateEffect(SDL_Haptic *haptic, int effect, SDL_HapticEffect *data)
Updates the properties of an effect.
int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
unsigned int SDL_HapticQuery(SDL_Haptic *haptic)
Gets the haptic device's supported features in bitwise manner.
GLuint GLsizei GLsizei * length
#define SDL_HAPTIC_LEFTRIGHT
Left/Right effect supported.
int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations)
SDL_HapticPeriodic periodic
int SDL_HapticStopEffect(SDL_Haptic *haptic, int effect)
Stops the haptic effect on its associated haptic device.
void SDL_HapticClose(SDL_Haptic *haptic)
Closes a haptic device previously opened with SDL_HapticOpen().
int SDL_HapticOpened(int device_index)
Checks if the haptic device at index has been opened.
int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *base)
SDL_Haptic * SDL_HapticOpenFromMouse(void)
Tries to open a haptic device from the current mouse.
static SDL_Haptic * SDL_haptics
SDL_Haptic * SDL_HapticOpenFromJoystick(SDL_Joystick *joystick)
Opens a haptic device for use from a joystick device.