Use SDL_bool instead an int return code in the SDL API

Most SDL functions used to indicate success or failure using an int return code. These functions have been changed to return SDL_bool.

Here is a coccinelle patch to change code that previously compared the return value to 0 and changes it to a boolean test:
@ bool_return_type  @
identifier func =~ "^(SDL_AddEventWatch|SDL_AddHintCallback|SDL_AddSurfaceAlternateImage|SDL_AddVulkanRenderSemaphores|SDL_BindAudioStream|SDL_BindAudioStreams|SDL_BlitSurface|SDL_BlitSurface9Grid|SDL_BlitSurfaceScaled|SDL_BlitSurfaceTiled|SDL_BlitSurfaceTiledWithScale|SDL_BlitSurfaceUnchecked|SDL_BlitSurfaceUncheckedScaled|SDL_CaptureMouse|SDL_ClearAudioStream|SDL_ClearClipboardData|SDL_ClearComposition|SDL_ClearError|SDL_ClearProperty|SDL_ClearSurface|SDL_CloseIO|SDL_CloseStorage|SDL_ConvertAudioSamples|SDL_ConvertEventToRenderCoordinates|SDL_ConvertPixels|SDL_ConvertPixelsAndColorspace|SDL_CopyFile|SDL_CopyProperties|SDL_CopyStorageFile|SDL_CreateDirectory|SDL_CreateStorageDirectory|SDL_CreateWindowAndRenderer|SDL_DateTimeToTime|SDL_DestroyWindowSurface|SDL_DetachVirtualJoystick|SDL_DisableScreenSaver|SDL_EnableScreenSaver|SDL_EnumerateDirectory|SDL_EnumerateProperties|SDL_EnumerateStorageDirectory|SDL_FillSurfaceRect|SDL_FillSurfaceRects|SDL_FlashWindow|SDL_FlipSurface|SDL_FlushAudioStream|SDL_FlushRenderer|SDL_GL_DestroyContext|SDL_GL_GetAttribute|SDL_GL_GetSwapInterval|SDL_GL_LoadLibrary|SDL_GL_MakeCurrent|SDL_GL_SetAttribute|SDL_GL_SetSwapInterval|SDL_GL_SwapWindow|SDL_GetAudioDeviceFormat|SDL_GetAudioStreamFormat|SDL_GetCameraFormat|SDL_GetClosestFullscreenDisplayMode|SDL_GetCurrentRenderOutputSize|SDL_GetCurrentTime|SDL_GetDXGIOutputInfo|SDL_GetDateTimeLocalePreferences|SDL_GetDisplayBounds|SDL_GetDisplayUsableBounds|SDL_GetGDKDefaultUser|SDL_GetGDKTaskQueue|SDL_GetGamepadSensorData|SDL_GetGamepadTouchpadFinger|SDL_GetHapticEffectStatus|SDL_GetJoystickBall|SDL_GetMasksForPixelFormat|SDL_GetPathInfo|SDL_GetRectUnion|SDL_GetRectUnionFloat|SDL_GetRenderClipRect|SDL_GetRenderColorScale|SDL_GetRenderDrawBlendMode|SDL_GetRenderDrawColor|SDL_GetRenderDrawColorFloat|SDL_GetRenderLogicalPresentation|SDL_GetRenderLogicalPresentationRect|SDL_GetRenderOutputSize|SDL_GetRenderSafeArea|SDL_GetRenderScale|SDL_GetRenderVSync|SDL_GetRenderViewport|SDL_GetSensorData|SDL_GetStorageFileSize|SDL_GetStoragePathInfo|SDL_GetSurfaceAlphaMod|SDL_GetSurfaceBlendMode|SDL_GetSurfaceClipRect|SDL_GetSurfaceColorKey|SDL_GetSurfaceColorMod|SDL_GetTextInputArea|SDL_GetTextureAlphaMod|SDL_GetTextureAlphaModFloat|SDL_GetTextureBlendMode|SDL_GetTextureColorMod|SDL_GetTextureColorModFloat|SDL_GetTextureScaleMode|SDL_GetTextureSize|SDL_GetWindowAspectRatio|SDL_GetWindowBordersSize|SDL_GetWindowMaximumSize|SDL_GetWindowMinimumSize|SDL_GetWindowPosition|SDL_GetWindowRelativeMouseMode|SDL_GetWindowSafeArea|SDL_GetWindowSize|SDL_GetWindowSizeInPixels|SDL_GetWindowSurfaceVSync|SDL_HideCursor|SDL_HideWindow|SDL_Init|SDL_InitHapticRumble|SDL_InitSubSystem|SDL_LoadWAV|SDL_LoadWAV_IO|SDL_LockAudioStream|SDL_LockProperties|SDL_LockSurface|SDL_LockTexture|SDL_LockTextureToSurface|SDL_MaximizeWindow|SDL_MinimizeWindow|SDL_MixAudio|SDL_OpenURL|SDL_OutOfMemory|SDL_PauseAudioDevice|SDL_PauseAudioStreamDevice|SDL_PauseHaptic|SDL_PlayHapticRumble|SDL_PremultiplyAlpha|SDL_PremultiplySurfaceAlpha|SDL_PushEvent|SDL_PutAudioStreamData|SDL_RaiseWindow|SDL_ReadStorageFile|SDL_ReadSurfacePixel|SDL_ReadSurfacePixelFloat|SDL_RegisterApp|SDL_ReloadGamepadMappings|SDL_RemovePath|SDL_RemoveStoragePath|SDL_RemoveTimer|SDL_RenamePath|SDL_RenameStoragePath|SDL_RenderClear|SDL_RenderCoordinatesFromWindow|SDL_RenderCoordinatesToWindow|SDL_RenderFillRect|SDL_RenderFillRects|SDL_RenderGeometry|SDL_RenderGeometryRaw|SDL_RenderLine|SDL_RenderLines|SDL_RenderPoint|SDL_RenderPoints|SDL_RenderPresent|SDL_RenderRect|SDL_RenderRects|SDL_RenderTexture|SDL_RenderTexture9Grid|SDL_RenderTextureRotated|SDL_RenderTextureTiled|SDL_RequestAndroidPermission|SDL_RestoreWindow|SDL_ResumeAudioDevice|SDL_ResumeAudioStreamDevice|SDL_ResumeHaptic|SDL_RumbleGamepad|SDL_RumbleGamepadTriggers|SDL_RumbleJoystick|SDL_RumbleJoystickTriggers|SDL_RunHapticEffect|SDL_SaveBMP|SDL_SaveBMP_IO|SDL_SendAndroidMessage|SDL_SendGamepadEffect|SDL_SendJoystickEffect|SDL_SendJoystickVirtualSensorData|SDL_SetAppMetadata|SDL_SetAppMetadataProperty|SDL_SetAudioDeviceGain|SDL_SetAudioPostmixCallback|SDL_SetAudioStreamFormat|SDL_SetAudioStreamFrequencyRatio|SDL_SetAudioStreamGain|SDL_SetAudioStreamGetCallback|SDL_SetAudioStreamInputChannelMap|SDL_SetAudioStreamOutputChannelMap|SDL_SetAudioStreamPutCallback|SDL_SetBooleanProperty|SDL_SetClipboardData|SDL_SetClipboardText|SDL_SetCursor|SDL_SetFloatProperty|SDL_SetGamepadLED|SDL_SetGamepadMapping|SDL_SetGamepadPlayerIndex|SDL_SetGamepadSensorEnabled|SDL_SetHapticAutocenter|SDL_SetHapticGain|SDL_SetJoystickLED|SDL_SetJoystickPlayerIndex|SDL_SetJoystickVirtualAxis|SDL_SetJoystickVirtualBall|SDL_SetJoystickVirtualButton|SDL_SetJoystickVirtualHat|SDL_SetJoystickVirtualTouchpad|SDL_SetLinuxThreadPriority|SDL_SetLinuxThreadPriorityAndPolicy|SDL_SetLogPriorityPrefix|SDL_SetMemoryFunctions|SDL_SetNumberProperty|SDL_SetPaletteColors|SDL_SetPointerProperty|SDL_SetPointerPropertyWithCleanup|SDL_SetPrimarySelectionText|SDL_SetRenderClipRect|SDL_SetRenderColorScale|SDL_SetRenderDrawBlendMode|SDL_SetRenderDrawColor|SDL_SetRenderDrawColorFloat|SDL_SetRenderLogicalPresentation|SDL_SetRenderScale|SDL_SetRenderTarget|SDL_SetRenderVSync|SDL_SetRenderViewport|SDL_SetScancodeName|SDL_SetStringProperty|SDL_SetSurfaceAlphaMod|SDL_SetSurfaceBlendMode|SDL_SetSurfaceColorKey|SDL_SetSurfaceColorMod|SDL_SetSurfaceColorspace|SDL_SetSurfacePalette|SDL_SetSurfaceRLE|SDL_SetTLS|SDL_SetTextInputArea|SDL_SetTextureAlphaMod|SDL_SetTextureAlphaModFloat|SDL_SetTextureBlendMode|SDL_SetTextureColorMod|SDL_SetTextureColorModFloat|SDL_SetTextureScaleMode|SDL_SetThreadPriority|SDL_SetWindowAlwaysOnTop|SDL_SetWindowAspectRatio|SDL_SetWindowBordered|SDL_SetWindowFocusable|SDL_SetWindowFullscreen|SDL_SetWindowFullscreenMode|SDL_SetWindowHitTest|SDL_SetWindowIcon|SDL_SetWindowKeyboardGrab|SDL_SetWindowMaximumSize|SDL_SetWindowMinimumSize|SDL_SetWindowModalFor|SDL_SetWindowMouseGrab|SDL_SetWindowMouseRect|SDL_SetWindowOpacity|SDL_SetWindowPosition|SDL_SetWindowRelativeMouseMode|SDL_SetWindowResizable|SDL_SetWindowShape|SDL_SetWindowSize|SDL_SetWindowSurfaceVSync|SDL_SetWindowTitle|SDL_SetiOSAnimationCallback|SDL_ShowAndroidToast|SDL_ShowCursor|SDL_ShowMessageBox|SDL_ShowSimpleMessageBox|SDL_ShowWindow|SDL_ShowWindowSystemMenu|SDL_StartTextInput|SDL_StartTextInputWithProperties|SDL_StopHapticEffect|SDL_StopHapticEffects|SDL_StopHapticRumble|SDL_StopTextInput|SDL_SyncWindow|SDL_TimeToDateTime|SDL_TryLockMutex|SDL_TryLockRWLockForReading|SDL_TryLockRWLockForWriting|SDL_TryWaitSemaphore|SDL_UnlockAudioStream|SDL_UpdateHapticEffect|SDL_UpdateNVTexture|SDL_UpdateTexture|SDL_UpdateWindowSurface|SDL_UpdateWindowSurfaceRects|SDL_UpdateYUVTexture|SDL_Vulkan_CreateSurface|SDL_Vulkan_LoadLibrary|SDL_WaitConditionTimeout|SDL_WaitSemaphoreTimeout|SDL_WarpMouseGlobal|SDL_WriteStorageFile|SDL_WriteSurfacePixel|SDL_WriteSurfacePixelFloat)$";
@@
(
  func(
  ...
  )
- == 0
|
- func(
+ !func(
  ...
  )
- < 0
|
- func(
+ !func(
  ...
  )
- != 0
|
- func(
+ !func(
  ...
  )
- == -1
)
This commit is contained in:
Sam Lantinga
2024-08-22 17:33:49 -07:00
parent d9a5ed75b9
commit 9ff3446f03
726 changed files with 11062 additions and 11472 deletions

View File

@@ -77,7 +77,7 @@ struct haptic_hweffect
* Prototypes.
*/
static void SDL_SYS_HapticFreeFFEFFECT(FFEFFECT *effect, int type);
static int HIDGetDeviceProduct(io_service_t dev, char *name);
static bool HIDGetDeviceProduct(io_service_t dev, char *name);
static SDL_hapticlist_item *SDL_hapticlist = NULL;
static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
@@ -141,7 +141,7 @@ static const char *FFStrError(unsigned int err)
/*
* Initializes the haptic subsystem.
*/
int SDL_SYS_HapticInit(void)
bool SDL_SYS_HapticInit(void)
{
IOReturn result;
io_iterator_t iter;
@@ -167,7 +167,7 @@ int SDL_SYS_HapticInit(void)
// IOServiceGetMatchingServices consumes dictionary.
if (!IOIteratorIsValid(iter)) { // No iterator.
return 0;
return true;
}
while ((device = IOIteratorNext(iter)) != IO_OBJECT_NULL) {
@@ -177,7 +177,7 @@ int SDL_SYS_HapticInit(void)
}
IOObjectRelease(iter);
return numhaptics;
return true;
}
int SDL_SYS_NumHaptics(void)
@@ -213,7 +213,7 @@ static SDL_hapticlist_item *HapticByInstanceID(SDL_HapticID instance_id)
return NULL;
}
int MacHaptic_MaybeAddDevice(io_object_t device)
bool MacHaptic_MaybeAddDevice(io_object_t device)
{
IOReturn result;
CFMutableDictionaryRef hidProperties;
@@ -221,19 +221,19 @@ int MacHaptic_MaybeAddDevice(io_object_t device)
SDL_hapticlist_item *item;
if (numhaptics == -1) {
return -1; // not initialized. We'll pick these up on enumeration if we init later.
return false; // not initialized. We'll pick these up on enumeration if we init later.
}
// Check for force feedback.
if (FFIsForceFeedback(device) != FF_OK) {
return -1;
return false;
}
// Make sure we don't already have it
for (item = SDL_hapticlist; item; item = item->next) {
if (IOObjectIsEqualTo((io_object_t)item->dev, device)) {
// Already added
return -1;
return false;
}
}
@@ -285,22 +285,22 @@ int MacHaptic_MaybeAddDevice(io_object_t device)
// Device has been added.
++numhaptics;
return numhaptics;
return true;
}
int MacHaptic_MaybeRemoveDevice(io_object_t device)
bool MacHaptic_MaybeRemoveDevice(io_object_t device)
{
SDL_hapticlist_item *item;
SDL_hapticlist_item *prev = NULL;
if (numhaptics == -1) {
return -1; // not initialized. ignore this.
return false; // not initialized. ignore this.
}
for (item = SDL_hapticlist; item; item = item->next) {
// found it, remove it.
if (IOObjectIsEqualTo((io_object_t)item->dev, device)) {
const int retval = item->haptic ? 0 : -1;
bool result = item->haptic ? true : false;
if (prev) {
prev->next = item->next;
@@ -318,12 +318,12 @@ int MacHaptic_MaybeRemoveDevice(io_object_t device)
IOObjectRelease(item->dev);
SDL_free(item);
return retval;
return result;
}
prev = item;
}
return -1;
return false;
}
SDL_HapticID SDL_SYS_HapticInstanceID(int index)
@@ -352,7 +352,7 @@ const char *SDL_SYS_HapticName(int index)
/*
* Gets the device's product name.
*/
static int HIDGetDeviceProduct(io_service_t dev, char *name)
static bool HIDGetDeviceProduct(io_service_t dev, char *name)
{
CFMutableDictionaryRef hidProperties, usbProperties;
io_registry_entry_t parent1, parent2;
@@ -412,7 +412,7 @@ static int HIDGetDeviceProduct(io_service_t dev, char *name)
return SDL_SetError("Haptic: Error getting registry entries.");
}
return 0;
return true;
}
#define FF_TEST(ff, s) \
@@ -421,7 +421,7 @@ static int HIDGetDeviceProduct(io_service_t dev, char *name)
/*
* Gets supported features.
*/
static unsigned int GetSupportedFeatures(SDL_Haptic *haptic)
static bool GetSupportedFeatures(SDL_Haptic *haptic)
{
HRESULT ret;
FFDeviceObjectReference device;
@@ -486,16 +486,15 @@ static unsigned int GetSupportedFeatures(SDL_Haptic *haptic)
supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
haptic->supported = supported;
return 0;
return true;
}
/*
* Opens the haptic device from the file descriptor.
*/
static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t service)
static bool SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t service)
{
HRESULT ret;
int ret2;
// Allocate the hwdata
haptic->hwdata = (struct haptic_hwdata *) SDL_calloc(1, sizeof(*haptic->hwdata));
@@ -511,8 +510,7 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
}
// Get supported features.
ret2 = GetSupportedFeatures(haptic);
if (ret2 < 0) {
if (!GetSupportedFeatures(haptic)) {
goto open_err;
}
@@ -541,7 +539,7 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
SDL_memset(haptic->effects, 0,
sizeof(struct haptic_effect) * haptic->neffects);
return 0;
return true;
// Error handling
open_err:
@@ -551,13 +549,13 @@ creat_err:
SDL_free(haptic->hwdata);
haptic->hwdata = NULL;
}
return -1;
return false;
}
/*
* Opens a haptic device for usage.
*/
int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
bool SDL_SYS_HapticOpen(SDL_Haptic *haptic)
{
SDL_hapticlist_item *item;
item = HapticByInstanceID(haptic->instance_id);
@@ -581,7 +579,7 @@ int SDL_SYS_HapticMouse(void)
++device_index;
}
return -1;
return 0;
}
/*
@@ -620,13 +618,13 @@ bool SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
/*
* Opens a SDL_Haptic from a SDL_Joystick.
*/
int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
bool SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
{
#ifdef SDL_JOYSTICK_IOKIT
SDL_hapticlist_item *item;
if (joystick->driver != &SDL_DARWIN_JoystickDriver) {
return -1;
return false;
}
for (item = SDL_hapticlist; item; item = item->next) {
if (IOObjectIsEqualTo((io_object_t)item->dev,
@@ -642,7 +640,7 @@ int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
return SDL_SYS_HapticOpenFromService(haptic, joystick->hwdata->ffservice);
#else
return -1;
return false;
#endif
}
@@ -709,7 +707,7 @@ static DWORD FFGetTriggerButton(Uint16 button)
/*
* Sets the direction.
*/
static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir, int naxes)
static bool SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir, int naxes)
{
LONG *rglDir;
@@ -717,13 +715,13 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir
if (naxes == 0) {
effect->dwFlags |= FFEFF_SPHERICAL; // Set as default.
effect->rglDirection = NULL;
return 0;
return true;
}
// Has axes.
rglDir = SDL_malloc(sizeof(LONG) * naxes);
if (!rglDir) {
return -1;
return false;
}
SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
effect->rglDirection = rglDir;
@@ -732,7 +730,7 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir
case SDL_HAPTIC_POLAR:
effect->dwFlags |= FFEFF_POLAR;
rglDir[0] = dir->dir[0];
return 0;
return true;
case SDL_HAPTIC_CARTESIAN:
effect->dwFlags |= FFEFF_CARTESIAN;
rglDir[0] = dir->dir[0];
@@ -742,7 +740,7 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir
if (naxes > 2) {
rglDir[2] = dir->dir[2];
}
return 0;
return true;
case SDL_HAPTIC_SPHERICAL:
effect->dwFlags |= FFEFF_SPHERICAL;
rglDir[0] = dir->dir[0];
@@ -752,11 +750,11 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir
if (naxes > 2) {
rglDir[2] = dir->dir[2];
}
return 0;
return true;
case SDL_HAPTIC_STEERING_AXIS:
effect->dwFlags |= FFEFF_CARTESIAN;
rglDir[0] = 0;
return 0;
return true;
default:
return SDL_SetError("Haptic: Unknown direction type.");
@@ -770,7 +768,7 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir
/*
* Creates the FFEFFECT from a SDL_HapticEffect.
*/
static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_HapticEffect *src)
static bool SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_HapticEffect *src)
{
int i;
FFCONSTANTFORCE *constant = NULL;
@@ -796,7 +794,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
// Envelope.
envelope = SDL_calloc(1, sizeof(FFENVELOPE));
if (!envelope) {
return -1;
return false;
}
dest->lpEnvelope = envelope;
envelope->dwSize = sizeof(FFENVELOPE); // Always should be this.
@@ -810,7 +808,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
if (dest->cAxes > 0) {
axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
if (!axes) {
return -1;
return false;
}
axes[0] = haptic->hwdata->axes[0]; // Always at least one axis.
if (dest->cAxes > 1) {
@@ -828,7 +826,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
hap_constant = &src->constant;
constant = SDL_calloc(1, sizeof(FFCONSTANTFORCE));
if (!constant) {
return -1;
return false;
}
// Specifics
@@ -843,8 +841,8 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
dest->dwStartDelay = hap_constant->delay * 1000; // In microseconds.
// Direction.
if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) {
return -1;
if (!SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes)) {
return false;
}
// Envelope
@@ -868,7 +866,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
hap_periodic = &src->periodic;
periodic = SDL_calloc(1, sizeof(FFPERIODIC));
if (!periodic) {
return -1;
return false;
}
// Specifics
@@ -887,8 +885,8 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
dest->dwStartDelay = hap_periodic->delay * 1000; // In microseconds.
// Direction.
if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes) < 0) {
return -1;
if (!SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes)) {
return false;
}
// Envelope
@@ -912,7 +910,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
if (dest->cAxes > 0) {
condition = SDL_calloc(dest->cAxes, sizeof(FFCONDITION));
if (!condition) {
return -1;
return false;
}
// Specifics
@@ -940,8 +938,8 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
dest->dwStartDelay = hap_condition->delay * 1000; // In microseconds.
// Direction.
if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes) < 0) {
return -1;
if (!SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes)) {
return false;
}
// Envelope - Not actually supported by most CONDITION implementations.
@@ -954,7 +952,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
hap_ramp = &src->ramp;
ramp = SDL_calloc(1, sizeof(FFRAMPFORCE));
if (!ramp) {
return -1;
return false;
}
// Specifics
@@ -970,8 +968,8 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
dest->dwStartDelay = hap_ramp->delay * 1000; // In microseconds.
// Direction.
if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) {
return -1;
if (!SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes)) {
return false;
}
// Envelope
@@ -991,7 +989,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
hap_custom = &src->custom;
custom = SDL_calloc(1, sizeof(FFCUSTOMFORCE));
if (!custom) {
return -1;
return false;
}
// Specifics
@@ -1013,9 +1011,8 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
dest->dwStartDelay = hap_custom->delay * 1000; // In microseconds.
// Direction.
if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) <
0) {
return -1;
if (!SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes)) {
return false;
}
// Envelope
@@ -1035,7 +1032,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
return SDL_SetError("Haptic: Unknown effect type.");
}
return 0;
return true;
}
/*
@@ -1114,7 +1111,7 @@ SDL_SYS_HapticEffectType(Uint16 type)
/*
* Creates a new haptic effect.
*/
int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
bool SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
const SDL_HapticEffect *base)
{
HRESULT ret;
@@ -1134,7 +1131,7 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
}
// Get the effect.
if (SDL_SYS_ToFFEFFECT(haptic, &effect->hweffect->effect, base) < 0) {
if (!SDL_SYS_ToFFEFFECT(haptic, &effect->hweffect->effect, base)) {
goto err_effectdone;
}
@@ -1147,20 +1144,20 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
goto err_effectdone;
}
return 0;
return true;
err_effectdone:
SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, base->type);
err_hweffect:
SDL_free(effect->hweffect);
effect->hweffect = NULL;
return -1;
return false;
}
/*
* Updates an effect.
*/
int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
bool SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
struct haptic_effect *effect,
const SDL_HapticEffect *data)
{
@@ -1170,7 +1167,7 @@ int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
// Get the effect.
SDL_memset(&temp, 0, sizeof(FFEFFECT));
if (SDL_SYS_ToFFEFFECT(haptic, &temp, data) < 0) {
if (!SDL_SYS_ToFFEFFECT(haptic, &temp, data)) {
goto err_update;
}
@@ -1194,17 +1191,17 @@ int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, data->type);
SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(FFEFFECT));
return 0;
return true;
err_update:
SDL_SYS_HapticFreeFFEFFECT(&temp, data->type);
return -1;
return false;
}
/*
* Runs an effect.
*/
int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
bool SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
Uint32 iterations)
{
HRESULT ret;
@@ -1224,13 +1221,13 @@ int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
FFStrError(ret));
}
return 0;
return true;
}
/*
* Stops an effect.
*/
int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
bool SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
{
HRESULT ret;
@@ -1240,7 +1237,7 @@ int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect)
FFStrError(ret));
}
return 0;
return true;
}
/*
@@ -1272,20 +1269,20 @@ int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic,
ret = FFEffectGetEffectStatus(effect->hweffect->ref, &status);
if (ret != FF_OK) {
return SDL_SetError("Haptic: Unable to get effect status: %s.",
FFStrError(ret));
SDL_SetError("Haptic: Unable to get effect status: %s.", FFStrError(ret));
return -1;
}
if (status == 0) {
return false;
return 0;
}
return true; // Assume it's playing or emulated.
return 1; // Assume it's playing or emulated.
}
/*
* Sets the gain.
*/
int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
bool SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
{
HRESULT ret;
Uint32 val;
@@ -1297,13 +1294,13 @@ int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
return SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret));
}
return 0;
return true;
}
/*
* Sets the autocentering.
*/
int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
bool SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
{
HRESULT ret;
Uint32 val;
@@ -1322,13 +1319,13 @@ int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
FFStrError(ret));
}
return 0;
return true;
}
/*
* Pauses the device.
*/
int SDL_SYS_HapticPause(SDL_Haptic *haptic)
bool SDL_SYS_HapticPause(SDL_Haptic *haptic)
{
HRESULT ret;
@@ -1338,29 +1335,29 @@ int SDL_SYS_HapticPause(SDL_Haptic *haptic)
return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
}
return 0;
return true;
}
/*
* Unpauses the device.
*/
int SDL_SYS_HapticUnpause(SDL_Haptic *haptic)
bool SDL_SYS_HapticResume(SDL_Haptic *haptic)
{
HRESULT ret;
ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
FFSFFC_CONTINUE);
if (ret != FF_OK) {
return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
return SDL_SetError("Haptic: Error resuming device: %s.", FFStrError(ret));
}
return 0;
return true;
}
/*
* Stops all currently playing effects.
*/
int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
bool SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
{
HRESULT ret;
@@ -1370,7 +1367,7 @@ int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
return SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret));
}
return 0;
return true;
}
#endif // SDL_HAPTIC_IOKIT