Merge commit 'dec0d4ec4153bf9fc2b78ae6c2df45b6ea8dde7a' as 'external/sdl/SDL'

This commit is contained in:
2023-07-25 22:27:55 +02:00
1663 changed files with 627495 additions and 0 deletions

813
external/sdl/SDL/src/haptic/SDL_haptic.c vendored Normal file
View File

@ -0,0 +1,813 @@
/*
Simple DirectMedia Layer
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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#include "SDL_syshaptic.h"
#include "SDL_haptic_c.h"
#include "../joystick/SDL_joystick_c.h" /* For SDL_IsJoystickValid */
/* 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
static SDL_Haptic *SDL_haptics = NULL;
#endif
/*
* Initializes the Haptic devices.
*/
int SDL_InitHaptics(void)
{
int status;
status = SDL_SYS_HapticInit();
if (status >= 0) {
status = 0;
}
return status;
}
/*
* Checks to see if the haptic device is valid
*/
static int ValidHaptic(SDL_Haptic *haptic)
{
int valid;
SDL_Haptic *hapticlist;
valid = 0;
if (haptic != NULL) {
hapticlist = SDL_haptics;
while (hapticlist) {
if (hapticlist == haptic) {
valid = 1;
break;
}
hapticlist = hapticlist->next;
}
}
/* Create the error here. */
if (valid == 0) {
SDL_SetError("Haptic: Invalid haptic device identifier");
}
return valid;
}
/*
* Returns the number of available devices.
*/
int SDL_NumHaptics(void)
{
return SDL_SYS_NumHaptics();
}
/*
* Gets the name of a Haptic device by 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",
SDL_NumHaptics());
return NULL;
}
return SDL_SYS_HapticName(device_index);
}
/*
* Opens a Haptic device.
*/
SDL_Haptic *SDL_HapticOpen(int device_index)
{
SDL_Haptic *haptic;
SDL_Haptic *hapticlist;
if ((device_index < 0) || (device_index >= SDL_NumHaptics())) {
SDL_SetError("Haptic: There are %d haptic devices available",
SDL_NumHaptics());
return NULL;
}
hapticlist = SDL_haptics;
/* If the haptic is already open, return it
* TODO: Should we create haptic instance IDs like the Joystick API?
*/
while (hapticlist) {
if (device_index == hapticlist->index) {
haptic = hapticlist;
++haptic->ref_count;
return haptic;
}
hapticlist = hapticlist->next;
}
/* Create the haptic device */
haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic));
if (haptic == NULL) {
SDL_OutOfMemory();
return NULL;
}
/* Initialize the haptic device */
SDL_memset(haptic, 0, sizeof(*haptic));
haptic->rumble_id = -1;
haptic->index = (Uint8)device_index;
if (SDL_SYS_HapticOpen(haptic) < 0) {
SDL_free(haptic);
return NULL;
}
/* Add haptic to list */
++haptic->ref_count;
/* Link the haptic in the list */
haptic->next = SDL_haptics;
SDL_haptics = haptic;
/* Disable autocenter and set gain to max. */
if (haptic->supported & SDL_HAPTIC_GAIN) {
SDL_HapticSetGain(haptic, 100);
}
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 opened;
SDL_Haptic *hapticlist;
/* Make sure it's valid. */
if ((device_index < 0) || (device_index >= SDL_NumHaptics())) {
SDL_SetError("Haptic: There are %d haptic devices available",
SDL_NumHaptics());
return 0;
}
opened = 0;
hapticlist = SDL_haptics;
/* TODO Should this use an instance ID? */
while (hapticlist) {
if (hapticlist->index == (Uint8)device_index) {
opened = 1;
break;
}
hapticlist = hapticlist->next;
}
return opened;
}
/*
* Returns the index to a haptic device.
*/
int SDL_HapticIndex(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
}
return haptic->index;
}
/*
* Returns SDL_TRUE if mouse is haptic, SDL_FALSE if it isn't.
*/
int SDL_MouseIsHaptic(void)
{
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)
{
int device_index;
device_index = SDL_SYS_HapticMouse();
if (device_index < 0) {
SDL_SetError("Haptic: Mouse isn't a haptic device.");
return NULL;
}
return SDL_HapticOpen(device_index);
}
/*
* Returns SDL_TRUE if joystick has haptic features.
*/
int SDL_JoystickIsHaptic(SDL_Joystick *joystick)
{
int ret;
SDL_LockJoysticks();
{
/* Must be a valid joystick */
if (!SDL_IsJoystickValid(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;
}
return -1;
}
/*
* Opens a haptic device from a joystick.
*/
SDL_Haptic *SDL_HapticOpenFromJoystick(SDL_Joystick *joystick)
{
SDL_Haptic *haptic;
SDL_Haptic *hapticlist;
/* Make sure there is room. */
if (SDL_NumHaptics() <= 0) {
SDL_SetError("Haptic: There are %d haptic devices available",
SDL_NumHaptics());
return NULL;
}
SDL_LockJoysticks();
{
/* Must be a valid joystick */
if (!SDL_IsJoystickValid(joystick)) {
SDL_SetError("Haptic: Joystick isn't valid.");
SDL_UnlockJoysticks();
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;
}
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;
/* Link the haptic in the list */
haptic->next = SDL_haptics;
SDL_haptics = haptic;
return haptic;
}
/*
* Closes a SDL_Haptic device.
*/
void SDL_HapticClose(SDL_Haptic *haptic)
{
int i;
SDL_Haptic *hapticlist;
SDL_Haptic *hapticlistprev;
/* Must be valid */
if (!ValidHaptic(haptic)) {
return;
}
/* Check if it's still in use */
if (--haptic->ref_count > 0) {
return;
}
/* Close it, properly removing effects if needed */
for (i = 0; i < haptic->neffects; i++) {
if (haptic->effects[i].hweffect != NULL) {
SDL_HapticDestroyEffect(haptic, i);
}
}
SDL_SYS_HapticClose(haptic);
/* Remove from the list */
hapticlist = SDL_haptics;
hapticlistprev = NULL;
while (hapticlist) {
if (haptic == hapticlist) {
if (hapticlistprev) {
/* unlink this entry */
hapticlistprev->next = hapticlist->next;
} else {
SDL_haptics = haptic->next;
}
break;
}
hapticlistprev = hapticlist;
hapticlist = hapticlist->next;
}
/* Free */
SDL_free(haptic);
}
/*
* Cleans up after the subsystem.
*/
void SDL_QuitHaptics(void)
{
while (SDL_haptics) {
SDL_HapticClose(SDL_haptics);
}
SDL_SYS_HapticQuit();
}
/*
* Returns the number of effects a haptic device has.
*/
int SDL_HapticNumEffects(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
}
return haptic->neffects;
}
/*
* Returns the number of effects a haptic device can play.
*/
int SDL_HapticNumEffectsPlaying(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
}
return haptic->nplaying;
}
/*
* Returns supported effects by the device.
*/
unsigned int SDL_HapticQuery(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return 0; /* same as if no effects were supported */
}
return haptic->supported;
}
/*
* Returns the number of axis on the device.
*/
int SDL_HapticNumAxes(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
}
return haptic->naxes;
}
/*
* Checks to see if the device can support the effect.
*/
int SDL_HapticEffectSupported(SDL_Haptic *haptic, SDL_HapticEffect *effect)
{
if (!ValidHaptic(haptic)) {
return -1;
}
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 i;
/* Check for device validity. */
if (!ValidHaptic(haptic)) {
return -1;
}
/* Check to see if effect is supported */
if (SDL_HapticEffectSupported(haptic, effect) == SDL_FALSE) {
return SDL_SetError("Haptic: Effect not supported by haptic device.");
}
/* See if there's a free slot */
for (i = 0; i < haptic->neffects; i++) {
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 */
}
SDL_memcpy(&haptic->effects[i].effect, effect,
sizeof(SDL_HapticEffect));
return i;
}
}
return SDL_SetError("Haptic: Device has no free space left.");
}
/*
* Checks to see if an effect is valid.
*/
static int ValidEffect(SDL_Haptic *haptic, int effect)
{
if ((effect < 0) || (effect >= haptic->neffects)) {
SDL_SetError("Haptic: Invalid effect identifier.");
return 0;
}
return 1;
}
/*
* Updates an effect.
*/
int SDL_HapticUpdateEffect(SDL_Haptic *haptic, int effect,
SDL_HapticEffect *data)
{
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
return -1;
}
/* Can't change type dynamically. */
if (data->type != haptic->effects[effect].effect.type) {
return SDL_SetError("Haptic: Updating effect type is illegal.");
}
/* Updates the effect */
if (SDL_SYS_HapticUpdateEffect(haptic, &haptic->effects[effect], data) <
0) {
return -1;
}
SDL_memcpy(&haptic->effects[effect].effect, data,
sizeof(SDL_HapticEffect));
return 0;
}
/*
* Runs the haptic effect on the device.
*/
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) {
return -1;
}
return 0;
}
/*
* Stops the haptic effect on the device.
*/
int SDL_HapticStopEffect(SDL_Haptic *haptic, int effect)
{
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
return -1;
}
/* Stop the effect */
if (SDL_SYS_HapticStopEffect(haptic, &haptic->effects[effect]) < 0) {
return -1;
}
return 0;
}
/*
* Gets rid of a haptic effect.
*/
void SDL_HapticDestroyEffect(SDL_Haptic *haptic, int effect)
{
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
return;
}
/* Not allocated */
if (haptic->effects[effect].hweffect == NULL) {
return;
}
SDL_SYS_HapticDestroyEffect(haptic, &haptic->effects[effect]);
}
/*
* Gets the status of a haptic effect.
*/
int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
{
if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
return -1;
}
if (!(haptic->supported & SDL_HAPTIC_STATUS)) {
return SDL_SetError("Haptic: Device does not support status queries.");
}
return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]);
}
/*
* Sets the global gain of the device.
*/
int SDL_HapticSetGain(SDL_Haptic *haptic, int gain)
{
const char *env;
int real_gain, max_gain;
if (!ValidHaptic(haptic)) {
return -1;
}
if (!(haptic->supported & SDL_HAPTIC_GAIN)) {
return SDL_SetError("Haptic: Device does not support setting gain.");
}
if ((gain < 0) || (gain > 100)) {
return SDL_SetError("Haptic: Gain must be between 0 and 100.");
}
/* We use the envvar to get the maximum gain. */
env = SDL_getenv("SDL_HAPTIC_GAIN_MAX");
if (env != NULL) {
max_gain = SDL_atoi(env);
/* Check for sanity. */
if (max_gain < 0) {
max_gain = 0;
} else if (max_gain > 100) {
max_gain = 100;
}
/* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */
real_gain = (gain * max_gain) / 100;
} else {
real_gain = gain;
}
if (SDL_SYS_HapticSetGain(haptic, real_gain) < 0) {
return -1;
}
return 0;
}
/*
* Makes the device autocenter, 0 disables.
*/
int SDL_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
{
if (!ValidHaptic(haptic)) {
return -1;
}
if (!(haptic->supported & SDL_HAPTIC_AUTOCENTER)) {
return SDL_SetError("Haptic: Device does not support setting autocenter.");
}
if ((autocenter < 0) || (autocenter > 100)) {
return SDL_SetError("Haptic: Autocenter must be between 0 and 100.");
}
if (SDL_SYS_HapticSetAutocenter(haptic, autocenter) < 0) {
return -1;
}
return 0;
}
/*
* Pauses the haptic device.
*/
int SDL_HapticPause(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
}
if (!(haptic->supported & SDL_HAPTIC_PAUSE)) {
return SDL_SetError("Haptic: Device does not support setting pausing.");
}
return SDL_SYS_HapticPause(haptic);
}
/*
* Unpauses the haptic device.
*/
int SDL_HapticUnpause(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
}
if (!(haptic->supported & SDL_HAPTIC_PAUSE)) {
return 0; /* Not going to be paused, so we pretend it's unpaused. */
}
return SDL_SYS_HapticUnpause(haptic);
}
/*
* Stops all the currently playing effects.
*/
int SDL_HapticStopAll(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
}
return SDL_SYS_HapticStopAll(haptic);
}
/*
* Checks to see if rumble is supported.
*/
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;
}
/*
* Initializes the haptic device for simple rumble playback.
*/
int SDL_HapticRumbleInit(SDL_Haptic *haptic)
{
SDL_HapticEffect *efx = &haptic->rumble_effect;
if (!ValidHaptic(haptic)) {
return -1;
}
/* Already allocated. */
if (haptic->rumble_id >= 0) {
return 0;
}
SDL_zerop(efx);
if (haptic->supported & SDL_HAPTIC_SINE) {
efx->type = SDL_HAPTIC_SINE;
efx->periodic.direction.type = SDL_HAPTIC_CARTESIAN;
efx->periodic.period = 1000;
efx->periodic.magnitude = 0x4000;
efx->periodic.length = 5000;
efx->periodic.attack_length = 0;
efx->periodic.fade_length = 0;
} else if (haptic->supported & SDL_HAPTIC_LEFTRIGHT) { /* XInput? */
efx->type = SDL_HAPTIC_LEFTRIGHT;
efx->leftright.length = 5000;
efx->leftright.large_magnitude = 0x4000;
efx->leftright.small_magnitude = 0x4000;
} else {
return SDL_SetError("Device doesn't support rumble");
}
haptic->rumble_id = SDL_HapticNewEffect(haptic, &haptic->rumble_effect);
if (haptic->rumble_id >= 0) {
return 0;
}
return -1;
}
/*
* Runs simple rumble on a haptic device
*/
int SDL_HapticRumblePlay(SDL_Haptic *haptic, float strength, Uint32 length)
{
SDL_HapticEffect *efx;
Sint16 magnitude;
if (!ValidHaptic(haptic)) {
return -1;
}
if (haptic->rumble_id < 0) {
return SDL_SetError("Haptic: Rumble effect not initialized on haptic device");
}
/* Clamp strength. */
if (strength > 1.0f) {
strength = 1.0f;
} else if (strength < 0.0f) {
strength = 0.0f;
}
magnitude = (Sint16)(32767.0f * strength);
efx = &haptic->rumble_effect;
if (efx->type == SDL_HAPTIC_SINE) {
efx->periodic.magnitude = magnitude;
efx->periodic.length = length;
} else if (efx->type == SDL_HAPTIC_LEFTRIGHT) {
efx->leftright.small_magnitude = efx->leftright.large_magnitude = magnitude;
efx->leftright.length = length;
} else {
SDL_assert(0 && "This should have been caught elsewhere");
}
if (SDL_HapticUpdateEffect(haptic, haptic->rumble_id, &haptic->rumble_effect) < 0) {
return -1;
}
return SDL_HapticRunEffect(haptic, haptic->rumble_id, 1);
}
/*
* Stops the simple rumble on a haptic device.
*/
int SDL_HapticRumbleStop(SDL_Haptic *haptic)
{
if (!ValidHaptic(haptic)) {
return -1;
}
if (haptic->rumble_id < 0) {
return SDL_SetError("Haptic: Rumble effect not initialized on haptic device");
}
return SDL_HapticStopEffect(haptic, haptic->rumble_id);
}

View File

@ -0,0 +1,28 @@
/*
Simple DirectMedia Layer
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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_haptic_c_h_
#define SDL_haptic_c_h_
extern int SDL_InitHaptics(void);
extern void SDL_QuitHaptics(void);
#endif /* SDL_haptic_c_h_ */

View File

@ -0,0 +1,213 @@
/*
Simple DirectMedia Layer
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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#ifndef SDL_syshaptic_h_
#define SDL_syshaptic_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 */
};
/*
* The real SDL_Haptic struct.
*/
struct SDL_Haptic
{
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_hwdata *hwdata; /* Driver dependent */
int ref_count; /* Count for multiple opens */
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 */
};
/*
* Scans the system for haptic devices.
*
* Returns number of devices on success, -1 on error.
*/
extern int SDL_SYS_HapticInit(void);
/* Function to return the number of haptic devices plugged in right now */
extern int SDL_SYS_NumHaptics(void);
/*
* Gets the device dependent name of the haptic device
*/
extern const char *SDL_SYS_HapticName(int index);
/*
* Opens the haptic device for usage. The haptic device should have
* the index value set previously.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticOpen(SDL_Haptic *haptic);
/*
* Returns the index of the haptic core pointer or -1 if none is found.
*/
int SDL_SYS_HapticMouse(void);
/*
* Checks to see if the joystick has haptic capabilities.
*
* 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);
/*
* Opens the haptic device for usage using the same device as
* the joystick.
*
* Returns 0 on success, -1 on error.
*/
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);
/*
* Closes a haptic device after usage.
*/
extern void SDL_SYS_HapticClose(SDL_Haptic *haptic);
/*
* Performs a cleanup on the haptic subsystem.
*/
extern void SDL_SYS_HapticQuit(void);
/*
* Creates a new haptic effect on the haptic device using base
* as a template for the effect.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic,
struct haptic_effect *effect,
SDL_HapticEffect *base);
/*
* Updates the haptic effect on the haptic device using data
* as a template.
*
* Returns 0 on success, -1 on error.
*/
extern int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
struct haptic_effect *effect,
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,
struct haptic_effect *effect,
Uint32 iterations);
/*
* Stops the effect on the haptic device.
*
* Returns 0 on success, -1 on error.
*/
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,
struct haptic_effect *effect);
/*
* Queries the device for the status of effect.
*
* Returns 0 if device is stopped, >0 if device is playing and
* -1 on error.
*/
extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic,
struct haptic_effect *effect);
/*
* Sets the global gain of the haptic device.
*
* Returns 0 on success, -1 on error.
*/
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);
/*
* Pauses the haptic device.
*
* Returns 0 on success, -1 on error.
*/
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);
/*
* 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);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* SDL_syshaptic_h_ */

View File

@ -0,0 +1,304 @@
/*
Simple DirectMedia Layer
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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#ifdef SDL_HAPTIC_ANDROID
#include "SDL_syshaptic_c.h"
#include "../SDL_syshaptic.h"
#include "../../core/android/SDL_android.h"
#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
#include "../../joystick/android/SDL_sysjoystick_c.h" /* For joystick hwdata */
typedef struct SDL_hapticlist_item
{
int device_id;
char *name;
SDL_Haptic *haptic;
struct SDL_hapticlist_item *next;
} SDL_hapticlist_item;
static SDL_hapticlist_item *SDL_hapticlist = NULL;
static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
static int numhaptics = 0;
int SDL_SYS_HapticInit(void)
{
Android_JNI_PollHapticDevices();
return numhaptics;
}
int SDL_SYS_NumHaptics(void)
{
return numhaptics;
}
static SDL_hapticlist_item *HapticByOrder(int index)
{
SDL_hapticlist_item *item = SDL_hapticlist;
if ((index < 0) || (index >= numhaptics)) {
return NULL;
}
while (index > 0) {
SDL_assert(item != NULL);
--index;
item = item->next;
}
return item;
}
static SDL_hapticlist_item *HapticByDevId(int device_id)
{
SDL_hapticlist_item *item;
for (item = SDL_hapticlist; item != NULL; item = item->next) {
if (device_id == item->device_id) {
/*SDL_Log("=+=+=+=+=+= HapticByDevId id [%d]", device_id);*/
return item;
}
}
return NULL;
}
const char *SDL_SYS_HapticName(int index)
{
SDL_hapticlist_item *item = HapticByOrder(index);
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)
{
if (item == NULL) {
SDL_SetError("No such device");
return NULL;
}
if (item->haptic != NULL) {
SDL_SetError("Haptic already opened");
return NULL;
}
haptic->hwdata = (struct haptic_hwdata *)item;
item->haptic = haptic;
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);
if (haptic->effects == NULL) {
SDL_OutOfMemory();
return NULL;
}
SDL_memset(haptic->effects, 0, sizeof(struct haptic_effect) * haptic->neffects);
return item;
}
static SDL_hapticlist_item *OpenHapticByOrder(SDL_Haptic *haptic, int index)
{
return OpenHaptic(haptic, HapticByOrder(index));
}
static SDL_hapticlist_item *OpenHapticByDevId(SDL_Haptic *haptic, int device_id)
{
return OpenHaptic(haptic, HapticByDevId(device_id));
}
int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
{
return OpenHapticByOrder(haptic, haptic->index) == NULL ? -1 : 0;
}
int SDL_SYS_HapticMouse(void)
{
return -1;
}
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)
{
return OpenHapticByDevId(haptic, ((joystick_hwdata *)joystick->hwdata)->device_id) == NULL ? -1 : 0;
}
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;
}
void SDL_SYS_HapticClose(SDL_Haptic *haptic)
{
((SDL_hapticlist_item *)haptic->hwdata)->haptic = NULL;
haptic->hwdata = NULL;
}
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.
*/
#if 0
SDL_hapticlist_item *item = NULL;
SDL_hapticlist_item *next = NULL;
for (item = SDL_hapticlist; item; item = next) {
next = item->next;
SDL_free(item);
}
SDL_hapticlist = SDL_hapticlist_tail = NULL;
numhaptics = 0;
return;
#endif
}
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)
{
return 0;
}
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);
return 0;
}
int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
{
Android_JNI_HapticStop(((SDL_hapticlist_item *)haptic->hwdata)->device_id);
return 0;
}
void SDL_SYS_HapticDestroyEffect(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)
{
return 0;
}
int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
{
return 0;
}
int SDL_SYS_HapticPause(SDL_Haptic *haptic)
{
return 0;
}
int SDL_SYS_HapticUnpause(SDL_Haptic *haptic)
{
return 0;
}
int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
{
return 0;
}
int Android_AddHaptic(int device_id, const char *name)
{
SDL_hapticlist_item *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);
if (item->name == NULL) {
SDL_free(item);
return -1;
}
if (SDL_hapticlist_tail == NULL) {
SDL_hapticlist = SDL_hapticlist_tail = item;
} else {
SDL_hapticlist_tail->next = item;
SDL_hapticlist_tail = item;
}
++numhaptics;
return numhaptics;
}
int Android_RemoveHaptic(int device_id)
{
SDL_hapticlist_item *item;
SDL_hapticlist_item *prev = NULL;
for (item = SDL_hapticlist; item != NULL; item = item->next) {
/* found it, remove it. */
if (device_id == item->device_id) {
const int retval = item->haptic ? item->haptic->index : -1;
if (prev != NULL) {
prev->next = item->next;
} else {
SDL_assert(SDL_hapticlist == item);
SDL_hapticlist = item->next;
}
if (item == SDL_hapticlist_tail) {
SDL_hapticlist_tail = prev;
}
/* Need to decrement the haptic count */
--numhaptics;
/* !!! TODO: Send a haptic remove event? */
SDL_free(item->name);
SDL_free(item);
return retval;
}
prev = item;
}
return -1;
}
#endif /* SDL_HAPTIC_ANDROID */

View File

@ -0,0 +1,28 @@
/*
Simple DirectMedia Layer
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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#ifdef SDL_HAPTIC_ANDROID
extern int Android_AddHaptic(int device_id, const char *name);
extern int Android_RemoveHaptic(int device_id);
#endif /* SDL_HAPTIC_ANDROID */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,29 @@
/*
Simple DirectMedia Layer
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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* 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);

View File

@ -0,0 +1,144 @@
/*
Simple DirectMedia Layer
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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#if defined(SDL_HAPTIC_DUMMY) || defined(SDL_HAPTIC_DISABLED)
#include "../SDL_syshaptic.h"
static int SDL_SYS_LogicError(void)
{
return SDL_SetError("Logic error: No haptic devices available.");
}
int SDL_SYS_HapticInit(void)
{
return 0;
}
int SDL_SYS_NumHaptics(void)
{
return 0;
}
const char *SDL_SYS_HapticName(int index)
{
SDL_SYS_LogicError();
return NULL;
}
int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
{
return SDL_SYS_LogicError();
}
int SDL_SYS_HapticMouse(void)
{
return -1;
}
int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
{
return 0;
}
int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
{
return SDL_SYS_LogicError();
}
int SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
{
return 0;
}
void SDL_SYS_HapticClose(SDL_Haptic *haptic)
{
return;
}
void SDL_SYS_HapticQuit(void)
{
return;
}
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)
{
return SDL_SYS_LogicError();
}
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)
{
return SDL_SYS_LogicError();
}
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)
{
return SDL_SYS_LogicError();
}
int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
{
return SDL_SYS_LogicError();
}
int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
{
return SDL_SYS_LogicError();
}
int SDL_SYS_HapticPause(SDL_Haptic *haptic)
{
return SDL_SYS_LogicError();
}
int SDL_SYS_HapticUnpause(SDL_Haptic *haptic)
{
return SDL_SYS_LogicError();
}
int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
{
return SDL_SYS_LogicError();
}
#endif /* SDL_HAPTIC_DUMMY || SDL_HAPTIC_DISABLED */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,53 @@
/*
Simple DirectMedia Layer
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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.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 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);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,445 @@
/*
Simple DirectMedia Layer
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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#if defined(SDL_HAPTIC_DINPUT) || defined(SDL_HAPTIC_XINPUT)
#include "../SDL_syshaptic.h"
#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
#include "../../joystick/windows/SDL_windowsjoystick_c.h" /* For joystick hwdata */
#include "../../joystick/windows/SDL_xinputjoystick_c.h" /* For xinput rumble */
#include "SDL_windowshaptic_c.h"
#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.
*/
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)
{
JoyStick_DeviceData *device;
if (SDL_DINPUT_HapticInit() < 0) {
return -1;
}
if (SDL_XINPUT_HapticInit() < 0) {
return -1;
}
/* The joystick subsystem will usually be initialized before haptics,
* so the initial HapticMaybeAddDevice() calls from the joystick
* subsystem will arrive too early to create haptic devices. We will
* invoke those callbacks again here to pick up any joysticks that
* were added prior to haptics initialization. */
for (device = SYS_Joystick; device; device = device->pNext) {
if (device->bXInputDevice) {
SDL_XINPUT_HapticMaybeAddDevice(device->XInputUserId);
} else {
SDL_DINPUT_HapticMaybeAddDevice(&device->dxdevice);
}
}
return numhaptics;
}
int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item)
{
if (SDL_hapticlist_tail == NULL) {
SDL_hapticlist = SDL_hapticlist_tail = item;
} else {
SDL_hapticlist_tail->next = item;
SDL_hapticlist_tail = item;
}
/* Device has been added. */
++numhaptics;
return numhaptics;
}
int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item)
{
const int retval = item->haptic ? item->haptic->index : -1;
if (prev != NULL) {
prev->next = item->next;
} else {
SDL_assert(SDL_hapticlist == item);
SDL_hapticlist = item->next;
}
if (item == SDL_hapticlist_tail) {
SDL_hapticlist_tail = prev;
}
--numhaptics;
/* !!! TODO: Send a haptic remove event? */
SDL_free(item);
return retval;
}
int SDL_SYS_NumHaptics(void)
{
return numhaptics;
}
static SDL_hapticlist_item *HapticByDevIndex(int device_index)
{
SDL_hapticlist_item *item = SDL_hapticlist;
if ((device_index < 0) || (device_index >= numhaptics)) {
return NULL;
}
while (device_index > 0) {
SDL_assert(item != NULL);
--device_index;
item = item->next;
}
return item;
}
/*
* Return the name of a haptic device, does not need to be opened.
*/
const char *SDL_SYS_HapticName(int index)
{
SDL_hapticlist_item *item = HapticByDevIndex(index);
return item->name;
}
/*
* Opens a haptic device for usage.
*/
int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
{
SDL_hapticlist_item *item = HapticByDevIndex(haptic->index);
if (item->bXInputHaptic) {
return SDL_XINPUT_HapticOpen(haptic, item);
} else {
return SDL_DINPUT_HapticOpen(haptic, item);
}
}
/*
* Opens a haptic device from first mouse it finds for usage.
*/
int SDL_SYS_HapticMouse(void)
{
#ifdef SDL_HAPTIC_DINPUT
SDL_hapticlist_item *item;
int index = 0;
/* Grab the first mouse haptic device we find. */
for (item = SDL_hapticlist; item != NULL; item = item->next) {
if (item->capabilities.dwDevType == DI8DEVCLASS_POINTER) {
return index;
}
++index;
}
#endif /* SDL_HAPTIC_DINPUT */
return -1;
}
/*
* Checks to see if a joystick has haptic features.
*/
int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
{
if (joystick->driver != &SDL_WINDOWS_JoystickDriver) {
return 0;
}
#ifdef SDL_HAPTIC_XINPUT
if (joystick->hwdata->bXInputHaptic) {
return 1;
}
#endif
#ifdef SDL_HAPTIC_DINPUT
if (joystick->hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) {
return 1;
}
#endif
return 0;
}
/*
* Checks to see if the haptic device and joystick are in reality the same.
*/
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. */
} else if (joystick->hwdata->bXInputHaptic) {
return SDL_XINPUT_JoystickSameHaptic(haptic, joystick);
} else {
return SDL_DINPUT_JoystickSameHaptic(haptic, joystick);
}
}
/*
* Opens a SDL_Haptic from a SDL_Joystick.
*/
int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
{
SDL_assert(joystick->driver == &SDL_WINDOWS_JoystickDriver);
if (joystick->hwdata->bXInputDevice) {
return SDL_XINPUT_HapticOpenFromJoystick(haptic, joystick);
} else {
return SDL_DINPUT_HapticOpenFromJoystick(haptic, joystick);
}
}
/*
* Closes the haptic device.
*/
void SDL_SYS_HapticClose(SDL_Haptic *haptic)
{
if (haptic->hwdata) {
/* Free effects. */
SDL_free(haptic->effects);
haptic->effects = NULL;
haptic->neffects = 0;
/* Clean up */
if (haptic->hwdata->bXInputHaptic) {
SDL_XINPUT_HapticClose(haptic);
} else {
SDL_DINPUT_HapticClose(haptic);
}
/* Free */
SDL_free(haptic->hwdata);
haptic->hwdata = NULL;
}
}
/*
* Clean up after system specific haptic stuff
*/
void SDL_SYS_HapticQuit(void)
{
SDL_hapticlist_item *item;
SDL_hapticlist_item *next = NULL;
SDL_Haptic *hapticitem = NULL;
extern SDL_Haptic *SDL_haptics;
for (hapticitem = SDL_haptics; hapticitem; hapticitem = hapticitem->next) {
if ((hapticitem->hwdata->bXInputHaptic) && (hapticitem->hwdata->thread)) {
/* we _have_ to stop the thread before we free the XInput DLL! */
SDL_AtomicSet(&hapticitem->hwdata->stopThread, 1);
SDL_WaitThread(hapticitem->hwdata->thread, NULL);
hapticitem->hwdata->thread = NULL;
}
}
for (item = SDL_hapticlist; item; item = next) {
/* Opened and not closed haptics are leaked, this is on purpose.
* Close your haptic devices after usage. */
/* !!! FIXME: (...is leaking on purpose a good idea?) - No, of course not. */
next = item->next;
SDL_free(item->name);
SDL_free(item);
}
SDL_XINPUT_HapticQuit();
SDL_DINPUT_HapticQuit();
numhaptics = 0;
SDL_hapticlist = NULL;
SDL_hapticlist_tail = NULL;
}
/*
* Creates a new haptic effect.
*/
int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
SDL_HapticEffect *base)
{
int result;
/* Alloc the effect. */
effect->hweffect = (struct haptic_hweffect *)
SDL_malloc(sizeof(struct haptic_hweffect));
if (effect->hweffect == NULL) {
SDL_OutOfMemory();
return -1;
}
SDL_zerop(effect->hweffect);
if (haptic->hwdata->bXInputHaptic) {
result = SDL_XINPUT_HapticNewEffect(haptic, effect, base);
} else {
result = SDL_DINPUT_HapticNewEffect(haptic, effect, base);
}
if (result < 0) {
SDL_free(effect->hweffect);
effect->hweffect = NULL;
}
return result;
}
/*
* Updates an effect.
*/
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);
} else {
return SDL_DINPUT_HapticUpdateEffect(haptic, effect, data);
}
}
/*
* Runs an effect.
*/
int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
Uint32 iterations)
{
if (haptic->hwdata->bXInputHaptic) {
return SDL_XINPUT_HapticRunEffect(haptic, effect, iterations);
} else {
return SDL_DINPUT_HapticRunEffect(haptic, effect, iterations);
}
}
/*
* Stops an effect.
*/
int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
{
if (haptic->hwdata->bXInputHaptic) {
return SDL_XINPUT_HapticStopEffect(haptic, effect);
} else {
return SDL_DINPUT_HapticStopEffect(haptic, effect);
}
}
/*
* Frees the effect.
*/
void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
{
if (haptic->hwdata->bXInputHaptic) {
SDL_XINPUT_HapticDestroyEffect(haptic, effect);
} else {
SDL_DINPUT_HapticDestroyEffect(haptic, effect);
}
SDL_free(effect->hweffect);
effect->hweffect = NULL;
}
/*
* Gets the status of a haptic effect.
*/
int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic,
struct haptic_effect *effect)
{
if (haptic->hwdata->bXInputHaptic) {
return SDL_XINPUT_HapticGetEffectStatus(haptic, effect);
} else {
return SDL_DINPUT_HapticGetEffectStatus(haptic, effect);
}
}
/*
* Sets the gain.
*/
int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
{
if (haptic->hwdata->bXInputHaptic) {
return SDL_XINPUT_HapticSetGain(haptic, gain);
} else {
return SDL_DINPUT_HapticSetGain(haptic, gain);
}
}
/*
* Sets the autocentering.
*/
int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
{
if (haptic->hwdata->bXInputHaptic) {
return SDL_XINPUT_HapticSetAutocenter(haptic, autocenter);
} else {
return SDL_DINPUT_HapticSetAutocenter(haptic, autocenter);
}
}
/*
* Pauses the device.
*/
int SDL_SYS_HapticPause(SDL_Haptic *haptic)
{
if (haptic->hwdata->bXInputHaptic) {
return SDL_XINPUT_HapticPause(haptic);
} else {
return SDL_DINPUT_HapticPause(haptic);
}
}
/*
* Pauses the device.
*/
int SDL_SYS_HapticUnpause(SDL_Haptic *haptic)
{
if (haptic->hwdata->bXInputHaptic) {
return SDL_XINPUT_HapticUnpause(haptic);
} else {
return SDL_DINPUT_HapticUnpause(haptic);
}
}
/*
* Stops all the playing effects on the device.
*/
int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
{
if (haptic->hwdata->bXInputHaptic) {
return SDL_XINPUT_HapticStopAll(haptic);
} else {
return SDL_DINPUT_HapticStopAll(haptic);
}
}
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* SDL_HAPTIC_DINPUT || SDL_HAPTIC_XINPUT */

View File

@ -0,0 +1,95 @@
/*
Simple DirectMedia Layer
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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#ifndef SDL_windowshaptic_c_h_
#define SDL_windowshaptic_c_h_
#include "../SDL_syshaptic.h"
#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.
*/
struct haptic_hwdata
{
#ifdef 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 */
SDL_Thread *thread;
SDL_Mutex *mutex;
Uint64 stopTicks;
SDL_AtomicInt stopThread;
};
/*
* Haptic system effect data.
*/
#if defined(SDL_HAPTIC_DINPUT) || defined(SDL_HAPTIC_XINPUT)
struct haptic_hweffect
{
#ifdef SDL_HAPTIC_DINPUT
DIEFFECT effect;
LPDIRECTINPUTEFFECT ref;
#endif
#ifdef SDL_HAPTIC_XINPUT
XINPUT_VIBRATION vibration;
#endif
};
#endif
/*
* List of available haptic devices.
*/
typedef struct SDL_hapticlist_item
{
char *name;
SDL_Haptic *haptic;
#ifdef SDL_HAPTIC_DINPUT
DIDEVICEINSTANCE instance;
DIDEVCAPS capabilities;
#endif
SDL_bool bXInputHaptic; /* Supports force feedback via XInput. */
Uint8 userid; /* XInput userid index for this joystick */
struct SDL_hapticlist_item *next;
} SDL_hapticlist_item;
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_ */

View File

@ -0,0 +1,446 @@
/*
Simple DirectMedia Layer
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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#include "../SDL_syshaptic.h"
#ifdef SDL_HAPTIC_XINPUT
#include "SDL_windowshaptic_c.h"
#include "SDL_xinputhaptic_c.h"
#include "../../core/windows/SDL_xinput.h"
#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)
{
if (SDL_GetHintBoolean(SDL_HINT_XINPUT_ENABLED, SDL_TRUE)) {
loaded_xinput = (WIN_LoadXInputDLL() == 0) ? SDL_TRUE : SDL_FALSE;
}
/* If the joystick subsystem is active, it will manage adding XInput haptic devices */
if (loaded_xinput && !SDL_WasInit(SDL_INIT_JOYSTICK)) {
DWORD i;
for (i = 0; i < XUSER_MAX_COUNT; i++) {
SDL_XINPUT_HapticMaybeAddDevice(i);
}
}
return 0;
}
int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
{
const Uint8 userid = (Uint8)dwUserid;
SDL_hapticlist_item *item;
XINPUT_VIBRATION state;
if ((!loaded_xinput) || (dwUserid >= XUSER_MAX_COUNT)) {
return -1;
}
/* 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 */
}
}
SDL_zero(state);
if (XINPUTSETSTATE(dwUserid, &state) != ERROR_SUCCESS) {
return -1; /* no force feedback on this device. */
}
item = (SDL_hapticlist_item *)SDL_malloc(sizeof(SDL_hapticlist_item));
if (item == NULL) {
return SDL_OutOfMemory();
}
SDL_zerop(item);
/* !!! FIXME: I'm not bothering to query for a real name right now (can we even?) */
{
char buf[64];
(void)SDL_snprintf(buf, sizeof(buf), "XInput Controller #%u", userid + 1);
item->name = SDL_strdup(buf);
}
if (!item->name) {
SDL_free(item);
return -1;
}
/* Copy the instance over, useful for creating devices. */
item->bXInputHaptic = SDL_TRUE;
item->userid = userid;
return SDL_SYS_AddHapticDevice(item);
}
int SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid)
{
const Uint8 userid = (Uint8)dwUserid;
SDL_hapticlist_item *item;
SDL_hapticlist_item *prev = NULL;
if ((!loaded_xinput) || (dwUserid >= XUSER_MAX_COUNT)) {
return -1;
}
for (item = SDL_hapticlist; item != NULL; item = item->next) {
if (item->bXInputHaptic && item->userid == userid) {
/* found it, remove it. */
return SDL_SYS_RemoveHapticDevice(prev, item);
}
prev = item;
}
return -1;
}
/* !!! FIXME: this is a hack, remove this later. */
/* Since XInput doesn't offer a way to vibrate for X time, we hook into
* SDL_PumpEvents() to check if it's time to stop vibrating with some
* frequency.
* In practice, this works for 99% of use cases. But in an ideal world,
* we do this in a separate thread so that:
* - we aren't bound to when the app chooses to pump the event queue.
* - we aren't adding more polling to the event queue
* - we can emulate all the haptic effects correctly (start on a delay,
* mix multiple effects, etc).
*
* 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)
{
struct haptic_hwdata *hwdata = (struct haptic_hwdata *)arg;
while (!SDL_AtomicGet(&hwdata->stopThread)) {
SDL_Delay(50);
SDL_LockMutex(hwdata->mutex);
/* If we're currently running and need to stop... */
if (hwdata->stopTicks) {
if ((hwdata->stopTicks != SDL_HAPTIC_INFINITY) && SDL_GetTicks() >= hwdata->stopTicks) {
XINPUT_VIBRATION vibration = { 0, 0 };
hwdata->stopTicks = 0;
XINPUTSETSTATE(hwdata->userid, &vibration);
}
}
SDL_UnlockMutex(hwdata->mutex);
}
return 0;
}
static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 userid)
{
char threadName[32];
XINPUT_VIBRATION vibration = { 0, 0 }; /* stop any current vibration */
XINPUTSETSTATE(userid, &vibration);
haptic->supported = SDL_HAPTIC_LEFTRIGHT;
haptic->neffects = 1;
haptic->nplaying = 1;
/* Prepare effects memory. */
haptic->effects = (struct haptic_effect *)
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
if (haptic->effects == NULL) {
return SDL_OutOfMemory();
}
/* Clear the memory */
SDL_memset(haptic->effects, 0,
sizeof(struct haptic_effect) * haptic->neffects);
haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata));
if (haptic->hwdata == NULL) {
SDL_free(haptic->effects);
haptic->effects = NULL;
return SDL_OutOfMemory();
}
SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
haptic->hwdata->bXInputHaptic = 1;
haptic->hwdata->userid = userid;
haptic->hwdata->mutex = SDL_CreateMutex();
if (haptic->hwdata->mutex == NULL) {
SDL_free(haptic->effects);
SDL_free(haptic->hwdata);
haptic->effects = NULL;
return SDL_SetError("Couldn't create XInput haptic mutex");
}
(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) {
SDL_DestroyMutex(haptic->hwdata->mutex);
SDL_free(haptic->effects);
SDL_free(haptic->hwdata);
haptic->effects = NULL;
return SDL_SetError("Couldn't create XInput haptic thread");
}
return 0;
}
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)
{
return haptic->hwdata->userid == joystick->hwdata->userid;
}
int SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
{
SDL_hapticlist_item *item;
Uint8 index = 0;
/* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
for (item = SDL_hapticlist; item != NULL; item = item->next) {
if (item->bXInputHaptic && item->userid == joystick->hwdata->userid) {
haptic->index = index;
return SDL_XINPUT_HapticOpenFromUserIndex(haptic, joystick->hwdata->userid);
}
++index;
}
return SDL_SetError("Couldn't find joystick in haptic device list");
}
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)
{
if (loaded_xinput) {
WIN_UnloadXInputDLL();
loaded_xinput = SDL_FALSE;
}
}
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 */
return SDL_XINPUT_HapticUpdateEffect(haptic, effect, base);
}
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);
/* SDL_HapticEffect has max magnitude of 32767, XInput expects 65535 max, so multiply */
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. */
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)
{
XINPUT_VIBRATION *vib = &effect->hweffect->vibration;
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;
} else if ((!effect->effect.leftright.length) || (!iterations)) {
/* do nothing. Effect runs for zero milliseconds. */
} else {
haptic->hwdata->stopTicks = SDL_GetTicks() + (effect->effect.leftright.length * iterations);
}
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)
{
XINPUT_VIBRATION vibration = { 0, 0 };
SDL_LockMutex(haptic->hwdata->mutex);
haptic->hwdata->stopTicks = 0;
SDL_UnlockMutex(haptic->hwdata->mutex);
return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS) ? 0 : -1;
}
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)
{
return SDL_Unsupported();
}
int SDL_XINPUT_HapticSetGain(SDL_Haptic *haptic, int gain)
{
return SDL_Unsupported();
}
int SDL_XINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
{
return SDL_Unsupported();
}
int SDL_XINPUT_HapticPause(SDL_Haptic *haptic)
{
return SDL_Unsupported();
}
int SDL_XINPUT_HapticUnpause(SDL_Haptic *haptic)
{
return SDL_Unsupported();
}
int SDL_XINPUT_HapticStopAll(SDL_Haptic *haptic)
{
XINPUT_VIBRATION vibration = { 0, 0 };
SDL_LockMutex(haptic->hwdata->mutex);
haptic->hwdata->stopTicks = 0;
SDL_UnlockMutex(haptic->hwdata->mutex);
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)
{
return 0;
}
int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
{
return SDL_Unsupported();
}
int SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid)
{
return SDL_Unsupported();
}
int SDL_XINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item)
{
return SDL_Unsupported();
}
int SDL_XINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
{
return SDL_Unsupported();
}
int SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
{
return SDL_Unsupported();
}
void SDL_XINPUT_HapticClose(SDL_Haptic *haptic)
{
}
void SDL_XINPUT_HapticQuit(void)
{
}
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)
{
return SDL_Unsupported();
}
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)
{
return SDL_Unsupported();
}
void SDL_XINPUT_HapticDestroyEffect(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)
{
return SDL_Unsupported();
}
int SDL_XINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
{
return SDL_Unsupported();
}
int SDL_XINPUT_HapticPause(SDL_Haptic *haptic)
{
return SDL_Unsupported();
}
int SDL_XINPUT_HapticUnpause(SDL_Haptic *haptic)
{
return SDL_Unsupported();
}
int SDL_XINPUT_HapticStopAll(SDL_Haptic *haptic)
{
return SDL_Unsupported();
}
#endif /* SDL_HAPTIC_XINPUT */

View File

@ -0,0 +1,53 @@
/*
Simple DirectMedia Layer
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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.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 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);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif