mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-08 02:46:26 +00:00
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base. In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted. The script I ran for the src directory is added as build-scripts/clang-format-src.sh This fixes: #6592 #6593 #6594
This commit is contained in:
@@ -23,8 +23,8 @@
|
||||
#ifdef SDL_HAPTIC_IOKIT
|
||||
|
||||
#include "../SDL_syshaptic.h"
|
||||
#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
|
||||
#include "../../joystick/darwin/SDL_iokitjoystick_c.h" /* For joystick hwdata */
|
||||
#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
|
||||
#include "../../joystick/darwin/SDL_iokitjoystick_c.h" /* For joystick hwdata */
|
||||
#include "SDL_syshaptic_c.h"
|
||||
|
||||
#include <IOKit/IOKitLib.h>
|
||||
@@ -34,7 +34,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
|
||||
|
||||
/*
|
||||
@@ -42,10 +42,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;
|
||||
@@ -54,30 +54,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;
|
||||
@@ -87,8 +85,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:
|
||||
@@ -140,12 +137,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;
|
||||
@@ -170,7 +165,7 @@ SDL_SYS_HapticInit(void)
|
||||
}
|
||||
/* IOServiceGetMatchingServices consumes dictionary. */
|
||||
|
||||
if (!IOIteratorIsValid(iter)) { /* No iterator. */
|
||||
if (!IOIteratorIsValid(iter)) { /* No iterator. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -184,14 +179,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;
|
||||
|
||||
@@ -208,8 +201,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;
|
||||
@@ -226,8 +218,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;
|
||||
}
|
||||
@@ -283,8 +275,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;
|
||||
@@ -295,7 +286,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) {
|
||||
@@ -336,8 +327,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;
|
||||
@@ -355,20 +345,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) {
|
||||
@@ -401,14 +390,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;
|
||||
@@ -460,9 +448,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 */
|
||||
@@ -478,12 +465,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;
|
||||
@@ -511,7 +496,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);
|
||||
@@ -527,7 +511,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);
|
||||
@@ -542,23 +525,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);
|
||||
@@ -566,12 +546,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;
|
||||
@@ -587,12 +565,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) {
|
||||
@@ -605,18 +581,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;
|
||||
}
|
||||
@@ -624,25 +598,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;
|
||||
}
|
||||
@@ -653,12 +625,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) {
|
||||
|
||||
@@ -676,12 +646,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;
|
||||
@@ -701,12 +669,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;
|
||||
|
||||
@@ -719,18 +685,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;
|
||||
}
|
||||
@@ -778,21 +742,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;
|
||||
@@ -805,10 +767,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));
|
||||
@@ -817,7 +779,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) {
|
||||
@@ -830,7 +792,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];
|
||||
}
|
||||
@@ -840,7 +802,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:
|
||||
@@ -860,17 +821,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 {
|
||||
@@ -898,8 +857,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;
|
||||
@@ -908,17 +867,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 {
|
||||
@@ -961,14 +918,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;
|
||||
}
|
||||
|
||||
@@ -993,10 +949,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) {
|
||||
@@ -1030,17 +986,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) <
|
||||
@@ -1049,8 +1005,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 {
|
||||
@@ -1062,7 +1017,6 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
||||
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
return SDL_SetError("Haptic: Unknown effect type.");
|
||||
}
|
||||
@@ -1070,12 +1024,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;
|
||||
|
||||
@@ -1084,8 +1036,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;
|
||||
}
|
||||
@@ -1096,7 +1048,6 @@ SDL_SYS_HapticFreeFFEFFECT(FFEFFECT * effect, int type)
|
||||
effect->rglDirection = NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Gets the effect type from the generic SDL haptic effect wrapper.
|
||||
*/
|
||||
@@ -1110,9 +1061,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;
|
||||
@@ -1147,13 +1098,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;
|
||||
@@ -1188,22 +1137,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;
|
||||
@@ -1218,11 +1165,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);
|
||||
@@ -1237,18 +1184,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;
|
||||
@@ -1269,12 +1214,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;
|
||||
|
||||
@@ -1287,12 +1230,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;
|
||||
|
||||
@@ -1307,13 +1248,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;
|
||||
@@ -1328,20 +1267,18 @@ 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;
|
||||
|
||||
val = gain * 100; /* macOS uses 0 to 10,000 */
|
||||
val = gain * 100; /* macOS uses 0 to 10,000 */
|
||||
ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
|
||||
FFPROP_FFGAIN, &val);
|
||||
if (ret != FF_OK) {
|
||||
@@ -1351,12 +1288,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;
|
||||
@@ -1378,12 +1313,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;
|
||||
|
||||
@@ -1396,12 +1329,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;
|
||||
|
||||
@@ -1414,12 +1345,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;
|
||||
|
||||
|
Reference in New Issue
Block a user