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:
Sam Lantinga
2022-11-30 12:51:59 -08:00
committed by GitHub
parent 14b902faca
commit 5750bcb174
781 changed files with 51659 additions and 55763 deletions

View File

@@ -37,19 +37,16 @@ extern HWND SDL_HelperWindow;
static const HWND SDL_HelperWindow = NULL;
#endif
/*
* Internal stuff.
*/
static SDL_bool coinitialized = SDL_FALSE;
static LPDIRECTINPUT8 dinput = NULL;
/*
* Like SDL_SetError but for DX error codes.
*/
static int
DI_SetError(const char *str, HRESULT err)
static int DI_SetError(const char *str, HRESULT err)
{
return SDL_SetError("Haptic error %s", str);
}
@@ -57,22 +54,20 @@ DI_SetError(const char *str, HRESULT err)
/*
* Callback to find the haptic devices.
*/
static BOOL CALLBACK
EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
static BOOL CALLBACK EnumHapticsCallback(const DIDEVICEINSTANCE *pdidInstance, VOID *pContext)
{
(void) pContext;
(void)pContext;
SDL_DINPUT_HapticMaybeAddDevice(pdidInstance);
return DIENUM_CONTINUE; /* continue enumerating */
return DIENUM_CONTINUE; /* continue enumerating */
}
int
SDL_DINPUT_HapticInit(void)
int SDL_DINPUT_HapticInit(void)
{
HRESULT ret;
HINSTANCE instance;
DWORD devClass;
if (dinput != NULL) { /* Already open. */
if (dinput != NULL) { /* Already open. */
return SDL_SetError("Haptic: SubSystem already open.");
}
@@ -89,7 +84,7 @@ SDL_DINPUT_HapticInit(void)
coinitialized = SDL_TRUE;
ret = CoCreateInstance(&CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER,
&IID_IDirectInput8, (LPVOID *) &dinput);
&IID_IDirectInput8, (LPVOID *)&dinput);
if (FAILED(ret)) {
SDL_SYS_HapticQuit();
return DI_SetError("CoCreateInstance", ret);
@@ -100,7 +95,7 @@ SDL_DINPUT_HapticInit(void)
if (instance == NULL) {
SDL_SYS_HapticQuit();
return SDL_SetError("GetModuleHandle() failed with error code %lu.",
GetLastError());
GetLastError());
}
ret = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION);
if (FAILED(ret)) {
@@ -120,7 +115,7 @@ SDL_DINPUT_HapticInit(void)
EnumHapticsCallback,
NULL,
DIEDFL_FORCEFEEDBACK |
DIEDFL_ATTACHEDONLY);
DIEDFL_ATTACHEDONLY);
if (FAILED(ret)) {
SDL_SYS_HapticQuit();
return DI_SetError("Enumerating DirectInput devices", ret);
@@ -130,8 +125,7 @@ SDL_DINPUT_HapticInit(void)
return 0;
}
int
SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance)
{
HRESULT ret;
LPDIRECTINPUTDEVICE8 device;
@@ -140,13 +134,13 @@ SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
SDL_hapticlist_item *item = NULL;
if (dinput == NULL) {
return -1; /* not initialized. We'll pick these up on enumeration if we init later. */
return -1; /* not initialized. We'll pick these up on enumeration if we init later. */
}
/* Make sure we don't already have it */
for (item = SDL_hapticlist; item; item = item->next) {
if ((!item->bXInputHaptic) && (SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0)) {
return -1; /* Already added */
return -1; /* Already added */
}
}
@@ -168,7 +162,7 @@ SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
}
if ((capabilities.dwFlags & needflags) != needflags) {
return -1; /* not a device we can use. */
return -1; /* not a device we can use. */
}
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
@@ -189,14 +183,13 @@ SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
return SDL_SYS_AddHapticDevice(item);
}
int
SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance)
{
SDL_hapticlist_item *item;
SDL_hapticlist_item *prev = NULL;
if (dinput == NULL) {
return -1; /* not initialized, ignore this. */
return -1; /* not initialized, ignore this. */
}
for (item = SDL_hapticlist; item != NULL; item = item->next) {
@@ -212,10 +205,9 @@ SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
/*
* Callback to get supported axes.
*/
static BOOL CALLBACK
DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
static BOOL CALLBACK DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
{
SDL_Haptic *haptic = (SDL_Haptic *) pvRef;
SDL_Haptic *haptic = (SDL_Haptic *)pvRef;
if ((dev->dwType & DIDFT_AXIS) && (dev->dwFlags & DIDOI_FFACTUATOR)) {
const GUID *guid = &dev->guidType;
@@ -233,7 +225,7 @@ DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
} else if (WIN_IsEqualGUID(guid, &GUID_RzAxis)) {
offset = DIJOFS_RZ;
} else {
return DIENUM_CONTINUE; /* can't use this, go on. */
return DIENUM_CONTINUE; /* can't use this, go on. */
}
haptic->hwdata->axes[haptic->naxes] = offset;
@@ -251,14 +243,13 @@ DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
/*
* Callback to get all supported effects.
*/
#define EFFECT_TEST(e,s) \
if (WIN_IsEqualGUID(&pei->guid, &(e))) \
haptic->supported |= (s)
static BOOL CALLBACK
DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv)
#define EFFECT_TEST(e, s) \
if (WIN_IsEqualGUID(&pei->guid, &(e))) \
haptic->supported |= (s)
static BOOL CALLBACK DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv)
{
/* Prepare the haptic device. */
SDL_Haptic *haptic = (SDL_Haptic *) pv;
SDL_Haptic *haptic = (SDL_Haptic *)pv;
/* Get supported. */
EFFECT_TEST(GUID_Spring, SDL_HAPTIC_SPRING);
@@ -289,8 +280,7 @@ DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv)
* - Reset actuators.
* - Get supported features.
*/
static int
SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device8, SDL_bool is_joystick)
static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVICE8 device8, SDL_bool is_joystick)
{
HRESULT ret;
DIPROPDWORD dipdw;
@@ -313,12 +303,12 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
!!! FIXME: to work, and that's probably the common case. Still,
!!! FIXME: ideally, We need to unify the opening code. */
if (!is_joystick) { /* if is_joystick, we already set this up elsewhere. */
if (!is_joystick) { /* if is_joystick, we already set this up elsewhere. */
/* Grab it exclusively to use force feedback stuff. */
ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device,
SDL_HelperWindow,
DISCL_EXCLUSIVE |
DISCL_BACKGROUND);
DISCL_BACKGROUND);
if (FAILED(ret)) {
DI_SetError("Setting cooperative level to exclusive", ret);
goto acquire_err;
@@ -332,7 +322,6 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
goto acquire_err;
}
/* Acquire the device. */
ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
if (FAILED(ret)) {
@@ -374,7 +363,7 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
DI_SetError("Enumerating supported effects", ret);
goto acquire_err;
}
if (haptic->supported == 0) { /* Error since device supports nothing. */
if (haptic->supported == 0) { /* Error since device supports nothing. */
SDL_SetError("Haptic: Internal error on finding supported effects.");
goto acquire_err;
}
@@ -387,7 +376,7 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
dipdw.dwData = 10000;
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
DIPROP_FFGAIN, &dipdw.diph);
if (!FAILED(ret)) { /* Gain is supported. */
if (!FAILED(ret)) { /* Gain is supported. */
haptic->supported |= SDL_HAPTIC_GAIN;
}
dipdw.diph.dwObj = 0;
@@ -395,7 +384,7 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
dipdw.dwData = DIPROPAUTOCENTER_OFF;
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
DIPROP_AUTOCENTER, &dipdw.diph);
if (!FAILED(ret)) { /* Autocenter is supported. */
if (!FAILED(ret)) { /* Autocenter is supported. */
haptic->supported |= SDL_HAPTIC_AUTOCENTER;
}
@@ -403,11 +392,11 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
haptic->supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
/* Check maximum effects. */
haptic->neffects = 128; /* This is not actually supported as thus under windows,
there is no way to tell the number of EFFECTS that a
device can hold, so we'll just use a "random" number
instead and put warnings in SDL_haptic.h */
haptic->nplaying = 128; /* Even more impossible to get this then neffects. */
haptic->neffects = 128; /* This is not actually supported as thus under windows,
there is no way to tell the number of EFFECTS that a
device can hold, so we'll just use a "random" number
instead and put warnings in SDL_haptic.h */
haptic->nplaying = 128; /* Even more impossible to get this then neffects. */
/* Prepare effects memory. */
haptic->effects = (struct haptic_effect *)
@@ -423,20 +412,19 @@ SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device
return 0;
/* Error handling */
acquire_err:
acquire_err:
IDirectInputDevice8_Unacquire(haptic->hwdata->device);
return -1;
}
int
SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
int SDL_DINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item)
{
HRESULT ret;
LPDIRECTINPUTDEVICE8 device;
/* Open the device */
ret = IDirectInput8_CreateDevice(dinput, &item->instance.guidInstance,
&device, NULL);
&device, NULL);
if (FAILED(ret)) {
DI_SetError("Creating DirectInput device", ret);
return -1;
@@ -449,8 +437,7 @@ SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
return 0;
}
int
SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
int SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
{
HRESULT ret;
DIDEVICEINSTANCE hap_instance, joy_instance;
@@ -460,12 +447,12 @@ SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
/* Get the device instances. */
ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device,
&hap_instance);
&hap_instance);
if (FAILED(ret)) {
return 0;
}
ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice,
&joy_instance);
&joy_instance);
if (FAILED(ret)) {
return 0;
}
@@ -473,8 +460,7 @@ SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
return WIN_IsEqualGUID(&hap_instance.guidInstance, &joy_instance.guidInstance);
}
int
SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
{
SDL_hapticlist_item *item;
int index = 0;
@@ -499,8 +485,7 @@ SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
return SDL_SetError("Couldn't find joystick in haptic device list");
}
void
SDL_DINPUT_HapticClose(SDL_Haptic * haptic)
void SDL_DINPUT_HapticClose(SDL_Haptic *haptic)
{
IDirectInputDevice8_Unacquire(haptic->hwdata->device);
@@ -510,8 +495,7 @@ SDL_DINPUT_HapticClose(SDL_Haptic * haptic)
}
}
void
SDL_DINPUT_HapticQuit(void)
void SDL_DINPUT_HapticQuit(void)
{
if (dinput != NULL) {
IDirectInput8_Release(dinput);
@@ -527,8 +511,7 @@ SDL_DINPUT_HapticQuit(void)
/*
* Converts an SDL trigger button to an DIEFFECT trigger button.
*/
static DWORD
DIGetTriggerButton(Uint16 button)
static DWORD DIGetTriggerButton(Uint16 button)
{
DWORD dwTriggerButton;
@@ -541,18 +524,16 @@ DIGetTriggerButton(Uint16 button)
return dwTriggerButton;
}
/*
* Sets the direction.
*/
static int
SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes)
static int SDL_SYS_SetDirection(DIEFFECT *effect, SDL_HapticDirection *dir, int naxes)
{
LONG *rglDir;
/* Handle no axes a part. */
if (naxes == 0) {
effect->dwFlags |= DIEFF_SPHERICAL; /* Set as default. */
effect->dwFlags |= DIEFF_SPHERICAL; /* Set as default. */
effect->rglDirection = NULL;
return 0;
}
@@ -601,20 +582,19 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes)
}
/* Clamps and converts. */
#define CCONVERT(x) (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
#define CCONVERT(x) (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
/* Just converts. */
#define CONVERT(x) (((x)*10000) / 0x7FFF)
#define CONVERT(x) (((x)*10000) / 0x7FFF)
/*
* Creates the DIEFFECT from a SDL_HapticEffect.
*/
static int
SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
SDL_HapticEffect * src)
static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
SDL_HapticEffect *src)
{
int i;
DICONSTANTFORCE *constant;
DIPERIODIC *periodic;
DICONDITION *condition; /* Actually an array of conditions - one per axis. */
DICONDITION *condition; /* Actually an array of conditions - one per axis. */
DIRAMPFORCE *ramp;
DICUSTOMFORCE *custom;
DIENVELOPE *envelope;
@@ -627,10 +607,10 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
/* Set global stuff. */
SDL_memset(dest, 0, sizeof(DIEFFECT));
dest->dwSize = sizeof(DIEFFECT); /* Set the structure size. */
dest->dwSamplePeriod = 0; /* Not used by us. */
dest->dwGain = 10000; /* Gain is set globally, not locally. */
dest->dwFlags = DIEFF_OBJECTOFFSETS; /* Seems obligatory. */
dest->dwSize = sizeof(DIEFFECT); /* Set the structure size. */
dest->dwSamplePeriod = 0; /* Not used by us. */
dest->dwGain = 10000; /* Gain is set globally, not locally. */
dest->dwFlags = DIEFF_OBJECTOFFSETS; /* Seems obligatory. */
/* Envelope. */
envelope = SDL_malloc(sizeof(DIENVELOPE));
@@ -639,7 +619,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
}
SDL_memset(envelope, 0, sizeof(DIENVELOPE));
dest->lpEnvelope = envelope;
envelope->dwSize = sizeof(DIENVELOPE); /* Always should be this. */
envelope->dwSize = sizeof(DIENVELOPE); /* Always should be this. */
/* Axes. */
if (src->constant.direction.type == SDL_HAPTIC_STEERING_AXIS) {
@@ -652,7 +632,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
if (axes == NULL) {
return SDL_OutOfMemory();
}
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
if (dest->cAxes > 1) {
axes[1] = haptic->hwdata->axes[1];
}
@@ -681,7 +661,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */
dest->dwTriggerButton = DIGetTriggerButton(hap_constant->button);
dest->dwTriggerRepeatInterval = hap_constant->interval;
dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */
dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */
/* Direction. */
if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) {
@@ -689,8 +669,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
}
/* Envelope */
if ((hap_constant->attack_length == 0)
&& (hap_constant->fade_length == 0)) {
if ((hap_constant->attack_length == 0) && (hap_constant->fade_length == 0)) {
SDL_free(dest->lpEnvelope);
dest->lpEnvelope = NULL;
} else {
@@ -719,7 +698,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude));
periodic->lOffset = CONVERT(hap_periodic->offset);
periodic->dwPhase =
(hap_periodic->phase + (hap_periodic->magnitude < 0 ? 18000 : 0)) % 36000;
(hap_periodic->phase + (hap_periodic->magnitude < 0 ? 18000 : 0)) % 36000;
periodic->dwPeriod = hap_periodic->period * 1000;
dest->cbTypeSpecificParams = sizeof(DIPERIODIC);
dest->lpvTypeSpecificParams = periodic;
@@ -728,17 +707,15 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
dest->dwDuration = hap_periodic->length * 1000; /* In microseconds. */
dest->dwTriggerButton = DIGetTriggerButton(hap_periodic->button);
dest->dwTriggerRepeatInterval = hap_periodic->interval;
dest->dwStartDelay = hap_periodic->delay * 1000; /* In microseconds. */
dest->dwStartDelay = hap_periodic->delay * 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(dest->lpEnvelope);
dest->lpEnvelope = NULL;
} else {
@@ -762,7 +739,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
SDL_memset(condition, 0, sizeof(DICONDITION));
/* Specifics */
for (i = 0; i < (int) dest->cAxes; i++) {
for (i = 0; i < (int)dest->cAxes; i++) {
condition[i].lOffset = CONVERT(hap_condition->center[i]);
condition[i].lPositiveCoefficient =
CONVERT(hap_condition->right_coeff[i]);
@@ -778,14 +755,13 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
dest->lpvTypeSpecificParams = condition;
/* Generics */
dest->dwDuration = hap_condition->length * 1000; /* In microseconds. */
dest->dwDuration = hap_condition->length * 1000; /* In microseconds. */
dest->dwTriggerButton = DIGetTriggerButton(hap_condition->button);
dest->dwTriggerRepeatInterval = hap_condition->interval;
dest->dwStartDelay = hap_condition->delay * 1000; /* In microseconds. */
dest->dwStartDelay = hap_condition->delay * 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;
}
@@ -810,10 +786,10 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
dest->lpvTypeSpecificParams = ramp;
/* Generics */
dest->dwDuration = hap_ramp->length * 1000; /* In microseconds. */
dest->dwDuration = hap_ramp->length * 1000; /* In microseconds. */
dest->dwTriggerButton = DIGetTriggerButton(hap_ramp->button);
dest->dwTriggerRepeatInterval = hap_ramp->interval;
dest->dwStartDelay = hap_ramp->delay * 1000; /* In microseconds. */
dest->dwStartDelay = hap_ramp->delay * 1000; /* In microseconds. */
/* Direction. */
if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) {
@@ -847,17 +823,17 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
custom->cSamples = hap_custom->samples;
custom->rglForceData =
SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) { /* Copy data. */
for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) { /* Copy data. */
custom->rglForceData[i] = CCONVERT(hap_custom->data[i]);
}
dest->cbTypeSpecificParams = sizeof(DICUSTOMFORCE);
dest->lpvTypeSpecificParams = custom;
/* Generics */
dest->dwDuration = hap_custom->length * 1000; /* In microseconds. */
dest->dwDuration = hap_custom->length * 1000; /* In microseconds. */
dest->dwTriggerButton = DIGetTriggerButton(hap_custom->button);
dest->dwTriggerRepeatInterval = hap_custom->interval;
dest->dwStartDelay = hap_custom->delay * 1000; /* In microseconds. */
dest->dwStartDelay = hap_custom->delay * 1000; /* In microseconds. */
/* Direction. */
if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) < 0) {
@@ -865,8 +841,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
}
/* Envelope */
if ((hap_custom->attack_length == 0)
&& (hap_custom->fade_length == 0)) {
if ((hap_custom->attack_length == 0) && (hap_custom->fade_length == 0)) {
SDL_free(dest->lpEnvelope);
dest->lpEnvelope = NULL;
} else {
@@ -885,12 +860,10 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
return 0;
}
/*
* Frees an DIEFFECT allocated by SDL_SYS_ToDIEFFECT.
*/
static void
SDL_SYS_HapticFreeDIEFFECT(DIEFFECT * effect, int type)
static void SDL_SYS_HapticFreeDIEFFECT(DIEFFECT *effect, int type)
{
DICUSTOMFORCE *custom;
@@ -899,8 +872,8 @@ SDL_SYS_HapticFreeDIEFFECT(DIEFFECT * effect, int type)
SDL_free(effect->rgdwAxes);
effect->rgdwAxes = NULL;
if (effect->lpvTypeSpecificParams != NULL) {
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
custom = (DICUSTOMFORCE *) effect->lpvTypeSpecificParams;
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
custom = (DICUSTOMFORCE *)effect->lpvTypeSpecificParams;
SDL_free(custom->rglForceData);
custom->rglForceData = NULL;
}
@@ -914,8 +887,7 @@ SDL_SYS_HapticFreeDIEFFECT(DIEFFECT * effect, int type)
/*
* Gets the effect type from the generic SDL haptic effect wrapper.
*/
static REFGUID
SDL_SYS_HapticEffectType(SDL_HapticEffect * effect)
static REFGUID SDL_SYS_HapticEffectType(SDL_HapticEffect *effect)
{
switch (effect->type) {
case SDL_HAPTIC_CONSTANT:
@@ -924,9 +896,9 @@ SDL_SYS_HapticEffectType(SDL_HapticEffect * effect)
case SDL_HAPTIC_RAMP:
return &GUID_RampForce;
/* !!! FIXME: put this back when we have more bits in 2.1 */
/* case SDL_HAPTIC_SQUARE:
return &GUID_Square; */
/* !!! FIXME: put this back when we have more bits in 2.1 */
/* case SDL_HAPTIC_SQUARE:
return &GUID_Square; */
case SDL_HAPTIC_SINE:
return &GUID_Sine;
@@ -959,8 +931,7 @@ SDL_SYS_HapticEffectType(SDL_HapticEffect * effect)
return NULL;
}
}
int
SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *base)
{
HRESULT ret;
REFGUID type = SDL_SYS_HapticEffectType(base);
@@ -976,8 +947,8 @@ SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SD
/* Create the actual effect. */
ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type,
&effect->hweffect->effect,
&effect->hweffect->ref, NULL);
&effect->hweffect->effect,
&effect->hweffect->ref, NULL);
if (FAILED(ret)) {
DI_SetError("Unable to create effect", ret);
goto err_effectdone;
@@ -990,8 +961,7 @@ err_effectdone:
return -1;
}
int
SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *data)
{
HRESULT ret;
DWORD flags;
@@ -1004,13 +974,13 @@ SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
}
/* Set the flags. Might be worthwhile to diff temp with loaded effect and
* only change those parameters. */
* only change those parameters. */
flags = DIEP_DIRECTION |
DIEP_DURATION |
DIEP_ENVELOPE |
DIEP_STARTDELAY |
DIEP_TRIGGERBUTTON |
DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS;
DIEP_DURATION |
DIEP_ENVELOPE |
DIEP_STARTDELAY |
DIEP_TRIGGERBUTTON |
DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS;
/* Create the actual effect. */
ret =
@@ -1044,8 +1014,7 @@ err_update:
return -1;
}
int
SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
int SDL_DINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations)
{
HRESULT ret;
DWORD iter;
@@ -1065,8 +1034,7 @@ SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Ui
return 0;
}
int
SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
int SDL_DINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
{
HRESULT ret;
@@ -1077,8 +1045,7 @@ SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
return 0;
}
void
SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
void SDL_DINPUT_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
{
HRESULT ret;
@@ -1089,8 +1056,7 @@ SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect
SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, effect->effect.type);
}
int
SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
int SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect)
{
HRESULT ret;
DWORD status;
@@ -1106,8 +1072,7 @@ SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effe
return SDL_TRUE;
}
int
SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
int SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain)
{
HRESULT ret;
DIPROPDWORD dipdw;
@@ -1117,19 +1082,18 @@ SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = gain * 100; /* 0 to 10,000 */
dipdw.dwData = gain * 100; /* 0 to 10,000 */
/* Try to set the autocenter. */
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
DIPROP_FFGAIN, &dipdw.diph);
DIPROP_FFGAIN, &dipdw.diph);
if (FAILED(ret)) {
return DI_SetError("Setting gain", ret);
}
return 0;
}
int
SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
int SDL_DINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
{
HRESULT ret;
DIPROPDWORD dipdw;
@@ -1139,54 +1103,50 @@ SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = (autocenter == 0) ? DIPROPAUTOCENTER_OFF :
DIPROPAUTOCENTER_ON;
dipdw.dwData = (autocenter == 0) ? DIPROPAUTOCENTER_OFF : DIPROPAUTOCENTER_ON;
/* Try to set the autocenter. */
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
DIPROP_AUTOCENTER, &dipdw.diph);
DIPROP_AUTOCENTER, &dipdw.diph);
if (FAILED(ret)) {
return DI_SetError("Setting autocenter", ret);
}
return 0;
}
int
SDL_DINPUT_HapticPause(SDL_Haptic * haptic)
int SDL_DINPUT_HapticPause(SDL_Haptic *haptic)
{
HRESULT ret;
/* Pause the device. */
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
DISFFC_PAUSE);
DISFFC_PAUSE);
if (FAILED(ret)) {
return DI_SetError("Pausing the device", ret);
}
return 0;
}
int
SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic)
int SDL_DINPUT_HapticUnpause(SDL_Haptic *haptic)
{
HRESULT ret;
/* Unpause the device. */
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
DISFFC_CONTINUE);
DISFFC_CONTINUE);
if (FAILED(ret)) {
return DI_SetError("Pausing the device", ret);
}
return 0;
}
int
SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic)
int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic)
{
HRESULT ret;
/* Try to stop the effects. */
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
DISFFC_STOPALL);
DISFFC_STOPALL);
if (FAILED(ret)) {
return DI_SetError("Stopping the device", ret);
}
@@ -1198,113 +1158,94 @@ SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic)
typedef struct DIDEVICEINSTANCE DIDEVICEINSTANCE;
typedef struct SDL_hapticlist_item SDL_hapticlist_item;
int
SDL_DINPUT_HapticInit(void)
int SDL_DINPUT_HapticInit(void)
{
return 0;
}
int
SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance)
{
return SDL_Unsupported();
}
int
SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance)
{
return SDL_Unsupported();
}
int
SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
int SDL_DINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item)
{
return SDL_Unsupported();
}
int
SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
int SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
{
return SDL_Unsupported();
}
int
SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
{
return SDL_Unsupported();
}
void
SDL_DINPUT_HapticClose(SDL_Haptic * haptic)
void SDL_DINPUT_HapticClose(SDL_Haptic *haptic)
{
}
void
SDL_DINPUT_HapticQuit(void)
void SDL_DINPUT_HapticQuit(void)
{
}
int
SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *base)
{
return SDL_Unsupported();
}
int
SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, SDL_HapticEffect *data)
{
return SDL_Unsupported();
}
int
SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
int SDL_DINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations)
{
return SDL_Unsupported();
}
int
SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
int SDL_DINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
{
return SDL_Unsupported();
}
void
SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
void SDL_DINPUT_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
{
}
int
SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
int SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect)
{
return SDL_Unsupported();
}
int
SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
int SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain)
{
return SDL_Unsupported();
}
int
SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
int SDL_DINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
{
return SDL_Unsupported();
}
int
SDL_DINPUT_HapticPause(SDL_Haptic * haptic)
int SDL_DINPUT_HapticPause(SDL_Haptic *haptic)
{
return SDL_Unsupported();
}
int
SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic)
int SDL_DINPUT_HapticUnpause(SDL_Haptic *haptic)
{
return SDL_Unsupported();
}
int
SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic)
int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic)
{
return SDL_Unsupported();
}