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
@ -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 */