mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
update sdl to 2.32.6
This commit is contained in:
parent
e557f5962b
commit
ddc1f8c1e2
1339 changed files with 53966 additions and 19207 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -23,9 +23,88 @@
|
|||
#include "SDL_syshaptic.h"
|
||||
#include "SDL_haptic_c.h"
|
||||
#include "../joystick/SDL_joystick_c.h" /* For SDL_PrivateJoystickValid */
|
||||
#include "SDL_hints.h"
|
||||
#include "../SDL_hints_c.h"
|
||||
|
||||
typedef struct SDL_Haptic_VIDPID_Naxes {
|
||||
Uint16 vid;
|
||||
Uint16 pid;
|
||||
Uint16 naxes;
|
||||
} SDL_Haptic_VIDPID_Naxes;
|
||||
|
||||
static void SDL_HapticLoadAxesList(SDL_Haptic_VIDPID_Naxes **entries, int *num_entries)
|
||||
{
|
||||
SDL_Haptic_VIDPID_Naxes entry;
|
||||
const char *spot;
|
||||
int length = 0;
|
||||
|
||||
spot = SDL_GetHint(SDL_HINT_JOYSTICK_HAPTIC_AXES);
|
||||
if (!spot)
|
||||
return;
|
||||
|
||||
while (SDL_sscanf(spot, "0x%hx/0x%hx/%hu%n", &entry.vid, &entry.pid, &entry.naxes, &length) == 3) {
|
||||
SDL_assert(length > 0);
|
||||
spot += length;
|
||||
length = 0;
|
||||
|
||||
if ((*num_entries % 8) == 0) {
|
||||
int new_max = *num_entries + 8;
|
||||
SDL_Haptic_VIDPID_Naxes *new_entries =
|
||||
(SDL_Haptic_VIDPID_Naxes *)SDL_realloc(*entries, new_max * sizeof(**entries));
|
||||
|
||||
// Out of memory, go with what we have already
|
||||
if (!new_entries)
|
||||
break;
|
||||
|
||||
*entries = new_entries;
|
||||
}
|
||||
(*entries)[(*num_entries)++] = entry;
|
||||
|
||||
if (spot[0] == ',')
|
||||
spot++;
|
||||
}
|
||||
}
|
||||
|
||||
// /* Return -1 if not found */
|
||||
static int SDL_HapticNaxesListIndex(struct SDL_Haptic_VIDPID_Naxes *entries, int num_entries, Uint16 vid, Uint16 pid)
|
||||
{
|
||||
int i;
|
||||
if (!entries)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < num_entries; ++i) {
|
||||
if (entries[i].vid == vid && entries[i].pid == pid)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if device needs a custom number of naxes
|
||||
static int SDL_HapticGetNaxes(Uint16 vid, Uint16 pid)
|
||||
{
|
||||
int num_entries = 0, index = 0, naxes = -1;
|
||||
SDL_Haptic_VIDPID_Naxes *naxes_list = NULL;
|
||||
|
||||
SDL_HapticLoadAxesList(&naxes_list, &num_entries);
|
||||
if (!num_entries || !naxes_list)
|
||||
return -1;
|
||||
|
||||
// Perform "wildcard" pass
|
||||
index = SDL_HapticNaxesListIndex(naxes_list, num_entries, 0xffff, 0xffff);
|
||||
if (index >= 0)
|
||||
naxes = naxes_list[index].naxes;
|
||||
|
||||
index = SDL_HapticNaxesListIndex(naxes_list, num_entries, vid, pid);
|
||||
if (index >= 0)
|
||||
naxes = naxes_list[index].naxes;
|
||||
|
||||
SDL_free(naxes_list);
|
||||
return naxes;
|
||||
}
|
||||
|
||||
/* Global for SDL_windowshaptic.c */
|
||||
#if (defined(SDL_HAPTIC_DINPUT) && SDL_HAPTIC_DINPUT) || (defined(SDL_HAPTIC_XINPUT) && SDL_HAPTIC_XINPUT)
|
||||
#if defined(SDL_HAPTIC_DINPUT) || defined(SDL_HAPTIC_XINPUT)
|
||||
SDL_Haptic *SDL_haptics = NULL;
|
||||
#else
|
||||
static SDL_Haptic *SDL_haptics = NULL;
|
||||
|
|
@ -55,7 +134,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,7 +203,7 @@ SDL_Haptic *SDL_HapticOpen(int device_index)
|
|||
|
||||
/* Create the haptic device */
|
||||
haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic));
|
||||
if (haptic == NULL) {
|
||||
if (!haptic) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -258,6 +337,8 @@ SDL_Haptic *SDL_HapticOpenFromJoystick(SDL_Joystick *joystick)
|
|||
{
|
||||
SDL_Haptic *haptic;
|
||||
SDL_Haptic *hapticlist;
|
||||
int naxes, general_axes;
|
||||
Uint16 vid, pid;
|
||||
|
||||
/* Make sure there is room. */
|
||||
if (SDL_NumHaptics() <= 0) {
|
||||
|
|
@ -296,7 +377,7 @@ SDL_Haptic *SDL_HapticOpenFromJoystick(SDL_Joystick *joystick)
|
|||
|
||||
/* Create the haptic device */
|
||||
haptic = (SDL_Haptic *)SDL_malloc(sizeof(*haptic));
|
||||
if (haptic == NULL) {
|
||||
if (!haptic) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_UnlockJoysticks();
|
||||
return NULL;
|
||||
|
|
@ -314,6 +395,18 @@ SDL_Haptic *SDL_HapticOpenFromJoystick(SDL_Joystick *joystick)
|
|||
}
|
||||
SDL_UnlockJoysticks();
|
||||
|
||||
vid = SDL_JoystickGetVendor(joystick);
|
||||
pid = SDL_JoystickGetProduct(joystick);
|
||||
general_axes = SDL_JoystickNumAxes(joystick);
|
||||
|
||||
naxes = SDL_HapticGetNaxes(vid, pid);
|
||||
if (naxes > 0)
|
||||
haptic->naxes = naxes;
|
||||
|
||||
// Limit to the actual number of axes found on the device
|
||||
if (general_axes >= 0 && naxes > general_axes)
|
||||
haptic->naxes = general_axes;
|
||||
|
||||
/* Add haptic to list */
|
||||
++haptic->ref_count;
|
||||
/* Link the haptic in the list */
|
||||
|
|
@ -609,7 +702,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. */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -80,7 +80,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;
|
||||
|
|
@ -92,7 +92,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;
|
||||
}
|
||||
|
|
@ -101,11 +101,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;
|
||||
}
|
||||
|
|
@ -117,7 +117,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) {
|
||||
if (!haptic->effects) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -149,7 +149,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)
|
||||
|
|
@ -257,18 +257,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;
|
||||
|
|
@ -284,12 +284,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);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -157,7 +157,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.");
|
||||
}
|
||||
|
||||
|
|
@ -229,7 +229,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");
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +265,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;
|
||||
|
|
@ -287,12 +287,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);
|
||||
|
|
@ -478,7 +478,7 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
|
|||
/* Allocate the hwdata */
|
||||
haptic->hwdata = (struct haptic_hwdata *)
|
||||
SDL_malloc(sizeof(*haptic->hwdata));
|
||||
if (haptic->hwdata == NULL) {
|
||||
if (!haptic->hwdata) {
|
||||
SDL_OutOfMemory();
|
||||
goto creat_err;
|
||||
}
|
||||
|
|
@ -516,7 +516,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) {
|
||||
if (!haptic->effects) {
|
||||
SDL_OutOfMemory();
|
||||
goto open_err;
|
||||
}
|
||||
|
|
@ -530,7 +530,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;
|
||||
}
|
||||
|
|
@ -703,7 +703,7 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, SDL_HapticDirection *dir, int
|
|||
|
||||
/* Has axes. */
|
||||
rglDir = SDL_malloc(sizeof(LONG) * naxes);
|
||||
if (rglDir == NULL) {
|
||||
if (!rglDir) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
|
||||
|
|
@ -776,7 +776,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
|
|||
|
||||
/* Envelope. */
|
||||
envelope = SDL_malloc(sizeof(FFENVELOPE));
|
||||
if (envelope == NULL) {
|
||||
if (!envelope) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(envelope, 0, sizeof(FFENVELOPE));
|
||||
|
|
@ -791,7 +791,7 @@ 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) {
|
||||
if (!axes) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
|
||||
|
|
@ -809,7 +809,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
|
|||
case SDL_HAPTIC_CONSTANT:
|
||||
hap_constant = &src->constant;
|
||||
constant = SDL_malloc(sizeof(FFCONSTANTFORCE));
|
||||
if (constant == NULL) {
|
||||
if (!constant) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(constant, 0, sizeof(FFCONSTANTFORCE));
|
||||
|
|
@ -851,7 +851,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
|
|||
case SDL_HAPTIC_SAWTOOTHDOWN:
|
||||
hap_periodic = &src->periodic;
|
||||
periodic = SDL_malloc(sizeof(FFPERIODIC));
|
||||
if (periodic == NULL) {
|
||||
if (!periodic) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(periodic, 0, sizeof(FFPERIODIC));
|
||||
|
|
@ -896,7 +896,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, SDL_HapticEffe
|
|||
hap_condition = &src->condition;
|
||||
if (dest->cAxes > 0) {
|
||||
condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
|
||||
if (condition == NULL) {
|
||||
if (!condition) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(condition, 0, sizeof(FFCONDITION));
|
||||
|
|
@ -939,7 +939,7 @@ 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) {
|
||||
if (!ramp) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(ramp, 0, sizeof(FFRAMPFORCE));
|
||||
|
|
@ -977,7 +977,7 @@ 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) {
|
||||
if (!custom) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE));
|
||||
|
|
@ -1037,7 +1037,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);
|
||||
|
|
@ -1112,14 +1112,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) {
|
||||
if (!effect->hweffect) {
|
||||
SDL_OutOfMemory();
|
||||
goto err_hweffect;
|
||||
}
|
||||
|
||||
/* Get the type. */
|
||||
type = SDL_SYS_HapticEffectType(base->type);
|
||||
if (type == NULL) {
|
||||
if (!type) {
|
||||
goto err_hweffect;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
#define MAX_HAPTICS 32 /* It's doubtful someone has more then 32 evdev */
|
||||
|
||||
static int MaybeAddDevice(const char *path);
|
||||
#if SDL_USE_LIBUDEV
|
||||
#ifdef SDL_USE_LIBUDEV
|
||||
static int MaybeRemoveDevice(const char *path);
|
||||
static void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath);
|
||||
#endif /* SDL_USE_LIBUDEV */
|
||||
|
|
@ -164,7 +164,7 @@ int SDL_SYS_HapticInit(void)
|
|||
MaybeAddDevice(path);
|
||||
}
|
||||
|
||||
#if SDL_USE_LIBUDEV
|
||||
#ifdef SDL_USE_LIBUDEV
|
||||
if (SDL_UDEV_Init() < 0) {
|
||||
return SDL_SetError("Could not initialize UDEV");
|
||||
}
|
||||
|
|
@ -203,10 +203,10 @@ static SDL_hapticlist_item *HapticByDevIndex(int device_index)
|
|||
return item;
|
||||
}
|
||||
|
||||
#if SDL_USE_LIBUDEV
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
@ -232,7 +232,7 @@ static int MaybeAddDevice(const char *path)
|
|||
int success;
|
||||
SDL_hapticlist_item *item;
|
||||
|
||||
if (path == NULL) {
|
||||
if (!path) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +242,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. */
|
||||
}
|
||||
|
|
@ -266,12 +266,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;
|
||||
}
|
||||
|
|
@ -279,7 +279,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;
|
||||
|
|
@ -293,22 +293,22 @@ static int MaybeAddDevice(const char *path)
|
|||
return numhaptics;
|
||||
}
|
||||
|
||||
#if SDL_USE_LIBUDEV
|
||||
#ifdef SDL_USE_LIBUDEV
|
||||
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);
|
||||
|
|
@ -365,7 +365,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;
|
||||
}
|
||||
|
|
@ -383,7 +383,7 @@ 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) {
|
||||
if (!haptic->hwdata) {
|
||||
SDL_OutOfMemory();
|
||||
goto open_err;
|
||||
}
|
||||
|
|
@ -403,7 +403,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) {
|
||||
if (!haptic->effects) {
|
||||
SDL_OutOfMemory();
|
||||
goto open_err;
|
||||
}
|
||||
|
|
@ -416,7 +416,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;
|
||||
}
|
||||
|
|
@ -608,7 +608,7 @@ void SDL_SYS_HapticQuit(void)
|
|||
SDL_free(item);
|
||||
}
|
||||
|
||||
#if SDL_USE_LIBUDEV
|
||||
#ifdef SDL_USE_LIBUDEV
|
||||
SDL_UDEV_DelCallback(haptic_udev_callback);
|
||||
SDL_UDEV_Quit();
|
||||
#endif /* SDL_USE_LIBUDEV */
|
||||
|
|
@ -647,17 +647,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;
|
||||
|
|
@ -823,7 +812,9 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect *src)
|
|||
dest->type = FF_FRICTION;
|
||||
}
|
||||
|
||||
dest->direction = 0; /* Handled by the condition-specifics. */
|
||||
if (SDL_SYS_ToDirection(&dest->direction, &condition->direction) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Replay */
|
||||
dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(condition->length);
|
||||
|
|
@ -889,7 +880,7 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect *src)
|
|||
|
||||
/* Header */
|
||||
dest->type = FF_RUMBLE;
|
||||
dest->direction = 0;
|
||||
dest->direction = 0x4000;
|
||||
|
||||
/* Replay */
|
||||
dest->replay.length = (leftright->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(leftright->length);
|
||||
|
|
@ -922,7 +913,7 @@ 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) {
|
||||
if (!effect->hweffect) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
#include "SDL_haptic.h"
|
||||
#include "../SDL_syshaptic.h"
|
||||
|
||||
#if SDL_HAPTIC_DINPUT
|
||||
#ifdef SDL_HAPTIC_DINPUT
|
||||
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_stdinc.h"
|
||||
|
|
@ -98,7 +98,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());
|
||||
|
|
@ -139,7 +139,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. */
|
||||
}
|
||||
|
||||
|
|
@ -172,7 +172,7 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance)
|
|||
}
|
||||
|
||||
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
|
||||
if (item == NULL) {
|
||||
if (!item) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -194,11 +194,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);
|
||||
|
|
@ -293,7 +293,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
|||
|
||||
/* Allocate the hwdata */
|
||||
haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata));
|
||||
if (haptic->hwdata == NULL) {
|
||||
if (!haptic->hwdata) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
|
||||
|
|
@ -407,7 +407,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) {
|
||||
if (!haptic->effects) {
|
||||
SDL_OutOfMemory();
|
||||
goto acquire_err;
|
||||
}
|
||||
|
|
@ -480,7 +480,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);
|
||||
|
|
@ -546,7 +546,7 @@ static int SDL_SYS_SetDirection(DIEFFECT *effect, SDL_HapticDirection *dir, int
|
|||
|
||||
/* Has axes. */
|
||||
rglDir = SDL_malloc(sizeof(LONG) * naxes);
|
||||
if (rglDir == NULL) {
|
||||
if (!rglDir) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
|
||||
|
|
@ -620,7 +620,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
|||
|
||||
/* Envelope. */
|
||||
envelope = SDL_malloc(sizeof(DIENVELOPE));
|
||||
if (envelope == NULL) {
|
||||
if (!envelope) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(envelope, 0, sizeof(DIENVELOPE));
|
||||
|
|
@ -635,7 +635,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
|||
}
|
||||
if (dest->cAxes > 0) {
|
||||
axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
|
||||
if (axes == NULL) {
|
||||
if (!axes) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
|
||||
|
|
@ -653,7 +653,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
|||
case SDL_HAPTIC_CONSTANT:
|
||||
hap_constant = &src->constant;
|
||||
constant = SDL_malloc(sizeof(DICONSTANTFORCE));
|
||||
if (constant == NULL) {
|
||||
if (!constant) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(constant, 0, sizeof(DICONSTANTFORCE));
|
||||
|
|
@ -695,7 +695,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
|||
case SDL_HAPTIC_SAWTOOTHDOWN:
|
||||
hap_periodic = &src->periodic;
|
||||
periodic = SDL_malloc(sizeof(DIPERIODIC));
|
||||
if (periodic == NULL) {
|
||||
if (!periodic) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(periodic, 0, sizeof(DIPERIODIC));
|
||||
|
|
@ -739,7 +739,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
|||
case SDL_HAPTIC_FRICTION:
|
||||
hap_condition = &src->condition;
|
||||
condition = SDL_malloc(sizeof(DICONDITION) * dest->cAxes);
|
||||
if (condition == NULL) {
|
||||
if (!condition) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(condition, 0, sizeof(DICONDITION));
|
||||
|
|
@ -780,7 +780,7 @@ 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) {
|
||||
if (!ramp) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(ramp, 0, sizeof(DIRAMPFORCE));
|
||||
|
|
@ -818,7 +818,7 @@ 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) {
|
||||
if (!custom) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(custom, 0, sizeof(DICUSTOMFORCE));
|
||||
|
|
@ -877,7 +877,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);
|
||||
|
|
@ -943,7 +943,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.");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_HAPTIC_DINPUT || SDL_HAPTIC_XINPUT
|
||||
#if defined(SDL_HAPTIC_DINPUT) || defined(SDL_HAPTIC_XINPUT)
|
||||
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_mutex.h"
|
||||
|
|
@ -81,7 +81,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;
|
||||
|
|
@ -97,7 +97,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);
|
||||
|
|
@ -160,12 +160,12 @@ int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
|
|||
*/
|
||||
int SDL_SYS_HapticMouse(void)
|
||||
{
|
||||
#if SDL_HAPTIC_DINPUT
|
||||
#ifdef SDL_HAPTIC_DINPUT
|
||||
SDL_hapticlist_item *item;
|
||||
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;
|
||||
}
|
||||
|
|
@ -183,12 +183,12 @@ int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
|
|||
if (joystick->driver != &SDL_WINDOWS_JoystickDriver) {
|
||||
return 0;
|
||||
}
|
||||
#if SDL_HAPTIC_XINPUT
|
||||
#ifdef SDL_HAPTIC_XINPUT
|
||||
if (joystick->hwdata->bXInputHaptic) {
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
#if SDL_HAPTIC_DINPUT
|
||||
#ifdef SDL_HAPTIC_DINPUT
|
||||
if (joystick->hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) {
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -299,7 +299,7 @@ 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) {
|
||||
if (!effect->hweffect) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -38,7 +38,7 @@ extern "C" {
|
|||
*/
|
||||
struct haptic_hwdata
|
||||
{
|
||||
#if SDL_HAPTIC_DINPUT
|
||||
#ifdef SDL_HAPTIC_DINPUT
|
||||
LPDIRECTINPUTDEVICE8 device;
|
||||
#endif
|
||||
DWORD axes[3]; /* Axes to use. */
|
||||
|
|
@ -54,14 +54,14 @@ struct haptic_hwdata
|
|||
/*
|
||||
* Haptic system effect data.
|
||||
*/
|
||||
#if SDL_HAPTIC_DINPUT || SDL_HAPTIC_XINPUT
|
||||
#if defined(SDL_HAPTIC_DINPUT) || defined(SDL_HAPTIC_XINPUT)
|
||||
struct haptic_hweffect
|
||||
{
|
||||
#if SDL_HAPTIC_DINPUT
|
||||
#ifdef SDL_HAPTIC_DINPUT
|
||||
DIEFFECT effect;
|
||||
LPDIRECTINPUTEFFECT ref;
|
||||
#endif
|
||||
#if SDL_HAPTIC_XINPUT
|
||||
#ifdef SDL_HAPTIC_XINPUT
|
||||
XINPUT_VIBRATION vibration;
|
||||
#endif
|
||||
};
|
||||
|
|
@ -74,7 +74,7 @@ typedef struct SDL_hapticlist_item
|
|||
{
|
||||
char *name;
|
||||
SDL_Haptic *haptic;
|
||||
#if SDL_HAPTIC_DINPUT
|
||||
#ifdef SDL_HAPTIC_DINPUT
|
||||
DIDEVICEINSTANCE instance;
|
||||
DIDEVCAPS capabilities;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
#include "SDL_haptic.h"
|
||||
#include "../SDL_syshaptic.h"
|
||||
|
||||
#if SDL_HAPTIC_XINPUT
|
||||
#ifdef SDL_HAPTIC_XINPUT
|
||||
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_timer.h"
|
||||
|
|
@ -84,7 +84,7 @@ int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
|
|||
}
|
||||
|
||||
item = (SDL_hapticlist_item *)SDL_malloc(sizeof(SDL_hapticlist_item));
|
||||
if (item == NULL) {
|
||||
if (!item) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +119,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);
|
||||
|
|
@ -178,7 +178,7 @@ 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) {
|
||||
if (!haptic->effects) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
/* Clear the memory */
|
||||
|
|
@ -186,7 +186,7 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us
|
|||
sizeof(struct haptic_effect) * haptic->neffects);
|
||||
|
||||
haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata));
|
||||
if (haptic->hwdata == NULL) {
|
||||
if (!haptic->hwdata) {
|
||||
SDL_free(haptic->effects);
|
||||
haptic->effects = NULL;
|
||||
return SDL_OutOfMemory();
|
||||
|
|
@ -197,7 +197,7 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us
|
|||
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;
|
||||
|
|
@ -207,7 +207,7 @@ static int SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 us
|
|||
(void)SDL_snprintf(threadName, sizeof(threadName), "SDLXInputDev%d", 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);
|
||||
|
|
@ -234,7 +234,7 @@ int SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick
|
|||
int 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);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue