mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-11 14:44:36 +00:00
Updates the SDL library to the latest standard bugfix release
This commit is contained in:
parent
cb766f2878
commit
083d2175ea
1280 changed files with 343926 additions and 179615 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -27,15 +27,14 @@
|
|||
/* Global for SDL_windowshaptic.c */
|
||||
#if (defined(SDL_HAPTIC_DINPUT) && SDL_HAPTIC_DINPUT) || (defined(SDL_HAPTIC_XINPUT) && SDL_HAPTIC_XINPUT)
|
||||
SDL_Haptic *SDL_haptics = NULL;
|
||||
#else
|
||||
#else
|
||||
static SDL_Haptic *SDL_haptics = NULL;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Initializes the Haptic devices.
|
||||
*/
|
||||
int
|
||||
SDL_HapticInit(void)
|
||||
int SDL_HapticInit(void)
|
||||
{
|
||||
int status;
|
||||
|
||||
|
|
@ -47,12 +46,10 @@ SDL_HapticInit(void)
|
|||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Checks to see if the haptic device is valid
|
||||
*/
|
||||
static int
|
||||
ValidHaptic(SDL_Haptic * haptic)
|
||||
static int ValidHaptic(SDL_Haptic *haptic)
|
||||
{
|
||||
int valid;
|
||||
SDL_Haptic *hapticlist;
|
||||
|
|
@ -60,8 +57,7 @@ ValidHaptic(SDL_Haptic * haptic)
|
|||
valid = 0;
|
||||
if (haptic != NULL) {
|
||||
hapticlist = SDL_haptics;
|
||||
while ( hapticlist )
|
||||
{
|
||||
while (hapticlist) {
|
||||
if (hapticlist == haptic) {
|
||||
valid = 1;
|
||||
break;
|
||||
|
|
@ -78,22 +74,18 @@ ValidHaptic(SDL_Haptic * haptic)
|
|||
return valid;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns the number of available devices.
|
||||
*/
|
||||
int
|
||||
SDL_NumHaptics(void)
|
||||
int SDL_NumHaptics(void)
|
||||
{
|
||||
return SDL_SYS_NumHaptics();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Gets the name of a Haptic device by index.
|
||||
*/
|
||||
const char *
|
||||
SDL_HapticName(int device_index)
|
||||
const char *SDL_HapticName(int device_index)
|
||||
{
|
||||
if ((device_index < 0) || (device_index >= SDL_NumHaptics())) {
|
||||
SDL_SetError("Haptic: There are %d haptic devices available",
|
||||
|
|
@ -103,12 +95,10 @@ SDL_HapticName(int device_index)
|
|||
return SDL_SYS_HapticName(device_index);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Opens a Haptic device.
|
||||
*/
|
||||
SDL_Haptic *
|
||||
SDL_HapticOpen(int device_index)
|
||||
SDL_Haptic *SDL_HapticOpen(int device_index)
|
||||
{
|
||||
SDL_Haptic *haptic;
|
||||
SDL_Haptic *hapticlist;
|
||||
|
|
@ -121,10 +111,9 @@ SDL_HapticOpen(int device_index)
|
|||
|
||||
hapticlist = SDL_haptics;
|
||||
/* If the haptic is already open, return it
|
||||
* TODO: Should we create haptic instance IDs like the Joystick API?
|
||||
*/
|
||||
while ( hapticlist )
|
||||
{
|
||||
* TODO: Should we create haptic instance IDs like the Joystick API?
|
||||
*/
|
||||
while (hapticlist) {
|
||||
if (device_index == hapticlist->index) {
|
||||
haptic = hapticlist;
|
||||
++haptic->ref_count;
|
||||
|
|
@ -134,14 +123,14 @@ SDL_HapticOpen(int device_index)
|
|||
}
|
||||
|
||||
/* Create the haptic device */
|
||||
haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
|
||||
haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic));
|
||||
if (haptic == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize the haptic device */
|
||||
SDL_memset(haptic, 0, (sizeof *haptic));
|
||||
SDL_memset(haptic, 0, sizeof(*haptic));
|
||||
haptic->rumble_id = -1;
|
||||
haptic->index = device_index;
|
||||
if (SDL_SYS_HapticOpen(haptic) < 0) {
|
||||
|
|
@ -156,20 +145,20 @@ SDL_HapticOpen(int device_index)
|
|||
SDL_haptics = haptic;
|
||||
|
||||
/* Disable autocenter and set gain to max. */
|
||||
if (haptic->supported & SDL_HAPTIC_GAIN)
|
||||
if (haptic->supported & SDL_HAPTIC_GAIN) {
|
||||
SDL_HapticSetGain(haptic, 100);
|
||||
if (haptic->supported & SDL_HAPTIC_AUTOCENTER)
|
||||
}
|
||||
if (haptic->supported & SDL_HAPTIC_AUTOCENTER) {
|
||||
SDL_HapticSetAutocenter(haptic, 0);
|
||||
}
|
||||
|
||||
return haptic;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns 1 if the device has been opened.
|
||||
*/
|
||||
int
|
||||
SDL_HapticOpened(int device_index)
|
||||
int SDL_HapticOpened(int device_index)
|
||||
{
|
||||
int opened;
|
||||
SDL_Haptic *hapticlist;
|
||||
|
|
@ -184,9 +173,8 @@ SDL_HapticOpened(int device_index)
|
|||
opened = 0;
|
||||
hapticlist = SDL_haptics;
|
||||
/* TODO Should this use an instance ID? */
|
||||
while ( hapticlist )
|
||||
{
|
||||
if (hapticlist->index == (Uint8) device_index) {
|
||||
while (hapticlist) {
|
||||
if (hapticlist->index == (Uint8)device_index) {
|
||||
opened = 1;
|
||||
break;
|
||||
}
|
||||
|
|
@ -195,12 +183,10 @@ SDL_HapticOpened(int device_index)
|
|||
return opened;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns the index to a haptic device.
|
||||
*/
|
||||
int
|
||||
SDL_HapticIndex(SDL_Haptic * haptic)
|
||||
int SDL_HapticIndex(SDL_Haptic *haptic)
|
||||
{
|
||||
if (!ValidHaptic(haptic)) {
|
||||
return -1;
|
||||
|
|
@ -209,24 +195,21 @@ SDL_HapticIndex(SDL_Haptic * haptic)
|
|||
return haptic->index;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns SDL_TRUE if mouse is haptic, SDL_FALSE if it isn't.
|
||||
*/
|
||||
int
|
||||
SDL_MouseIsHaptic(void)
|
||||
int SDL_MouseIsHaptic(void)
|
||||
{
|
||||
if (SDL_SYS_HapticMouse() < 0)
|
||||
if (SDL_SYS_HapticMouse() < 0) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns the haptic device if mouse is haptic or NULL elsewise.
|
||||
*/
|
||||
SDL_Haptic *
|
||||
SDL_HapticOpenFromMouse(void)
|
||||
SDL_Haptic *SDL_HapticOpenFromMouse(void)
|
||||
{
|
||||
int device_index;
|
||||
|
||||
|
|
@ -240,36 +223,38 @@ SDL_HapticOpenFromMouse(void)
|
|||
return SDL_HapticOpen(device_index);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns SDL_TRUE if joystick has haptic features.
|
||||
*/
|
||||
int
|
||||
SDL_JoystickIsHaptic(SDL_Joystick * joystick)
|
||||
int SDL_JoystickIsHaptic(SDL_Joystick *joystick)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Must be a valid joystick */
|
||||
if (!SDL_PrivateJoystickValid(joystick)) {
|
||||
return -1;
|
||||
SDL_LockJoysticks();
|
||||
{
|
||||
/* Must be a valid joystick */
|
||||
if (!SDL_PrivateJoystickValid(joystick)) {
|
||||
SDL_UnlockJoysticks();
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = SDL_SYS_JoystickIsHaptic(joystick);
|
||||
}
|
||||
SDL_UnlockJoysticks();
|
||||
|
||||
if (ret > 0) {
|
||||
return SDL_TRUE;
|
||||
} else if (ret == 0) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
ret = SDL_SYS_JoystickIsHaptic(joystick);
|
||||
|
||||
if (ret > 0)
|
||||
return SDL_TRUE;
|
||||
else if (ret == 0)
|
||||
return SDL_FALSE;
|
||||
else
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Opens a haptic device from a joystick.
|
||||
*/
|
||||
SDL_Haptic *
|
||||
SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
|
||||
SDL_Haptic *SDL_HapticOpenFromJoystick(SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_Haptic *haptic;
|
||||
SDL_Haptic *hapticlist;
|
||||
|
|
@ -281,45 +266,53 @@ SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Must be a valid joystick */
|
||||
if (!SDL_PrivateJoystickValid(joystick)) {
|
||||
SDL_SetError("Haptic: Joystick isn't valid.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Joystick must be haptic */
|
||||
if (SDL_SYS_JoystickIsHaptic(joystick) <= 0) {
|
||||
SDL_SetError("Haptic: Joystick isn't a haptic device.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hapticlist = SDL_haptics;
|
||||
/* Check to see if joystick's haptic is already open */
|
||||
while ( hapticlist )
|
||||
SDL_LockJoysticks();
|
||||
{
|
||||
if (SDL_SYS_JoystickSameHaptic(hapticlist, joystick)) {
|
||||
haptic = hapticlist;
|
||||
++haptic->ref_count;
|
||||
return haptic;
|
||||
/* Must be a valid joystick */
|
||||
if (!SDL_PrivateJoystickValid(joystick)) {
|
||||
SDL_SetError("Haptic: Joystick isn't valid.");
|
||||
SDL_UnlockJoysticks();
|
||||
return NULL;
|
||||
}
|
||||
hapticlist = hapticlist->next;
|
||||
}
|
||||
|
||||
/* Create the haptic device */
|
||||
haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
|
||||
if (haptic == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
/* Joystick must be haptic */
|
||||
if (SDL_SYS_JoystickIsHaptic(joystick) <= 0) {
|
||||
SDL_SetError("Haptic: Joystick isn't a haptic device.");
|
||||
SDL_UnlockJoysticks();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize the haptic device */
|
||||
SDL_memset(haptic, 0, sizeof(SDL_Haptic));
|
||||
haptic->rumble_id = -1;
|
||||
if (SDL_SYS_HapticOpenFromJoystick(haptic, joystick) < 0) {
|
||||
SDL_SetError("Haptic: SDL_SYS_HapticOpenFromJoystick failed.");
|
||||
SDL_free(haptic);
|
||||
return NULL;
|
||||
hapticlist = SDL_haptics;
|
||||
/* Check to see if joystick's haptic is already open */
|
||||
while (hapticlist) {
|
||||
if (SDL_SYS_JoystickSameHaptic(hapticlist, joystick)) {
|
||||
haptic = hapticlist;
|
||||
++haptic->ref_count;
|
||||
SDL_UnlockJoysticks();
|
||||
return haptic;
|
||||
}
|
||||
hapticlist = hapticlist->next;
|
||||
}
|
||||
|
||||
/* Create the haptic device */
|
||||
haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic));
|
||||
if (haptic == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_UnlockJoysticks();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize the haptic device */
|
||||
SDL_memset(haptic, 0, sizeof(SDL_Haptic));
|
||||
haptic->rumble_id = -1;
|
||||
if (SDL_SYS_HapticOpenFromJoystick(haptic, joystick) < 0) {
|
||||
SDL_SetError("Haptic: SDL_SYS_HapticOpenFromJoystick failed.");
|
||||
SDL_free(haptic);
|
||||
SDL_UnlockJoysticks();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
SDL_UnlockJoysticks();
|
||||
|
||||
/* Add haptic to list */
|
||||
++haptic->ref_count;
|
||||
|
|
@ -330,12 +323,10 @@ SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
|
|||
return haptic;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Closes a SDL_Haptic device.
|
||||
*/
|
||||
void
|
||||
SDL_HapticClose(SDL_Haptic * haptic)
|
||||
void SDL_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
int i;
|
||||
SDL_Haptic *hapticlist;
|
||||
|
|
@ -362,17 +353,12 @@ SDL_HapticClose(SDL_Haptic * haptic)
|
|||
/* Remove from the list */
|
||||
hapticlist = SDL_haptics;
|
||||
hapticlistprev = NULL;
|
||||
while ( hapticlist )
|
||||
{
|
||||
if (haptic == hapticlist)
|
||||
{
|
||||
if ( hapticlistprev )
|
||||
{
|
||||
while (hapticlist) {
|
||||
if (haptic == hapticlist) {
|
||||
if (hapticlistprev) {
|
||||
/* unlink this entry */
|
||||
hapticlistprev->next = hapticlist->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SDL_haptics = haptic->next;
|
||||
}
|
||||
|
||||
|
|
@ -389,8 +375,7 @@ SDL_HapticClose(SDL_Haptic * haptic)
|
|||
/*
|
||||
* Cleans up after the subsystem.
|
||||
*/
|
||||
void
|
||||
SDL_HapticQuit(void)
|
||||
void SDL_HapticQuit(void)
|
||||
{
|
||||
while (SDL_haptics) {
|
||||
SDL_HapticClose(SDL_haptics);
|
||||
|
|
@ -402,8 +387,7 @@ SDL_HapticQuit(void)
|
|||
/*
|
||||
* Returns the number of effects a haptic device has.
|
||||
*/
|
||||
int
|
||||
SDL_HapticNumEffects(SDL_Haptic * haptic)
|
||||
int SDL_HapticNumEffects(SDL_Haptic *haptic)
|
||||
{
|
||||
if (!ValidHaptic(haptic)) {
|
||||
return -1;
|
||||
|
|
@ -412,12 +396,10 @@ SDL_HapticNumEffects(SDL_Haptic * haptic)
|
|||
return haptic->neffects;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns the number of effects a haptic device can play.
|
||||
*/
|
||||
int
|
||||
SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic)
|
||||
int SDL_HapticNumEffectsPlaying(SDL_Haptic *haptic)
|
||||
{
|
||||
if (!ValidHaptic(haptic)) {
|
||||
return -1;
|
||||
|
|
@ -426,12 +408,10 @@ SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic)
|
|||
return haptic->nplaying;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns supported effects by the device.
|
||||
*/
|
||||
unsigned int
|
||||
SDL_HapticQuery(SDL_Haptic * haptic)
|
||||
unsigned int SDL_HapticQuery(SDL_Haptic *haptic)
|
||||
{
|
||||
if (!ValidHaptic(haptic)) {
|
||||
return 0; /* same as if no effects were supported */
|
||||
|
|
@ -440,12 +420,10 @@ SDL_HapticQuery(SDL_Haptic * haptic)
|
|||
return haptic->supported;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns the number of axis on the device.
|
||||
*/
|
||||
int
|
||||
SDL_HapticNumAxes(SDL_Haptic * haptic)
|
||||
int SDL_HapticNumAxes(SDL_Haptic *haptic)
|
||||
{
|
||||
if (!ValidHaptic(haptic)) {
|
||||
return -1;
|
||||
|
|
@ -457,23 +435,22 @@ SDL_HapticNumAxes(SDL_Haptic * haptic)
|
|||
/*
|
||||
* Checks to see if the device can support the effect.
|
||||
*/
|
||||
int
|
||||
SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
|
||||
int SDL_HapticEffectSupported(SDL_Haptic *haptic, SDL_HapticEffect *effect)
|
||||
{
|
||||
if (!ValidHaptic(haptic)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((haptic->supported & effect->type) != 0)
|
||||
if ((haptic->supported & effect->type) != 0) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates a new haptic effect.
|
||||
*/
|
||||
int
|
||||
SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
|
||||
int SDL_HapticNewEffect(SDL_Haptic *haptic, SDL_HapticEffect *effect)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -492,9 +469,8 @@ SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
|
|||
if (haptic->effects[i].hweffect == NULL) {
|
||||
|
||||
/* Now let the backend create the real effect */
|
||||
if (SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect)
|
||||
!= 0) {
|
||||
return -1; /* Backend failed to create effect */
|
||||
if (SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect) != 0) {
|
||||
return -1; /* Backend failed to create effect */
|
||||
}
|
||||
|
||||
SDL_memcpy(&haptic->effects[i].effect, effect,
|
||||
|
|
@ -509,8 +485,7 @@ SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
|
|||
/*
|
||||
* Checks to see if an effect is valid.
|
||||
*/
|
||||
static int
|
||||
ValidEffect(SDL_Haptic * haptic, int effect)
|
||||
static int ValidEffect(SDL_Haptic *haptic, int effect)
|
||||
{
|
||||
if ((effect < 0) || (effect >= haptic->neffects)) {
|
||||
SDL_SetError("Haptic: Invalid effect identifier.");
|
||||
|
|
@ -522,9 +497,8 @@ ValidEffect(SDL_Haptic * haptic, int effect)
|
|||
/*
|
||||
* Updates an effect.
|
||||
*/
|
||||
int
|
||||
SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect,
|
||||
SDL_HapticEffect * data)
|
||||
int SDL_HapticUpdateEffect(SDL_Haptic *haptic, int effect,
|
||||
SDL_HapticEffect *data)
|
||||
{
|
||||
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
|
||||
return -1;
|
||||
|
|
@ -546,20 +520,17 @@ SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect,
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Runs the haptic effect on the device.
|
||||
*/
|
||||
int
|
||||
SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, Uint32 iterations)
|
||||
int SDL_HapticRunEffect(SDL_Haptic *haptic, int effect, Uint32 iterations)
|
||||
{
|
||||
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Run the effect */
|
||||
if (SDL_SYS_HapticRunEffect(haptic, &haptic->effects[effect], iterations)
|
||||
< 0) {
|
||||
if (SDL_SYS_HapticRunEffect(haptic, &haptic->effects[effect], iterations) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -569,8 +540,7 @@ SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, Uint32 iterations)
|
|||
/*
|
||||
* Stops the haptic effect on the device.
|
||||
*/
|
||||
int
|
||||
SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
|
||||
int SDL_HapticStopEffect(SDL_Haptic *haptic, int effect)
|
||||
{
|
||||
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
|
||||
return -1;
|
||||
|
|
@ -587,8 +557,7 @@ SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
|
|||
/*
|
||||
* Gets rid of a haptic effect.
|
||||
*/
|
||||
void
|
||||
SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
|
||||
void SDL_HapticDestroyEffect(SDL_Haptic *haptic, int effect)
|
||||
{
|
||||
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
|
||||
return;
|
||||
|
|
@ -605,14 +574,13 @@ SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
|
|||
/*
|
||||
* Gets the status of a haptic effect.
|
||||
*/
|
||||
int
|
||||
SDL_HapticGetEffectStatus(SDL_Haptic * haptic, int effect)
|
||||
int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
|
||||
{
|
||||
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) {
|
||||
if (!(haptic->supported & SDL_HAPTIC_STATUS)) {
|
||||
return SDL_SetError("Haptic: Device does not support status queries.");
|
||||
}
|
||||
|
||||
|
|
@ -622,8 +590,7 @@ SDL_HapticGetEffectStatus(SDL_Haptic * haptic, int effect)
|
|||
/*
|
||||
* Sets the global gain of the device.
|
||||
*/
|
||||
int
|
||||
SDL_HapticSetGain(SDL_Haptic * haptic, int gain)
|
||||
int SDL_HapticSetGain(SDL_Haptic *haptic, int gain)
|
||||
{
|
||||
const char *env;
|
||||
int real_gain, max_gain;
|
||||
|
|
@ -632,7 +599,7 @@ SDL_HapticSetGain(SDL_Haptic * haptic, int gain)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) {
|
||||
if (!(haptic->supported & SDL_HAPTIC_GAIN)) {
|
||||
return SDL_SetError("Haptic: Device does not support setting gain.");
|
||||
}
|
||||
|
||||
|
|
@ -646,10 +613,11 @@ SDL_HapticSetGain(SDL_Haptic * haptic, int gain)
|
|||
max_gain = SDL_atoi(env);
|
||||
|
||||
/* Check for sanity. */
|
||||
if (max_gain < 0)
|
||||
if (max_gain < 0) {
|
||||
max_gain = 0;
|
||||
else if (max_gain > 100)
|
||||
} else if (max_gain > 100) {
|
||||
max_gain = 100;
|
||||
}
|
||||
|
||||
/* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */
|
||||
real_gain = (gain * max_gain) / 100;
|
||||
|
|
@ -667,14 +635,13 @@ SDL_HapticSetGain(SDL_Haptic * haptic, int gain)
|
|||
/*
|
||||
* Makes the device autocenter, 0 disables.
|
||||
*/
|
||||
int
|
||||
SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
||||
int SDL_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
|
||||
{
|
||||
if (!ValidHaptic(haptic)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) {
|
||||
if (!(haptic->supported & SDL_HAPTIC_AUTOCENTER)) {
|
||||
return SDL_SetError("Haptic: Device does not support setting autocenter.");
|
||||
}
|
||||
|
||||
|
|
@ -692,14 +659,13 @@ SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
|||
/*
|
||||
* Pauses the haptic device.
|
||||
*/
|
||||
int
|
||||
SDL_HapticPause(SDL_Haptic * haptic)
|
||||
int SDL_HapticPause(SDL_Haptic *haptic)
|
||||
{
|
||||
if (!ValidHaptic(haptic)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) {
|
||||
if (!(haptic->supported & SDL_HAPTIC_PAUSE)) {
|
||||
return SDL_SetError("Haptic: Device does not support setting pausing.");
|
||||
}
|
||||
|
||||
|
|
@ -709,15 +675,14 @@ SDL_HapticPause(SDL_Haptic * haptic)
|
|||
/*
|
||||
* Unpauses the haptic device.
|
||||
*/
|
||||
int
|
||||
SDL_HapticUnpause(SDL_Haptic * haptic)
|
||||
int SDL_HapticUnpause(SDL_Haptic *haptic)
|
||||
{
|
||||
if (!ValidHaptic(haptic)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) {
|
||||
return 0; /* Not going to be paused, so we pretend it's unpaused. */
|
||||
if (!(haptic->supported & SDL_HAPTIC_PAUSE)) {
|
||||
return 0; /* Not going to be paused, so we pretend it's unpaused. */
|
||||
}
|
||||
|
||||
return SDL_SYS_HapticUnpause(haptic);
|
||||
|
|
@ -726,8 +691,7 @@ SDL_HapticUnpause(SDL_Haptic * haptic)
|
|||
/*
|
||||
* Stops all the currently playing effects.
|
||||
*/
|
||||
int
|
||||
SDL_HapticStopAll(SDL_Haptic * haptic)
|
||||
int SDL_HapticStopAll(SDL_Haptic *haptic)
|
||||
{
|
||||
if (!ValidHaptic(haptic)) {
|
||||
return -1;
|
||||
|
|
@ -739,22 +703,20 @@ SDL_HapticStopAll(SDL_Haptic * haptic)
|
|||
/*
|
||||
* Checks to see if rumble is supported.
|
||||
*/
|
||||
int
|
||||
SDL_HapticRumbleSupported(SDL_Haptic * haptic)
|
||||
int SDL_HapticRumbleSupported(SDL_Haptic *haptic)
|
||||
{
|
||||
if (!ValidHaptic(haptic)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Most things can use SINE, but XInput only has LEFTRIGHT. */
|
||||
return ((haptic->supported & (SDL_HAPTIC_SINE|SDL_HAPTIC_LEFTRIGHT)) != 0);
|
||||
return (haptic->supported & (SDL_HAPTIC_SINE | SDL_HAPTIC_LEFTRIGHT)) != 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initializes the haptic device for simple rumble playback.
|
||||
*/
|
||||
int
|
||||
SDL_HapticRumbleInit(SDL_Haptic * haptic)
|
||||
int SDL_HapticRumbleInit(SDL_Haptic *haptic)
|
||||
{
|
||||
SDL_HapticEffect *efx = &haptic->rumble_effect;
|
||||
|
||||
|
|
@ -776,7 +738,7 @@ SDL_HapticRumbleInit(SDL_Haptic * haptic)
|
|||
efx->periodic.length = 5000;
|
||||
efx->periodic.attack_length = 0;
|
||||
efx->periodic.fade_length = 0;
|
||||
} else if (haptic->supported & SDL_HAPTIC_LEFTRIGHT) { /* XInput? */
|
||||
} else if (haptic->supported & SDL_HAPTIC_LEFTRIGHT) { /* XInput? */
|
||||
efx->type = SDL_HAPTIC_LEFTRIGHT;
|
||||
efx->leftright.length = 5000;
|
||||
efx->leftright.large_magnitude = 0x4000;
|
||||
|
|
@ -795,8 +757,7 @@ SDL_HapticRumbleInit(SDL_Haptic * haptic)
|
|||
/*
|
||||
* Runs simple rumble on a haptic device
|
||||
*/
|
||||
int
|
||||
SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length)
|
||||
int SDL_HapticRumblePlay(SDL_Haptic *haptic, float strength, Uint32 length)
|
||||
{
|
||||
SDL_HapticEffect *efx;
|
||||
Sint16 magnitude;
|
||||
|
|
@ -815,7 +776,7 @@ SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length)
|
|||
} else if (strength < 0.0f) {
|
||||
strength = 0.0f;
|
||||
}
|
||||
magnitude = (Sint16)(32767.0f*strength);
|
||||
magnitude = (Sint16)(32767.0f * strength);
|
||||
|
||||
efx = &haptic->rumble_effect;
|
||||
if (efx->type == SDL_HAPTIC_SINE) {
|
||||
|
|
@ -838,8 +799,7 @@ SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length)
|
|||
/*
|
||||
* Stops the simple rumble on a haptic device.
|
||||
*/
|
||||
int
|
||||
SDL_HapticRumbleStop(SDL_Haptic * haptic)
|
||||
int SDL_HapticRumbleStop(SDL_Haptic *haptic)
|
||||
{
|
||||
if (!ValidHaptic(haptic)) {
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -26,11 +26,15 @@
|
|||
|
||||
#include "SDL_haptic.h"
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct haptic_effect
|
||||
{
|
||||
SDL_HapticEffect effect; /* The current event */
|
||||
struct haptic_hweffect *hweffect; /* The hardware behind the event */
|
||||
SDL_HapticEffect effect; /* The current event */
|
||||
struct haptic_hweffect *hweffect; /* The hardware behind the event */
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -38,20 +42,20 @@ struct haptic_effect
|
|||
*/
|
||||
struct _SDL_Haptic
|
||||
{
|
||||
Uint8 index; /* Stores index it is attached to */
|
||||
Uint8 index; /* Stores index it is attached to */
|
||||
|
||||
struct haptic_effect *effects; /* Allocated effects */
|
||||
int neffects; /* Maximum amount of effects */
|
||||
int nplaying; /* Maximum amount of effects to play at the same time */
|
||||
unsigned int supported; /* Supported effects */
|
||||
int naxes; /* Number of axes on the device. */
|
||||
struct haptic_effect *effects; /* Allocated effects */
|
||||
int neffects; /* Maximum amount of effects */
|
||||
int nplaying; /* Maximum amount of effects to play at the same time */
|
||||
unsigned int supported; /* Supported effects */
|
||||
int naxes; /* Number of axes on the device. */
|
||||
|
||||
struct haptic_hwdata *hwdata; /* Driver dependent */
|
||||
int ref_count; /* Count for multiple opens */
|
||||
struct haptic_hwdata *hwdata; /* Driver dependent */
|
||||
int ref_count; /* Count for multiple opens */
|
||||
|
||||
int rumble_id; /* ID of rumble effect for simple rumble API. */
|
||||
int rumble_id; /* ID of rumble effect for simple rumble API. */
|
||||
SDL_HapticEffect rumble_effect; /* Rumble effect. */
|
||||
struct _SDL_Haptic *next; /* pointer to next haptic we have allocated */
|
||||
struct _SDL_Haptic *next; /* pointer to next haptic we have allocated */
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -75,7 +79,7 @@ extern const char *SDL_SYS_HapticName(int index);
|
|||
*
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
extern int SDL_SYS_HapticOpen(SDL_Haptic * haptic);
|
||||
extern int SDL_SYS_HapticOpen(SDL_Haptic *haptic);
|
||||
|
||||
/*
|
||||
* Returns the index of the haptic core pointer or -1 if none is found.
|
||||
|
|
@ -88,7 +92,7 @@ int SDL_SYS_HapticMouse(void);
|
|||
* Returns >0 if haptic capabilities are detected, 0 if haptic
|
||||
* capabilities aren't detected and -1 on error.
|
||||
*/
|
||||
extern int SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick);
|
||||
extern int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick);
|
||||
|
||||
/*
|
||||
* Opens the haptic device for usage using the same device as
|
||||
|
|
@ -96,20 +100,20 @@ extern int SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick);
|
|||
*
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
extern int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic,
|
||||
SDL_Joystick * joystick);
|
||||
extern int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic,
|
||||
SDL_Joystick *joystick);
|
||||
/*
|
||||
* Checks to see if haptic device and joystick device are the same.
|
||||
*
|
||||
* Returns 1 if they are the same, 0 if they aren't.
|
||||
*/
|
||||
extern int SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic,
|
||||
SDL_Joystick * joystick);
|
||||
extern int SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic,
|
||||
SDL_Joystick *joystick);
|
||||
|
||||
/*
|
||||
* Closes a haptic device after usage.
|
||||
*/
|
||||
extern void SDL_SYS_HapticClose(SDL_Haptic * haptic);
|
||||
extern void SDL_SYS_HapticClose(SDL_Haptic *haptic);
|
||||
|
||||
/*
|
||||
* Performs a cleanup on the haptic subsystem.
|
||||
|
|
@ -122,9 +126,9 @@ extern void SDL_SYS_HapticQuit(void);
|
|||
*
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
extern int SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
|
||||
extern int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect,
|
||||
SDL_HapticEffect * base);
|
||||
SDL_HapticEffect *base);
|
||||
|
||||
/*
|
||||
* Updates the haptic effect on the haptic device using data
|
||||
|
|
@ -132,16 +136,16 @@ extern int SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
|
|||
*
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
extern int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
|
||||
extern int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect,
|
||||
SDL_HapticEffect * data);
|
||||
SDL_HapticEffect *data);
|
||||
|
||||
/*
|
||||
* Runs the effect on the haptic device.
|
||||
*
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic,
|
||||
extern int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect,
|
||||
Uint32 iterations);
|
||||
|
||||
|
|
@ -150,13 +154,13 @@ extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic,
|
|||
*
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
extern int SDL_SYS_HapticStopEffect(SDL_Haptic * haptic,
|
||||
extern int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect);
|
||||
|
||||
/*
|
||||
* Cleanups up the effect on the haptic device.
|
||||
*/
|
||||
extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic,
|
||||
extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect);
|
||||
|
||||
/*
|
||||
|
|
@ -165,7 +169,7 @@ extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic,
|
|||
* Returns 0 if device is stopped, >0 if device is playing and
|
||||
* -1 on error.
|
||||
*/
|
||||
extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
|
||||
extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect);
|
||||
|
||||
/*
|
||||
|
|
@ -173,35 +177,40 @@ extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
|
|||
*
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
extern int SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain);
|
||||
extern int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain);
|
||||
|
||||
/*
|
||||
* Sets the autocenter feature of the haptic device.
|
||||
*
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
extern int SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
|
||||
extern int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter);
|
||||
|
||||
/*
|
||||
* Pauses the haptic device.
|
||||
*
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
extern int SDL_SYS_HapticPause(SDL_Haptic * haptic);
|
||||
extern int SDL_SYS_HapticPause(SDL_Haptic *haptic);
|
||||
|
||||
/*
|
||||
* Unpauses the haptic device.
|
||||
*
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
extern int SDL_SYS_HapticUnpause(SDL_Haptic * haptic);
|
||||
extern int SDL_SYS_HapticUnpause(SDL_Haptic *haptic);
|
||||
|
||||
/*
|
||||
* Stops all the currently playing haptic effects on the device.
|
||||
*
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
extern int SDL_SYS_HapticStopAll(SDL_Haptic * haptic);
|
||||
extern int SDL_SYS_HapticStopAll(SDL_Haptic *haptic);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_syshaptic_h_ */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -44,9 +44,7 @@ static SDL_hapticlist_item *SDL_hapticlist = NULL;
|
|||
static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
|
||||
static int numhaptics = 0;
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticInit(void)
|
||||
int SDL_SYS_HapticInit(void)
|
||||
{
|
||||
/* Support for device connect/disconnect is API >= 16 only,
|
||||
* so we poll every three seconds
|
||||
|
|
@ -57,17 +55,15 @@ SDL_SYS_HapticInit(void)
|
|||
timeout = SDL_GetTicks() + 3000;
|
||||
Android_JNI_PollHapticDevices();
|
||||
}
|
||||
return (numhaptics);
|
||||
return numhaptics;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_NumHaptics(void)
|
||||
int SDL_SYS_NumHaptics(void)
|
||||
{
|
||||
return (numhaptics);
|
||||
return numhaptics;
|
||||
}
|
||||
|
||||
static SDL_hapticlist_item *
|
||||
HapticByOrder(int index)
|
||||
static SDL_hapticlist_item *HapticByOrder(int index)
|
||||
{
|
||||
SDL_hapticlist_item *item = SDL_hapticlist;
|
||||
if ((index < 0) || (index >= numhaptics)) {
|
||||
|
|
@ -81,8 +77,7 @@ HapticByOrder(int index)
|
|||
return item;
|
||||
}
|
||||
|
||||
static SDL_hapticlist_item *
|
||||
HapticByDevId (int device_id)
|
||||
static SDL_hapticlist_item *HapticByDevId(int device_id)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
for (item = SDL_hapticlist; item != NULL; item = item->next) {
|
||||
|
|
@ -94,22 +89,19 @@ HapticByDevId (int device_id)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
SDL_SYS_HapticName(int index)
|
||||
const char *SDL_SYS_HapticName(int index)
|
||||
{
|
||||
SDL_hapticlist_item *item = HapticByOrder(index);
|
||||
if (item == NULL ) {
|
||||
if (item == NULL) {
|
||||
SDL_SetError("No such device");
|
||||
return NULL;
|
||||
}
|
||||
return item->name;
|
||||
}
|
||||
|
||||
|
||||
static SDL_hapticlist_item *
|
||||
OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item *item)
|
||||
static SDL_hapticlist_item *OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item *item)
|
||||
{
|
||||
if (item == NULL ) {
|
||||
if (item == NULL) {
|
||||
SDL_SetError("No such device");
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -124,75 +116,59 @@ OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item *item)
|
|||
haptic->supported = SDL_HAPTIC_LEFTRIGHT;
|
||||
haptic->neffects = 1;
|
||||
haptic->nplaying = haptic->neffects;
|
||||
haptic->effects = (struct haptic_effect *)SDL_malloc (sizeof (struct haptic_effect) * haptic->neffects);
|
||||
haptic->effects = (struct haptic_effect *)SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
|
||||
if (haptic->effects == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
SDL_memset(haptic->effects, 0, sizeof (struct haptic_effect) * haptic->neffects);
|
||||
SDL_memset(haptic->effects, 0, sizeof(struct haptic_effect) * haptic->neffects);
|
||||
return item;
|
||||
}
|
||||
|
||||
static SDL_hapticlist_item *
|
||||
OpenHapticByOrder(SDL_Haptic *haptic, int index)
|
||||
static SDL_hapticlist_item *OpenHapticByOrder(SDL_Haptic *haptic, int index)
|
||||
{
|
||||
return OpenHaptic (haptic, HapticByOrder(index));
|
||||
return OpenHaptic(haptic, HapticByOrder(index));
|
||||
}
|
||||
|
||||
static SDL_hapticlist_item *
|
||||
OpenHapticByDevId(SDL_Haptic *haptic, int device_id)
|
||||
static SDL_hapticlist_item *OpenHapticByDevId(SDL_Haptic *haptic, int device_id)
|
||||
{
|
||||
return OpenHaptic (haptic, HapticByDevId(device_id));
|
||||
return OpenHaptic(haptic, HapticByDevId(device_id));
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_HapticOpen(SDL_Haptic *haptic)
|
||||
int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
|
||||
{
|
||||
return (OpenHapticByOrder(haptic, haptic->index) == NULL ? -1 : 0);
|
||||
return OpenHapticByOrder(haptic, haptic->index) == NULL ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticMouse(void)
|
||||
int SDL_SYS_HapticMouse(void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
|
||||
int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
item = HapticByDevId(((joystick_hwdata *)joystick->hwdata)->device_id);
|
||||
return (item != NULL) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
return (OpenHapticByDevId(haptic, ((joystick_hwdata *)joystick->hwdata)->device_id) == NULL ? -1 : 0);
|
||||
return OpenHapticByDevId(haptic, ((joystick_hwdata *)joystick->hwdata)->device_id) == NULL ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
return (((SDL_hapticlist_item *)haptic->hwdata)->device_id == ((joystick_hwdata *)joystick->hwdata)->device_id ? 1 : 0);
|
||||
return ((SDL_hapticlist_item *)haptic->hwdata)->device_id == ((joystick_hwdata *)joystick->hwdata)->device_id ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SDL_SYS_HapticClose(SDL_Haptic * haptic)
|
||||
void SDL_SYS_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
((SDL_hapticlist_item *)haptic->hwdata)->haptic = NULL;
|
||||
haptic->hwdata = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SDL_SYS_HapticQuit(void)
|
||||
void SDL_SYS_HapticQuit(void)
|
||||
{
|
||||
/* We don't have any way to scan for joysticks (and their vibrators) at init, so don't wipe the list
|
||||
* of joysticks here in case this is a reinit.
|
||||
|
|
@ -212,107 +188,83 @@ SDL_SYS_HapticQuit(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
|
||||
struct haptic_effect *effect, SDL_HapticEffect * base)
|
||||
int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect, SDL_HapticEffect *base)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
|
||||
struct haptic_effect *effect,
|
||||
SDL_HapticEffect * data)
|
||||
int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect,
|
||||
SDL_HapticEffect *data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
||||
Uint32 iterations)
|
||||
int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
Uint32 iterations)
|
||||
{
|
||||
float large = effect->effect.leftright.large_magnitude / 32767.0f;
|
||||
float small = effect->effect.leftright.small_magnitude / 32767.0f;
|
||||
|
||||
float total = (large * 0.6f) + (small * 0.4f);
|
||||
|
||||
Android_JNI_HapticRun (((SDL_hapticlist_item *)haptic->hwdata)->device_id, total, effect->effect.leftright.length);
|
||||
Android_JNI_HapticRun(((SDL_hapticlist_item *)haptic->hwdata)->device_id, total, effect->effect.leftright.length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
Android_JNI_HapticStop (((SDL_hapticlist_item *)haptic->hwdata)->device_id);
|
||||
Android_JNI_HapticStop(((SDL_hapticlist_item *)haptic->hwdata)->device_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
|
||||
struct haptic_effect *effect)
|
||||
int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
|
||||
int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
||||
int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_HapticPause(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticPause(SDL_Haptic *haptic)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticUnpause(SDL_Haptic *haptic)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
Android_AddHaptic(int device_id, const char *name)
|
||||
int Android_AddHaptic(int device_id, const char *name)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
item = (SDL_hapticlist_item *) SDL_calloc(1, sizeof (SDL_hapticlist_item));
|
||||
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
|
||||
if (item == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
item->device_id = device_id;
|
||||
item->name = SDL_strdup (name);
|
||||
item->name = SDL_strdup(name);
|
||||
if (item->name == NULL) {
|
||||
SDL_free (item);
|
||||
SDL_free(item);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -327,8 +279,7 @@ Android_AddHaptic(int device_id, const char *name)
|
|||
return numhaptics;
|
||||
}
|
||||
|
||||
int
|
||||
Android_RemoveHaptic(int device_id)
|
||||
int Android_RemoveHaptic(int device_id)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
SDL_hapticlist_item *prev = NULL;
|
||||
|
|
@ -361,7 +312,6 @@ Android_RemoveHaptic(int device_id)
|
|||
return -1;
|
||||
}
|
||||
|
||||
|
||||
#endif /* SDL_HAPTIC_ANDROID */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
#include <ForceFeedback/ForceFeedbackConstants.h>
|
||||
|
||||
#ifndef IO_OBJECT_NULL
|
||||
#define IO_OBJECT_NULL ((io_service_t)0)
|
||||
#define IO_OBJECT_NULL ((io_service_t)0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -45,10 +45,10 @@
|
|||
*/
|
||||
typedef struct SDL_hapticlist_item
|
||||
{
|
||||
char name[256]; /* Name of the device. */
|
||||
char name[256]; /* Name of the device. */
|
||||
|
||||
io_service_t dev; /* Node we use to create the device. */
|
||||
SDL_Haptic *haptic; /* Haptic currently associated with it. */
|
||||
io_service_t dev; /* Node we use to create the device. */
|
||||
SDL_Haptic *haptic; /* Haptic currently associated with it. */
|
||||
|
||||
/* Usage pages for determining if it's a mouse or not. */
|
||||
long usage;
|
||||
|
|
@ -57,30 +57,28 @@ typedef struct SDL_hapticlist_item
|
|||
struct SDL_hapticlist_item *next;
|
||||
} SDL_hapticlist_item;
|
||||
|
||||
|
||||
/*
|
||||
* Haptic system hardware data.
|
||||
*/
|
||||
struct haptic_hwdata
|
||||
{
|
||||
FFDeviceObjectReference device; /* Hardware device. */
|
||||
FFDeviceObjectReference device; /* Hardware device. */
|
||||
UInt8 axes[3];
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Haptic system effect data.
|
||||
*/
|
||||
struct haptic_hweffect
|
||||
{
|
||||
FFEffectObjectReference ref; /* Reference. */
|
||||
struct FFEFFECT effect; /* Hardware effect. */
|
||||
FFEffectObjectReference ref; /* Reference. */
|
||||
struct FFEFFECT effect; /* Hardware effect. */
|
||||
};
|
||||
|
||||
/*
|
||||
* Prototypes.
|
||||
*/
|
||||
static void SDL_SYS_HapticFreeFFEFFECT(FFEFFECT * effect, int type);
|
||||
static void SDL_SYS_HapticFreeFFEFFECT(FFEFFECT *effect, int type);
|
||||
static int HIDGetDeviceProduct(io_service_t dev, char *name);
|
||||
|
||||
static SDL_hapticlist_item *SDL_hapticlist = NULL;
|
||||
|
|
@ -90,8 +88,7 @@ static int numhaptics = -1;
|
|||
/*
|
||||
* Like strerror but for force feedback errors.
|
||||
*/
|
||||
static const char *
|
||||
FFStrError(unsigned int err)
|
||||
static const char *FFStrError(unsigned int err)
|
||||
{
|
||||
switch (err) {
|
||||
case FFERR_DEVICEFULL:
|
||||
|
|
@ -143,12 +140,10 @@ FFStrError(unsigned int err)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initializes the haptic subsystem.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticInit(void)
|
||||
int SDL_SYS_HapticInit(void)
|
||||
{
|
||||
IOReturn result;
|
||||
io_iterator_t iter;
|
||||
|
|
@ -167,13 +162,13 @@ SDL_SYS_HapticInit(void)
|
|||
}
|
||||
|
||||
/* Now search I/O Registry for matching devices. */
|
||||
result = IOServiceGetMatchingServices(kIOMasterPortDefault, match, &iter);
|
||||
result = IOServiceGetMatchingServices(kIOMainPortDefault, match, &iter);
|
||||
if (result != kIOReturnSuccess) {
|
||||
return SDL_SetError("Haptic: Couldn't create a HID object iterator.");
|
||||
}
|
||||
/* IOServiceGetMatchingServices consumes dictionary. */
|
||||
|
||||
if (!IOIteratorIsValid(iter)) { /* No iterator. */
|
||||
if (!IOIteratorIsValid(iter)) { /* No iterator. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -187,14 +182,12 @@ SDL_SYS_HapticInit(void)
|
|||
return numhaptics;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_NumHaptics(void)
|
||||
int SDL_SYS_NumHaptics(void)
|
||||
{
|
||||
return numhaptics;
|
||||
}
|
||||
|
||||
static SDL_hapticlist_item *
|
||||
HapticByDevIndex(int device_index)
|
||||
static SDL_hapticlist_item *HapticByDevIndex(int device_index)
|
||||
{
|
||||
SDL_hapticlist_item *item = SDL_hapticlist;
|
||||
|
||||
|
|
@ -211,8 +204,7 @@ HapticByDevIndex(int device_index)
|
|||
return item;
|
||||
}
|
||||
|
||||
int
|
||||
MacHaptic_MaybeAddDevice( io_object_t device )
|
||||
int MacHaptic_MaybeAddDevice(io_object_t device)
|
||||
{
|
||||
IOReturn result;
|
||||
CFMutableDictionaryRef hidProperties;
|
||||
|
|
@ -229,9 +221,8 @@ MacHaptic_MaybeAddDevice( io_object_t device )
|
|||
}
|
||||
|
||||
/* Make sure we don't already have it */
|
||||
for (item = SDL_hapticlist; item ; item = item->next)
|
||||
{
|
||||
if (IOObjectIsEqualTo((io_object_t) item->dev, device)) {
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
if (IOObjectIsEqualTo((io_object_t)item->dev, device)) {
|
||||
/* Already added */
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -287,8 +278,7 @@ MacHaptic_MaybeAddDevice( io_object_t device )
|
|||
return numhaptics;
|
||||
}
|
||||
|
||||
int
|
||||
MacHaptic_MaybeRemoveDevice( io_object_t device )
|
||||
int MacHaptic_MaybeRemoveDevice(io_object_t device)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
SDL_hapticlist_item *prev = NULL;
|
||||
|
|
@ -299,7 +289,7 @@ MacHaptic_MaybeRemoveDevice( io_object_t device )
|
|||
|
||||
for (item = SDL_hapticlist; item != NULL; item = item->next) {
|
||||
/* found it, remove it. */
|
||||
if (IOObjectIsEqualTo((io_object_t) item->dev, device)) {
|
||||
if (IOObjectIsEqualTo((io_object_t)item->dev, device)) {
|
||||
const int retval = item->haptic ? item->haptic->index : -1;
|
||||
|
||||
if (prev != NULL) {
|
||||
|
|
@ -329,8 +319,7 @@ MacHaptic_MaybeRemoveDevice( io_object_t device )
|
|||
/*
|
||||
* Return the name of a haptic device, does not need to be opened.
|
||||
*/
|
||||
const char *
|
||||
SDL_SYS_HapticName(int index)
|
||||
const char *SDL_SYS_HapticName(int index)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
item = HapticByDevIndex(index);
|
||||
|
|
@ -340,8 +329,7 @@ SDL_SYS_HapticName(int index)
|
|||
/*
|
||||
* Gets the device's product name.
|
||||
*/
|
||||
static int
|
||||
HIDGetDeviceProduct(io_service_t dev, char *name)
|
||||
static int HIDGetDeviceProduct(io_service_t dev, char *name)
|
||||
{
|
||||
CFMutableDictionaryRef hidProperties, usbProperties;
|
||||
io_registry_entry_t parent1, parent2;
|
||||
|
|
@ -359,20 +347,19 @@ HIDGetDeviceProduct(io_service_t dev, char *name)
|
|||
* get dictionary for USB properties: step up two levels and get CF dictionary for USB properties
|
||||
*/
|
||||
if ((KERN_SUCCESS ==
|
||||
IORegistryEntryGetParentEntry(dev, kIOServicePlane, &parent1))
|
||||
&& (KERN_SUCCESS ==
|
||||
IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2))
|
||||
&& (KERN_SUCCESS ==
|
||||
IORegistryEntryCreateCFProperties(parent2, &usbProperties,
|
||||
kCFAllocatorDefault,
|
||||
kNilOptions))) {
|
||||
IORegistryEntryGetParentEntry(dev, kIOServicePlane, &parent1)) &&
|
||||
(KERN_SUCCESS ==
|
||||
IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2)) &&
|
||||
(KERN_SUCCESS ==
|
||||
IORegistryEntryCreateCFProperties(parent2, &usbProperties,
|
||||
kCFAllocatorDefault,
|
||||
kNilOptions))) {
|
||||
if (usbProperties) {
|
||||
CFTypeRef refCF = 0;
|
||||
/* get device info
|
||||
* try hid dictionary first, if fail then go to USB dictionary
|
||||
*/
|
||||
|
||||
|
||||
/* Get product name */
|
||||
refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
|
||||
if (!refCF) {
|
||||
|
|
@ -405,14 +392,13 @@ HIDGetDeviceProduct(io_service_t dev, char *name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#define FF_TEST(ff, s) \
|
||||
if (features.supportedEffects & (ff)) supported |= (s)
|
||||
#define FF_TEST(ff, s) \
|
||||
if (features.supportedEffects & (ff)) \
|
||||
supported |= (s)
|
||||
/*
|
||||
* Gets supported features.
|
||||
*/
|
||||
static unsigned int
|
||||
GetSupportedFeatures(SDL_Haptic * haptic)
|
||||
static unsigned int GetSupportedFeatures(SDL_Haptic *haptic)
|
||||
{
|
||||
HRESULT ret;
|
||||
FFDeviceObjectReference device;
|
||||
|
|
@ -464,9 +450,8 @@ GetSupportedFeatures(SDL_Haptic * haptic)
|
|||
if (ret == FF_OK) {
|
||||
supported |= SDL_HAPTIC_AUTOCENTER;
|
||||
} else if (ret != FFERR_UNSUPPORTED) {
|
||||
return SDL_SetError
|
||||
("Haptic: Unable to get if device supports autocenter: %s.",
|
||||
FFStrError(ret));
|
||||
return SDL_SetError("Haptic: Unable to get if device supports autocenter: %s.",
|
||||
FFStrError(ret));
|
||||
}
|
||||
|
||||
/* Check for axes, we have an artificial limit on axes */
|
||||
|
|
@ -482,12 +467,10 @@ GetSupportedFeatures(SDL_Haptic * haptic)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Opens the haptic device from the file descriptor.
|
||||
*/
|
||||
static int
|
||||
SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service)
|
||||
static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t service)
|
||||
{
|
||||
HRESULT ret;
|
||||
int ret2;
|
||||
|
|
@ -515,7 +498,6 @@ SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service)
|
|||
goto open_err;
|
||||
}
|
||||
|
||||
|
||||
/* Reset and then enable actuators. */
|
||||
ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
|
||||
FFSFFC_RESET);
|
||||
|
|
@ -531,7 +513,6 @@ SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service)
|
|||
goto open_err;
|
||||
}
|
||||
|
||||
|
||||
/* Allocate effects memory. */
|
||||
haptic->effects = (struct haptic_effect *)
|
||||
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
|
||||
|
|
@ -546,23 +527,20 @@ SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service)
|
|||
return 0;
|
||||
|
||||
/* Error handling */
|
||||
open_err:
|
||||
open_err:
|
||||
FFReleaseDevice(haptic->hwdata->device);
|
||||
creat_err:
|
||||
creat_err:
|
||||
if (haptic->hwdata != NULL) {
|
||||
SDL_free(haptic->hwdata);
|
||||
haptic->hwdata = NULL;
|
||||
}
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Opens a haptic device for usage.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticOpen(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
item = HapticByDevIndex(haptic->index);
|
||||
|
|
@ -570,12 +548,10 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic)
|
|||
return SDL_SYS_HapticOpenFromService(haptic, item->dev);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Opens a haptic device from first mouse it finds for usage.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticMouse(void)
|
||||
int SDL_SYS_HapticMouse(void)
|
||||
{
|
||||
int device_index = 0;
|
||||
SDL_hapticlist_item *item;
|
||||
|
|
@ -591,12 +567,10 @@ SDL_SYS_HapticMouse(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Checks to see if a joystick has haptic features.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
|
||||
int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_IOKIT
|
||||
if (joystick->driver != &SDL_DARWIN_JoystickDriver) {
|
||||
|
|
@ -609,18 +583,16 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
|
|||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Checks to see if the haptic device and joystick are in reality the same.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_IOKIT
|
||||
if (joystick->driver != &SDL_DARWIN_JoystickDriver) {
|
||||
return 0;
|
||||
}
|
||||
if (IOObjectIsEqualTo((io_object_t) ((size_t)haptic->hwdata->device),
|
||||
if (IOObjectIsEqualTo((io_object_t)((size_t)haptic->hwdata->device),
|
||||
joystick->hwdata->ffservice)) {
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -628,25 +600,23 @@ SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Opens a SDL_Haptic from a SDL_Joystick.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_IOKIT
|
||||
int device_index = 0;
|
||||
SDL_hapticlist_item *item;
|
||||
|
||||
|
||||
if (joystick->driver != &SDL_DARWIN_JoystickDriver) {
|
||||
return -1;
|
||||
}
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
if (IOObjectIsEqualTo((io_object_t) item->dev,
|
||||
joystick->hwdata->ffservice)) {
|
||||
haptic->index = device_index;
|
||||
break;
|
||||
if (IOObjectIsEqualTo((io_object_t)item->dev,
|
||||
joystick->hwdata->ffservice)) {
|
||||
haptic->index = device_index;
|
||||
break;
|
||||
}
|
||||
++device_index;
|
||||
}
|
||||
|
|
@ -657,12 +627,10 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Closes the haptic device.
|
||||
*/
|
||||
void
|
||||
SDL_SYS_HapticClose(SDL_Haptic * haptic)
|
||||
void SDL_SYS_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
if (haptic->hwdata) {
|
||||
|
||||
|
|
@ -680,12 +648,10 @@ SDL_SYS_HapticClose(SDL_Haptic * haptic)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Clean up after system specific haptic stuff
|
||||
*/
|
||||
void
|
||||
SDL_SYS_HapticQuit(void)
|
||||
void SDL_SYS_HapticQuit(void)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
SDL_hapticlist_item *next = NULL;
|
||||
|
|
@ -705,12 +671,10 @@ SDL_SYS_HapticQuit(void)
|
|||
SDL_hapticlist_tail = NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Converts an SDL trigger button to an FFEFFECT trigger button.
|
||||
*/
|
||||
static DWORD
|
||||
FFGetTriggerButton(Uint16 button)
|
||||
static DWORD FFGetTriggerButton(Uint16 button)
|
||||
{
|
||||
DWORD dwTriggerButton;
|
||||
|
||||
|
|
@ -723,18 +687,16 @@ FFGetTriggerButton(Uint16 button)
|
|||
return dwTriggerButton;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Sets the direction.
|
||||
*/
|
||||
static int
|
||||
SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes)
|
||||
static int SDL_SYS_SetDirection(FFEFFECT *effect, SDL_HapticDirection *dir, int naxes)
|
||||
{
|
||||
LONG *rglDir;
|
||||
|
||||
/* Handle no axes a part. */
|
||||
if (naxes == 0) {
|
||||
effect->dwFlags |= FFEFF_SPHERICAL; /* Set as default. */
|
||||
effect->dwFlags |= FFEFF_SPHERICAL; /* Set as default. */
|
||||
effect->rglDirection = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -782,21 +744,19 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* Clamps and converts. */
|
||||
#define CCONVERT(x) (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
|
||||
#define CCONVERT(x) (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
|
||||
/* Just converts. */
|
||||
#define CONVERT(x) (((x)*10000) / 0x7FFF)
|
||||
#define CONVERT(x) (((x)*10000) / 0x7FFF)
|
||||
/*
|
||||
* Creates the FFEFFECT from a SDL_HapticEffect.
|
||||
*/
|
||||
static int
|
||||
SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
||||
static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffect *src)
|
||||
{
|
||||
int i;
|
||||
FFCONSTANTFORCE *constant = NULL;
|
||||
FFPERIODIC *periodic = NULL;
|
||||
FFCONDITION *condition = NULL; /* Actually an array of conditions - one per axis. */
|
||||
FFCONDITION *condition = NULL; /* Actually an array of conditions - one per axis. */
|
||||
FFRAMPFORCE *ramp = NULL;
|
||||
FFCUSTOMFORCE *custom = NULL;
|
||||
FFENVELOPE *envelope = NULL;
|
||||
|
|
@ -809,10 +769,10 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
|||
|
||||
/* Set global stuff. */
|
||||
SDL_memset(dest, 0, sizeof(FFEFFECT));
|
||||
dest->dwSize = sizeof(FFEFFECT); /* Set the structure size. */
|
||||
dest->dwSamplePeriod = 0; /* Not used by us. */
|
||||
dest->dwGain = 10000; /* Gain is set globally, not locally. */
|
||||
dest->dwFlags = FFEFF_OBJECTOFFSETS; /* Seems obligatory. */
|
||||
dest->dwSize = sizeof(FFEFFECT); /* Set the structure size. */
|
||||
dest->dwSamplePeriod = 0; /* Not used by us. */
|
||||
dest->dwGain = 10000; /* Gain is set globally, not locally. */
|
||||
dest->dwFlags = FFEFF_OBJECTOFFSETS; /* Seems obligatory. */
|
||||
|
||||
/* Envelope. */
|
||||
envelope = SDL_malloc(sizeof(FFENVELOPE));
|
||||
|
|
@ -821,7 +781,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
|||
}
|
||||
SDL_memset(envelope, 0, sizeof(FFENVELOPE));
|
||||
dest->lpEnvelope = envelope;
|
||||
envelope->dwSize = sizeof(FFENVELOPE); /* Always should be this. */
|
||||
envelope->dwSize = sizeof(FFENVELOPE); /* Always should be this. */
|
||||
|
||||
/* Axes. */
|
||||
if (src->constant.direction.type == SDL_HAPTIC_STEERING_AXIS) {
|
||||
|
|
@ -834,7 +794,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
|||
if (axes == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
|
||||
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
|
||||
if (dest->cAxes > 1) {
|
||||
axes[1] = haptic->hwdata->axes[1];
|
||||
}
|
||||
|
|
@ -844,7 +804,6 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
|||
dest->rgdwAxes = axes;
|
||||
}
|
||||
|
||||
|
||||
/* The big type handling switch, even bigger then Linux's version. */
|
||||
switch (src->type) {
|
||||
case SDL_HAPTIC_CONSTANT:
|
||||
|
|
@ -864,17 +823,15 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
|||
dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */
|
||||
dest->dwTriggerButton = FFGetTriggerButton(hap_constant->button);
|
||||
dest->dwTriggerRepeatInterval = hap_constant->interval;
|
||||
dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */
|
||||
|
||||
/* Direction. */
|
||||
if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes)
|
||||
< 0) {
|
||||
if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Envelope */
|
||||
if ((hap_constant->attack_length == 0)
|
||||
&& (hap_constant->fade_length == 0)) {
|
||||
if ((hap_constant->attack_length == 0) && (hap_constant->fade_length == 0)) {
|
||||
SDL_free(envelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
} else {
|
||||
|
|
@ -902,8 +859,8 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
|||
/* Specifics */
|
||||
periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude));
|
||||
periodic->lOffset = CONVERT(hap_periodic->offset);
|
||||
periodic->dwPhase =
|
||||
(hap_periodic->phase + (hap_periodic->magnitude < 0 ? 18000 : 0)) % 36000;
|
||||
periodic->dwPhase =
|
||||
(hap_periodic->phase + (hap_periodic->magnitude < 0 ? 18000 : 0)) % 36000;
|
||||
periodic->dwPeriod = hap_periodic->period * 1000;
|
||||
dest->cbTypeSpecificParams = sizeof(FFPERIODIC);
|
||||
dest->lpvTypeSpecificParams = periodic;
|
||||
|
|
@ -912,17 +869,15 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
|||
dest->dwDuration = hap_periodic->length * 1000; /* In microseconds. */
|
||||
dest->dwTriggerButton = FFGetTriggerButton(hap_periodic->button);
|
||||
dest->dwTriggerRepeatInterval = hap_periodic->interval;
|
||||
dest->dwStartDelay = hap_periodic->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_periodic->delay * 1000; /* In microseconds. */
|
||||
|
||||
/* Direction. */
|
||||
if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes)
|
||||
< 0) {
|
||||
if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Envelope */
|
||||
if ((hap_periodic->attack_length == 0)
|
||||
&& (hap_periodic->fade_length == 0)) {
|
||||
if ((hap_periodic->attack_length == 0) && (hap_periodic->fade_length == 0)) {
|
||||
SDL_free(envelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
} else {
|
||||
|
|
@ -965,14 +920,13 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
|||
dest->lpvTypeSpecificParams = condition;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_condition->length * 1000; /* In microseconds. */
|
||||
dest->dwDuration = hap_condition->length * 1000; /* In microseconds. */
|
||||
dest->dwTriggerButton = FFGetTriggerButton(hap_condition->button);
|
||||
dest->dwTriggerRepeatInterval = hap_condition->interval;
|
||||
dest->dwStartDelay = hap_condition->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_condition->delay * 1000; /* In microseconds. */
|
||||
|
||||
/* Direction. */
|
||||
if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes)
|
||||
< 0) {
|
||||
if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -997,10 +951,10 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
|||
dest->lpvTypeSpecificParams = ramp;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_ramp->length * 1000; /* In microseconds. */
|
||||
dest->dwDuration = hap_ramp->length * 1000; /* In microseconds. */
|
||||
dest->dwTriggerButton = FFGetTriggerButton(hap_ramp->button);
|
||||
dest->dwTriggerRepeatInterval = hap_ramp->interval;
|
||||
dest->dwStartDelay = hap_ramp->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_ramp->delay * 1000; /* In microseconds. */
|
||||
|
||||
/* Direction. */
|
||||
if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) {
|
||||
|
|
@ -1034,17 +988,17 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
|||
custom->cSamples = hap_custom->samples;
|
||||
custom->rglForceData =
|
||||
SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
|
||||
for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) { /* Copy data. */
|
||||
for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) { /* Copy data. */
|
||||
custom->rglForceData[i] = CCONVERT(hap_custom->data[i]);
|
||||
}
|
||||
dest->cbTypeSpecificParams = sizeof(FFCUSTOMFORCE);
|
||||
dest->lpvTypeSpecificParams = custom;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_custom->length * 1000; /* In microseconds. */
|
||||
dest->dwDuration = hap_custom->length * 1000; /* In microseconds. */
|
||||
dest->dwTriggerButton = FFGetTriggerButton(hap_custom->button);
|
||||
dest->dwTriggerRepeatInterval = hap_custom->interval;
|
||||
dest->dwStartDelay = hap_custom->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_custom->delay * 1000; /* In microseconds. */
|
||||
|
||||
/* Direction. */
|
||||
if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) <
|
||||
|
|
@ -1053,8 +1007,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
|||
}
|
||||
|
||||
/* Envelope */
|
||||
if ((hap_custom->attack_length == 0)
|
||||
&& (hap_custom->fade_length == 0)) {
|
||||
if ((hap_custom->attack_length == 0) && (hap_custom->fade_length == 0)) {
|
||||
SDL_free(envelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
} else {
|
||||
|
|
@ -1066,7 +1019,6 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
|||
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
return SDL_SetError("Haptic: Unknown effect type.");
|
||||
}
|
||||
|
|
@ -1074,12 +1026,10 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Frees an FFEFFECT allocated by SDL_SYS_ToFFEFFECT.
|
||||
*/
|
||||
static void
|
||||
SDL_SYS_HapticFreeFFEFFECT(FFEFFECT * effect, int type)
|
||||
static void SDL_SYS_HapticFreeFFEFFECT(FFEFFECT *effect, int type)
|
||||
{
|
||||
FFCUSTOMFORCE *custom;
|
||||
|
||||
|
|
@ -1088,8 +1038,8 @@ SDL_SYS_HapticFreeFFEFFECT(FFEFFECT * effect, int type)
|
|||
SDL_free(effect->rgdwAxes);
|
||||
effect->rgdwAxes = NULL;
|
||||
if (effect->lpvTypeSpecificParams != NULL) {
|
||||
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
|
||||
custom = (FFCUSTOMFORCE *) effect->lpvTypeSpecificParams;
|
||||
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
|
||||
custom = (FFCUSTOMFORCE *)effect->lpvTypeSpecificParams;
|
||||
SDL_free(custom->rglForceData);
|
||||
custom->rglForceData = NULL;
|
||||
}
|
||||
|
|
@ -1100,7 +1050,6 @@ SDL_SYS_HapticFreeFFEFFECT(FFEFFECT * effect, int type)
|
|||
effect->rglDirection = NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Gets the effect type from the generic SDL haptic effect wrapper.
|
||||
*/
|
||||
|
|
@ -1114,9 +1063,9 @@ SDL_SYS_HapticEffectType(Uint16 type)
|
|||
case SDL_HAPTIC_RAMP:
|
||||
return kFFEffectType_RampForce_ID;
|
||||
|
||||
/* !!! FIXME: put this back when we have more bits in 2.1 */
|
||||
/* case SDL_HAPTIC_SQUARE:
|
||||
return kFFEffectType_Square_ID; */
|
||||
/* !!! FIXME: put this back when we have more bits in 2.1 */
|
||||
/* case SDL_HAPTIC_SQUARE:
|
||||
return kFFEffectType_Square_ID; */
|
||||
|
||||
case SDL_HAPTIC_SINE:
|
||||
return kFFEffectType_Sine_ID;
|
||||
|
|
@ -1151,13 +1100,11 @@ SDL_SYS_HapticEffectType(Uint16 type)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Creates a new haptic effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
||||
SDL_HapticEffect * base)
|
||||
int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
SDL_HapticEffect *base)
|
||||
{
|
||||
HRESULT ret;
|
||||
CFUUIDRef type;
|
||||
|
|
@ -1192,22 +1139,20 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
|
||||
return 0;
|
||||
|
||||
err_effectdone:
|
||||
err_effectdone:
|
||||
SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, base->type);
|
||||
err_hweffect:
|
||||
err_hweffect:
|
||||
SDL_free(effect->hweffect);
|
||||
effect->hweffect = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Updates an effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
|
||||
struct haptic_effect *effect,
|
||||
SDL_HapticEffect * data)
|
||||
int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect,
|
||||
SDL_HapticEffect *data)
|
||||
{
|
||||
HRESULT ret;
|
||||
FFEffectParameterFlag flags;
|
||||
|
|
@ -1222,11 +1167,11 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
|
|||
/* Set the flags. Might be worthwhile to diff temp with loaded effect and
|
||||
* only change those parameters. */
|
||||
flags = FFEP_DIRECTION |
|
||||
FFEP_DURATION |
|
||||
FFEP_ENVELOPE |
|
||||
FFEP_STARTDELAY |
|
||||
FFEP_TRIGGERBUTTON |
|
||||
FFEP_TRIGGERREPEATINTERVAL | FFEP_TYPESPECIFICPARAMS;
|
||||
FFEP_DURATION |
|
||||
FFEP_ENVELOPE |
|
||||
FFEP_STARTDELAY |
|
||||
FFEP_TRIGGERBUTTON |
|
||||
FFEP_TRIGGERREPEATINTERVAL | FFEP_TYPESPECIFICPARAMS;
|
||||
|
||||
/* Create the actual effect. */
|
||||
ret = FFEffectSetParameters(effect->hweffect->ref, &temp, flags);
|
||||
|
|
@ -1241,18 +1186,16 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
|
|||
|
||||
return 0;
|
||||
|
||||
err_update:
|
||||
err_update:
|
||||
SDL_SYS_HapticFreeFFEFFECT(&temp, data->type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Runs an effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
||||
Uint32 iterations)
|
||||
int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
Uint32 iterations)
|
||||
{
|
||||
HRESULT ret;
|
||||
Uint32 iter;
|
||||
|
|
@ -1260,8 +1203,9 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
/* Check if it's infinite. */
|
||||
if (iterations == SDL_HAPTIC_INFINITY) {
|
||||
iter = FF_INFINITE;
|
||||
} else
|
||||
} else {
|
||||
iter = iterations;
|
||||
}
|
||||
|
||||
/* Run the effect. */
|
||||
ret = FFEffectStart(effect->hweffect->ref, iter, 0);
|
||||
|
|
@ -1273,12 +1217,10 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Stops an effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
|
|
@ -1291,12 +1233,10 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Frees the effect.
|
||||
*/
|
||||
void
|
||||
SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
|
|
@ -1311,13 +1251,11 @@ SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
|||
effect->hweffect = NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Gets the status of a haptic effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
|
||||
struct haptic_effect *effect)
|
||||
int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect)
|
||||
{
|
||||
HRESULT ret;
|
||||
FFEffectStatusFlag status;
|
||||
|
|
@ -1332,15 +1270,13 @@ SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
|
|||
if (status == 0) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_TRUE; /* Assume it's playing or emulated. */
|
||||
return SDL_TRUE; /* Assume it's playing or emulated. */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Sets the gain.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
|
||||
int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
|
||||
{
|
||||
HRESULT ret;
|
||||
Uint32 val;
|
||||
|
|
@ -1355,12 +1291,10 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Sets the autocentering.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
||||
int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
|
||||
{
|
||||
HRESULT ret;
|
||||
Uint32 val;
|
||||
|
|
@ -1382,12 +1316,10 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Pauses the device.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticPause(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticPause(SDL_Haptic *haptic)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
|
|
@ -1400,12 +1332,10 @@ SDL_SYS_HapticPause(SDL_Haptic * haptic)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Unpauses the device.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticUnpause(SDL_Haptic *haptic)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
|
|
@ -1418,12 +1348,10 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Stops all currently playing effects.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -19,8 +19,13 @@
|
|||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
extern int MacHaptic_MaybeAddDevice( io_object_t device );
|
||||
extern int MacHaptic_MaybeRemoveDevice( io_object_t device );
|
||||
/* Things named "Master" were renamed to "Main" in macOS 12.0's SDK. */
|
||||
#include <AvailabilityMacros.h>
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000
|
||||
#define kIOMainPortDefault kIOMasterPortDefault
|
||||
#endif
|
||||
|
||||
extern int MacHaptic_MaybeAddDevice(io_object_t device);
|
||||
extern int MacHaptic_MaybeRemoveDevice(io_object_t device);
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -25,158 +25,119 @@
|
|||
#include "SDL_haptic.h"
|
||||
#include "../SDL_syshaptic.h"
|
||||
|
||||
|
||||
static int
|
||||
SDL_SYS_LogicError(void)
|
||||
static int SDL_SYS_LogicError(void)
|
||||
{
|
||||
return SDL_SetError("Logic error: No haptic devices available.");
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticInit(void)
|
||||
int SDL_SYS_HapticInit(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_NumHaptics(void)
|
||||
int SDL_SYS_NumHaptics(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
SDL_SYS_HapticName(int index)
|
||||
const char *SDL_SYS_HapticName(int index)
|
||||
{
|
||||
SDL_SYS_LogicError();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticOpen(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
|
||||
{
|
||||
return SDL_SYS_LogicError();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticMouse(void)
|
||||
int SDL_SYS_HapticMouse(void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
|
||||
int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
return SDL_SYS_LogicError();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SDL_SYS_HapticClose(SDL_Haptic * haptic)
|
||||
void SDL_SYS_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SDL_SYS_HapticQuit(void)
|
||||
void SDL_SYS_HapticQuit(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
|
||||
struct haptic_effect *effect, SDL_HapticEffect * base)
|
||||
int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect, SDL_HapticEffect *base)
|
||||
{
|
||||
return SDL_SYS_LogicError();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
|
||||
struct haptic_effect *effect,
|
||||
SDL_HapticEffect * data)
|
||||
int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect,
|
||||
SDL_HapticEffect *data)
|
||||
{
|
||||
return SDL_SYS_LogicError();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
||||
Uint32 iterations)
|
||||
int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
Uint32 iterations)
|
||||
{
|
||||
return SDL_SYS_LogicError();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
return SDL_SYS_LogicError();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
SDL_SYS_LogicError();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
|
||||
struct haptic_effect *effect)
|
||||
int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect)
|
||||
{
|
||||
return SDL_SYS_LogicError();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
|
||||
int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
|
||||
{
|
||||
return SDL_SYS_LogicError();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
||||
int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
|
||||
{
|
||||
return SDL_SYS_LogicError();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_HapticPause(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticPause(SDL_Haptic *haptic)
|
||||
{
|
||||
return SDL_SYS_LogicError();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticUnpause(SDL_Haptic *haptic)
|
||||
{
|
||||
return SDL_SYS_LogicError();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
|
||||
{
|
||||
return SDL_SYS_LogicError();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -30,12 +30,12 @@
|
|||
#include "../../core/linux/SDL_evdev_capabilities.h"
|
||||
#include "../../core/linux/SDL_udev.h"
|
||||
|
||||
#include <unistd.h> /* close */
|
||||
#include <linux/input.h> /* Force feedback linux stuff. */
|
||||
#include <fcntl.h> /* O_RDWR */
|
||||
#include <limits.h> /* INT_MAX */
|
||||
#include <errno.h> /* errno, strerror */
|
||||
#include <sys/stat.h> /* stat */
|
||||
#include <unistd.h> /* close */
|
||||
#include <linux/input.h> /* Force feedback linux stuff. */
|
||||
#include <fcntl.h> /* O_RDWR */
|
||||
#include <limits.h> /* INT_MAX */
|
||||
#include <errno.h> /* errno, strerror */
|
||||
#include <sys/stat.h> /* stat */
|
||||
|
||||
/* Just in case. */
|
||||
#ifndef M_PI
|
||||
|
|
@ -56,43 +56,42 @@ static void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class,
|
|||
*/
|
||||
typedef struct SDL_hapticlist_item
|
||||
{
|
||||
char *fname; /* Dev path name (like /dev/input/event1) */
|
||||
SDL_Haptic *haptic; /* Associated haptic. */
|
||||
char *fname; /* Dev path name (like /dev/input/event1) */
|
||||
SDL_Haptic *haptic; /* Associated haptic. */
|
||||
dev_t dev_num;
|
||||
struct SDL_hapticlist_item *next;
|
||||
} SDL_hapticlist_item;
|
||||
|
||||
|
||||
/*
|
||||
* Haptic system hardware data.
|
||||
*/
|
||||
struct haptic_hwdata
|
||||
{
|
||||
int fd; /* File descriptor of the device. */
|
||||
char *fname; /* Points to the name in SDL_hapticlist. */
|
||||
int fd; /* File descriptor of the device. */
|
||||
char *fname; /* Points to the name in SDL_hapticlist. */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Haptic system effect data.
|
||||
*/
|
||||
struct haptic_hweffect
|
||||
{
|
||||
struct ff_effect effect; /* The linux kernel effect structure. */
|
||||
struct ff_effect effect; /* The linux kernel effect structure. */
|
||||
};
|
||||
|
||||
static SDL_hapticlist_item *SDL_hapticlist = NULL;
|
||||
static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
|
||||
static int numhaptics = 0;
|
||||
|
||||
#define EV_TEST(ev,f) \
|
||||
if (test_bit((ev), features)) ret |= (f);
|
||||
#define EV_TEST(ev, f) \
|
||||
if (test_bit((ev), features)) { \
|
||||
ret |= (f); \
|
||||
}
|
||||
/*
|
||||
* Test whether a device has haptic properties.
|
||||
* Returns available properties or 0 if there are none.
|
||||
*/
|
||||
static int
|
||||
EV_IsHaptic(int fd)
|
||||
static int EV_IsHaptic(int fd)
|
||||
{
|
||||
unsigned int ret;
|
||||
unsigned long features[1 + FF_MAX / sizeof(unsigned long)];
|
||||
|
|
@ -126,12 +125,10 @@ EV_IsHaptic(int fd)
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Tests whether a device is a mouse or not.
|
||||
*/
|
||||
static int
|
||||
EV_IsMouse(int fd)
|
||||
static int EV_IsMouse(int fd)
|
||||
{
|
||||
unsigned long argp[40];
|
||||
|
||||
|
|
@ -151,8 +148,7 @@ EV_IsMouse(int fd)
|
|||
/*
|
||||
* Initializes the haptic subsystem by finding available devices.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticInit(void)
|
||||
int SDL_SYS_HapticInit(void)
|
||||
{
|
||||
const char joydev_pattern[] = "/dev/input/event%d";
|
||||
char path[PATH_MAX];
|
||||
|
|
@ -164,8 +160,7 @@ SDL_SYS_HapticInit(void)
|
|||
*/
|
||||
i = 0;
|
||||
for (j = 0; j < MAX_HAPTICS; ++j) {
|
||||
|
||||
SDL_snprintf(path, PATH_MAX, joydev_pattern, i++);
|
||||
(void)SDL_snprintf(path, PATH_MAX, joydev_pattern, i++);
|
||||
MaybeAddDevice(path);
|
||||
}
|
||||
|
||||
|
|
@ -174,7 +169,7 @@ SDL_SYS_HapticInit(void)
|
|||
return SDL_SetError("Could not initialize UDEV");
|
||||
}
|
||||
|
||||
if ( SDL_UDEV_AddCallback(haptic_udev_callback) < 0) {
|
||||
if (SDL_UDEV_AddCallback(haptic_udev_callback) < 0) {
|
||||
SDL_UDEV_Quit();
|
||||
return SDL_SetError("Could not setup haptic <-> udev callback");
|
||||
}
|
||||
|
|
@ -186,14 +181,12 @@ SDL_SYS_HapticInit(void)
|
|||
return numhaptics;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_NumHaptics(void)
|
||||
int SDL_SYS_NumHaptics(void)
|
||||
{
|
||||
return numhaptics;
|
||||
}
|
||||
|
||||
static SDL_hapticlist_item *
|
||||
HapticByDevIndex(int device_index)
|
||||
static SDL_hapticlist_item *HapticByDevIndex(int device_index)
|
||||
{
|
||||
SDL_hapticlist_item *item = SDL_hapticlist;
|
||||
|
||||
|
|
@ -217,25 +210,22 @@ static void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class,
|
|||
return;
|
||||
}
|
||||
|
||||
switch( udev_type )
|
||||
{
|
||||
case SDL_UDEV_DEVICEADDED:
|
||||
MaybeAddDevice(devpath);
|
||||
break;
|
||||
switch (udev_type) {
|
||||
case SDL_UDEV_DEVICEADDED:
|
||||
MaybeAddDevice(devpath);
|
||||
break;
|
||||
|
||||
case SDL_UDEV_DEVICEREMOVED:
|
||||
MaybeRemoveDevice(devpath);
|
||||
break;
|
||||
case SDL_UDEV_DEVICEREMOVED:
|
||||
MaybeRemoveDevice(devpath);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
#endif /* SDL_USE_LIBUDEV */
|
||||
|
||||
static int
|
||||
MaybeAddDevice(const char *path)
|
||||
static int MaybeAddDevice(const char *path)
|
||||
{
|
||||
struct stat sb;
|
||||
int fd;
|
||||
|
|
@ -254,7 +244,7 @@ MaybeAddDevice(const char *path)
|
|||
/* check for duplicates */
|
||||
for (item = SDL_hapticlist; item != NULL; item = item->next) {
|
||||
if (item->dev_num == sb.st_rdev) {
|
||||
return -1; /* duplicate. */
|
||||
return -1; /* duplicate. */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -275,7 +265,7 @@ MaybeAddDevice(const char *path)
|
|||
return -1;
|
||||
}
|
||||
|
||||
item = (SDL_hapticlist_item *) SDL_calloc(1, sizeof (SDL_hapticlist_item));
|
||||
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
|
||||
if (item == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -304,8 +294,7 @@ MaybeAddDevice(const char *path)
|
|||
}
|
||||
|
||||
#if SDL_USE_LIBUDEV
|
||||
static int
|
||||
MaybeRemoveDevice(const char* path)
|
||||
static int MaybeRemoveDevice(const char *path)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
SDL_hapticlist_item *prev = NULL;
|
||||
|
|
@ -347,8 +336,7 @@ MaybeRemoveDevice(const char* path)
|
|||
/*
|
||||
* Gets the name from a file descriptor.
|
||||
*/
|
||||
static const char *
|
||||
SDL_SYS_HapticNameFromFD(int fd)
|
||||
static const char *SDL_SYS_HapticNameFromFD(int fd)
|
||||
{
|
||||
static char namebuf[128];
|
||||
|
||||
|
|
@ -360,12 +348,10 @@ SDL_SYS_HapticNameFromFD(int fd)
|
|||
return namebuf;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return the name of a haptic device, does not need to be opened.
|
||||
*/
|
||||
const char *
|
||||
SDL_SYS_HapticName(int index)
|
||||
const char *SDL_SYS_HapticName(int index)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
int fd;
|
||||
|
|
@ -389,12 +375,10 @@ SDL_SYS_HapticName(int index)
|
|||
return name;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Opens the haptic device from the file descriptor.
|
||||
*/
|
||||
static int
|
||||
SDL_SYS_HapticOpenFromFD(SDL_Haptic * haptic, int fd)
|
||||
static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd)
|
||||
{
|
||||
/* Allocate the hwdata */
|
||||
haptic->hwdata = (struct haptic_hwdata *)
|
||||
|
|
@ -408,7 +392,7 @@ SDL_SYS_HapticOpenFromFD(SDL_Haptic * haptic, int fd)
|
|||
/* Set the data. */
|
||||
haptic->hwdata->fd = fd;
|
||||
haptic->supported = EV_IsHaptic(fd);
|
||||
haptic->naxes = 2; /* Hardcoded for now, not sure if it's possible to find out. */
|
||||
haptic->naxes = 2; /* Hardcoded for now, not sure if it's possible to find out. */
|
||||
|
||||
/* Set the effects */
|
||||
if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) {
|
||||
|
|
@ -416,7 +400,7 @@ SDL_SYS_HapticOpenFromFD(SDL_Haptic * haptic, int fd)
|
|||
strerror(errno));
|
||||
goto open_err;
|
||||
}
|
||||
haptic->nplaying = haptic->neffects; /* Linux makes no distinction. */
|
||||
haptic->nplaying = haptic->neffects; /* Linux makes no distinction. */
|
||||
haptic->effects = (struct haptic_effect *)
|
||||
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
|
||||
if (haptic->effects == NULL) {
|
||||
|
|
@ -430,7 +414,7 @@ SDL_SYS_HapticOpenFromFD(SDL_Haptic * haptic, int fd)
|
|||
return 0;
|
||||
|
||||
/* Error handling */
|
||||
open_err:
|
||||
open_err:
|
||||
close(fd);
|
||||
if (haptic->hwdata != NULL) {
|
||||
SDL_free(haptic->hwdata);
|
||||
|
|
@ -439,12 +423,10 @@ SDL_SYS_HapticOpenFromFD(SDL_Haptic * haptic, int fd)
|
|||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Opens a haptic device for usage.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticOpen(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
|
|
@ -465,16 +447,14 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic)
|
|||
}
|
||||
|
||||
/* Set the fname. */
|
||||
haptic->hwdata->fname = SDL_strdup( item->fname );
|
||||
haptic->hwdata->fname = SDL_strdup(item->fname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Opens a haptic device from first mouse it finds for usage.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticMouse(void)
|
||||
int SDL_SYS_HapticMouse(void)
|
||||
{
|
||||
int fd;
|
||||
int device_index = 0;
|
||||
|
|
@ -502,14 +482,14 @@ SDL_SYS_HapticMouse(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Checks to see if a joystick has haptic features.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
|
||||
int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_LINUX
|
||||
SDL_AssertJoysticksLocked();
|
||||
|
||||
if (joystick->driver != &SDL_LINUX_JoystickDriver) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
|
@ -520,14 +500,14 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
|
|||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Checks to see if the haptic device and joystick are in reality the same.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_LINUX
|
||||
SDL_AssertJoysticksLocked();
|
||||
|
||||
if (joystick->driver != &SDL_LINUX_JoystickDriver) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -540,19 +520,19 @@ SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Opens a SDL_Haptic from a SDL_Joystick.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_LINUX
|
||||
int device_index = 0;
|
||||
int fd;
|
||||
int ret;
|
||||
SDL_hapticlist_item *item;
|
||||
|
||||
|
||||
SDL_AssertJoysticksLocked();
|
||||
|
||||
if (joystick->driver != &SDL_LINUX_JoystickDriver) {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -579,7 +559,7 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||
return -1;
|
||||
}
|
||||
|
||||
haptic->hwdata->fname = SDL_strdup( joystick->hwdata->fname );
|
||||
haptic->hwdata->fname = SDL_strdup(joystick->hwdata->fname);
|
||||
|
||||
return 0;
|
||||
#else
|
||||
|
|
@ -587,12 +567,10 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Closes the haptic device.
|
||||
*/
|
||||
void
|
||||
SDL_SYS_HapticClose(SDL_Haptic * haptic)
|
||||
void SDL_SYS_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
if (haptic->hwdata) {
|
||||
|
||||
|
|
@ -614,12 +592,10 @@ SDL_SYS_HapticClose(SDL_Haptic * haptic)
|
|||
SDL_memset(haptic, 0, sizeof(SDL_Haptic));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Clean up after system specific haptic stuff
|
||||
*/
|
||||
void
|
||||
SDL_SYS_HapticQuit(void)
|
||||
void SDL_SYS_HapticQuit(void)
|
||||
{
|
||||
SDL_hapticlist_item *item = NULL;
|
||||
SDL_hapticlist_item *next = NULL;
|
||||
|
|
@ -642,12 +618,10 @@ SDL_SYS_HapticQuit(void)
|
|||
SDL_hapticlist_tail = NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Converts an SDL button to a ff_trigger button.
|
||||
*/
|
||||
static Uint16
|
||||
SDL_SYS_ToButton(Uint16 button)
|
||||
static Uint16 SDL_SYS_ToButton(Uint16 button)
|
||||
{
|
||||
Uint16 ff_button;
|
||||
|
||||
|
|
@ -664,12 +638,10 @@ SDL_SYS_ToButton(Uint16 button)
|
|||
return ff_button;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initializes the ff_effect usable direction from a SDL_HapticDirection.
|
||||
*/
|
||||
static int
|
||||
SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
|
||||
static int SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection *src)
|
||||
{
|
||||
Uint32 tmp;
|
||||
|
||||
|
|
@ -687,29 +659,29 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
|
|||
i.e. the opposite convention of SDL directions.
|
||||
*/
|
||||
tmp = ((src->dir[0] % 36000) * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
|
||||
*dest = (Uint16) tmp;
|
||||
*dest = (Uint16)tmp;
|
||||
break;
|
||||
|
||||
case SDL_HAPTIC_SPHERICAL:
|
||||
/*
|
||||
We convert to polar, because that's the only supported direction on Linux.
|
||||
The first value of a spherical direction is practically the same as a
|
||||
Polar direction, except that we have to add 90 degrees. It is the angle
|
||||
from EAST {1,0} towards SOUTH {0,1}.
|
||||
--> add 9000
|
||||
--> finally convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
|
||||
*/
|
||||
tmp = ((src->dir[0]) + 9000) % 36000; /* Convert to polars */
|
||||
tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
|
||||
*dest = (Uint16) tmp;
|
||||
/*
|
||||
We convert to polar, because that's the only supported direction on Linux.
|
||||
The first value of a spherical direction is practically the same as a
|
||||
Polar direction, except that we have to add 90 degrees. It is the angle
|
||||
from EAST {1,0} towards SOUTH {0,1}.
|
||||
--> add 9000
|
||||
--> finally convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
|
||||
*/
|
||||
tmp = ((src->dir[0]) + 9000) % 36000; /* Convert to polars */
|
||||
tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
|
||||
*dest = (Uint16)tmp;
|
||||
break;
|
||||
|
||||
case SDL_HAPTIC_CARTESIAN:
|
||||
if (!src->dir[1])
|
||||
if (!src->dir[1]) {
|
||||
*dest = (src->dir[0] >= 0 ? 0x4000 : 0xC000);
|
||||
else if (!src->dir[0])
|
||||
} else if (!src->dir[0]) {
|
||||
*dest = (src->dir[1] >= 0 ? 0x8000 : 0);
|
||||
else {
|
||||
} else {
|
||||
float f = SDL_atan2(src->dir[1], src->dir[0]); /* Ideally we'd use fixed point math instead of floats... */
|
||||
/*
|
||||
SDL_atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
|
||||
|
|
@ -723,7 +695,7 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
|
|||
*/
|
||||
tmp = (((Sint32) (f * 18000. / M_PI)) + 45000) % 36000;
|
||||
tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
|
||||
*dest = (Uint16) tmp;
|
||||
*dest = (Uint16)tmp;
|
||||
}
|
||||
break;
|
||||
case SDL_HAPTIC_STEERING_AXIS:
|
||||
|
|
@ -736,14 +708,12 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#define CLAMP(x) (((x) > 32767) ? 32767 : x)
|
||||
#define CLAMP(x) (((x) > 32767) ? 32767 : x)
|
||||
/*
|
||||
* Initializes the Linux effect struct from a haptic_effect.
|
||||
* Values above 32767 (for unsigned) are unspecified so we must clamp.
|
||||
*/
|
||||
static int
|
||||
SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
|
||||
static int SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect *src)
|
||||
{
|
||||
SDL_HapticConstant *constant;
|
||||
SDL_HapticPeriodic *periodic;
|
||||
|
|
@ -760,12 +730,12 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
|
|||
|
||||
/* Header */
|
||||
dest->type = FF_CONSTANT;
|
||||
if (SDL_SYS_ToDirection(&dest->direction, &constant->direction) == -1)
|
||||
if (SDL_SYS_ToDirection(&dest->direction, &constant->direction) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Replay */
|
||||
dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ?
|
||||
0 : CLAMP(constant->length);
|
||||
dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(constant->length);
|
||||
dest->replay.delay = CLAMP(constant->delay);
|
||||
|
||||
/* Trigger */
|
||||
|
|
@ -795,12 +765,12 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
|
|||
|
||||
/* Header */
|
||||
dest->type = FF_PERIODIC;
|
||||
if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1)
|
||||
if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Replay */
|
||||
dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ?
|
||||
0 : CLAMP(periodic->length);
|
||||
dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(periodic->length);
|
||||
dest->replay.delay = CLAMP(periodic->delay);
|
||||
|
||||
/* Trigger */
|
||||
|
|
@ -808,17 +778,18 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
|
|||
dest->trigger.interval = CLAMP(periodic->interval);
|
||||
|
||||
/* Periodic */
|
||||
if (periodic->type == SDL_HAPTIC_SINE)
|
||||
if (periodic->type == SDL_HAPTIC_SINE) {
|
||||
dest->u.periodic.waveform = FF_SINE;
|
||||
/* !!! FIXME: put this back when we have more bits in 2.1 */
|
||||
/* else if (periodic->type == SDL_HAPTIC_SQUARE)
|
||||
dest->u.periodic.waveform = FF_SQUARE; */
|
||||
else if (periodic->type == SDL_HAPTIC_TRIANGLE)
|
||||
/* !!! FIXME: put this back when we have more bits in 2.1 */
|
||||
/* else if (periodic->type == SDL_HAPTIC_SQUARE)
|
||||
dest->u.periodic.waveform = FF_SQUARE; */
|
||||
} else if (periodic->type == SDL_HAPTIC_TRIANGLE) {
|
||||
dest->u.periodic.waveform = FF_TRIANGLE;
|
||||
else if (periodic->type == SDL_HAPTIC_SAWTOOTHUP)
|
||||
} else if (periodic->type == SDL_HAPTIC_SAWTOOTHUP) {
|
||||
dest->u.periodic.waveform = FF_SAW_UP;
|
||||
else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN)
|
||||
} else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN) {
|
||||
dest->u.periodic.waveform = FF_SAW_DOWN;
|
||||
}
|
||||
dest->u.periodic.period = CLAMP(periodic->period);
|
||||
dest->u.periodic.magnitude = periodic->magnitude;
|
||||
dest->u.periodic.offset = periodic->offset;
|
||||
|
|
@ -842,19 +813,20 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
|
|||
condition = &src->condition;
|
||||
|
||||
/* Header */
|
||||
if (condition->type == SDL_HAPTIC_SPRING)
|
||||
if (condition->type == SDL_HAPTIC_SPRING) {
|
||||
dest->type = FF_SPRING;
|
||||
else if (condition->type == SDL_HAPTIC_DAMPER)
|
||||
} else if (condition->type == SDL_HAPTIC_DAMPER) {
|
||||
dest->type = FF_DAMPER;
|
||||
else if (condition->type == SDL_HAPTIC_INERTIA)
|
||||
} else if (condition->type == SDL_HAPTIC_INERTIA) {
|
||||
dest->type = FF_INERTIA;
|
||||
else if (condition->type == SDL_HAPTIC_FRICTION)
|
||||
} else if (condition->type == SDL_HAPTIC_FRICTION) {
|
||||
dest->type = FF_FRICTION;
|
||||
dest->direction = 0; /* Handled by the condition-specifics. */
|
||||
}
|
||||
|
||||
dest->direction = 0; /* Handled by the condition-specifics. */
|
||||
|
||||
/* Replay */
|
||||
dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ?
|
||||
0 : CLAMP(condition->length);
|
||||
dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(condition->length);
|
||||
dest->replay.delay = CLAMP(condition->delay);
|
||||
|
||||
/* Trigger */
|
||||
|
|
@ -888,12 +860,12 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
|
|||
|
||||
/* Header */
|
||||
dest->type = FF_RAMP;
|
||||
if (SDL_SYS_ToDirection(&dest->direction, &ramp->direction) == -1)
|
||||
if (SDL_SYS_ToDirection(&dest->direction, &ramp->direction) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Replay */
|
||||
dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ?
|
||||
0 : CLAMP(ramp->length);
|
||||
dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(ramp->length);
|
||||
dest->replay.delay = CLAMP(ramp->delay);
|
||||
|
||||
/* Trigger */
|
||||
|
|
@ -920,8 +892,7 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
|
|||
dest->direction = 0;
|
||||
|
||||
/* Replay */
|
||||
dest->replay.length = (leftright->length == SDL_HAPTIC_INFINITY) ?
|
||||
0 : CLAMP(leftright->length);
|
||||
dest->replay.length = (leftright->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(leftright->length);
|
||||
|
||||
/* Trigger */
|
||||
dest->trigger.button = 0;
|
||||
|
|
@ -933,7 +904,6 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
|
|||
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
return SDL_SetError("Haptic: Unknown effect type.");
|
||||
}
|
||||
|
|
@ -941,13 +911,11 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Creates a new haptic effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
||||
SDL_HapticEffect * base)
|
||||
int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
SDL_HapticEffect *base)
|
||||
{
|
||||
struct ff_effect *linux_effect;
|
||||
|
||||
|
|
@ -963,7 +931,7 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
if (SDL_SYS_ToFFEffect(linux_effect, base) != 0) {
|
||||
goto new_effect_err;
|
||||
}
|
||||
linux_effect->id = -1; /* Have the kernel give it an id */
|
||||
linux_effect->id = -1; /* Have the kernel give it an id */
|
||||
|
||||
/* Upload the effect */
|
||||
if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) {
|
||||
|
|
@ -974,23 +942,21 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
|
||||
return 0;
|
||||
|
||||
new_effect_err:
|
||||
new_effect_err:
|
||||
SDL_free(effect->hweffect);
|
||||
effect->hweffect = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Updates an effect.
|
||||
*
|
||||
* Note: Dynamically updating the direction can in some cases force
|
||||
* the effect to restart and run once.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
|
||||
struct haptic_effect *effect,
|
||||
SDL_HapticEffect * data)
|
||||
int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect,
|
||||
SDL_HapticEffect *data)
|
||||
{
|
||||
struct ff_effect linux_effect;
|
||||
|
||||
|
|
@ -1013,13 +979,11 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
|
|||
return effect->hweffect->effect.id;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Runs an effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
||||
Uint32 iterations)
|
||||
int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
Uint32 iterations)
|
||||
{
|
||||
struct input_event run;
|
||||
|
||||
|
|
@ -1029,19 +993,17 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
/* We don't actually have infinity here, so we just do INT_MAX which is pretty damn close. */
|
||||
run.value = (iterations > INT_MAX) ? INT_MAX : iterations;
|
||||
|
||||
if (write(haptic->hwdata->fd, (const void *) &run, sizeof(run)) < 0) {
|
||||
if (write(haptic->hwdata->fd, (const void *)&run, sizeof(run)) < 0) {
|
||||
return SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Stops an effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
struct input_event stop;
|
||||
|
||||
|
|
@ -1049,7 +1011,7 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
|||
stop.code = effect->hweffect->effect.id;
|
||||
stop.value = 0;
|
||||
|
||||
if (write(haptic->hwdata->fd, (const void *) &stop, sizeof(stop)) < 0) {
|
||||
if (write(haptic->hwdata->fd, (const void *)&stop, sizeof(stop)) < 0) {
|
||||
return SDL_SetError("Haptic: Unable to stop the effect: %s",
|
||||
strerror(errno));
|
||||
}
|
||||
|
|
@ -1057,12 +1019,10 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Frees the effect.
|
||||
*/
|
||||
void
|
||||
SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
if (ioctl(haptic->hwdata->fd, EVIOCRMFF, effect->hweffect->effect.id) < 0) {
|
||||
SDL_SetError("Haptic: Error removing the effect from the device: %s",
|
||||
|
|
@ -1072,15 +1032,13 @@ SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
|||
effect->hweffect = NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Gets the status of a haptic effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
|
||||
struct haptic_effect *effect)
|
||||
int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect)
|
||||
{
|
||||
#if 0 /* Not supported atm. */
|
||||
#if 0 /* Not supported atm. */
|
||||
struct input_event ie;
|
||||
|
||||
ie.type = EV_FF;
|
||||
|
|
@ -1097,12 +1055,10 @@ SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
|
|||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Sets the gain.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
|
||||
int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
|
||||
{
|
||||
struct input_event ie;
|
||||
|
||||
|
|
@ -1117,12 +1073,10 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Sets the autocentering.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
||||
int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
|
||||
{
|
||||
struct input_event ie;
|
||||
|
||||
|
|
@ -1137,32 +1091,26 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Pausing is not supported atm by linux.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticPause(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticPause(SDL_Haptic *haptic)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Unpausing is not supported atm by linux.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticUnpause(SDL_Haptic *haptic)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Stops all the currently playing effects.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
|
||||
{
|
||||
int i, ret;
|
||||
|
||||
|
|
@ -1171,8 +1119,7 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
|
|||
if (haptic->effects[i].hweffect != NULL) {
|
||||
ret = SDL_SYS_HapticStopEffect(haptic, &haptic->effects[i]);
|
||||
if (ret < 0) {
|
||||
return SDL_SetError
|
||||
("Haptic: Error while trying to stop all playing effects.");
|
||||
return SDL_SetError("Haptic: Error while trying to stop all playing effects.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#if SDL_HAPTIC_DINPUT
|
||||
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_windowshaptic_c.h"
|
||||
|
|
@ -36,8 +37,11 @@
|
|||
/*
|
||||
* External stuff.
|
||||
*/
|
||||
#ifdef SDL_VIDEO_DRIVER_WINDOWS
|
||||
extern HWND SDL_HelperWindow;
|
||||
|
||||
#else
|
||||
static const HWND SDL_HelperWindow = NULL;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Internal stuff.
|
||||
|
|
@ -45,12 +49,10 @@ extern HWND SDL_HelperWindow;
|
|||
static SDL_bool coinitialized = SDL_FALSE;
|
||||
static LPDIRECTINPUT8 dinput = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* Like SDL_SetError but for DX error codes.
|
||||
*/
|
||||
static int
|
||||
DI_SetError(const char *str, HRESULT err)
|
||||
static int DI_SetError(const char *str, HRESULT err)
|
||||
{
|
||||
return SDL_SetError("Haptic error %s", str);
|
||||
}
|
||||
|
|
@ -58,25 +60,28 @@ DI_SetError(const char *str, HRESULT err)
|
|||
/*
|
||||
* Callback to find the haptic devices.
|
||||
*/
|
||||
static BOOL CALLBACK
|
||||
EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
|
||||
static BOOL CALLBACK EnumHapticsCallback(const DIDEVICEINSTANCE *pdidInstance, VOID *pContext)
|
||||
{
|
||||
(void) pContext;
|
||||
(void)pContext;
|
||||
SDL_DINPUT_HapticMaybeAddDevice(pdidInstance);
|
||||
return DIENUM_CONTINUE; /* continue enumerating */
|
||||
return DIENUM_CONTINUE; /* continue enumerating */
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticInit(void)
|
||||
int SDL_DINPUT_HapticInit(void)
|
||||
{
|
||||
HRESULT ret;
|
||||
HINSTANCE instance;
|
||||
DWORD devClass;
|
||||
|
||||
if (dinput != NULL) { /* Already open. */
|
||||
if (dinput != NULL) { /* Already open. */
|
||||
return SDL_SetError("Haptic: SubSystem already open.");
|
||||
}
|
||||
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_DIRECTINPUT_ENABLED, SDL_TRUE)) {
|
||||
/* In some environments, IDirectInput8_Initialize / _EnumDevices can take a minute even with no controllers. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = WIN_CoInitialize();
|
||||
if (FAILED(ret)) {
|
||||
return DI_SetError("Coinitialize", ret);
|
||||
|
|
@ -85,7 +90,7 @@ SDL_DINPUT_HapticInit(void)
|
|||
coinitialized = SDL_TRUE;
|
||||
|
||||
ret = CoCreateInstance(&CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER,
|
||||
&IID_IDirectInput8, (LPVOID *) &dinput);
|
||||
&IID_IDirectInput8, (LPVOID *)&dinput);
|
||||
if (FAILED(ret)) {
|
||||
SDL_SYS_HapticQuit();
|
||||
return DI_SetError("CoCreateInstance", ret);
|
||||
|
|
@ -96,7 +101,7 @@ SDL_DINPUT_HapticInit(void)
|
|||
if (instance == NULL) {
|
||||
SDL_SYS_HapticQuit();
|
||||
return SDL_SetError("GetModuleHandle() failed with error code %lu.",
|
||||
GetLastError());
|
||||
GetLastError());
|
||||
}
|
||||
ret = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION);
|
||||
if (FAILED(ret)) {
|
||||
|
|
@ -116,7 +121,7 @@ SDL_DINPUT_HapticInit(void)
|
|||
EnumHapticsCallback,
|
||||
NULL,
|
||||
DIEDFL_FORCEFEEDBACK |
|
||||
DIEDFL_ATTACHEDONLY);
|
||||
DIEDFL_ATTACHEDONLY);
|
||||
if (FAILED(ret)) {
|
||||
SDL_SYS_HapticQuit();
|
||||
return DI_SetError("Enumerating DirectInput devices", ret);
|
||||
|
|
@ -126,8 +131,7 @@ SDL_DINPUT_HapticInit(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
|
||||
int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance)
|
||||
{
|
||||
HRESULT ret;
|
||||
LPDIRECTINPUTDEVICE8 device;
|
||||
|
|
@ -136,13 +140,13 @@ SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
|
|||
SDL_hapticlist_item *item = NULL;
|
||||
|
||||
if (dinput == NULL) {
|
||||
return -1; /* not initialized. We'll pick these up on enumeration if we init later. */
|
||||
return -1; /* not initialized. We'll pick these up on enumeration if we init later. */
|
||||
}
|
||||
|
||||
/* Make sure we don't already have it */
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
if ((!item->bXInputHaptic) && (SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0)) {
|
||||
return -1; /* Already added */
|
||||
return -1; /* Already added */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +168,7 @@ SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
|
|||
}
|
||||
|
||||
if ((capabilities.dwFlags & needflags) != needflags) {
|
||||
return -1; /* not a device we can use. */
|
||||
return -1; /* not a device we can use. */
|
||||
}
|
||||
|
||||
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
|
||||
|
|
@ -185,14 +189,13 @@ SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
|
|||
return SDL_SYS_AddHapticDevice(item);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
|
||||
int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
SDL_hapticlist_item *prev = NULL;
|
||||
|
||||
if (dinput == NULL) {
|
||||
return -1; /* not initialized, ignore this. */
|
||||
return -1; /* not initialized, ignore this. */
|
||||
}
|
||||
|
||||
for (item = SDL_hapticlist; item != NULL; item = item->next) {
|
||||
|
|
@ -208,10 +211,9 @@ SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
|
|||
/*
|
||||
* Callback to get supported axes.
|
||||
*/
|
||||
static BOOL CALLBACK
|
||||
DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
|
||||
static BOOL CALLBACK DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
|
||||
{
|
||||
SDL_Haptic *haptic = (SDL_Haptic *) pvRef;
|
||||
SDL_Haptic *haptic = (SDL_Haptic *)pvRef;
|
||||
|
||||
if ((dev->dwType & DIDFT_AXIS) && (dev->dwFlags & DIDOI_FFACTUATOR)) {
|
||||
const GUID *guid = &dev->guidType;
|
||||
|
|
@ -229,7 +231,7 @@ DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
|
|||
} else if (WIN_IsEqualGUID(guid, &GUID_RzAxis)) {
|
||||
offset = DIJOFS_RZ;
|
||||
} else {
|
||||
return DIENUM_CONTINUE; /* can't use this, go on. */
|
||||
return DIENUM_CONTINUE; /* can't use this, go on. */
|
||||
}
|
||||
|
||||
haptic->hwdata->axes[haptic->naxes] = offset;
|
||||
|
|
@ -247,14 +249,13 @@ DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
|
|||
/*
|
||||
* Callback to get all supported effects.
|
||||
*/
|
||||
#define EFFECT_TEST(e,s) \
|
||||
if (WIN_IsEqualGUID(&pei->guid, &(e))) \
|
||||
haptic->supported |= (s)
|
||||
static BOOL CALLBACK
|
||||
DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv)
|
||||
#define EFFECT_TEST(e, s) \
|
||||
if (WIN_IsEqualGUID(&pei->guid, &(e))) \
|
||||
haptic->supported |= (s)
|
||||
static BOOL CALLBACK DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv)
|
||||
{
|
||||
/* Prepare the haptic device. */
|
||||
SDL_Haptic *haptic = (SDL_Haptic *) pv;
|
||||
SDL_Haptic *haptic = (SDL_Haptic *)pv;
|
||||
|
||||
/* Get supported. */
|
||||
EFFECT_TEST(GUID_Spring, SDL_HAPTIC_SPRING);
|
||||
|
|
@ -285,8 +286,7 @@ DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv)
|
|||
* - Reset actuators.
|
||||
* - Get supported features.
|
||||
*/
|
||||
static int
|
||||
SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device8, SDL_bool is_joystick)
|
||||
static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVICE8 device8, SDL_bool is_joystick)
|
||||
{
|
||||
HRESULT ret;
|
||||
DIPROPDWORD dipdw;
|
||||
|
|
@ -309,12 +309,12 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
|
|||
!!! FIXME: to work, and that's probably the common case. Still,
|
||||
!!! FIXME: ideally, We need to unify the opening code. */
|
||||
|
||||
if (!is_joystick) { /* if is_joystick, we already set this up elsewhere. */
|
||||
if (!is_joystick) { /* if is_joystick, we already set this up elsewhere. */
|
||||
/* Grab it exclusively to use force feedback stuff. */
|
||||
ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device,
|
||||
SDL_HelperWindow,
|
||||
DISCL_EXCLUSIVE |
|
||||
DISCL_BACKGROUND);
|
||||
DISCL_BACKGROUND);
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Setting cooperative level to exclusive", ret);
|
||||
goto acquire_err;
|
||||
|
|
@ -328,7 +328,6 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
|
|||
goto acquire_err;
|
||||
}
|
||||
|
||||
|
||||
/* Acquire the device. */
|
||||
ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
|
||||
if (FAILED(ret)) {
|
||||
|
|
@ -370,7 +369,7 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
|
|||
DI_SetError("Enumerating supported effects", ret);
|
||||
goto acquire_err;
|
||||
}
|
||||
if (haptic->supported == 0) { /* Error since device supports nothing. */
|
||||
if (haptic->supported == 0) { /* Error since device supports nothing. */
|
||||
SDL_SetError("Haptic: Internal error on finding supported effects.");
|
||||
goto acquire_err;
|
||||
}
|
||||
|
|
@ -383,7 +382,7 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
|
|||
dipdw.dwData = 10000;
|
||||
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
|
||||
DIPROP_FFGAIN, &dipdw.diph);
|
||||
if (!FAILED(ret)) { /* Gain is supported. */
|
||||
if (!FAILED(ret)) { /* Gain is supported. */
|
||||
haptic->supported |= SDL_HAPTIC_GAIN;
|
||||
}
|
||||
dipdw.diph.dwObj = 0;
|
||||
|
|
@ -391,7 +390,7 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
|
|||
dipdw.dwData = DIPROPAUTOCENTER_OFF;
|
||||
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
|
||||
DIPROP_AUTOCENTER, &dipdw.diph);
|
||||
if (!FAILED(ret)) { /* Autocenter is supported. */
|
||||
if (!FAILED(ret)) { /* Autocenter is supported. */
|
||||
haptic->supported |= SDL_HAPTIC_AUTOCENTER;
|
||||
}
|
||||
|
||||
|
|
@ -399,11 +398,11 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
|
|||
haptic->supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
|
||||
|
||||
/* Check maximum effects. */
|
||||
haptic->neffects = 128; /* This is not actually supported as thus under windows,
|
||||
there is no way to tell the number of EFFECTS that a
|
||||
device can hold, so we'll just use a "random" number
|
||||
instead and put warnings in SDL_haptic.h */
|
||||
haptic->nplaying = 128; /* Even more impossible to get this then neffects. */
|
||||
haptic->neffects = 128; /* This is not actually supported as thus under windows,
|
||||
there is no way to tell the number of EFFECTS that a
|
||||
device can hold, so we'll just use a "random" number
|
||||
instead and put warnings in SDL_haptic.h */
|
||||
haptic->nplaying = 128; /* Even more impossible to get this then neffects. */
|
||||
|
||||
/* Prepare effects memory. */
|
||||
haptic->effects = (struct haptic_effect *)
|
||||
|
|
@ -419,20 +418,19 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
|
|||
return 0;
|
||||
|
||||
/* Error handling */
|
||||
acquire_err:
|
||||
acquire_err:
|
||||
IDirectInputDevice8_Unacquire(haptic->hwdata->device);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
|
||||
int SDL_DINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item)
|
||||
{
|
||||
HRESULT ret;
|
||||
LPDIRECTINPUTDEVICE8 device;
|
||||
|
||||
/* Open the device */
|
||||
ret = IDirectInput8_CreateDevice(dinput, &item->instance.guidInstance,
|
||||
&device, NULL);
|
||||
&device, NULL);
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Creating DirectInput device", ret);
|
||||
return -1;
|
||||
|
|
@ -445,8 +443,7 @@ SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
HRESULT ret;
|
||||
DIDEVICEINSTANCE hap_instance, joy_instance;
|
||||
|
|
@ -456,12 +453,12 @@ SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||
|
||||
/* Get the device instances. */
|
||||
ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device,
|
||||
&hap_instance);
|
||||
&hap_instance);
|
||||
if (FAILED(ret)) {
|
||||
return 0;
|
||||
}
|
||||
ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice,
|
||||
&joy_instance);
|
||||
&joy_instance);
|
||||
if (FAILED(ret)) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -469,8 +466,7 @@ SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||
return WIN_IsEqualGUID(&hap_instance.guidInstance, &joy_instance.guidInstance);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
int index = 0;
|
||||
|
|
@ -495,8 +491,7 @@ SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||
return SDL_SetError("Couldn't find joystick in haptic device list");
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DINPUT_HapticClose(SDL_Haptic * haptic)
|
||||
void SDL_DINPUT_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
IDirectInputDevice8_Unacquire(haptic->hwdata->device);
|
||||
|
||||
|
|
@ -506,8 +501,7 @@ SDL_DINPUT_HapticClose(SDL_Haptic * haptic)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DINPUT_HapticQuit(void)
|
||||
void SDL_DINPUT_HapticQuit(void)
|
||||
{
|
||||
if (dinput != NULL) {
|
||||
IDirectInput8_Release(dinput);
|
||||
|
|
@ -523,8 +517,7 @@ SDL_DINPUT_HapticQuit(void)
|
|||
/*
|
||||
* Converts an SDL trigger button to an DIEFFECT trigger button.
|
||||
*/
|
||||
static DWORD
|
||||
DIGetTriggerButton(Uint16 button)
|
||||
static DWORD DIGetTriggerButton(Uint16 button)
|
||||
{
|
||||
DWORD dwTriggerButton;
|
||||
|
||||
|
|
@ -537,18 +530,16 @@ DIGetTriggerButton(Uint16 button)
|
|||
return dwTriggerButton;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Sets the direction.
|
||||
*/
|
||||
static int
|
||||
SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes)
|
||||
static int SDL_SYS_SetDirection(DIEFFECT *effect, SDL_HapticDirection *dir, int naxes)
|
||||
{
|
||||
LONG *rglDir;
|
||||
|
||||
/* Handle no axes a part. */
|
||||
if (naxes == 0) {
|
||||
effect->dwFlags |= DIEFF_SPHERICAL; /* Set as default. */
|
||||
effect->dwFlags |= DIEFF_SPHERICAL; /* Set as default. */
|
||||
effect->rglDirection = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -569,18 +560,22 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes)
|
|||
case SDL_HAPTIC_CARTESIAN:
|
||||
effect->dwFlags |= DIEFF_CARTESIAN;
|
||||
rglDir[0] = dir->dir[0];
|
||||
if (naxes > 1)
|
||||
if (naxes > 1) {
|
||||
rglDir[1] = dir->dir[1];
|
||||
if (naxes > 2)
|
||||
}
|
||||
if (naxes > 2) {
|
||||
rglDir[2] = dir->dir[2];
|
||||
}
|
||||
return 0;
|
||||
case SDL_HAPTIC_SPHERICAL:
|
||||
effect->dwFlags |= DIEFF_SPHERICAL;
|
||||
rglDir[0] = dir->dir[0];
|
||||
if (naxes > 1)
|
||||
if (naxes > 1) {
|
||||
rglDir[1] = dir->dir[1];
|
||||
if (naxes > 2)
|
||||
}
|
||||
if (naxes > 2) {
|
||||
rglDir[2] = dir->dir[2];
|
||||
}
|
||||
return 0;
|
||||
case SDL_HAPTIC_STEERING_AXIS:
|
||||
effect->dwFlags |= DIEFF_CARTESIAN;
|
||||
|
|
@ -593,20 +588,19 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes)
|
|||
}
|
||||
|
||||
/* Clamps and converts. */
|
||||
#define CCONVERT(x) (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
|
||||
#define CCONVERT(x) (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
|
||||
/* Just converts. */
|
||||
#define CONVERT(x) (((x)*10000) / 0x7FFF)
|
||||
#define CONVERT(x) (((x)*10000) / 0x7FFF)
|
||||
/*
|
||||
* Creates the DIEFFECT from a SDL_HapticEffect.
|
||||
*/
|
||||
static int
|
||||
SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
||||
SDL_HapticEffect * src)
|
||||
static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
SDL_HapticEffect *src)
|
||||
{
|
||||
int i;
|
||||
DICONSTANTFORCE *constant;
|
||||
DIPERIODIC *periodic;
|
||||
DICONDITION *condition; /* Actually an array of conditions - one per axis. */
|
||||
DICONDITION *condition; /* Actually an array of conditions - one per axis. */
|
||||
DIRAMPFORCE *ramp;
|
||||
DICUSTOMFORCE *custom;
|
||||
DIENVELOPE *envelope;
|
||||
|
|
@ -619,10 +613,10 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
|
||||
/* Set global stuff. */
|
||||
SDL_memset(dest, 0, sizeof(DIEFFECT));
|
||||
dest->dwSize = sizeof(DIEFFECT); /* Set the structure size. */
|
||||
dest->dwSamplePeriod = 0; /* Not used by us. */
|
||||
dest->dwGain = 10000; /* Gain is set globally, not locally. */
|
||||
dest->dwFlags = DIEFF_OBJECTOFFSETS; /* Seems obligatory. */
|
||||
dest->dwSize = sizeof(DIEFFECT); /* Set the structure size. */
|
||||
dest->dwSamplePeriod = 0; /* Not used by us. */
|
||||
dest->dwGain = 10000; /* Gain is set globally, not locally. */
|
||||
dest->dwFlags = DIEFF_OBJECTOFFSETS; /* Seems obligatory. */
|
||||
|
||||
/* Envelope. */
|
||||
envelope = SDL_malloc(sizeof(DIENVELOPE));
|
||||
|
|
@ -631,7 +625,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
}
|
||||
SDL_memset(envelope, 0, sizeof(DIENVELOPE));
|
||||
dest->lpEnvelope = envelope;
|
||||
envelope->dwSize = sizeof(DIENVELOPE); /* Always should be this. */
|
||||
envelope->dwSize = sizeof(DIENVELOPE); /* Always should be this. */
|
||||
|
||||
/* Axes. */
|
||||
if (src->constant.direction.type == SDL_HAPTIC_STEERING_AXIS) {
|
||||
|
|
@ -644,7 +638,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
if (axes == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
|
||||
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
|
||||
if (dest->cAxes > 1) {
|
||||
axes[1] = haptic->hwdata->axes[1];
|
||||
}
|
||||
|
|
@ -670,10 +664,10 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
dest->lpvTypeSpecificParams = constant;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */
|
||||
dest->dwDuration = hap_constant->length * 1000UL; /* In microseconds. */
|
||||
dest->dwTriggerButton = DIGetTriggerButton(hap_constant->button);
|
||||
dest->dwTriggerRepeatInterval = hap_constant->interval;
|
||||
dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_constant->delay * 1000UL; /* In microseconds. */
|
||||
|
||||
/* Direction. */
|
||||
if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) {
|
||||
|
|
@ -681,15 +675,14 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
}
|
||||
|
||||
/* Envelope */
|
||||
if ((hap_constant->attack_length == 0)
|
||||
&& (hap_constant->fade_length == 0)) {
|
||||
if ((hap_constant->attack_length == 0) && (hap_constant->fade_length == 0)) {
|
||||
SDL_free(dest->lpEnvelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
} else {
|
||||
envelope->dwAttackLevel = CCONVERT(hap_constant->attack_level);
|
||||
envelope->dwAttackTime = hap_constant->attack_length * 1000;
|
||||
envelope->dwAttackTime = hap_constant->attack_length * 1000UL;
|
||||
envelope->dwFadeLevel = CCONVERT(hap_constant->fade_level);
|
||||
envelope->dwFadeTime = hap_constant->fade_length * 1000;
|
||||
envelope->dwFadeTime = hap_constant->fade_length * 1000UL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -711,33 +704,31 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude));
|
||||
periodic->lOffset = CONVERT(hap_periodic->offset);
|
||||
periodic->dwPhase =
|
||||
(hap_periodic->phase + (hap_periodic->magnitude < 0 ? 18000 : 0)) % 36000;
|
||||
(hap_periodic->phase + (hap_periodic->magnitude < 0 ? 18000 : 0)) % 36000;
|
||||
periodic->dwPeriod = hap_periodic->period * 1000;
|
||||
dest->cbTypeSpecificParams = sizeof(DIPERIODIC);
|
||||
dest->lpvTypeSpecificParams = periodic;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_periodic->length * 1000; /* In microseconds. */
|
||||
dest->dwDuration = hap_periodic->length * 1000UL; /* In microseconds. */
|
||||
dest->dwTriggerButton = DIGetTriggerButton(hap_periodic->button);
|
||||
dest->dwTriggerRepeatInterval = hap_periodic->interval;
|
||||
dest->dwStartDelay = hap_periodic->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_periodic->delay * 1000UL; /* In microseconds. */
|
||||
|
||||
/* Direction. */
|
||||
if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes)
|
||||
< 0) {
|
||||
if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Envelope */
|
||||
if ((hap_periodic->attack_length == 0)
|
||||
&& (hap_periodic->fade_length == 0)) {
|
||||
if ((hap_periodic->attack_length == 0) && (hap_periodic->fade_length == 0)) {
|
||||
SDL_free(dest->lpEnvelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
} else {
|
||||
envelope->dwAttackLevel = CCONVERT(hap_periodic->attack_level);
|
||||
envelope->dwAttackTime = hap_periodic->attack_length * 1000;
|
||||
envelope->dwAttackTime = hap_periodic->attack_length * 1000UL;
|
||||
envelope->dwFadeLevel = CCONVERT(hap_periodic->fade_level);
|
||||
envelope->dwFadeTime = hap_periodic->fade_length * 1000;
|
||||
envelope->dwFadeTime = hap_periodic->fade_length * 1000UL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -754,7 +745,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
SDL_memset(condition, 0, sizeof(DICONDITION));
|
||||
|
||||
/* Specifics */
|
||||
for (i = 0; i < (int) dest->cAxes; i++) {
|
||||
for (i = 0; i < (int)dest->cAxes; i++) {
|
||||
condition[i].lOffset = CONVERT(hap_condition->center[i]);
|
||||
condition[i].lPositiveCoefficient =
|
||||
CONVERT(hap_condition->right_coeff[i]);
|
||||
|
|
@ -770,14 +761,13 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
dest->lpvTypeSpecificParams = condition;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_condition->length * 1000; /* In microseconds. */
|
||||
dest->dwDuration = hap_condition->length * 1000UL; /* In microseconds. */
|
||||
dest->dwTriggerButton = DIGetTriggerButton(hap_condition->button);
|
||||
dest->dwTriggerRepeatInterval = hap_condition->interval;
|
||||
dest->dwStartDelay = hap_condition->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_condition->delay * 1000UL; /* In microseconds. */
|
||||
|
||||
/* Direction. */
|
||||
if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes)
|
||||
< 0) {
|
||||
if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -802,10 +792,10 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
dest->lpvTypeSpecificParams = ramp;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_ramp->length * 1000; /* In microseconds. */
|
||||
dest->dwDuration = hap_ramp->length * 1000UL; /* In microseconds. */
|
||||
dest->dwTriggerButton = DIGetTriggerButton(hap_ramp->button);
|
||||
dest->dwTriggerRepeatInterval = hap_ramp->interval;
|
||||
dest->dwStartDelay = hap_ramp->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_ramp->delay * 1000UL; /* In microseconds. */
|
||||
|
||||
/* Direction. */
|
||||
if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) {
|
||||
|
|
@ -818,9 +808,9 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
dest->lpEnvelope = NULL;
|
||||
} else {
|
||||
envelope->dwAttackLevel = CCONVERT(hap_ramp->attack_level);
|
||||
envelope->dwAttackTime = hap_ramp->attack_length * 1000;
|
||||
envelope->dwAttackTime = hap_ramp->attack_length * 1000UL;
|
||||
envelope->dwFadeLevel = CCONVERT(hap_ramp->fade_level);
|
||||
envelope->dwFadeTime = hap_ramp->fade_length * 1000;
|
||||
envelope->dwFadeTime = hap_ramp->fade_length * 1000UL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -835,21 +825,21 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
|
||||
/* Specifics */
|
||||
custom->cChannels = hap_custom->channels;
|
||||
custom->dwSamplePeriod = hap_custom->period * 1000;
|
||||
custom->dwSamplePeriod = hap_custom->period * 1000UL;
|
||||
custom->cSamples = hap_custom->samples;
|
||||
custom->rglForceData =
|
||||
SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
|
||||
for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) { /* Copy data. */
|
||||
for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) { /* Copy data. */
|
||||
custom->rglForceData[i] = CCONVERT(hap_custom->data[i]);
|
||||
}
|
||||
dest->cbTypeSpecificParams = sizeof(DICUSTOMFORCE);
|
||||
dest->lpvTypeSpecificParams = custom;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_custom->length * 1000; /* In microseconds. */
|
||||
dest->dwDuration = hap_custom->length * 1000UL; /* In microseconds. */
|
||||
dest->dwTriggerButton = DIGetTriggerButton(hap_custom->button);
|
||||
dest->dwTriggerRepeatInterval = hap_custom->interval;
|
||||
dest->dwStartDelay = hap_custom->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_custom->delay * 1000UL; /* In microseconds. */
|
||||
|
||||
/* Direction. */
|
||||
if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) < 0) {
|
||||
|
|
@ -857,15 +847,14 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
}
|
||||
|
||||
/* Envelope */
|
||||
if ((hap_custom->attack_length == 0)
|
||||
&& (hap_custom->fade_length == 0)) {
|
||||
if ((hap_custom->attack_length == 0) && (hap_custom->fade_length == 0)) {
|
||||
SDL_free(dest->lpEnvelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
} else {
|
||||
envelope->dwAttackLevel = CCONVERT(hap_custom->attack_level);
|
||||
envelope->dwAttackTime = hap_custom->attack_length * 1000;
|
||||
envelope->dwAttackTime = hap_custom->attack_length * 1000UL;
|
||||
envelope->dwFadeLevel = CCONVERT(hap_custom->fade_level);
|
||||
envelope->dwFadeTime = hap_custom->fade_length * 1000;
|
||||
envelope->dwFadeTime = hap_custom->fade_length * 1000UL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -877,12 +866,10 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Frees an DIEFFECT allocated by SDL_SYS_ToDIEFFECT.
|
||||
*/
|
||||
static void
|
||||
SDL_SYS_HapticFreeDIEFFECT(DIEFFECT * effect, int type)
|
||||
static void SDL_SYS_HapticFreeDIEFFECT(DIEFFECT *effect, int type)
|
||||
{
|
||||
DICUSTOMFORCE *custom;
|
||||
|
||||
|
|
@ -891,8 +878,8 @@ SDL_SYS_HapticFreeDIEFFECT(DIEFFECT * effect, int type)
|
|||
SDL_free(effect->rgdwAxes);
|
||||
effect->rgdwAxes = NULL;
|
||||
if (effect->lpvTypeSpecificParams != NULL) {
|
||||
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
|
||||
custom = (DICUSTOMFORCE *) effect->lpvTypeSpecificParams;
|
||||
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
|
||||
custom = (DICUSTOMFORCE *)effect->lpvTypeSpecificParams;
|
||||
SDL_free(custom->rglForceData);
|
||||
custom->rglForceData = NULL;
|
||||
}
|
||||
|
|
@ -906,8 +893,8 @@ SDL_SYS_HapticFreeDIEFFECT(DIEFFECT * effect, int type)
|
|||
/*
|
||||
* Gets the effect type from the generic SDL haptic effect wrapper.
|
||||
*/
|
||||
static REFGUID
|
||||
SDL_SYS_HapticEffectType(SDL_HapticEffect * effect)
|
||||
/* NOLINTNEXTLINE(readability-const-return-type): Can't fix Windows' headers */
|
||||
static REFGUID SDL_SYS_HapticEffectType(SDL_HapticEffect *effect)
|
||||
{
|
||||
switch (effect->type) {
|
||||
case SDL_HAPTIC_CONSTANT:
|
||||
|
|
@ -916,9 +903,9 @@ SDL_SYS_HapticEffectType(SDL_HapticEffect * effect)
|
|||
case SDL_HAPTIC_RAMP:
|
||||
return &GUID_RampForce;
|
||||
|
||||
/* !!! FIXME: put this back when we have more bits in 2.1 */
|
||||
/* case SDL_HAPTIC_SQUARE:
|
||||
return &GUID_Square; */
|
||||
/* !!! FIXME: put this back when we have more bits in 2.1 */
|
||||
/* case SDL_HAPTIC_SQUARE:
|
||||
return &GUID_Square; */
|
||||
|
||||
case SDL_HAPTIC_SINE:
|
||||
return &GUID_Sine;
|
||||
|
|
@ -951,8 +938,7 @@ SDL_SYS_HapticEffectType(SDL_HapticEffect * effect)
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
int
|
||||
SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
|
||||
int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *base)
|
||||
{
|
||||
HRESULT ret;
|
||||
REFGUID type = SDL_SYS_HapticEffectType(base);
|
||||
|
|
@ -968,8 +954,8 @@ SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SD
|
|||
|
||||
/* Create the actual effect. */
|
||||
ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type,
|
||||
&effect->hweffect->effect,
|
||||
&effect->hweffect->ref, NULL);
|
||||
&effect->hweffect->effect,
|
||||
&effect->hweffect->ref, NULL);
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Unable to create effect", ret);
|
||||
goto err_effectdone;
|
||||
|
|
@ -982,8 +968,7 @@ err_effectdone:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
|
||||
int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *data)
|
||||
{
|
||||
HRESULT ret;
|
||||
DWORD flags;
|
||||
|
|
@ -996,13 +981,13 @@ SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
}
|
||||
|
||||
/* Set the flags. Might be worthwhile to diff temp with loaded effect and
|
||||
* only change those parameters. */
|
||||
* only change those parameters. */
|
||||
flags = DIEP_DIRECTION |
|
||||
DIEP_DURATION |
|
||||
DIEP_ENVELOPE |
|
||||
DIEP_STARTDELAY |
|
||||
DIEP_TRIGGERBUTTON |
|
||||
DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS;
|
||||
DIEP_DURATION |
|
||||
DIEP_ENVELOPE |
|
||||
DIEP_STARTDELAY |
|
||||
DIEP_TRIGGERBUTTON |
|
||||
DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS;
|
||||
|
||||
/* Create the actual effect. */
|
||||
ret =
|
||||
|
|
@ -1036,8 +1021,7 @@ err_update:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
|
||||
int SDL_DINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations)
|
||||
{
|
||||
HRESULT ret;
|
||||
DWORD iter;
|
||||
|
|
@ -1057,8 +1041,7 @@ SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Ui
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
int SDL_DINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
|
|
@ -1069,8 +1052,7 @@ SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
void SDL_DINPUT_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
|
|
@ -1081,8 +1063,7 @@ SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect
|
|||
SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, effect->effect.type);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
int SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
HRESULT ret;
|
||||
DWORD status;
|
||||
|
|
@ -1092,13 +1073,13 @@ SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effe
|
|||
return DI_SetError("Getting effect status", ret);
|
||||
}
|
||||
|
||||
if (status == 0)
|
||||
if (status == 0) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
|
||||
int SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain)
|
||||
{
|
||||
HRESULT ret;
|
||||
DIPROPDWORD dipdw;
|
||||
|
|
@ -1108,19 +1089,18 @@ SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
|
|||
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||
dipdw.diph.dwObj = 0;
|
||||
dipdw.diph.dwHow = DIPH_DEVICE;
|
||||
dipdw.dwData = gain * 100; /* 0 to 10,000 */
|
||||
dipdw.dwData = (DWORD)gain * 100; /* 0 to 10,000 */
|
||||
|
||||
/* Try to set the autocenter. */
|
||||
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
|
||||
DIPROP_FFGAIN, &dipdw.diph);
|
||||
DIPROP_FFGAIN, &dipdw.diph);
|
||||
if (FAILED(ret)) {
|
||||
return DI_SetError("Setting gain", ret);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
||||
int SDL_DINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
|
||||
{
|
||||
HRESULT ret;
|
||||
DIPROPDWORD dipdw;
|
||||
|
|
@ -1130,54 +1110,50 @@ SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
|||
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||
dipdw.diph.dwObj = 0;
|
||||
dipdw.diph.dwHow = DIPH_DEVICE;
|
||||
dipdw.dwData = (autocenter == 0) ? DIPROPAUTOCENTER_OFF :
|
||||
DIPROPAUTOCENTER_ON;
|
||||
dipdw.dwData = (autocenter == 0) ? DIPROPAUTOCENTER_OFF : DIPROPAUTOCENTER_ON;
|
||||
|
||||
/* Try to set the autocenter. */
|
||||
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
|
||||
DIPROP_AUTOCENTER, &dipdw.diph);
|
||||
DIPROP_AUTOCENTER, &dipdw.diph);
|
||||
if (FAILED(ret)) {
|
||||
return DI_SetError("Setting autocenter", ret);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticPause(SDL_Haptic * haptic)
|
||||
int SDL_DINPUT_HapticPause(SDL_Haptic *haptic)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
/* Pause the device. */
|
||||
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
|
||||
DISFFC_PAUSE);
|
||||
DISFFC_PAUSE);
|
||||
if (FAILED(ret)) {
|
||||
return DI_SetError("Pausing the device", ret);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic)
|
||||
int SDL_DINPUT_HapticUnpause(SDL_Haptic *haptic)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
/* Unpause the device. */
|
||||
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
|
||||
DISFFC_CONTINUE);
|
||||
DISFFC_CONTINUE);
|
||||
if (FAILED(ret)) {
|
||||
return DI_SetError("Pausing the device", ret);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic)
|
||||
int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
/* Try to stop the effects. */
|
||||
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
|
||||
DISFFC_STOPALL);
|
||||
DISFFC_STOPALL);
|
||||
if (FAILED(ret)) {
|
||||
return DI_SetError("Stopping the device", ret);
|
||||
}
|
||||
|
|
@ -1189,113 +1165,94 @@ SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic)
|
|||
typedef struct DIDEVICEINSTANCE DIDEVICEINSTANCE;
|
||||
typedef struct SDL_hapticlist_item SDL_hapticlist_item;
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticInit(void)
|
||||
int SDL_DINPUT_HapticInit(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
|
||||
int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
|
||||
int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
|
||||
int SDL_DINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DINPUT_HapticClose(SDL_Haptic * haptic)
|
||||
void SDL_DINPUT_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DINPUT_HapticQuit(void)
|
||||
void SDL_DINPUT_HapticQuit(void)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
|
||||
int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *base)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
|
||||
int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *data)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
|
||||
int SDL_DINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
int SDL_DINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
void SDL_DINPUT_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
int SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
|
||||
int SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
||||
int SDL_DINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticPause(SDL_Haptic * haptic)
|
||||
int SDL_DINPUT_HapticPause(SDL_Haptic *haptic)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic)
|
||||
int SDL_DINPUT_HapticUnpause(SDL_Haptic *haptic)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic)
|
||||
int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -23,25 +23,34 @@
|
|||
#include "SDL_haptic.h"
|
||||
#include "SDL_windowshaptic_c.h"
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int SDL_DINPUT_HapticInit(void);
|
||||
extern int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance);
|
||||
extern int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance);
|
||||
extern int SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item);
|
||||
extern int SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick);
|
||||
extern int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick);
|
||||
extern void SDL_DINPUT_HapticClose(SDL_Haptic * haptic);
|
||||
extern int SDL_DINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item);
|
||||
extern int SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick);
|
||||
extern int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick);
|
||||
extern void SDL_DINPUT_HapticClose(SDL_Haptic *haptic);
|
||||
extern void SDL_DINPUT_HapticQuit(void);
|
||||
extern int SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base);
|
||||
extern int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data);
|
||||
extern int SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations);
|
||||
extern int SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect);
|
||||
extern void SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect);
|
||||
extern int SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect);
|
||||
extern int SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain);
|
||||
extern int SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
|
||||
extern int SDL_DINPUT_HapticPause(SDL_Haptic * haptic);
|
||||
extern int SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic);
|
||||
extern int SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic);
|
||||
extern int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *base);
|
||||
extern int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *data);
|
||||
extern int SDL_DINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations);
|
||||
extern int SDL_DINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect);
|
||||
extern void SDL_DINPUT_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect);
|
||||
extern int SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect);
|
||||
extern int SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain);
|
||||
extern int SDL_DINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter);
|
||||
extern int SDL_DINPUT_HapticPause(SDL_Haptic *haptic);
|
||||
extern int SDL_DINPUT_HapticUnpause(SDL_Haptic *haptic);
|
||||
extern int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -37,6 +37,10 @@
|
|||
#include "SDL_dinputhaptic_c.h"
|
||||
#include "SDL_xinputhaptic_c.h"
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Internal stuff.
|
||||
|
|
@ -45,14 +49,12 @@ SDL_hapticlist_item *SDL_hapticlist = NULL;
|
|||
static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
|
||||
static int numhaptics = 0;
|
||||
|
||||
|
||||
/*
|
||||
* Initializes the haptic subsystem.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticInit(void)
|
||||
int SDL_SYS_HapticInit(void)
|
||||
{
|
||||
JoyStick_DeviceData* device;
|
||||
JoyStick_DeviceData *device;
|
||||
|
||||
if (SDL_DINPUT_HapticInit() < 0) {
|
||||
return -1;
|
||||
|
|
@ -77,8 +79,7 @@ SDL_SYS_HapticInit(void)
|
|||
return numhaptics;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item)
|
||||
int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item)
|
||||
{
|
||||
if (SDL_hapticlist_tail == NULL) {
|
||||
SDL_hapticlist = SDL_hapticlist_tail = item;
|
||||
|
|
@ -93,8 +94,7 @@ SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item)
|
|||
return numhaptics;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item)
|
||||
int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item)
|
||||
{
|
||||
const int retval = item->haptic ? item->haptic->index : -1;
|
||||
if (prev != NULL) {
|
||||
|
|
@ -112,14 +112,12 @@ SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item)
|
|||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_NumHaptics(void)
|
||||
int SDL_SYS_NumHaptics(void)
|
||||
{
|
||||
return numhaptics;
|
||||
}
|
||||
|
||||
static SDL_hapticlist_item *
|
||||
HapticByDevIndex(int device_index)
|
||||
static SDL_hapticlist_item *HapticByDevIndex(int device_index)
|
||||
{
|
||||
SDL_hapticlist_item *item = SDL_hapticlist;
|
||||
|
||||
|
|
@ -138,8 +136,7 @@ HapticByDevIndex(int device_index)
|
|||
/*
|
||||
* Return the name of a haptic device, does not need to be opened.
|
||||
*/
|
||||
const char *
|
||||
SDL_SYS_HapticName(int index)
|
||||
const char *SDL_SYS_HapticName(int index)
|
||||
{
|
||||
SDL_hapticlist_item *item = HapticByDevIndex(index);
|
||||
return item->name;
|
||||
|
|
@ -148,8 +145,7 @@ SDL_SYS_HapticName(int index)
|
|||
/*
|
||||
* Opens a haptic device for usage.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticOpen(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
|
||||
{
|
||||
SDL_hapticlist_item *item = HapticByDevIndex(haptic->index);
|
||||
if (item->bXInputHaptic) {
|
||||
|
|
@ -159,12 +155,10 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Opens a haptic device from first mouse it finds for usage.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticMouse(void)
|
||||
int SDL_SYS_HapticMouse(void)
|
||||
{
|
||||
#if SDL_HAPTIC_DINPUT
|
||||
SDL_hapticlist_item *item;
|
||||
|
|
@ -181,12 +175,10 @@ SDL_SYS_HapticMouse(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Checks to see if a joystick has haptic features.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
|
||||
int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
|
||||
{
|
||||
if (joystick->driver != &SDL_WINDOWS_JoystickDriver) {
|
||||
return 0;
|
||||
|
|
@ -207,14 +199,13 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
|
|||
/*
|
||||
* Checks to see if the haptic device and joystick are in reality the same.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
if (joystick->driver != &SDL_WINDOWS_JoystickDriver) {
|
||||
return 0;
|
||||
}
|
||||
if (joystick->hwdata->bXInputHaptic != haptic->hwdata->bXInputHaptic) {
|
||||
return 0; /* one is XInput, one is not; not the same device. */
|
||||
return 0; /* one is XInput, one is not; not the same device. */
|
||||
} else if (joystick->hwdata->bXInputHaptic) {
|
||||
return SDL_XINPUT_JoystickSameHaptic(haptic, joystick);
|
||||
} else {
|
||||
|
|
@ -225,8 +216,7 @@ SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||
/*
|
||||
* Opens a SDL_Haptic from a SDL_Joystick.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_assert(joystick->driver == &SDL_WINDOWS_JoystickDriver);
|
||||
|
||||
|
|
@ -240,8 +230,7 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||
/*
|
||||
* Closes the haptic device.
|
||||
*/
|
||||
void
|
||||
SDL_SYS_HapticClose(SDL_Haptic * haptic)
|
||||
void SDL_SYS_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
if (haptic->hwdata) {
|
||||
|
||||
|
|
@ -266,8 +255,7 @@ SDL_SYS_HapticClose(SDL_Haptic * haptic)
|
|||
/*
|
||||
* Clean up after system specific haptic stuff
|
||||
*/
|
||||
void
|
||||
SDL_SYS_HapticQuit(void)
|
||||
void SDL_SYS_HapticQuit(void)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
SDL_hapticlist_item *next = NULL;
|
||||
|
|
@ -303,9 +291,8 @@ SDL_SYS_HapticQuit(void)
|
|||
/*
|
||||
* Creates a new haptic effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
||||
SDL_HapticEffect * base)
|
||||
int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
SDL_HapticEffect *base)
|
||||
{
|
||||
int result;
|
||||
|
||||
|
|
@ -333,10 +320,9 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
/*
|
||||
* Updates an effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
|
||||
struct haptic_effect *effect,
|
||||
SDL_HapticEffect * data)
|
||||
int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect,
|
||||
SDL_HapticEffect *data)
|
||||
{
|
||||
if (haptic->hwdata->bXInputHaptic) {
|
||||
return SDL_XINPUT_HapticUpdateEffect(haptic, effect, data);
|
||||
|
|
@ -348,9 +334,8 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
|
|||
/*
|
||||
* Runs an effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
||||
Uint32 iterations)
|
||||
int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
Uint32 iterations)
|
||||
{
|
||||
if (haptic->hwdata->bXInputHaptic) {
|
||||
return SDL_XINPUT_HapticRunEffect(haptic, effect, iterations);
|
||||
|
|
@ -362,8 +347,7 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
/*
|
||||
* Stops an effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
if (haptic->hwdata->bXInputHaptic) {
|
||||
return SDL_XINPUT_HapticStopEffect(haptic, effect);
|
||||
|
|
@ -375,8 +359,7 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
|||
/*
|
||||
* Frees the effect.
|
||||
*/
|
||||
void
|
||||
SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
if (haptic->hwdata->bXInputHaptic) {
|
||||
SDL_XINPUT_HapticDestroyEffect(haptic, effect);
|
||||
|
|
@ -390,9 +373,8 @@ SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
|||
/*
|
||||
* Gets the status of a haptic effect.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
|
||||
struct haptic_effect *effect)
|
||||
int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect)
|
||||
{
|
||||
if (haptic->hwdata->bXInputHaptic) {
|
||||
return SDL_XINPUT_HapticGetEffectStatus(haptic, effect);
|
||||
|
|
@ -404,8 +386,7 @@ SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
|
|||
/*
|
||||
* Sets the gain.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
|
||||
int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
|
||||
{
|
||||
if (haptic->hwdata->bXInputHaptic) {
|
||||
return SDL_XINPUT_HapticSetGain(haptic, gain);
|
||||
|
|
@ -417,8 +398,7 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
|
|||
/*
|
||||
* Sets the autocentering.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
||||
int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
|
||||
{
|
||||
if (haptic->hwdata->bXInputHaptic) {
|
||||
return SDL_XINPUT_HapticSetAutocenter(haptic, autocenter);
|
||||
|
|
@ -430,8 +410,7 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
|||
/*
|
||||
* Pauses the device.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticPause(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticPause(SDL_Haptic *haptic)
|
||||
{
|
||||
if (haptic->hwdata->bXInputHaptic) {
|
||||
return SDL_XINPUT_HapticPause(haptic);
|
||||
|
|
@ -443,8 +422,7 @@ SDL_SYS_HapticPause(SDL_Haptic * haptic)
|
|||
/*
|
||||
* Pauses the device.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticUnpause(SDL_Haptic *haptic)
|
||||
{
|
||||
if (haptic->hwdata->bXInputHaptic) {
|
||||
return SDL_XINPUT_HapticUnpause(haptic);
|
||||
|
|
@ -456,8 +434,7 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
|
|||
/*
|
||||
* Stops all the playing effects on the device.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
|
||||
int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
|
||||
{
|
||||
if (haptic->hwdata->bXInputHaptic) {
|
||||
return SDL_XINPUT_HapticStopAll(haptic);
|
||||
|
|
@ -466,6 +443,11 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
|
|||
}
|
||||
}
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_HAPTIC_DINPUT || SDL_HAPTIC_XINPUT */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -28,6 +28,11 @@
|
|||
#include "../../core/windows/SDL_directx.h"
|
||||
#include "../../core/windows/SDL_xinput.h"
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Haptic system hardware data.
|
||||
*/
|
||||
|
|
@ -36,17 +41,16 @@ struct haptic_hwdata
|
|||
#if SDL_HAPTIC_DINPUT
|
||||
LPDIRECTINPUTDEVICE8 device;
|
||||
#endif
|
||||
DWORD axes[3]; /* Axes to use. */
|
||||
SDL_bool is_joystick; /* Device is loaded as joystick. */
|
||||
Uint8 bXInputHaptic; /* Supports force feedback via XInput. */
|
||||
Uint8 userid; /* XInput userid index for this joystick */
|
||||
DWORD axes[3]; /* Axes to use. */
|
||||
SDL_bool is_joystick; /* Device is loaded as joystick. */
|
||||
Uint8 bXInputHaptic; /* Supports force feedback via XInput. */
|
||||
Uint8 userid; /* XInput userid index for this joystick */
|
||||
SDL_Thread *thread;
|
||||
SDL_mutex *mutex;
|
||||
Uint32 stopTicks;
|
||||
SDL_atomic_t stopThread;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Haptic system effect data.
|
||||
*/
|
||||
|
|
@ -64,8 +68,8 @@ struct haptic_hweffect
|
|||
#endif
|
||||
|
||||
/*
|
||||
* List of available haptic devices.
|
||||
*/
|
||||
* List of available haptic devices.
|
||||
*/
|
||||
typedef struct SDL_hapticlist_item
|
||||
{
|
||||
char *name;
|
||||
|
|
@ -75,7 +79,7 @@ typedef struct SDL_hapticlist_item
|
|||
DIDEVCAPS capabilities;
|
||||
#endif
|
||||
SDL_bool bXInputHaptic; /* Supports force feedback via XInput. */
|
||||
Uint8 userid; /* XInput userid index for this joystick */
|
||||
Uint8 userid; /* XInput userid index for this joystick */
|
||||
struct SDL_hapticlist_item *next;
|
||||
} SDL_hapticlist_item;
|
||||
|
||||
|
|
@ -84,7 +88,11 @@ extern SDL_hapticlist_item *SDL_hapticlist;
|
|||
extern int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item);
|
||||
extern int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_windowshaptic_c_h_ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -35,17 +35,20 @@
|
|||
#include "../../joystick/windows/SDL_windowsjoystick_c.h"
|
||||
#include "../../thread/SDL_systhread.h"
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Internal stuff.
|
||||
*/
|
||||
static SDL_bool loaded_xinput = SDL_FALSE;
|
||||
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticInit(void)
|
||||
int SDL_XINPUT_HapticInit(void)
|
||||
{
|
||||
if (SDL_GetHintBoolean(SDL_HINT_XINPUT_ENABLED, SDL_TRUE)) {
|
||||
loaded_xinput = (WIN_LoadXInputDLL() == 0);
|
||||
loaded_xinput = (WIN_LoadXInputDLL() == 0) ? SDL_TRUE : SDL_FALSE;
|
||||
}
|
||||
|
||||
/* If the joystick subsystem is active, it will manage adding XInput haptic devices */
|
||||
|
|
@ -58,8 +61,7 @@ SDL_XINPUT_HapticInit(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
|
||||
int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
|
||||
{
|
||||
const Uint8 userid = (Uint8)dwUserid;
|
||||
SDL_hapticlist_item *item;
|
||||
|
|
@ -72,13 +74,13 @@ SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
|
|||
/* Make sure we don't already have it */
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
if (item->bXInputHaptic && item->userid == userid) {
|
||||
return -1; /* Already added */
|
||||
return -1; /* Already added */
|
||||
}
|
||||
}
|
||||
|
||||
SDL_zero(state);
|
||||
if (XINPUTSETSTATE(dwUserid, &state) != ERROR_SUCCESS) {
|
||||
return -1; /* no force feedback on this device. */
|
||||
return -1; /* no force feedback on this device. */
|
||||
}
|
||||
|
||||
item = (SDL_hapticlist_item *)SDL_malloc(sizeof(SDL_hapticlist_item));
|
||||
|
|
@ -91,7 +93,7 @@ SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
|
|||
/* !!! FIXME: I'm not bothering to query for a real name right now (can we even?) */
|
||||
{
|
||||
char buf[64];
|
||||
SDL_snprintf(buf, sizeof(buf), "XInput Controller #%u", (unsigned int)(userid + 1));
|
||||
(void)SDL_snprintf(buf, sizeof(buf), "XInput Controller #%u", userid + 1);
|
||||
item->name = SDL_strdup(buf);
|
||||
}
|
||||
|
||||
|
|
@ -107,8 +109,7 @@ SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
|
|||
return SDL_SYS_AddHapticDevice(item);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid)
|
||||
int SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid)
|
||||
{
|
||||
const Uint8 userid = (Uint8)dwUserid;
|
||||
SDL_hapticlist_item *item;
|
||||
|
|
@ -142,10 +143,9 @@ SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid)
|
|||
* Mostly, this is here to get rumbling to work, and all the other features
|
||||
* are absent in the XInput path for now. :(
|
||||
*/
|
||||
static int SDLCALL
|
||||
SDL_RunXInputHaptic(void *arg)
|
||||
static int SDLCALL SDL_RunXInputHaptic(void *arg)
|
||||
{
|
||||
struct haptic_hwdata *hwdata = (struct haptic_hwdata *) arg;
|
||||
struct haptic_hwdata *hwdata = (struct haptic_hwdata *)arg;
|
||||
|
||||
while (!SDL_AtomicGet(&hwdata->stopThread)) {
|
||||
SDL_Delay(50);
|
||||
|
|
@ -164,11 +164,10 @@ SDL_RunXInputHaptic(void *arg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 userid)
|
||||
static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 userid)
|
||||
{
|
||||
char threadName[32];
|
||||
XINPUT_VIBRATION vibration = { 0, 0 }; /* stop any current vibration */
|
||||
XINPUT_VIBRATION vibration = { 0, 0 }; /* stop any current vibration */
|
||||
XINPUTSETSTATE(userid, &vibration);
|
||||
|
||||
haptic->supported = SDL_HAPTIC_LEFTRIGHT;
|
||||
|
|
@ -184,9 +183,9 @@ SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 userid)
|
|||
}
|
||||
/* Clear the memory */
|
||||
SDL_memset(haptic->effects, 0,
|
||||
sizeof(struct haptic_effect) * haptic->neffects);
|
||||
sizeof(struct haptic_effect) * haptic->neffects);
|
||||
|
||||
haptic->hwdata = (struct haptic_hwdata *) SDL_malloc(sizeof(*haptic->hwdata));
|
||||
haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata));
|
||||
if (haptic->hwdata == NULL) {
|
||||
SDL_free(haptic->effects);
|
||||
haptic->effects = NULL;
|
||||
|
|
@ -205,7 +204,7 @@ SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 userid)
|
|||
return SDL_SetError("Couldn't create XInput haptic mutex");
|
||||
}
|
||||
|
||||
SDL_snprintf(threadName, sizeof(threadName), "SDLXInputDev%d", (int)userid);
|
||||
(void)SDL_snprintf(threadName, sizeof(threadName), "SDLXInputDev%d", userid);
|
||||
haptic->hwdata->thread = SDL_CreateThreadInternal(SDL_RunXInputHaptic, threadName, 64 * 1024, haptic->hwdata);
|
||||
|
||||
if (haptic->hwdata->thread == NULL) {
|
||||
|
|
@ -219,20 +218,17 @@ SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 userid)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
|
||||
int SDL_XINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item)
|
||||
{
|
||||
return SDL_XINPUT_HapticOpenFromUserIndex(haptic, item->userid);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_XINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
return (haptic->hwdata->userid == joystick->hwdata->userid);
|
||||
return haptic->hwdata->userid == joystick->hwdata->userid;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
int index = 0;
|
||||
|
|
@ -249,16 +245,14 @@ SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||
return SDL_SetError("Couldn't find joystick in haptic device list");
|
||||
}
|
||||
|
||||
void
|
||||
SDL_XINPUT_HapticClose(SDL_Haptic * haptic)
|
||||
void SDL_XINPUT_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
SDL_AtomicSet(&haptic->hwdata->stopThread, 1);
|
||||
SDL_WaitThread(haptic->hwdata->thread, NULL);
|
||||
SDL_DestroyMutex(haptic->hwdata->mutex);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_XINPUT_HapticQuit(void)
|
||||
void SDL_XINPUT_HapticQuit(void)
|
||||
{
|
||||
if (loaded_xinput) {
|
||||
WIN_UnloadXInputDLL();
|
||||
|
|
@ -266,15 +260,13 @@ SDL_XINPUT_HapticQuit(void)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
|
||||
int SDL_XINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *base)
|
||||
{
|
||||
SDL_assert(base->type == SDL_HAPTIC_LEFTRIGHT); /* should catch this at higher level */
|
||||
SDL_assert(base->type == SDL_HAPTIC_LEFTRIGHT); /* should catch this at higher level */
|
||||
return SDL_XINPUT_HapticUpdateEffect(haptic, effect, base);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
|
||||
int SDL_XINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *data)
|
||||
{
|
||||
XINPUT_VIBRATION *vib = &effect->hweffect->vibration;
|
||||
SDL_assert(data->type == SDL_HAPTIC_LEFTRIGHT);
|
||||
|
|
@ -282,18 +274,17 @@ SDL_XINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
vib->wLeftMotorSpeed = data->leftright.large_magnitude * 2;
|
||||
vib->wRightMotorSpeed = data->leftright.small_magnitude * 2;
|
||||
SDL_LockMutex(haptic->hwdata->mutex);
|
||||
if (haptic->hwdata->stopTicks) { /* running right now? Update it. */
|
||||
if (haptic->hwdata->stopTicks) { /* running right now? Update it. */
|
||||
XINPUTSETSTATE(haptic->hwdata->userid, vib);
|
||||
}
|
||||
SDL_UnlockMutex(haptic->hwdata->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
|
||||
int SDL_XINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations)
|
||||
{
|
||||
XINPUT_VIBRATION *vib = &effect->hweffect->vibration;
|
||||
SDL_assert(effect->effect.type == SDL_HAPTIC_LEFTRIGHT); /* should catch this at higher level */
|
||||
SDL_assert(effect->effect.type == SDL_HAPTIC_LEFTRIGHT); /* should catch this at higher level */
|
||||
SDL_LockMutex(haptic->hwdata->mutex);
|
||||
if (effect->effect.leftright.length == SDL_HAPTIC_INFINITY || iterations == SDL_HAPTIC_INFINITY) {
|
||||
haptic->hwdata->stopTicks = SDL_HAPTIC_INFINITY;
|
||||
|
|
@ -302,15 +293,14 @@ SDL_XINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Ui
|
|||
} else {
|
||||
haptic->hwdata->stopTicks = SDL_GetTicks() + (effect->effect.leftright.length * iterations);
|
||||
if ((haptic->hwdata->stopTicks == SDL_HAPTIC_INFINITY) || (haptic->hwdata->stopTicks == 0)) {
|
||||
haptic->hwdata->stopTicks = 1; /* fix edge cases. */
|
||||
haptic->hwdata->stopTicks = 1; /* fix edge cases. */
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(haptic->hwdata->mutex);
|
||||
return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
int SDL_XINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
XINPUT_VIBRATION vibration = { 0, 0 };
|
||||
SDL_LockMutex(haptic->hwdata->mutex);
|
||||
|
|
@ -319,44 +309,37 @@ SDL_XINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
|||
return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS) ? 0 : -1;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_XINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
void SDL_XINPUT_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
SDL_XINPUT_HapticStopEffect(haptic, effect);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
int SDL_XINPUT_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
|
||||
int SDL_XINPUT_HapticSetGain(SDL_Haptic *haptic, int gain)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
||||
int SDL_XINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticPause(SDL_Haptic * haptic)
|
||||
int SDL_XINPUT_HapticPause(SDL_Haptic *haptic)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticUnpause(SDL_Haptic * haptic)
|
||||
int SDL_XINPUT_HapticUnpause(SDL_Haptic *haptic)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticStopAll(SDL_Haptic * haptic)
|
||||
int SDL_XINPUT_HapticStopAll(SDL_Haptic *haptic)
|
||||
{
|
||||
XINPUT_VIBRATION vibration = { 0, 0 };
|
||||
SDL_LockMutex(haptic->hwdata->mutex);
|
||||
|
|
@ -365,119 +348,105 @@ SDL_XINPUT_HapticStopAll(SDL_Haptic * haptic)
|
|||
return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS) ? 0 : -1;
|
||||
}
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#else /* !SDL_HAPTIC_XINPUT */
|
||||
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
|
||||
typedef struct SDL_hapticlist_item SDL_hapticlist_item;
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticInit(void)
|
||||
int SDL_XINPUT_HapticInit(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
|
||||
int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid)
|
||||
int SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
|
||||
int SDL_XINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_XINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
void
|
||||
SDL_XINPUT_HapticClose(SDL_Haptic * haptic)
|
||||
void SDL_XINPUT_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
SDL_XINPUT_HapticQuit(void)
|
||||
void SDL_XINPUT_HapticQuit(void)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
|
||||
int SDL_XINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *base)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
|
||||
int SDL_XINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *data)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
|
||||
int SDL_XINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
int SDL_XINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
void
|
||||
SDL_XINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
void SDL_XINPUT_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
|
||||
int SDL_XINPUT_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
|
||||
int SDL_XINPUT_HapticSetGain(SDL_Haptic *haptic, int gain)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
||||
int SDL_XINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticPause(SDL_Haptic * haptic)
|
||||
int SDL_XINPUT_HapticPause(SDL_Haptic *haptic)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticUnpause(SDL_Haptic * haptic)
|
||||
int SDL_XINPUT_HapticUnpause(SDL_Haptic *haptic)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_HapticStopAll(SDL_Haptic * haptic)
|
||||
int SDL_XINPUT_HapticStopAll(SDL_Haptic *haptic)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -23,25 +23,34 @@
|
|||
#include "SDL_haptic.h"
|
||||
#include "SDL_windowshaptic_c.h"
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int SDL_XINPUT_HapticInit(void);
|
||||
extern int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid);
|
||||
extern int SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid);
|
||||
extern int SDL_XINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item);
|
||||
extern int SDL_XINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick);
|
||||
extern int SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick);
|
||||
extern void SDL_XINPUT_HapticClose(SDL_Haptic * haptic);
|
||||
extern int SDL_XINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item);
|
||||
extern int SDL_XINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick);
|
||||
extern int SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick);
|
||||
extern void SDL_XINPUT_HapticClose(SDL_Haptic *haptic);
|
||||
extern void SDL_XINPUT_HapticQuit(void);
|
||||
extern int SDL_XINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base);
|
||||
extern int SDL_XINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data);
|
||||
extern int SDL_XINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations);
|
||||
extern int SDL_XINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect);
|
||||
extern void SDL_XINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect);
|
||||
extern int SDL_XINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect);
|
||||
extern int SDL_XINPUT_HapticSetGain(SDL_Haptic * haptic, int gain);
|
||||
extern int SDL_XINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
|
||||
extern int SDL_XINPUT_HapticPause(SDL_Haptic * haptic);
|
||||
extern int SDL_XINPUT_HapticUnpause(SDL_Haptic * haptic);
|
||||
extern int SDL_XINPUT_HapticStopAll(SDL_Haptic * haptic);
|
||||
extern int SDL_XINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *base);
|
||||
extern int SDL_XINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *data);
|
||||
extern int SDL_XINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations);
|
||||
extern int SDL_XINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect);
|
||||
extern void SDL_XINPUT_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect);
|
||||
extern int SDL_XINPUT_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect);
|
||||
extern int SDL_XINPUT_HapticSetGain(SDL_Haptic *haptic, int gain);
|
||||
extern int SDL_XINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter);
|
||||
extern int SDL_XINPUT_HapticPause(SDL_Haptic *haptic);
|
||||
extern int SDL_XINPUT_HapticUnpause(SDL_Haptic *haptic);
|
||||
extern int SDL_XINPUT_HapticStopAll(SDL_Haptic *haptic);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue