21 #include "../SDL_internal.h" 25 #include "../joystick/SDL_joystick_c.h" 55 SDL_Haptic *hapticlist;
62 if (hapticlist == haptic) {
66 hapticlist = hapticlist->next;
72 SDL_SetError(
"Haptic: Invalid haptic device identifier");
96 SDL_SetError(
"Haptic: There are %d haptic devices available",
111 SDL_Haptic *hapticlist;
114 SDL_SetError(
"Haptic: There are %d haptic devices available",
125 if (device_index == hapticlist->index) {
130 hapticlist = hapticlist->next;
134 haptic = (SDL_Haptic *)
SDL_malloc((
sizeof *haptic));
135 if (haptic ==
NULL) {
142 haptic->rumble_id = -1;
143 haptic->index = device_index;
172 SDL_Haptic *hapticlist;
176 SDL_SetError(
"Haptic: There are %d haptic devices available",
186 if (hapticlist->index == (
Uint8) device_index) {
190 hapticlist = hapticlist->next;
206 return haptic->index;
232 if (device_index < 0) {
272 SDL_Haptic *hapticlist;
276 SDL_SetError(
"Haptic: There are %d haptic devices available",
289 SDL_SetError(
"Haptic: Joystick isn't a haptic device.");
302 hapticlist = hapticlist->next;
306 haptic = (SDL_Haptic *)
SDL_malloc((
sizeof *haptic));
307 if (haptic ==
NULL) {
314 haptic->rumble_id = -1;
316 SDL_SetError(
"Haptic: SDL_SYS_HapticOpenFromJoystick failed.");
338 SDL_Haptic *hapticlist;
339 SDL_Haptic *hapticlistprev;
347 if (--haptic->ref_count > 0) {
352 for (i = 0; i < haptic->neffects; i++) {
353 if (haptic->effects[i].hweffect !=
NULL) {
361 hapticlistprev =
NULL;
364 if (haptic == hapticlist)
366 if ( hapticlistprev )
369 hapticlistprev->next = hapticlist->next;
378 hapticlistprev = hapticlist;
379 hapticlist = hapticlist->next;
407 return haptic->neffects;
421 return haptic->nplaying;
435 return haptic->supported;
449 return haptic->naxes;
462 if ((haptic->supported & effect->
type) != 0)
482 return SDL_SetError(
"Haptic: Effect not supported by haptic device.");
486 for (i = 0; i < haptic->neffects; i++) {
487 if (haptic->effects[i].hweffect ==
NULL) {
495 SDL_memcpy(&haptic->effects[i].effect, effect,
501 return SDL_SetError(
"Haptic: Device has no free space left.");
510 if ((effect < 0) || (effect >= haptic->neffects)) {
529 if (data->
type != haptic->effects[effect].effect.type) {
530 return SDL_SetError(
"Haptic: Updating effect type is illegal.");
539 SDL_memcpy(&haptic->effects[effect].effect, data,
593 if (haptic->effects[effect].hweffect ==
NULL) {
611 return SDL_SetError(
"Haptic: Device does not support status queries.");
624 int real_gain, max_gain;
631 return SDL_SetError(
"Haptic: Device does not support setting gain.");
634 if ((gain < 0) || (gain > 100)) {
635 return SDL_SetError(
"Haptic: Gain must be between 0 and 100.");
646 else if (max_gain > 100)
650 real_gain = (gain * max_gain) / 100;
673 return SDL_SetError(
"Haptic: Device does not support setting autocenter.");
676 if ((autocenter < 0) || (autocenter > 100)) {
677 return SDL_SetError(
"Haptic: Autocenter must be between 0 and 100.");
698 return SDL_SetError(
"Haptic: Device does not support setting pausing.");
761 if (haptic->rumble_id >= 0) {
783 if (haptic->rumble_id >= 0) {
802 if (haptic->rumble_id < 0) {
803 return SDL_SetError(
"Haptic: Rumble effect not initialized on haptic device");
807 if (strength > 1.0
f) {
809 }
else if (strength < 0.0
f) {
812 magnitude = (
Sint16)(32767.0
f*strength);
814 efx = &haptic->rumble_effect;
822 SDL_assert(0 &&
"This should have been caught elsewhere");
842 if (haptic->rumble_id < 0) {
843 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)
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_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.
SDL_Haptic * SDL_HapticOpenFromJoystick(SDL_Joystick *joystick)
Opens a haptic device for use from a joystick device.