Merge commit '852f2a6343518919e5ca8d3c1bbcab9f493e3cd8'

This commit is contained in:
2024-01-17 17:02:59 +01:00
1244 changed files with 50102 additions and 28146 deletions

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -55,7 +55,7 @@ static int ValidHaptic(SDL_Haptic *haptic)
SDL_Haptic *hapticlist;
valid = 0;
if (haptic != NULL) {
if (haptic) {
hapticlist = SDL_haptics;
while (hapticlist) {
if (hapticlist == haptic) {
@ -124,8 +124,7 @@ SDL_Haptic *SDL_HapticOpen(int device_index)
/* Create the haptic device */
haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic));
if (haptic == NULL) {
SDL_OutOfMemory();
if (!haptic) {
return NULL;
}
@ -296,8 +295,7 @@ SDL_Haptic *SDL_HapticOpenFromJoystick(SDL_Joystick *joystick)
/* Create the haptic device */
haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic));
if (haptic == NULL) {
SDL_OutOfMemory();
if (!haptic) {
SDL_UnlockJoysticks();
return NULL;
}
@ -609,7 +607,7 @@ int SDL_HapticSetGain(SDL_Haptic *haptic, int gain)
/* We use the envvar to get the maximum gain. */
env = SDL_getenv("SDL_HAPTIC_GAIN_MAX");
if (env != NULL) {
if (env) {
max_gain = SDL_atoi(env);
/* Check for sanity. */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -69,7 +69,7 @@ static SDL_hapticlist_item *HapticByOrder(int index)
static SDL_hapticlist_item *HapticByDevId(int device_id)
{
SDL_hapticlist_item *item;
for (item = SDL_hapticlist; item != NULL; item = item->next) {
for (item = SDL_hapticlist; item; item = item->next) {
if (device_id == item->device_id) {
/*SDL_Log("=+=+=+=+=+= HapticByDevId id [%d]", device_id);*/
return item;
@ -81,7 +81,7 @@ static SDL_hapticlist_item *HapticByDevId(int device_id)
const char *SDL_SYS_HapticName(int index)
{
SDL_hapticlist_item *item = HapticByOrder(index);
if (item == NULL) {
if (!item) {
SDL_SetError("No such device");
return NULL;
}
@ -90,11 +90,11 @@ const char *SDL_SYS_HapticName(int index)
static SDL_hapticlist_item *OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item *item)
{
if (item == NULL) {
if (!item) {
SDL_SetError("No such device");
return NULL;
}
if (item->haptic != NULL) {
if (item->haptic) {
SDL_SetError("Haptic already opened");
return NULL;
}
@ -106,8 +106,7 @@ static SDL_hapticlist_item *OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item *
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();
if (!haptic->effects) {
return NULL;
}
SDL_memset(haptic->effects, 0, sizeof(struct haptic_effect) * haptic->neffects);
@ -138,7 +137,7 @@ int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
{
SDL_hapticlist_item *item;
item = HapticByDevId(((joystick_hwdata *)joystick->hwdata)->device_id);
return (item != NULL) ? 1 : 0;
return (item) ? 1 : 0;
}
int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
@ -246,18 +245,18 @@ 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) {
if (!item) {
return -1;
}
item->device_id = device_id;
item->name = SDL_strdup(name);
if (item->name == NULL) {
if (!item->name) {
SDL_free(item);
return -1;
}
if (SDL_hapticlist_tail == NULL) {
if (!SDL_hapticlist_tail) {
SDL_hapticlist = SDL_hapticlist_tail = item;
} else {
SDL_hapticlist_tail->next = item;
@ -273,12 +272,12 @@ int Android_RemoveHaptic(int device_id)
SDL_hapticlist_item *item;
SDL_hapticlist_item *prev = NULL;
for (item = SDL_hapticlist; item != NULL; item = item->next) {
for (item = SDL_hapticlist; item; 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) {
if (prev) {
prev->next = item->next;
} else {
SDL_assert(SDL_hapticlist == item);

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -154,7 +154,7 @@ int SDL_SYS_HapticInit(void)
/* Get HID devices. */
match = IOServiceMatching(kIOHIDDeviceKey);
if (match == NULL) {
if (!match) {
return SDL_SetError("Haptic: Failed to get IOServiceMatching.");
}
@ -226,7 +226,7 @@ int MacHaptic_MaybeAddDevice(io_object_t device)
}
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
if (item == NULL) {
if (!item) {
return SDL_SetError("Could not allocate haptic storage");
}
@ -262,7 +262,7 @@ int MacHaptic_MaybeAddDevice(io_object_t device)
CFRelease(hidProperties);
}
if (SDL_hapticlist_tail == NULL) {
if (!SDL_hapticlist_tail) {
SDL_hapticlist = SDL_hapticlist_tail = item;
} else {
SDL_hapticlist_tail->next = item;
@ -284,12 +284,12 @@ int MacHaptic_MaybeRemoveDevice(io_object_t device)
return -1; /* not initialized. ignore this. */
}
for (item = SDL_hapticlist; item != NULL; item = item->next) {
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 ? item->haptic->index : -1;
if (prev != NULL) {
if (prev) {
prev->next = item->next;
} else {
SDL_assert(SDL_hapticlist == item);
@ -473,13 +473,10 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
int ret2;
/* Allocate the hwdata */
haptic->hwdata = (struct haptic_hwdata *)
SDL_malloc(sizeof(*haptic->hwdata));
if (haptic->hwdata == NULL) {
SDL_OutOfMemory();
haptic->hwdata = (struct haptic_hwdata *) SDL_calloc(1, sizeof(*haptic->hwdata));
if (!haptic->hwdata) {
goto creat_err;
}
SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
/* Open the device */
ret = FFCreateDevice(service, &haptic->hwdata->device);
@ -512,8 +509,7 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
/* Allocate effects memory. */
haptic->effects = (struct haptic_effect *)
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
if (haptic->effects == NULL) {
SDL_OutOfMemory();
if (!haptic->effects) {
goto open_err;
}
/* Clear the memory */
@ -526,7 +522,7 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
open_err:
FFReleaseDevice(haptic->hwdata->device);
creat_err:
if (haptic->hwdata != NULL) {
if (haptic->hwdata) {
SDL_free(haptic->hwdata);
haptic->hwdata = NULL;
}
@ -699,8 +695,8 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, SDL_HapticDirection *dir, int
/* Has axes. */
rglDir = SDL_malloc(sizeof(LONG) * naxes);
if (rglDir == NULL) {
return SDL_OutOfMemory();
if (!rglDir) {
return -1;
}
SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
effect->rglDirection = rglDir;
@ -771,11 +767,10 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
dest->dwFlags = FFEFF_OBJECTOFFSETS; /* Seems obligatory. */
/* Envelope. */
envelope = SDL_malloc(sizeof(FFENVELOPE));
if (envelope == NULL) {
return SDL_OutOfMemory();
envelope = SDL_calloc(1, sizeof(FFENVELOPE));
if (!envelope) {
return -1;
}
SDL_memset(envelope, 0, sizeof(FFENVELOPE));
dest->lpEnvelope = envelope;
envelope->dwSize = sizeof(FFENVELOPE); /* Always should be this. */
@ -787,8 +782,8 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
}
if (dest->cAxes > 0) {
axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
if (axes == NULL) {
return SDL_OutOfMemory();
if (!axes) {
return -1;
}
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
if (dest->cAxes > 1) {
@ -804,11 +799,10 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
switch (src->type) {
case SDL_HAPTIC_CONSTANT:
hap_constant = &src->constant;
constant = SDL_malloc(sizeof(FFCONSTANTFORCE));
if (constant == NULL) {
return SDL_OutOfMemory();
constant = SDL_calloc(1, sizeof(FFCONSTANTFORCE));
if (!constant) {
return -1;
}
SDL_memset(constant, 0, sizeof(FFCONSTANTFORCE));
/* Specifics */
constant->lMagnitude = CONVERT(hap_constant->level);
@ -846,11 +840,10 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
case SDL_HAPTIC_SAWTOOTHUP:
case SDL_HAPTIC_SAWTOOTHDOWN:
hap_periodic = &src->periodic;
periodic = SDL_malloc(sizeof(FFPERIODIC));
if (periodic == NULL) {
return SDL_OutOfMemory();
periodic = SDL_calloc(1, sizeof(FFPERIODIC));
if (!periodic) {
return -1;
}
SDL_memset(periodic, 0, sizeof(FFPERIODIC));
/* Specifics */
periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude));
@ -891,11 +884,10 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
case SDL_HAPTIC_FRICTION:
hap_condition = &src->condition;
if (dest->cAxes > 0) {
condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
if (condition == NULL) {
return SDL_OutOfMemory();
condition = SDL_calloc(dest->cAxes, sizeof(FFCONDITION));
if (!condition) {
return -1;
}
SDL_memset(condition, 0, sizeof(FFCONDITION));
/* Specifics */
for (i = 0; i < dest->cAxes; i++) {
@ -934,11 +926,10 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
case SDL_HAPTIC_RAMP:
hap_ramp = &src->ramp;
ramp = SDL_malloc(sizeof(FFRAMPFORCE));
if (ramp == NULL) {
return SDL_OutOfMemory();
ramp = SDL_calloc(1, sizeof(FFRAMPFORCE));
if (!ramp) {
return -1;
}
SDL_memset(ramp, 0, sizeof(FFRAMPFORCE));
/* Specifics */
ramp->lStart = CONVERT(hap_ramp->start);
@ -972,11 +963,10 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
case SDL_HAPTIC_CUSTOM:
hap_custom = &src->custom;
custom = SDL_malloc(sizeof(FFCUSTOMFORCE));
if (custom == NULL) {
return SDL_OutOfMemory();
custom = SDL_calloc(1, sizeof(FFCUSTOMFORCE));
if (!custom) {
return -1;
}
SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE));
/* Specifics */
custom->cChannels = hap_custom->channels;
@ -1033,7 +1023,7 @@ static void SDL_SYS_HapticFreeFFEFFECT(FFEFFECT *effect, int type)
effect->lpEnvelope = NULL;
SDL_free(effect->rgdwAxes);
effect->rgdwAxes = NULL;
if (effect->lpvTypeSpecificParams != NULL) {
if (effect->lpvTypeSpecificParams) {
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
custom = (FFCUSTOMFORCE *)effect->lpvTypeSpecificParams;
SDL_free(custom->rglForceData);
@ -1107,15 +1097,14 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
/* Alloc the effect. */
effect->hweffect = (struct haptic_hweffect *)
SDL_malloc(sizeof(struct haptic_hweffect));
if (effect->hweffect == NULL) {
SDL_OutOfMemory();
SDL_calloc(1, sizeof(struct haptic_hweffect));
if (!effect->hweffect) {
goto err_hweffect;
}
/* Get the type. */
type = SDL_SYS_HapticEffectType(base->type);
if (type == NULL) {
if (!type) {
goto err_hweffect;
}

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -199,7 +199,7 @@ static SDL_hapticlist_item *HapticByDevIndex(int device_index)
#ifdef SDL_USE_LIBUDEV
static void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath)
{
if (devpath == NULL || !(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
if (!devpath || !(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
return;
}
@ -225,7 +225,7 @@ static int MaybeAddDevice(const char *path)
int success;
SDL_hapticlist_item *item;
if (path == NULL) {
if (!path) {
return -1;
}
@ -235,7 +235,7 @@ static int MaybeAddDevice(const char *path)
}
/* check for duplicates */
for (item = SDL_hapticlist; item != NULL; item = item->next) {
for (item = SDL_hapticlist; item; item = item->next) {
if (item->dev_num == sb.st_rdev) {
return -1; /* duplicate. */
}
@ -259,12 +259,12 @@ static int MaybeAddDevice(const char *path)
}
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
if (item == NULL) {
if (!item) {
return -1;
}
item->fname = SDL_strdup(path);
if (item->fname == NULL) {
if (!item->fname) {
SDL_free(item);
return -1;
}
@ -272,7 +272,7 @@ static int MaybeAddDevice(const char *path)
item->dev_num = sb.st_rdev;
/* TODO: should we add instance IDs? */
if (SDL_hapticlist_tail == NULL) {
if (!SDL_hapticlist_tail) {
SDL_hapticlist = SDL_hapticlist_tail = item;
} else {
SDL_hapticlist_tail->next = item;
@ -292,16 +292,16 @@ static int MaybeRemoveDevice(const char *path)
SDL_hapticlist_item *item;
SDL_hapticlist_item *prev = NULL;
if (path == NULL) {
if (!path) {
return -1;
}
for (item = SDL_hapticlist; item != NULL; item = item->next) {
for (item = SDL_hapticlist; item; item = item->next) {
/* found it, remove it. */
if (SDL_strcmp(path, item->fname) == 0) {
const int retval = item->haptic ? item->haptic->index : -1;
if (prev != NULL) {
if (prev) {
prev->next = item->next;
} else {
SDL_assert(SDL_hapticlist == item);
@ -358,7 +358,7 @@ const char *SDL_SYS_HapticName(int index)
if (fd >= 0) {
name = SDL_SYS_HapticNameFromFD(fd);
if (name == NULL) {
if (!name) {
/* No name found, return device character device */
name = item->fname;
}
@ -375,12 +375,10 @@ static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd)
{
/* Allocate the hwdata */
haptic->hwdata = (struct haptic_hwdata *)
SDL_malloc(sizeof(*haptic->hwdata));
if (haptic->hwdata == NULL) {
SDL_OutOfMemory();
SDL_calloc(1, sizeof(*haptic->hwdata));
if (!haptic->hwdata) {
goto open_err;
}
SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
/* Set the data. */
haptic->hwdata->fd = fd;
@ -396,8 +394,7 @@ static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd)
haptic->nplaying = haptic->neffects; /* Linux makes no distinction. */
haptic->effects = (struct haptic_effect *)
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
if (haptic->effects == NULL) {
SDL_OutOfMemory();
if (!haptic->effects) {
goto open_err;
}
/* Clear the memory */
@ -409,7 +406,7 @@ static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd)
/* Error handling */
open_err:
close(fd);
if (haptic->hwdata != NULL) {
if (haptic->hwdata) {
SDL_free(haptic->hwdata);
haptic->hwdata = NULL;
}
@ -640,17 +637,6 @@ static int SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection *src)
switch (src->type) {
case SDL_HAPTIC_POLAR:
/* Linux directions start from south.
(and range from 0 to 0xFFFF)
Quoting include/linux/input.h, line 926:
Direction of the effect is encoded as follows:
0 deg -> 0x0000 (down)
90 deg -> 0x4000 (left)
180 deg -> 0x8000 (up)
270 deg -> 0xC000 (right)
The force pulls into the direction specified by Linux directions,
i.e. the opposite convention of SDL directions.
*/
tmp = ((src->dir[0] % 36000) * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
*dest = (Uint16)tmp;
break;
@ -914,9 +900,9 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
/* Allocate the hardware effect */
effect->hweffect = (struct haptic_hweffect *)
SDL_malloc(sizeof(struct haptic_hweffect));
if (effect->hweffect == NULL) {
return SDL_OutOfMemory();
SDL_calloc(1, sizeof(struct haptic_hweffect));
if (!effect->hweffect) {
return -1;
}
/* Prepare the ff_effect */

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -92,7 +92,7 @@ int SDL_DINPUT_HapticInit(void)
/* Because we used CoCreateInstance, we need to Initialize it, first. */
instance = GetModuleHandle(NULL);
if (instance == NULL) {
if (!instance) {
SDL_SYS_HapticQuit();
return SDL_SetError("GetModuleHandle() failed with error code %lu.",
GetLastError());
@ -133,7 +133,7 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance)
DIDEVCAPS capabilities;
SDL_hapticlist_item *item = NULL;
if (dinput == NULL) {
if (!dinput) {
return -1; /* not initialized. We'll pick these up on enumeration if we init later. */
}
@ -166,8 +166,8 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance)
}
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
if (item == NULL) {
return SDL_OutOfMemory();
if (!item) {
return -1;
}
item->name = WIN_StringToUTF8(pdidInstance->tszProductName);
@ -188,11 +188,11 @@ int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance)
SDL_hapticlist_item *item;
SDL_hapticlist_item *prev = NULL;
if (dinput == NULL) {
if (!dinput) {
return -1; /* not initialized, ignore this. */
}
for (item = SDL_hapticlist; item != NULL; item = item->next) {
for (item = SDL_hapticlist; item; item = item->next) {
if (!item->bXInputHaptic && SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0) {
/* found it, remove it. */
return SDL_SYS_RemoveHapticDevice(prev, item);
@ -286,11 +286,10 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
DIPROPDWORD dipdw;
/* Allocate the hwdata */
haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata));
if (haptic->hwdata == NULL) {
return SDL_OutOfMemory();
haptic->hwdata = (struct haptic_hwdata *)SDL_calloc(1, sizeof(*haptic->hwdata));
if (!haptic->hwdata) {
return -1;
}
SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
/* We'll use the device8 from now on. */
haptic->hwdata->device = device8;
@ -401,8 +400,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
/* Prepare effects memory. */
haptic->effects = (struct haptic_effect *)
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
if (haptic->effects == NULL) {
SDL_OutOfMemory();
if (!haptic->effects) {
goto acquire_err;
}
/* Clear the memory */
@ -474,7 +472,7 @@ int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick
}
/* 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) {
for (item = SDL_hapticlist; item; item = item->next) {
if (!item->bXInputHaptic && WIN_IsEqualGUID(&item->instance.guidInstance, &joy_instance.guidInstance)) {
haptic->index = index;
return SDL_DINPUT_HapticOpenFromDevice(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
@ -540,8 +538,8 @@ static int SDL_SYS_SetDirection(DIEFFECT *effect, SDL_HapticDirection *dir, int
/* Has axes. */
rglDir = SDL_malloc(sizeof(LONG) * naxes);
if (rglDir == NULL) {
return SDL_OutOfMemory();
if (!rglDir) {
return -1;
}
SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
effect->rglDirection = rglDir;
@ -613,11 +611,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
dest->dwFlags = DIEFF_OBJECTOFFSETS; /* Seems obligatory. */
/* Envelope. */
envelope = SDL_malloc(sizeof(DIENVELOPE));
if (envelope == NULL) {
return SDL_OutOfMemory();
envelope = SDL_calloc(1, sizeof(DIENVELOPE));
if (!envelope) {
return -1;
}
SDL_memset(envelope, 0, sizeof(DIENVELOPE));
dest->lpEnvelope = envelope;
envelope->dwSize = sizeof(DIENVELOPE); /* Always should be this. */
@ -629,8 +626,8 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
}
if (dest->cAxes > 0) {
axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
if (axes == NULL) {
return SDL_OutOfMemory();
if (!axes) {
return -1;
}
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
if (dest->cAxes > 1) {
@ -646,11 +643,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
switch (src->type) {
case SDL_HAPTIC_CONSTANT:
hap_constant = &src->constant;
constant = SDL_malloc(sizeof(DICONSTANTFORCE));
if (constant == NULL) {
return SDL_OutOfMemory();
constant = SDL_calloc(1, sizeof(DICONSTANTFORCE));
if (!constant) {
return -1;
}
SDL_memset(constant, 0, sizeof(DICONSTANTFORCE));
/* Specifics */
constant->lMagnitude = CONVERT(hap_constant->level);
@ -688,11 +684,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
case SDL_HAPTIC_SAWTOOTHUP:
case SDL_HAPTIC_SAWTOOTHDOWN:
hap_periodic = &src->periodic;
periodic = SDL_malloc(sizeof(DIPERIODIC));
if (periodic == NULL) {
return SDL_OutOfMemory();
periodic = SDL_calloc(1, sizeof(DIPERIODIC));
if (!periodic) {
return -1;
}
SDL_memset(periodic, 0, sizeof(DIPERIODIC));
/* Specifics */
periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude));
@ -732,11 +727,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
case SDL_HAPTIC_INERTIA:
case SDL_HAPTIC_FRICTION:
hap_condition = &src->condition;
condition = SDL_malloc(sizeof(DICONDITION) * dest->cAxes);
if (condition == NULL) {
return SDL_OutOfMemory();
condition = SDL_calloc(dest->cAxes, sizeof(DICONDITION));
if (!condition) {
return -1;
}
SDL_memset(condition, 0, sizeof(DICONDITION));
/* Specifics */
for (i = 0; i < (int)dest->cAxes; i++) {
@ -773,11 +767,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
case SDL_HAPTIC_RAMP:
hap_ramp = &src->ramp;
ramp = SDL_malloc(sizeof(DIRAMPFORCE));
if (ramp == NULL) {
return SDL_OutOfMemory();
ramp = SDL_calloc(1, sizeof(DIRAMPFORCE));
if (!ramp) {
return -1;
}
SDL_memset(ramp, 0, sizeof(DIRAMPFORCE));
/* Specifics */
ramp->lStart = CONVERT(hap_ramp->start);
@ -811,11 +804,10 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
case SDL_HAPTIC_CUSTOM:
hap_custom = &src->custom;
custom = SDL_malloc(sizeof(DICUSTOMFORCE));
if (custom == NULL) {
return SDL_OutOfMemory();
custom = SDL_calloc(1, sizeof(DICUSTOMFORCE));
if (!custom) {
return -1;
}
SDL_memset(custom, 0, sizeof(DICUSTOMFORCE));
/* Specifics */
custom->cChannels = hap_custom->channels;
@ -871,7 +863,7 @@ static void SDL_SYS_HapticFreeDIEFFECT(DIEFFECT *effect, int type)
effect->lpEnvelope = NULL;
SDL_free(effect->rgdwAxes);
effect->rgdwAxes = NULL;
if (effect->lpvTypeSpecificParams != NULL) {
if (effect->lpvTypeSpecificParams) {
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
custom = (DICUSTOMFORCE *)effect->lpvTypeSpecificParams;
SDL_free(custom->rglForceData);
@ -937,7 +929,7 @@ int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
HRESULT ret;
REFGUID type = SDL_SYS_HapticEffectType(base);
if (type == NULL) {
if (!type) {
return SDL_SetError("Haptic: Unknown effect type.");
}

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -75,7 +75,7 @@ int SDL_SYS_HapticInit(void)
int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item)
{
if (SDL_hapticlist_tail == NULL) {
if (!SDL_hapticlist_tail) {
SDL_hapticlist = SDL_hapticlist_tail = item;
} else {
SDL_hapticlist_tail->next = item;
@ -91,7 +91,7 @@ int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item)
int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item)
{
const int retval = item->haptic ? item->haptic->index : -1;
if (prev != NULL) {
if (prev) {
prev->next = item->next;
} else {
SDL_assert(SDL_hapticlist == item);
@ -159,7 +159,7 @@ int SDL_SYS_HapticMouse(void)
int index = 0;
/* Grab the first mouse haptic device we find. */
for (item = SDL_hapticlist; item != NULL; item = item->next) {
for (item = SDL_hapticlist; item; item = item->next) {
if (item->capabilities.dwDevType == DI8DEVCLASS_POINTER) {
return index;
}
@ -291,13 +291,10 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
int result;
/* Alloc the effect. */
effect->hweffect = (struct haptic_hweffect *)
SDL_malloc(sizeof(struct haptic_hweffect));
if (effect->hweffect == NULL) {
SDL_OutOfMemory();
effect->hweffect = (struct haptic_hweffect *) SDL_calloc(1, sizeof(struct haptic_hweffect));
if (!effect->hweffect) {
return -1;
}
SDL_zerop(effect->hweffect);
if (haptic->hwdata->bXInputHaptic) {
result = SDL_XINPUT_HapticNewEffect(haptic, effect, base);

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -43,7 +43,7 @@ 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;
loaded_xinput = (WIN_LoadXInputDLL() == 0);
}
/* If the joystick subsystem is active, it will manage adding XInput haptic devices */
@ -78,17 +78,15 @@ int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
return -1; /* no force feedback on this device. */
}
item = (SDL_hapticlist_item *)SDL_malloc(sizeof(SDL_hapticlist_item));
if (item == NULL) {
return SDL_OutOfMemory();
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
if (!item) {
return -1;
}
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);
(void)SDL_snprintf(buf, sizeof(buf), "XInput Controller #%d", 1 + userid);
item->name = SDL_strdup(buf);
}
@ -114,7 +112,7 @@ int SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid)
return -1;
}
for (item = SDL_hapticlist; item != NULL; item = item->next) {
for (item = SDL_hapticlist; item; item = item->next) {
if (item->bXInputHaptic && item->userid == userid) {
/* found it, remove it. */
return SDL_SYS_RemoveHapticDevice(prev, item);
@ -173,36 +171,35 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us
/* Prepare effects memory. */
haptic->effects = (struct haptic_effect *)
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
if (haptic->effects == NULL) {
return SDL_OutOfMemory();
if (!haptic->effects) {
return -1;
}
/* 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) {
haptic->hwdata = (struct haptic_hwdata *)SDL_calloc(1, sizeof(*haptic->hwdata));
if (!haptic->hwdata) {
SDL_free(haptic->effects);
haptic->effects = NULL;
return SDL_OutOfMemory();
return -1;
}
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) {
if (!haptic->hwdata->mutex) {
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);
(void)SDL_snprintf(threadName, sizeof(threadName), "SDLXInputDev%u", userid);
haptic->hwdata->thread = SDL_CreateThreadInternal(SDL_RunXInputHaptic, threadName, 64 * 1024, haptic->hwdata);
if (haptic->hwdata->thread == NULL) {
if (!haptic->hwdata->thread) {
SDL_DestroyMutex(haptic->hwdata->mutex);
SDL_free(haptic->effects);
SDL_free(haptic->hwdata);
@ -229,7 +226,7 @@ int SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick
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) {
for (item = SDL_hapticlist; item; item = item->next) {
if (item->bXInputHaptic && item->userid == joystick->hwdata->userid) {
haptic->index = index;
return SDL_XINPUT_HapticOpenFromUserIndex(haptic, joystick->hwdata->userid);
@ -286,7 +283,7 @@ int SDL_XINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
} 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);
haptic->hwdata->stopTicks = SDL_GetTicks() + ((Uint64)effect->effect.leftright.length * iterations);
}
SDL_UnlockMutex(haptic->hwdata->mutex);
return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1;

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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