Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "SDL_syshaptic.h"
|
||||
#include "SDL_haptic_c.h"
|
||||
#include "../joystick/SDL_joystick_c.h" /* For SDL_IsJoystickValid */
|
||||
#include "../joystick/SDL_joystick_c.h" // For SDL_IsJoystickValid
|
||||
|
||||
static SDL_Haptic *SDL_haptics = NULL;
|
||||
|
||||
@@ -127,13 +127,13 @@ SDL_Haptic *SDL_OpenHaptic(SDL_HapticID instance_id)
|
||||
hapticlist = hapticlist->next;
|
||||
}
|
||||
|
||||
/* Create the haptic device */
|
||||
// Create the haptic device
|
||||
haptic = (SDL_Haptic *)SDL_calloc(1, sizeof(*haptic));
|
||||
if (!haptic) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize the haptic device */
|
||||
// Initialize the haptic device
|
||||
SDL_SetObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC, SDL_TRUE);
|
||||
haptic->instance_id = instance_id;
|
||||
haptic->rumble_id = -1;
|
||||
@@ -149,13 +149,13 @@ SDL_Haptic *SDL_OpenHaptic(SDL_HapticID instance_id)
|
||||
}
|
||||
}
|
||||
|
||||
/* Add haptic to list */
|
||||
// Add haptic to list
|
||||
++haptic->ref_count;
|
||||
/* Link the haptic in the list */
|
||||
// Link the haptic in the list
|
||||
haptic->next = SDL_haptics;
|
||||
SDL_haptics = haptic;
|
||||
|
||||
/* Disable autocenter and set gain to max. */
|
||||
// Disable autocenter and set gain to max.
|
||||
if (haptic->supported & SDL_HAPTIC_GAIN) {
|
||||
SDL_SetHapticGain(haptic, 100);
|
||||
}
|
||||
@@ -220,7 +220,7 @@ SDL_bool SDL_IsJoystickHaptic(SDL_Joystick *joystick)
|
||||
|
||||
SDL_LockJoysticks();
|
||||
{
|
||||
/* Must be a valid joystick */
|
||||
// Must be a valid joystick
|
||||
if (SDL_IsJoystickValid(joystick) &&
|
||||
!SDL_IsGamepad(SDL_GetJoystickID(joystick))) {
|
||||
result = SDL_SYS_JoystickIsHaptic(joystick);
|
||||
@@ -238,14 +238,14 @@ SDL_Haptic *SDL_OpenHapticFromJoystick(SDL_Joystick *joystick)
|
||||
|
||||
SDL_LockJoysticks();
|
||||
{
|
||||
/* Must be a valid joystick */
|
||||
// Must be a valid joystick
|
||||
if (!SDL_IsJoystickValid(joystick)) {
|
||||
SDL_SetError("Haptic: Joystick isn't valid.");
|
||||
SDL_UnlockJoysticks();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Joystick must be haptic */
|
||||
// Joystick must be haptic
|
||||
if (SDL_IsGamepad(SDL_GetJoystickID(joystick)) ||
|
||||
SDL_SYS_JoystickIsHaptic(joystick) <= 0) {
|
||||
SDL_SetError("Haptic: Joystick isn't a haptic device.");
|
||||
@@ -254,7 +254,7 @@ SDL_Haptic *SDL_OpenHapticFromJoystick(SDL_Joystick *joystick)
|
||||
}
|
||||
|
||||
hapticlist = SDL_haptics;
|
||||
/* Check to see if joystick's haptic is already open */
|
||||
// Check to see if joystick's haptic is already open
|
||||
while (hapticlist) {
|
||||
if (SDL_SYS_JoystickSameHaptic(hapticlist, joystick)) {
|
||||
haptic = hapticlist;
|
||||
@@ -265,7 +265,7 @@ SDL_Haptic *SDL_OpenHapticFromJoystick(SDL_Joystick *joystick)
|
||||
hapticlist = hapticlist->next;
|
||||
}
|
||||
|
||||
/* Create the haptic device */
|
||||
// Create the haptic device
|
||||
haptic = (SDL_Haptic *)SDL_calloc(1, sizeof(*haptic));
|
||||
if (!haptic) {
|
||||
SDL_UnlockJoysticks();
|
||||
@@ -286,9 +286,9 @@ SDL_Haptic *SDL_OpenHapticFromJoystick(SDL_Joystick *joystick)
|
||||
}
|
||||
SDL_UnlockJoysticks();
|
||||
|
||||
/* Add haptic to list */
|
||||
// Add haptic to list
|
||||
++haptic->ref_count;
|
||||
/* Link the haptic in the list */
|
||||
// Link the haptic in the list
|
||||
haptic->next = SDL_haptics;
|
||||
SDL_haptics = haptic;
|
||||
|
||||
@@ -303,12 +303,12 @@ void SDL_CloseHaptic(SDL_Haptic *haptic)
|
||||
|
||||
CHECK_HAPTIC_MAGIC(haptic,);
|
||||
|
||||
/* Check if it's still in use */
|
||||
// Check if it's still in use
|
||||
if (--haptic->ref_count > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Close it, properly removing effects if needed */
|
||||
// Close it, properly removing effects if needed
|
||||
for (i = 0; i < haptic->neffects; i++) {
|
||||
if (haptic->effects[i].hweffect != NULL) {
|
||||
SDL_DestroyHapticEffect(haptic, i);
|
||||
@@ -317,13 +317,13 @@ void SDL_CloseHaptic(SDL_Haptic *haptic)
|
||||
SDL_SYS_HapticClose(haptic);
|
||||
SDL_SetObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC, SDL_FALSE);
|
||||
|
||||
/* Remove from the list */
|
||||
// Remove from the list
|
||||
hapticlist = SDL_haptics;
|
||||
hapticlistprev = NULL;
|
||||
while (hapticlist) {
|
||||
if (haptic == hapticlist) {
|
||||
if (hapticlistprev) {
|
||||
/* unlink this entry */
|
||||
// unlink this entry
|
||||
hapticlistprev->next = hapticlist->next;
|
||||
} else {
|
||||
SDL_haptics = haptic->next;
|
||||
@@ -335,7 +335,7 @@ void SDL_CloseHaptic(SDL_Haptic *haptic)
|
||||
hapticlist = hapticlist->next;
|
||||
}
|
||||
|
||||
/* Free the data associated with this device */
|
||||
// Free the data associated with this device
|
||||
SDL_free(haptic->name);
|
||||
SDL_free(haptic);
|
||||
}
|
||||
@@ -401,18 +401,18 @@ int SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect)
|
||||
return SDL_InvalidParamError("effect");
|
||||
}
|
||||
|
||||
/* Check to see if effect is supported */
|
||||
// Check to see if effect is supported
|
||||
if (SDL_HapticEffectSupported(haptic, effect) == SDL_FALSE) {
|
||||
return SDL_SetError("Haptic: Effect not supported by haptic device.");
|
||||
}
|
||||
|
||||
/* See if there's a free slot */
|
||||
// See if there's a free slot
|
||||
for (i = 0; i < haptic->neffects; i++) {
|
||||
if (haptic->effects[i].hweffect == NULL) {
|
||||
|
||||
/* Now let the backend create the real effect */
|
||||
// Now let the backend create the real effect
|
||||
if (SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect) < 0) {
|
||||
return -1; /* Backend failed to create effect */
|
||||
return -1; // Backend failed to create effect
|
||||
}
|
||||
|
||||
SDL_memcpy(&haptic->effects[i].effect, effect,
|
||||
@@ -445,12 +445,12 @@ int SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffec
|
||||
return SDL_InvalidParamError("data");
|
||||
}
|
||||
|
||||
/* Can't change type dynamically. */
|
||||
// Can't change type dynamically.
|
||||
if (data->type != haptic->effects[effect].effect.type) {
|
||||
return SDL_SetError("Haptic: Updating effect type is illegal.");
|
||||
}
|
||||
|
||||
/* Updates the effect */
|
||||
// Updates the effect
|
||||
if (SDL_SYS_HapticUpdateEffect(haptic, &haptic->effects[effect], data) <
|
||||
0) {
|
||||
return -1;
|
||||
@@ -469,7 +469,7 @@ int SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Run the effect */
|
||||
// Run the effect
|
||||
if (SDL_SYS_HapticRunEffect(haptic, &haptic->effects[effect], iterations) < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -485,7 +485,7 @@ int SDL_StopHapticEffect(SDL_Haptic *haptic, int effect)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Stop the effect */
|
||||
// Stop the effect
|
||||
if (SDL_SYS_HapticStopEffect(haptic, &haptic->effects[effect]) < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -501,7 +501,7 @@ void SDL_DestroyHapticEffect(SDL_Haptic *haptic, int effect)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Not allocated */
|
||||
// Not allocated
|
||||
if (haptic->effects[effect].hweffect == NULL) {
|
||||
return;
|
||||
}
|
||||
@@ -539,19 +539,19 @@ int SDL_SetHapticGain(SDL_Haptic *haptic, int gain)
|
||||
return SDL_SetError("Haptic: Gain must be between 0 and 100.");
|
||||
}
|
||||
|
||||
/* The user can use an environment variable to override the max gain. */
|
||||
// The user can use an environment variable to override the max gain.
|
||||
env = SDL_getenv("SDL_HAPTIC_GAIN_MAX");
|
||||
if (env) {
|
||||
max_gain = SDL_atoi(env);
|
||||
|
||||
/* Check for sanity. */
|
||||
// Check for sanity.
|
||||
if (max_gain < 0) {
|
||||
max_gain = 0;
|
||||
} else if (max_gain > 100) {
|
||||
max_gain = 100;
|
||||
}
|
||||
|
||||
/* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */
|
||||
// We'll scale it linearly with SDL_HAPTIC_GAIN_MAX
|
||||
real_gain = (gain * max_gain) / 100;
|
||||
} else {
|
||||
real_gain = gain;
|
||||
@@ -599,7 +599,7 @@ int SDL_ResumeHaptic(SDL_Haptic *haptic)
|
||||
CHECK_HAPTIC_MAGIC(haptic, -1);
|
||||
|
||||
if (!(haptic->supported & SDL_HAPTIC_PAUSE)) {
|
||||
return 0; /* Not going to be paused, so we pretend it's unpaused. */
|
||||
return 0; // Not going to be paused, so we pretend it's unpaused.
|
||||
}
|
||||
|
||||
return SDL_SYS_HapticUnpause(haptic);
|
||||
@@ -616,7 +616,7 @@ SDL_bool SDL_HapticRumbleSupported(SDL_Haptic *haptic)
|
||||
{
|
||||
CHECK_HAPTIC_MAGIC(haptic, SDL_FALSE);
|
||||
|
||||
/* Most things can use SINE, but XInput only has LEFTRIGHT. */
|
||||
// Most things can use SINE, but XInput only has LEFTRIGHT.
|
||||
return (haptic->supported & (SDL_HAPTIC_SINE | SDL_HAPTIC_LEFTRIGHT)) != 0;
|
||||
}
|
||||
|
||||
@@ -626,7 +626,7 @@ int SDL_InitHapticRumble(SDL_Haptic *haptic)
|
||||
|
||||
CHECK_HAPTIC_MAGIC(haptic, -1);
|
||||
|
||||
/* Already allocated. */
|
||||
// Already allocated.
|
||||
if (haptic->rumble_id >= 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -640,7 +640,7 @@ int SDL_InitHapticRumble(SDL_Haptic *haptic)
|
||||
efx->periodic.length = 5000;
|
||||
efx->periodic.attack_length = 0;
|
||||
efx->periodic.fade_length = 0;
|
||||
} else if (haptic->supported & SDL_HAPTIC_LEFTRIGHT) { /* XInput? */
|
||||
} else if (haptic->supported & SDL_HAPTIC_LEFTRIGHT) { // XInput?
|
||||
efx->type = SDL_HAPTIC_LEFTRIGHT;
|
||||
efx->leftright.length = 5000;
|
||||
efx->leftright.large_magnitude = 0x4000;
|
||||
@@ -667,7 +667,7 @@ int SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length)
|
||||
return SDL_SetError("Haptic: Rumble effect not initialized on haptic device");
|
||||
}
|
||||
|
||||
/* Clamp strength. */
|
||||
// Clamp strength.
|
||||
if (strength > 1.0f) {
|
||||
strength = 1.0f;
|
||||
} else if (strength < 0.0f) {
|
||||
|
||||
@@ -25,4 +25,4 @@
|
||||
extern int SDL_InitHaptics(void);
|
||||
extern void SDL_QuitHaptics(void);
|
||||
|
||||
#endif /* SDL_haptic_c_h_ */
|
||||
#endif // SDL_haptic_c_h_
|
||||
|
||||
@@ -24,15 +24,15 @@
|
||||
#ifndef SDL_syshaptic_h_
|
||||
#define SDL_syshaptic_h_
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
// Set up for C function definitions, even when using C++
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct haptic_effect
|
||||
{
|
||||
SDL_HapticEffect effect; /* The current event */
|
||||
struct haptic_hweffect *hweffect; /* The hardware behind the event */
|
||||
SDL_HapticEffect effect; // The current event
|
||||
struct haptic_hweffect *hweffect; // The hardware behind the event
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -40,21 +40,21 @@ struct haptic_effect
|
||||
*/
|
||||
struct SDL_Haptic
|
||||
{
|
||||
SDL_HapticID instance_id; /* Device instance, monotonically increasing from 0 */
|
||||
char *name; /* Device name - system dependent */
|
||||
SDL_HapticID instance_id; // Device instance, monotonically increasing from 0
|
||||
char *name; // Device name - system dependent
|
||||
|
||||
struct haptic_effect *effects; /* Allocated effects */
|
||||
int neffects; /* Maximum amount of effects */
|
||||
int nplaying; /* Maximum amount of effects to play at the same time */
|
||||
Uint32 supported; /* Supported effects and features */
|
||||
int naxes; /* Number of axes on the device. */
|
||||
struct haptic_effect *effects; // Allocated effects
|
||||
int neffects; // Maximum amount of effects
|
||||
int nplaying; // Maximum amount of effects to play at the same time
|
||||
Uint32 supported; // Supported effects and features
|
||||
int naxes; // Number of axes on the device.
|
||||
|
||||
struct haptic_hwdata *hwdata; /* Driver dependent */
|
||||
int ref_count; /* Count for multiple opens */
|
||||
struct haptic_hwdata *hwdata; // Driver dependent
|
||||
int ref_count; // Count for multiple opens
|
||||
|
||||
int rumble_id; /* ID of rumble effect for simple rumble API. */
|
||||
SDL_HapticEffect rumble_effect; /* Rumble effect. */
|
||||
struct SDL_Haptic *next; /* pointer to next haptic we have allocated */
|
||||
int rumble_id; // ID of rumble effect for simple rumble API.
|
||||
SDL_HapticEffect rumble_effect; // Rumble effect.
|
||||
struct SDL_Haptic *next; // pointer to next haptic we have allocated
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -64,7 +64,7 @@ struct SDL_Haptic
|
||||
*/
|
||||
extern int SDL_SYS_HapticInit(void);
|
||||
|
||||
/* Function to return the number of haptic devices plugged in right now */
|
||||
// Function to return the number of haptic devices plugged in right now
|
||||
extern int SDL_SYS_NumHaptics(void);
|
||||
|
||||
/*
|
||||
@@ -208,9 +208,9 @@ extern int SDL_SYS_HapticUnpause(SDL_Haptic *haptic);
|
||||
*/
|
||||
extern int SDL_SYS_HapticStopAll(SDL_Haptic *haptic);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
// Ends C function definitions when using C++
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_syshaptic_h_ */
|
||||
#endif // SDL_syshaptic_h_
|
||||
|
||||
@@ -277,7 +277,7 @@ int Android_RemoveHaptic(int device_id)
|
||||
SDL_hapticlist_item *prev = NULL;
|
||||
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
/* found it, remove it. */
|
||||
// found it, remove it.
|
||||
if (device_id == item->device_id) {
|
||||
const int retval = item->haptic ? 0 : -1;
|
||||
|
||||
@@ -291,9 +291,9 @@ int Android_RemoveHaptic(int device_id)
|
||||
SDL_hapticlist_tail = prev;
|
||||
}
|
||||
|
||||
/* Need to decrement the haptic count */
|
||||
// Need to decrement the haptic count
|
||||
--numhaptics;
|
||||
/* !!! TODO: Send a haptic remove event? */
|
||||
// !!! TODO: Send a haptic remove event?
|
||||
|
||||
SDL_free(item->name);
|
||||
SDL_free(item);
|
||||
@@ -304,4 +304,4 @@ int Android_RemoveHaptic(int device_id)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif /* SDL_HAPTIC_ANDROID */
|
||||
#endif // SDL_HAPTIC_ANDROID
|
||||
|
||||
@@ -25,4 +25,4 @@
|
||||
extern int Android_AddHaptic(int device_id, const char *name);
|
||||
extern int Android_RemoveHaptic(int device_id);
|
||||
|
||||
#endif /* SDL_HAPTIC_ANDROID */
|
||||
#endif // SDL_HAPTIC_ANDROID
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
#ifdef SDL_HAPTIC_IOKIT
|
||||
|
||||
#include "../SDL_syshaptic.h"
|
||||
#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
|
||||
#include "../../joystick/darwin/SDL_iokitjoystick_c.h" /* For joystick hwdata */
|
||||
#include "../../joystick/SDL_sysjoystick.h" // For the real SDL_Joystick
|
||||
#include "../../joystick/darwin/SDL_iokitjoystick_c.h" // For joystick hwdata
|
||||
#include "SDL_syshaptic_c.h"
|
||||
|
||||
#include <IOKit/IOKitLib.h>
|
||||
@@ -43,12 +43,12 @@
|
||||
typedef struct SDL_hapticlist_item
|
||||
{
|
||||
SDL_HapticID instance_id;
|
||||
char name[256]; /* Name of the device. */
|
||||
char name[256]; // Name of the device.
|
||||
|
||||
io_service_t dev; /* Node we use to create the device. */
|
||||
SDL_Haptic *haptic; /* Haptic currently associated with it. */
|
||||
io_service_t dev; // Node we use to create the device.
|
||||
SDL_Haptic *haptic; // Haptic currently associated with it.
|
||||
|
||||
/* Usage pages for determining if it's a mouse or not. */
|
||||
// Usage pages for determining if it's a mouse or not.
|
||||
long usage;
|
||||
long usagePage;
|
||||
|
||||
@@ -60,7 +60,7 @@ typedef struct SDL_hapticlist_item
|
||||
*/
|
||||
struct haptic_hwdata
|
||||
{
|
||||
FFDeviceObjectReference device; /* Hardware device. */
|
||||
FFDeviceObjectReference device; // Hardware device.
|
||||
UInt8 axes[3];
|
||||
};
|
||||
|
||||
@@ -69,8 +69,8 @@ struct haptic_hwdata
|
||||
*/
|
||||
struct haptic_hweffect
|
||||
{
|
||||
FFEffectObjectReference ref; /* Reference. */
|
||||
struct FFEFFECT effect; /* Hardware effect. */
|
||||
FFEffectObjectReference ref; // Reference.
|
||||
struct FFEFFECT effect; // Hardware effect.
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -91,7 +91,7 @@ static const char *FFStrError(unsigned int err)
|
||||
switch (err) {
|
||||
case FFERR_DEVICEFULL:
|
||||
return "device full";
|
||||
/* This should be valid, but for some reason isn't defined... */
|
||||
// This should be valid, but for some reason isn't defined...
|
||||
/* case FFERR_DEVICENOTREG:
|
||||
return "device not registered"; */
|
||||
case FFERR_DEVICEPAUSED:
|
||||
@@ -153,26 +153,26 @@ int SDL_SYS_HapticInit(void)
|
||||
}
|
||||
numhaptics = 0;
|
||||
|
||||
/* Get HID devices. */
|
||||
// Get HID devices.
|
||||
match = IOServiceMatching(kIOHIDDeviceKey);
|
||||
if (!match) {
|
||||
return SDL_SetError("Haptic: Failed to get IOServiceMatching.");
|
||||
}
|
||||
|
||||
/* Now search I/O Registry for matching devices. */
|
||||
// Now search I/O Registry for matching devices.
|
||||
result = IOServiceGetMatchingServices(kIOMainPortDefault, match, &iter);
|
||||
if (result != kIOReturnSuccess) {
|
||||
return SDL_SetError("Haptic: Couldn't create a HID object iterator.");
|
||||
}
|
||||
/* IOServiceGetMatchingServices consumes dictionary. */
|
||||
// IOServiceGetMatchingServices consumes dictionary.
|
||||
|
||||
if (!IOIteratorIsValid(iter)) { /* No iterator. */
|
||||
if (!IOIteratorIsValid(iter)) { // No iterator.
|
||||
return 0;
|
||||
}
|
||||
|
||||
while ((device = IOIteratorNext(iter)) != IO_OBJECT_NULL) {
|
||||
MacHaptic_MaybeAddDevice(device);
|
||||
/* always release as the AddDevice will retain IF it's a forcefeedback device */
|
||||
// always release as the AddDevice will retain IF it's a forcefeedback device
|
||||
IOObjectRelease(device);
|
||||
}
|
||||
IOObjectRelease(iter);
|
||||
@@ -221,18 +221,18 @@ 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 -1; // not initialized. We'll pick these up on enumeration if we init later.
|
||||
}
|
||||
|
||||
/* Check for force feedback. */
|
||||
// Check for force feedback.
|
||||
if (FFIsForceFeedback(device) != FF_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Make sure we don't already have it */
|
||||
// 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 */
|
||||
// Already added
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -243,14 +243,14 @@ int MacHaptic_MaybeAddDevice(io_object_t device)
|
||||
}
|
||||
item->instance_id = SDL_GetNextObjectID();
|
||||
|
||||
/* retain it as we are going to keep it around a while */
|
||||
// retain it as we are going to keep it around a while
|
||||
IOObjectRetain(device);
|
||||
|
||||
/* Set basic device data. */
|
||||
// Set basic device data.
|
||||
HIDGetDeviceProduct(device, item->name);
|
||||
item->dev = device;
|
||||
|
||||
/* Set usage pages. */
|
||||
// Set usage pages.
|
||||
hidProperties = 0;
|
||||
refCF = 0;
|
||||
result = IORegistryEntryCreateCFProperties(device,
|
||||
@@ -282,7 +282,7 @@ int MacHaptic_MaybeAddDevice(io_object_t device)
|
||||
SDL_hapticlist_tail = item;
|
||||
}
|
||||
|
||||
/* Device has been added. */
|
||||
// Device has been added.
|
||||
++numhaptics;
|
||||
|
||||
return numhaptics;
|
||||
@@ -294,11 +294,11 @@ int MacHaptic_MaybeRemoveDevice(io_object_t device)
|
||||
SDL_hapticlist_item *prev = NULL;
|
||||
|
||||
if (numhaptics == -1) {
|
||||
return -1; /* not initialized. ignore this. */
|
||||
return -1; // not initialized. ignore this.
|
||||
}
|
||||
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
/* found it, remove it. */
|
||||
// found it, remove it.
|
||||
if (IOObjectIsEqualTo((io_object_t)item->dev, device)) {
|
||||
const int retval = item->haptic ? 0 : -1;
|
||||
|
||||
@@ -312,9 +312,9 @@ int MacHaptic_MaybeRemoveDevice(io_object_t device)
|
||||
SDL_hapticlist_tail = prev;
|
||||
}
|
||||
|
||||
/* Need to decrement the haptic count */
|
||||
// Need to decrement the haptic count
|
||||
--numhaptics;
|
||||
/* !!! TODO: Send a haptic remove event? */
|
||||
// !!! TODO: Send a haptic remove event?
|
||||
|
||||
IOObjectRelease(item->dev);
|
||||
SDL_free(item);
|
||||
@@ -383,7 +383,7 @@ static int HIDGetDeviceProduct(io_service_t dev, char *name)
|
||||
* try hid dictionary first, if fail then go to USB dictionary
|
||||
*/
|
||||
|
||||
/* Get product name */
|
||||
// Get product name
|
||||
refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
|
||||
if (!refCF) {
|
||||
refCF = CFDictionaryGetValue(usbProperties,
|
||||
@@ -401,7 +401,7 @@ static int HIDGetDeviceProduct(io_service_t dev, char *name)
|
||||
return SDL_SetError("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties.");
|
||||
}
|
||||
|
||||
/* Release stuff. */
|
||||
// Release stuff.
|
||||
if (kIOReturnSuccess != IOObjectRelease(parent2)) {
|
||||
SDL_SetError("Haptic: IOObjectRelease error with parent2.");
|
||||
}
|
||||
@@ -438,11 +438,11 @@ static unsigned int GetSupportedFeatures(SDL_Haptic *haptic)
|
||||
|
||||
supported = 0;
|
||||
|
||||
/* Get maximum effects. */
|
||||
// Get maximum effects.
|
||||
haptic->neffects = features.storageCapacity;
|
||||
haptic->nplaying = features.playbackCapacity;
|
||||
|
||||
/* Test for effects. */
|
||||
// Test for effects.
|
||||
FF_TEST(FFCAP_ET_CONSTANTFORCE, SDL_HAPTIC_CONSTANT);
|
||||
FF_TEST(FFCAP_ET_RAMPFORCE, SDL_HAPTIC_RAMP);
|
||||
FF_TEST(FFCAP_ET_SQUARE, SDL_HAPTIC_SQUARE);
|
||||
@@ -456,7 +456,7 @@ static unsigned int GetSupportedFeatures(SDL_Haptic *haptic)
|
||||
FF_TEST(FFCAP_ET_FRICTION, SDL_HAPTIC_FRICTION);
|
||||
FF_TEST(FFCAP_ET_CUSTOMFORCE, SDL_HAPTIC_CUSTOM);
|
||||
|
||||
/* Check if supports gain. */
|
||||
// Check if supports gain.
|
||||
ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_FFGAIN,
|
||||
&val, sizeof(val));
|
||||
if (ret == FF_OK) {
|
||||
@@ -466,7 +466,7 @@ static unsigned int GetSupportedFeatures(SDL_Haptic *haptic)
|
||||
FFStrError(ret));
|
||||
}
|
||||
|
||||
/* Checks if supports autocenter. */
|
||||
// Checks if supports autocenter.
|
||||
ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER,
|
||||
&val, sizeof(val));
|
||||
if (ret == FF_OK) {
|
||||
@@ -476,13 +476,13 @@ static unsigned int GetSupportedFeatures(SDL_Haptic *haptic)
|
||||
FFStrError(ret));
|
||||
}
|
||||
|
||||
/* Check for axes, we have an artificial limit on axes */
|
||||
// Check for axes, we have an artificial limit on axes
|
||||
haptic->naxes = ((features.numFfAxes) > 3) ? 3 : features.numFfAxes;
|
||||
/* Actually store the axes we want to use */
|
||||
// Actually store the axes we want to use
|
||||
SDL_memcpy(haptic->hwdata->axes, features.ffAxes,
|
||||
haptic->naxes * sizeof(Uint8));
|
||||
|
||||
/* Always supported features. */
|
||||
// Always supported features.
|
||||
supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
|
||||
|
||||
haptic->supported = supported;
|
||||
@@ -497,26 +497,26 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
|
||||
HRESULT ret;
|
||||
int ret2;
|
||||
|
||||
/* Allocate the hwdata */
|
||||
// Allocate the hwdata
|
||||
haptic->hwdata = (struct haptic_hwdata *) SDL_calloc(1, sizeof(*haptic->hwdata));
|
||||
if (!haptic->hwdata) {
|
||||
goto creat_err;
|
||||
}
|
||||
|
||||
/* Open the device */
|
||||
// Open the device
|
||||
ret = FFCreateDevice(service, &haptic->hwdata->device);
|
||||
if (ret != FF_OK) {
|
||||
SDL_SetError("Haptic: Unable to create device from service: %s.", FFStrError(ret));
|
||||
goto creat_err;
|
||||
}
|
||||
|
||||
/* Get supported features. */
|
||||
// Get supported features.
|
||||
ret2 = GetSupportedFeatures(haptic);
|
||||
if (ret2 < 0) {
|
||||
goto open_err;
|
||||
}
|
||||
|
||||
/* Reset and then enable actuators. */
|
||||
// Reset and then enable actuators.
|
||||
ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
|
||||
FFSFFC_RESET);
|
||||
if (ret != FF_OK) {
|
||||
@@ -531,19 +531,19 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic
|
||||
goto open_err;
|
||||
}
|
||||
|
||||
/* Allocate effects memory. */
|
||||
// Allocate effects memory.
|
||||
haptic->effects = (struct haptic_effect *)
|
||||
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
|
||||
if (!haptic->effects) {
|
||||
goto open_err;
|
||||
}
|
||||
/* Clear the memory */
|
||||
// Clear the memory
|
||||
SDL_memset(haptic->effects, 0,
|
||||
sizeof(struct haptic_effect) * haptic->neffects);
|
||||
|
||||
return 0;
|
||||
|
||||
/* Error handling */
|
||||
// Error handling
|
||||
open_err:
|
||||
FFReleaseDevice(haptic->hwdata->device);
|
||||
creat_err:
|
||||
@@ -653,15 +653,15 @@ void SDL_SYS_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
if (haptic->hwdata) {
|
||||
|
||||
/* Free Effects. */
|
||||
// Free Effects.
|
||||
SDL_free(haptic->effects);
|
||||
haptic->effects = NULL;
|
||||
haptic->neffects = 0;
|
||||
|
||||
/* Clean up */
|
||||
// Clean up
|
||||
FFReleaseDevice(haptic->hwdata->device);
|
||||
|
||||
/* Free */
|
||||
// Free
|
||||
SDL_free(haptic->hwdata);
|
||||
haptic->hwdata = NULL;
|
||||
}
|
||||
@@ -680,7 +680,7 @@ void SDL_SYS_HapticQuit(void)
|
||||
/* Opened and not closed haptics are leaked, this is on purpose.
|
||||
* Close your haptic devices after usage. */
|
||||
|
||||
/* Free the io_service_t */
|
||||
// Free the io_service_t
|
||||
IOObjectRelease(item->dev);
|
||||
SDL_free(item);
|
||||
}
|
||||
@@ -713,14 +713,14 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir
|
||||
{
|
||||
LONG *rglDir;
|
||||
|
||||
/* Handle no axes a part. */
|
||||
// Handle no axes a part.
|
||||
if (naxes == 0) {
|
||||
effect->dwFlags |= FFEFF_SPHERICAL; /* Set as default. */
|
||||
effect->dwFlags |= FFEFF_SPHERICAL; // Set as default.
|
||||
effect->rglDirection = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Has axes. */
|
||||
// Has axes.
|
||||
rglDir = SDL_malloc(sizeof(LONG) * naxes);
|
||||
if (!rglDir) {
|
||||
return -1;
|
||||
@@ -763,9 +763,9 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir
|
||||
}
|
||||
}
|
||||
|
||||
/* Clamps and converts. */
|
||||
// Clamps and converts.
|
||||
#define CCONVERT(x) (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
|
||||
/* Just converts. */
|
||||
// Just converts.
|
||||
#define CONVERT(x) (((x)*10000) / 0x7FFF)
|
||||
/*
|
||||
* Creates the FFEFFECT from a SDL_HapticEffect.
|
||||
@@ -775,7 +775,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
|
||||
int i;
|
||||
FFCONSTANTFORCE *constant = NULL;
|
||||
FFPERIODIC *periodic = NULL;
|
||||
FFCONDITION *condition = NULL; /* Actually an array of conditions - one per axis. */
|
||||
FFCONDITION *condition = NULL; // Actually an array of conditions - one per axis.
|
||||
FFRAMPFORCE *ramp = NULL;
|
||||
FFCUSTOMFORCE *custom = NULL;
|
||||
FFENVELOPE *envelope = NULL;
|
||||
@@ -786,22 +786,22 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
|
||||
const SDL_HapticCustom *hap_custom = NULL;
|
||||
DWORD *axes = NULL;
|
||||
|
||||
/* Set global stuff. */
|
||||
// Set global stuff.
|
||||
SDL_memset(dest, 0, sizeof(FFEFFECT));
|
||||
dest->dwSize = sizeof(FFEFFECT); /* Set the structure size. */
|
||||
dest->dwSamplePeriod = 0; /* Not used by us. */
|
||||
dest->dwGain = 10000; /* Gain is set globally, not locally. */
|
||||
dest->dwFlags = FFEFF_OBJECTOFFSETS; /* Seems obligatory. */
|
||||
dest->dwSize = sizeof(FFEFFECT); // Set the structure size.
|
||||
dest->dwSamplePeriod = 0; // Not used by us.
|
||||
dest->dwGain = 10000; // Gain is set globally, not locally.
|
||||
dest->dwFlags = FFEFF_OBJECTOFFSETS; // Seems obligatory.
|
||||
|
||||
/* Envelope. */
|
||||
// Envelope.
|
||||
envelope = SDL_calloc(1, sizeof(FFENVELOPE));
|
||||
if (!envelope) {
|
||||
return -1;
|
||||
}
|
||||
dest->lpEnvelope = envelope;
|
||||
envelope->dwSize = sizeof(FFENVELOPE); /* Always should be this. */
|
||||
envelope->dwSize = sizeof(FFENVELOPE); // Always should be this.
|
||||
|
||||
/* Axes. */
|
||||
// Axes.
|
||||
if (src->constant.direction.type == SDL_HAPTIC_STEERING_AXIS) {
|
||||
dest->cAxes = 1;
|
||||
} else {
|
||||
@@ -812,7 +812,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
|
||||
if (!axes) {
|
||||
return -1;
|
||||
}
|
||||
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
|
||||
axes[0] = haptic->hwdata->axes[0]; // Always at least one axis.
|
||||
if (dest->cAxes > 1) {
|
||||
axes[1] = haptic->hwdata->axes[1];
|
||||
}
|
||||
@@ -822,7 +822,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
|
||||
dest->rgdwAxes = axes;
|
||||
}
|
||||
|
||||
/* The big type handling switch, even bigger then Linux's version. */
|
||||
// The big type handling switch, even bigger then Linux's version.
|
||||
switch (src->type) {
|
||||
case SDL_HAPTIC_CONSTANT:
|
||||
hap_constant = &src->constant;
|
||||
@@ -831,23 +831,23 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Specifics */
|
||||
// Specifics
|
||||
constant->lMagnitude = CONVERT(hap_constant->level);
|
||||
dest->cbTypeSpecificParams = sizeof(FFCONSTANTFORCE);
|
||||
dest->lpvTypeSpecificParams = constant;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */
|
||||
// Generics
|
||||
dest->dwDuration = hap_constant->length * 1000; // In microseconds.
|
||||
dest->dwTriggerButton = FFGetTriggerButton(hap_constant->button);
|
||||
dest->dwTriggerRepeatInterval = hap_constant->interval;
|
||||
dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_constant->delay * 1000; // In microseconds.
|
||||
|
||||
/* Direction. */
|
||||
// Direction.
|
||||
if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Envelope */
|
||||
// Envelope
|
||||
if ((hap_constant->attack_length == 0) && (hap_constant->fade_length == 0)) {
|
||||
SDL_free(envelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
@@ -871,7 +871,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Specifics */
|
||||
// Specifics
|
||||
periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude));
|
||||
periodic->lOffset = CONVERT(hap_periodic->offset);
|
||||
periodic->dwPhase =
|
||||
@@ -880,18 +880,18 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
|
||||
dest->cbTypeSpecificParams = sizeof(FFPERIODIC);
|
||||
dest->lpvTypeSpecificParams = periodic;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_periodic->length * 1000; /* In microseconds. */
|
||||
// Generics
|
||||
dest->dwDuration = hap_periodic->length * 1000; // In microseconds.
|
||||
dest->dwTriggerButton = FFGetTriggerButton(hap_periodic->button);
|
||||
dest->dwTriggerRepeatInterval = hap_periodic->interval;
|
||||
dest->dwStartDelay = hap_periodic->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_periodic->delay * 1000; // In microseconds.
|
||||
|
||||
/* Direction. */
|
||||
// Direction.
|
||||
if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Envelope */
|
||||
// Envelope
|
||||
if ((hap_periodic->attack_length == 0) && (hap_periodic->fade_length == 0)) {
|
||||
SDL_free(envelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
@@ -915,7 +915,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Specifics */
|
||||
// Specifics
|
||||
for (i = 0; i < dest->cAxes; i++) {
|
||||
condition[i].lOffset = CONVERT(hap_condition->center[i]);
|
||||
condition[i].lPositiveCoefficient =
|
||||
@@ -933,18 +933,18 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
|
||||
dest->cbTypeSpecificParams = sizeof(FFCONDITION) * dest->cAxes;
|
||||
dest->lpvTypeSpecificParams = condition;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_condition->length * 1000; /* In microseconds. */
|
||||
// Generics
|
||||
dest->dwDuration = hap_condition->length * 1000; // In microseconds.
|
||||
dest->dwTriggerButton = FFGetTriggerButton(hap_condition->button);
|
||||
dest->dwTriggerRepeatInterval = hap_condition->interval;
|
||||
dest->dwStartDelay = hap_condition->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_condition->delay * 1000; // In microseconds.
|
||||
|
||||
/* Direction. */
|
||||
// Direction.
|
||||
if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Envelope - Not actually supported by most CONDITION implementations. */
|
||||
// Envelope - Not actually supported by most CONDITION implementations.
|
||||
SDL_free(dest->lpEnvelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
|
||||
@@ -957,24 +957,24 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Specifics */
|
||||
// Specifics
|
||||
ramp->lStart = CONVERT(hap_ramp->start);
|
||||
ramp->lEnd = CONVERT(hap_ramp->end);
|
||||
dest->cbTypeSpecificParams = sizeof(FFRAMPFORCE);
|
||||
dest->lpvTypeSpecificParams = ramp;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_ramp->length * 1000; /* In microseconds. */
|
||||
// Generics
|
||||
dest->dwDuration = hap_ramp->length * 1000; // In microseconds.
|
||||
dest->dwTriggerButton = FFGetTriggerButton(hap_ramp->button);
|
||||
dest->dwTriggerRepeatInterval = hap_ramp->interval;
|
||||
dest->dwStartDelay = hap_ramp->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_ramp->delay * 1000; // In microseconds.
|
||||
|
||||
/* Direction. */
|
||||
// Direction.
|
||||
if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Envelope */
|
||||
// Envelope
|
||||
if ((hap_ramp->attack_length == 0) && (hap_ramp->fade_length == 0)) {
|
||||
SDL_free(envelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
@@ -994,31 +994,31 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Specifics */
|
||||
// Specifics
|
||||
custom->cChannels = hap_custom->channels;
|
||||
custom->dwSamplePeriod = hap_custom->period * 1000;
|
||||
custom->cSamples = hap_custom->samples;
|
||||
custom->rglForceData =
|
||||
SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
|
||||
for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) { /* Copy data. */
|
||||
for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) { // Copy data.
|
||||
custom->rglForceData[i] = CCONVERT(hap_custom->data[i]);
|
||||
}
|
||||
dest->cbTypeSpecificParams = sizeof(FFCUSTOMFORCE);
|
||||
dest->lpvTypeSpecificParams = custom;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_custom->length * 1000; /* In microseconds. */
|
||||
// Generics
|
||||
dest->dwDuration = hap_custom->length * 1000; // In microseconds.
|
||||
dest->dwTriggerButton = FFGetTriggerButton(hap_custom->button);
|
||||
dest->dwTriggerRepeatInterval = hap_custom->interval;
|
||||
dest->dwStartDelay = hap_custom->delay * 1000; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_custom->delay * 1000; // In microseconds.
|
||||
|
||||
/* Direction. */
|
||||
// Direction.
|
||||
if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) <
|
||||
0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Envelope */
|
||||
// Envelope
|
||||
if ((hap_custom->attack_length == 0) && (hap_custom->fade_length == 0)) {
|
||||
SDL_free(envelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
@@ -1050,7 +1050,7 @@ static void SDL_SYS_HapticFreeFFEFFECT(FFEFFECT *effect, int type)
|
||||
SDL_free(effect->rgdwAxes);
|
||||
effect->rgdwAxes = NULL;
|
||||
if (effect->lpvTypeSpecificParams) {
|
||||
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
|
||||
if (type == SDL_HAPTIC_CUSTOM) { // Must free the custom data.
|
||||
custom = (FFCUSTOMFORCE *)effect->lpvTypeSpecificParams;
|
||||
SDL_free(custom->rglForceData);
|
||||
custom->rglForceData = NULL;
|
||||
@@ -1120,25 +1120,25 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
HRESULT ret;
|
||||
CFUUIDRef type;
|
||||
|
||||
/* Alloc the effect. */
|
||||
// Alloc the effect.
|
||||
effect->hweffect = (struct haptic_hweffect *)
|
||||
SDL_calloc(1, sizeof(struct haptic_hweffect));
|
||||
if (!effect->hweffect) {
|
||||
goto err_hweffect;
|
||||
}
|
||||
|
||||
/* Get the type. */
|
||||
// Get the type.
|
||||
type = SDL_SYS_HapticEffectType(base->type);
|
||||
if (!type) {
|
||||
goto err_hweffect;
|
||||
}
|
||||
|
||||
/* Get the effect. */
|
||||
// Get the effect.
|
||||
if (SDL_SYS_ToFFEFFECT(haptic, &effect->hweffect->effect, base) < 0) {
|
||||
goto err_effectdone;
|
||||
}
|
||||
|
||||
/* Create the actual effect. */
|
||||
// Create the actual effect.
|
||||
ret = FFDeviceCreateEffect(haptic->hwdata->device, type,
|
||||
&effect->hweffect->effect,
|
||||
&effect->hweffect->ref);
|
||||
@@ -1168,7 +1168,7 @@ int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
|
||||
FFEffectParameterFlag flags;
|
||||
FFEFFECT temp;
|
||||
|
||||
/* Get the effect. */
|
||||
// Get the effect.
|
||||
SDL_memset(&temp, 0, sizeof(FFEFFECT));
|
||||
if (SDL_SYS_ToFFEFFECT(haptic, &temp, data) < 0) {
|
||||
goto err_update;
|
||||
@@ -1183,14 +1183,14 @@ int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
|
||||
FFEP_TRIGGERBUTTON |
|
||||
FFEP_TRIGGERREPEATINTERVAL | FFEP_TYPESPECIFICPARAMS;
|
||||
|
||||
/* Create the actual effect. */
|
||||
// Create the actual effect.
|
||||
ret = FFEffectSetParameters(effect->hweffect->ref, &temp, flags);
|
||||
if (ret != FF_OK) {
|
||||
SDL_SetError("Haptic: Unable to update effect: %s.", FFStrError(ret));
|
||||
goto err_update;
|
||||
}
|
||||
|
||||
/* Copy it over. */
|
||||
// Copy it over.
|
||||
SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, data->type);
|
||||
SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(FFEFFECT));
|
||||
|
||||
@@ -1210,14 +1210,14 @@ int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
HRESULT ret;
|
||||
Uint32 iter;
|
||||
|
||||
/* Check if it's infinite. */
|
||||
// Check if it's infinite.
|
||||
if (iterations == SDL_HAPTIC_INFINITY) {
|
||||
iter = FF_INFINITE;
|
||||
} else {
|
||||
iter = iterations;
|
||||
}
|
||||
|
||||
/* Run the effect. */
|
||||
// Run the effect.
|
||||
ret = FFEffectStart(effect->hweffect->ref, iter, 0);
|
||||
if (ret != FF_OK) {
|
||||
return SDL_SetError("Haptic: Unable to run the effect: %s.",
|
||||
@@ -1279,7 +1279,7 @@ int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic,
|
||||
if (status == 0) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_TRUE; /* Assume it's playing or emulated. */
|
||||
return SDL_TRUE; // Assume it's playing or emulated.
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1290,7 +1290,7 @@ int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain)
|
||||
HRESULT ret;
|
||||
Uint32 val;
|
||||
|
||||
val = gain * 100; /* macOS uses 0 to 10,000 */
|
||||
val = gain * 100; // macOS uses 0 to 10,000
|
||||
ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
|
||||
FFPROP_FFGAIN, &val);
|
||||
if (ret != FF_OK) {
|
||||
@@ -1308,7 +1308,7 @@ int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
|
||||
HRESULT ret;
|
||||
Uint32 val;
|
||||
|
||||
/* macOS only has 0 (off) and 1 (on) */
|
||||
// macOS only has 0 (off) and 1 (on)
|
||||
if (autocenter == 0) {
|
||||
val = 0;
|
||||
} else {
|
||||
@@ -1373,4 +1373,4 @@ int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_HAPTIC_IOKIT */
|
||||
#endif // SDL_HAPTIC_IOKIT
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/* Things named "Master" were renamed to "Main" in macOS 12.0's SDK. */
|
||||
// Things named "Master" were renamed to "Main" in macOS 12.0's SDK.
|
||||
#include <AvailabilityMacros.h>
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000
|
||||
#define kIOMainPortDefault kIOMasterPortDefault
|
||||
|
||||
@@ -147,4 +147,4 @@ int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
|
||||
return SDL_SYS_LogicError();
|
||||
}
|
||||
|
||||
#endif /* SDL_HAPTIC_DUMMY || SDL_HAPTIC_DISABLED */
|
||||
#endif // SDL_HAPTIC_DUMMY || SDL_HAPTIC_DISABLED
|
||||
|
||||
@@ -23,26 +23,26 @@
|
||||
#ifdef SDL_HAPTIC_LINUX
|
||||
|
||||
#include "../SDL_syshaptic.h"
|
||||
#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
|
||||
#include "../../joystick/linux/SDL_sysjoystick_c.h" /* For joystick hwdata */
|
||||
#include "../../joystick/SDL_sysjoystick.h" // For the real SDL_Joystick
|
||||
#include "../../joystick/linux/SDL_sysjoystick_c.h" // For joystick hwdata
|
||||
#include "../../core/linux/SDL_evdev_capabilities.h"
|
||||
#include "../../core/linux/SDL_udev.h"
|
||||
|
||||
#include <unistd.h> /* close */
|
||||
#include <linux/input.h> /* Force feedback linux stuff. */
|
||||
#include <fcntl.h> /* O_RDWR */
|
||||
#include <limits.h> /* INT_MAX */
|
||||
#include <errno.h> /* errno */
|
||||
#include <string.h> /* strerror */
|
||||
#include <sys/stat.h> /* stat */
|
||||
#include <unistd.h> // close
|
||||
#include <linux/input.h> // Force feedback linux stuff.
|
||||
#include <fcntl.h> // O_RDWR
|
||||
#include <limits.h> // INT_MAX
|
||||
#include <errno.h> // errno
|
||||
#include <string.h> // strerror
|
||||
#include <sys/stat.h> // stat
|
||||
|
||||
#define MAX_HAPTICS 32 /* It's doubtful someone has more then 32 evdev */
|
||||
#define MAX_HAPTICS 32 // It's doubtful someone has more then 32 evdev
|
||||
|
||||
static int MaybeAddDevice(const char *path);
|
||||
#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 */
|
||||
#endif // SDL_USE_LIBUDEV
|
||||
|
||||
/*
|
||||
* List of available haptic devices.
|
||||
@@ -50,8 +50,8 @@ static void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class,
|
||||
typedef struct SDL_hapticlist_item
|
||||
{
|
||||
SDL_HapticID instance_id;
|
||||
char *fname; /* Dev path name (like /dev/input/event1) */
|
||||
SDL_Haptic *haptic; /* Associated haptic. */
|
||||
char *fname; // Dev path name (like /dev/input/event1)
|
||||
SDL_Haptic *haptic; // Associated haptic.
|
||||
dev_t dev_num;
|
||||
struct SDL_hapticlist_item *next;
|
||||
} SDL_hapticlist_item;
|
||||
@@ -61,8 +61,8 @@ typedef struct SDL_hapticlist_item
|
||||
*/
|
||||
struct haptic_hwdata
|
||||
{
|
||||
int fd; /* File descriptor of the device. */
|
||||
char *fname; /* Points to the name in SDL_hapticlist. */
|
||||
int fd; // File descriptor of the device.
|
||||
char *fname; // Points to the name in SDL_hapticlist.
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -70,7 +70,7 @@ struct haptic_hwdata
|
||||
*/
|
||||
struct haptic_hweffect
|
||||
{
|
||||
struct ff_effect effect; /* The linux kernel effect structure. */
|
||||
struct ff_effect effect; // The linux kernel effect structure.
|
||||
};
|
||||
|
||||
static SDL_hapticlist_item *SDL_hapticlist = NULL;
|
||||
@@ -90,14 +90,14 @@ static int EV_IsHaptic(int fd)
|
||||
unsigned int ret;
|
||||
unsigned long features[1 + FF_MAX / sizeof(unsigned long)];
|
||||
|
||||
/* Ask device for what it has. */
|
||||
// Ask device for what it has.
|
||||
ret = 0;
|
||||
if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(features)), features) < 0) {
|
||||
return SDL_SetError("Haptic: Unable to get device's features: %s",
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
/* Convert supported features to SDL_HAPTIC platform-neutral features. */
|
||||
// Convert supported features to SDL_HAPTIC platform-neutral features.
|
||||
EV_TEST(FF_CONSTANT, SDL_HAPTIC_CONSTANT);
|
||||
EV_TEST(FF_SINE, SDL_HAPTIC_SINE);
|
||||
EV_TEST(FF_SQUARE, SDL_HAPTIC_SQUARE);
|
||||
@@ -114,7 +114,7 @@ static int EV_IsHaptic(int fd)
|
||||
EV_TEST(FF_AUTOCENTER, SDL_HAPTIC_AUTOCENTER);
|
||||
EV_TEST(FF_RUMBLE, SDL_HAPTIC_LEFTRIGHT);
|
||||
|
||||
/* Return what it supports. */
|
||||
// Return what it supports.
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -125,12 +125,12 @@ static int EV_IsMouse(int fd)
|
||||
{
|
||||
unsigned long argp[40];
|
||||
|
||||
/* Ask for supported features. */
|
||||
// Ask for supported features.
|
||||
if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(argp)), argp) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Currently we only test for BTN_MOUSE which can give fake positives. */
|
||||
// Currently we only test for BTN_MOUSE which can give fake positives.
|
||||
if (test_bit(BTN_MOUSE, argp) != 0) {
|
||||
return 1;
|
||||
}
|
||||
@@ -167,9 +167,9 @@ int SDL_SYS_HapticInit(void)
|
||||
return SDL_SetError("Could not setup haptic <-> udev callback");
|
||||
}
|
||||
|
||||
/* Force a scan to build the initial device list */
|
||||
// Force a scan to build the initial device list
|
||||
SDL_UDEV_Scan();
|
||||
#endif /* SDL_USE_LIBUDEV */
|
||||
#endif // SDL_USE_LIBUDEV
|
||||
|
||||
return numhaptics;
|
||||
}
|
||||
@@ -227,7 +227,7 @@ static void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class,
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* SDL_USE_LIBUDEV */
|
||||
#endif // SDL_USE_LIBUDEV
|
||||
|
||||
static int MaybeAddDevice(const char *path)
|
||||
{
|
||||
@@ -240,23 +240,23 @@ static int MaybeAddDevice(const char *path)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* try to open */
|
||||
// try to open
|
||||
fd = open(path, O_RDWR | O_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* get file status */
|
||||
// get file status
|
||||
if (fstat(fd, &sb) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* check for duplicates */
|
||||
// check for duplicates
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
if (item->dev_num == sb.st_rdev) {
|
||||
close(fd);
|
||||
return -1; /* duplicate. */
|
||||
return -1; // duplicate.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ static int MaybeAddDevice(const char *path)
|
||||
printf("Checking %s\n", path);
|
||||
#endif
|
||||
|
||||
/* see if it works */
|
||||
// see if it works
|
||||
success = EV_IsHaptic(fd);
|
||||
close(fd);
|
||||
if (success <= 0) {
|
||||
@@ -285,7 +285,7 @@ static int MaybeAddDevice(const char *path)
|
||||
|
||||
item->dev_num = sb.st_rdev;
|
||||
|
||||
/* TODO: should we add instance IDs? */
|
||||
// TODO: should we add instance IDs?
|
||||
if (!SDL_hapticlist_tail) {
|
||||
SDL_hapticlist = SDL_hapticlist_tail = item;
|
||||
} else {
|
||||
@@ -295,7 +295,7 @@ static int MaybeAddDevice(const char *path)
|
||||
|
||||
++numhaptics;
|
||||
|
||||
/* !!! TODO: Send a haptic add event? */
|
||||
// !!! TODO: Send a haptic add event?
|
||||
|
||||
return numhaptics;
|
||||
}
|
||||
@@ -311,7 +311,7 @@ static int MaybeRemoveDevice(const char *path)
|
||||
}
|
||||
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
/* found it, remove it. */
|
||||
// found it, remove it.
|
||||
if (SDL_strcmp(path, item->fname) == 0) {
|
||||
const int retval = item->haptic ? 0 : -1;
|
||||
|
||||
@@ -325,9 +325,9 @@ static int MaybeRemoveDevice(const char *path)
|
||||
SDL_hapticlist_tail = prev;
|
||||
}
|
||||
|
||||
/* Need to decrement the haptic count */
|
||||
// Need to decrement the haptic count
|
||||
--numhaptics;
|
||||
/* !!! TODO: Send a haptic remove event? */
|
||||
// !!! TODO: Send a haptic remove event?
|
||||
|
||||
SDL_free(item->fname);
|
||||
SDL_free(item);
|
||||
@@ -338,7 +338,7 @@ static int MaybeRemoveDevice(const char *path)
|
||||
|
||||
return -1;
|
||||
}
|
||||
#endif /* SDL_USE_LIBUDEV */
|
||||
#endif // SDL_USE_LIBUDEV
|
||||
|
||||
/*
|
||||
* Return the instance ID of a haptic device, does not need to be opened.
|
||||
@@ -361,7 +361,7 @@ static const char *SDL_SYS_HapticNameFromFD(int fd)
|
||||
{
|
||||
static char namebuf[128];
|
||||
|
||||
/* We use the evdev name ioctl. */
|
||||
// We use the evdev name ioctl.
|
||||
if (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -380,14 +380,14 @@ const char *SDL_SYS_HapticName(int index)
|
||||
|
||||
item = HapticByDevIndex(index);
|
||||
if (item) {
|
||||
/* Open the haptic device. */
|
||||
// Open the haptic device.
|
||||
fd = open(item->fname, O_RDONLY | O_CLOEXEC, 0);
|
||||
|
||||
if (fd >= 0) {
|
||||
|
||||
name = SDL_SYS_HapticNameFromFD(fd);
|
||||
if (!name) {
|
||||
/* No name found, return device character device */
|
||||
// No name found, return device character device
|
||||
name = item->fname;
|
||||
}
|
||||
close(fd);
|
||||
@@ -401,37 +401,37 @@ const char *SDL_SYS_HapticName(int index)
|
||||
*/
|
||||
static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd)
|
||||
{
|
||||
/* Allocate the hwdata */
|
||||
// Allocate the hwdata
|
||||
haptic->hwdata = (struct haptic_hwdata *)
|
||||
SDL_calloc(1, sizeof(*haptic->hwdata));
|
||||
if (!haptic->hwdata) {
|
||||
goto open_err;
|
||||
}
|
||||
|
||||
/* Set the data. */
|
||||
// Set the data.
|
||||
haptic->hwdata->fd = fd;
|
||||
haptic->supported = EV_IsHaptic(fd);
|
||||
haptic->naxes = 2; /* Hardcoded for now, not sure if it's possible to find out. */
|
||||
haptic->naxes = 2; // Hardcoded for now, not sure if it's possible to find out.
|
||||
|
||||
/* Set the effects */
|
||||
// Set the effects
|
||||
if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) {
|
||||
SDL_SetError("Haptic: Unable to query device memory: %s",
|
||||
strerror(errno));
|
||||
goto open_err;
|
||||
}
|
||||
haptic->nplaying = haptic->neffects; /* Linux makes no distinction. */
|
||||
haptic->nplaying = haptic->neffects; // Linux makes no distinction.
|
||||
haptic->effects = (struct haptic_effect *)
|
||||
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
|
||||
if (!haptic->effects) {
|
||||
goto open_err;
|
||||
}
|
||||
/* Clear the memory */
|
||||
// Clear the memory
|
||||
SDL_memset(haptic->effects, 0,
|
||||
sizeof(struct haptic_effect) * haptic->neffects);
|
||||
|
||||
return 0;
|
||||
|
||||
/* Error handling */
|
||||
// Error handling
|
||||
open_err:
|
||||
close(fd);
|
||||
if (haptic->hwdata) {
|
||||
@@ -451,20 +451,20 @@ int SDL_SYS_HapticOpen(SDL_Haptic *haptic)
|
||||
SDL_hapticlist_item *item;
|
||||
|
||||
item = HapticByInstanceID(haptic->instance_id);
|
||||
/* Open the character device */
|
||||
// Open the character device
|
||||
fd = open(item->fname, O_RDWR | O_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
return SDL_SetError("Haptic: Unable to open %s: %s",
|
||||
item->fname, strerror(errno));
|
||||
}
|
||||
|
||||
/* Try to create the haptic. */
|
||||
ret = SDL_SYS_HapticOpenFromFD(haptic, fd); /* Already closes on error. */
|
||||
// Try to create the haptic.
|
||||
ret = SDL_SYS_HapticOpenFromFD(haptic, fd); // Already closes on error.
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set the fname. */
|
||||
// Set the fname.
|
||||
haptic->hwdata->fname = SDL_strdup(item->fname);
|
||||
return 0;
|
||||
}
|
||||
@@ -479,14 +479,14 @@ int SDL_SYS_HapticMouse(void)
|
||||
SDL_hapticlist_item *item;
|
||||
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
/* Open the device. */
|
||||
// Open the device.
|
||||
fd = open(item->fname, O_RDWR | O_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
return SDL_SetError("Haptic: Unable to open %s: %s",
|
||||
item->fname, strerror(errno));
|
||||
}
|
||||
|
||||
/* Is it a mouse? */
|
||||
// Is it a mouse?
|
||||
if (EV_IsMouse(fd)) {
|
||||
close(fd);
|
||||
return device_index;
|
||||
@@ -554,7 +554,7 @@ int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
if (joystick->driver != &SDL_LINUX_JoystickDriver) {
|
||||
return -1;
|
||||
}
|
||||
/* Find the joystick in the haptic list. */
|
||||
// Find the joystick in the haptic list.
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
if (SDL_strcmp(item->fname, joystick->hwdata->fname) == 0) {
|
||||
haptic->instance_id = item->instance_id;
|
||||
@@ -567,7 +567,7 @@ int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
return SDL_SetError("Haptic: Unable to open %s: %s",
|
||||
joystick->hwdata->fname, strerror(errno));
|
||||
}
|
||||
ret = SDL_SYS_HapticOpenFromFD(haptic, fd); /* Already closes on error. */
|
||||
ret = SDL_SYS_HapticOpenFromFD(haptic, fd); // Already closes on error.
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -591,21 +591,21 @@ void SDL_SYS_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
if (haptic->hwdata) {
|
||||
|
||||
/* Free effects. */
|
||||
// Free effects.
|
||||
SDL_free(haptic->effects);
|
||||
haptic->effects = NULL;
|
||||
haptic->neffects = 0;
|
||||
|
||||
/* Clean up */
|
||||
// Clean up
|
||||
close(haptic->hwdata->fd);
|
||||
|
||||
/* Free */
|
||||
// Free
|
||||
SDL_free(haptic->hwdata->fname);
|
||||
SDL_free(haptic->hwdata);
|
||||
haptic->hwdata = NULL;
|
||||
}
|
||||
|
||||
/* Clear the rest. */
|
||||
// Clear the rest.
|
||||
SDL_memset(haptic, 0, sizeof(SDL_Haptic));
|
||||
}
|
||||
|
||||
@@ -628,7 +628,7 @@ void SDL_SYS_HapticQuit(void)
|
||||
#ifdef SDL_USE_LIBUDEV
|
||||
SDL_UDEV_DelCallback(haptic_udev_callback);
|
||||
SDL_UDEV_Quit();
|
||||
#endif /* SDL_USE_LIBUDEV */
|
||||
#endif // SDL_USE_LIBUDEV
|
||||
|
||||
numhaptics = 0;
|
||||
SDL_hapticlist = NULL;
|
||||
@@ -664,7 +664,7 @@ static int SDL_SYS_ToDirection(Uint16 *dest, const SDL_HapticDirection *src)
|
||||
|
||||
switch (src->type) {
|
||||
case SDL_HAPTIC_POLAR:
|
||||
tmp = ((src->dir[0] % 36000) * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
|
||||
tmp = ((src->dir[0] % 36000) * 0x8000) / 18000; // convert to range [0,0xFFFF]
|
||||
*dest = (Uint16)tmp;
|
||||
break;
|
||||
|
||||
@@ -677,8 +677,8 @@ static int SDL_SYS_ToDirection(Uint16 *dest, const SDL_HapticDirection *src)
|
||||
--> add 9000
|
||||
--> finally convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
|
||||
*/
|
||||
tmp = ((src->dir[0]) + 9000) % 36000; /* Convert to polars */
|
||||
tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
|
||||
tmp = ((src->dir[0]) + 9000) % 36000; // Convert to polars
|
||||
tmp = (tmp * 0x8000) / 18000; // convert to range [0,0xFFFF]
|
||||
*dest = (Uint16)tmp;
|
||||
break;
|
||||
|
||||
@@ -688,7 +688,7 @@ static int SDL_SYS_ToDirection(Uint16 *dest, const SDL_HapticDirection *src)
|
||||
} else if (!src->dir[0]) {
|
||||
*dest = (src->dir[1] >= 0 ? 0x8000 : 0);
|
||||
} else {
|
||||
float f = SDL_atan2f(src->dir[1], src->dir[0]); /* Ideally we'd use fixed point math instead of floats... */
|
||||
float f = SDL_atan2f(src->dir[1], src->dir[0]); // Ideally we'd use fixed point math instead of floats...
|
||||
/*
|
||||
SDL_atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
|
||||
- Y-axis-value is the second coordinate (from center to SOUTH)
|
||||
@@ -700,7 +700,7 @@ static int SDL_SYS_ToDirection(Uint16 *dest, const SDL_HapticDirection *src)
|
||||
--> finally convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
|
||||
*/
|
||||
tmp = (((Sint32)(f * 18000.0 / SDL_PI_D)) + 45000) % 36000;
|
||||
tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
|
||||
tmp = (tmp * 0x8000) / 18000; // convert to range [0,0xFFFF]
|
||||
*dest = (Uint16)tmp;
|
||||
}
|
||||
break;
|
||||
@@ -727,31 +727,31 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *sr
|
||||
const SDL_HapticRamp *ramp;
|
||||
const SDL_HapticLeftRight *leftright;
|
||||
|
||||
/* Clear up */
|
||||
// Clear up
|
||||
SDL_memset(dest, 0, sizeof(struct ff_effect));
|
||||
|
||||
switch (src->type) {
|
||||
case SDL_HAPTIC_CONSTANT:
|
||||
constant = &src->constant;
|
||||
|
||||
/* Header */
|
||||
// Header
|
||||
dest->type = FF_CONSTANT;
|
||||
if (SDL_SYS_ToDirection(&dest->direction, &constant->direction) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Replay */
|
||||
// Replay
|
||||
dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(constant->length);
|
||||
dest->replay.delay = CLAMP(constant->delay);
|
||||
|
||||
/* Trigger */
|
||||
// Trigger
|
||||
dest->trigger.button = SDL_SYS_ToButton(constant->button);
|
||||
dest->trigger.interval = CLAMP(constant->interval);
|
||||
|
||||
/* Constant */
|
||||
// Constant
|
||||
dest->u.constant.level = constant->level;
|
||||
|
||||
/* Envelope */
|
||||
// Envelope
|
||||
dest->u.constant.envelope.attack_length =
|
||||
CLAMP(constant->attack_length);
|
||||
dest->u.constant.envelope.attack_level =
|
||||
@@ -768,21 +768,21 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *sr
|
||||
case SDL_HAPTIC_SAWTOOTHDOWN:
|
||||
periodic = &src->periodic;
|
||||
|
||||
/* Header */
|
||||
// Header
|
||||
dest->type = FF_PERIODIC;
|
||||
if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Replay */
|
||||
// Replay
|
||||
dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(periodic->length);
|
||||
dest->replay.delay = CLAMP(periodic->delay);
|
||||
|
||||
/* Trigger */
|
||||
// Trigger
|
||||
dest->trigger.button = SDL_SYS_ToButton(periodic->button);
|
||||
dest->trigger.interval = CLAMP(periodic->interval);
|
||||
|
||||
/* Periodic */
|
||||
// Periodic
|
||||
if (periodic->type == SDL_HAPTIC_SINE) {
|
||||
dest->u.periodic.waveform = FF_SINE;
|
||||
} else if (periodic->type == SDL_HAPTIC_SQUARE) {
|
||||
@@ -797,10 +797,10 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *sr
|
||||
dest->u.periodic.period = CLAMP(periodic->period);
|
||||
dest->u.periodic.magnitude = periodic->magnitude;
|
||||
dest->u.periodic.offset = periodic->offset;
|
||||
/* Linux phase is defined in interval "[0x0000, 0x10000[", corresponds with "[0deg, 360deg[" phase shift. */
|
||||
// Linux phase is defined in interval "[0x0000, 0x10000[", corresponds with "[0deg, 360deg[" phase shift.
|
||||
dest->u.periodic.phase = ((Uint32)periodic->phase * 0x10000U) / 36000;
|
||||
|
||||
/* Envelope */
|
||||
// Envelope
|
||||
dest->u.periodic.envelope.attack_length =
|
||||
CLAMP(periodic->attack_length);
|
||||
dest->u.periodic.envelope.attack_level =
|
||||
@@ -816,7 +816,7 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *sr
|
||||
case SDL_HAPTIC_FRICTION:
|
||||
condition = &src->condition;
|
||||
|
||||
/* Header */
|
||||
// Header
|
||||
if (condition->type == SDL_HAPTIC_SPRING) {
|
||||
dest->type = FF_SPRING;
|
||||
} else if (condition->type == SDL_HAPTIC_DAMPER) {
|
||||
@@ -827,25 +827,25 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *sr
|
||||
dest->type = FF_FRICTION;
|
||||
}
|
||||
|
||||
dest->direction = 0; /* Handled by the condition-specifics. */
|
||||
dest->direction = 0; // Handled by the condition-specifics.
|
||||
|
||||
/* Replay */
|
||||
// Replay
|
||||
dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(condition->length);
|
||||
dest->replay.delay = CLAMP(condition->delay);
|
||||
|
||||
/* Trigger */
|
||||
// Trigger
|
||||
dest->trigger.button = SDL_SYS_ToButton(condition->button);
|
||||
dest->trigger.interval = CLAMP(condition->interval);
|
||||
|
||||
/* Condition */
|
||||
/* X axis */
|
||||
// Condition
|
||||
// X axis
|
||||
dest->u.condition[0].right_saturation = condition->right_sat[0];
|
||||
dest->u.condition[0].left_saturation = condition->left_sat[0];
|
||||
dest->u.condition[0].right_coeff = condition->right_coeff[0];
|
||||
dest->u.condition[0].left_coeff = condition->left_coeff[0];
|
||||
dest->u.condition[0].deadband = condition->deadband[0];
|
||||
dest->u.condition[0].center = condition->center[0];
|
||||
/* Y axis */
|
||||
// Y axis
|
||||
dest->u.condition[1].right_saturation = condition->right_sat[1];
|
||||
dest->u.condition[1].left_saturation = condition->left_sat[1];
|
||||
dest->u.condition[1].right_coeff = condition->right_coeff[1];
|
||||
@@ -862,25 +862,25 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *sr
|
||||
case SDL_HAPTIC_RAMP:
|
||||
ramp = &src->ramp;
|
||||
|
||||
/* Header */
|
||||
// Header
|
||||
dest->type = FF_RAMP;
|
||||
if (SDL_SYS_ToDirection(&dest->direction, &ramp->direction) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Replay */
|
||||
// Replay
|
||||
dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(ramp->length);
|
||||
dest->replay.delay = CLAMP(ramp->delay);
|
||||
|
||||
/* Trigger */
|
||||
// Trigger
|
||||
dest->trigger.button = SDL_SYS_ToButton(ramp->button);
|
||||
dest->trigger.interval = CLAMP(ramp->interval);
|
||||
|
||||
/* Ramp */
|
||||
// Ramp
|
||||
dest->u.ramp.start_level = ramp->start;
|
||||
dest->u.ramp.end_level = ramp->end;
|
||||
|
||||
/* Envelope */
|
||||
// Envelope
|
||||
dest->u.ramp.envelope.attack_length = CLAMP(ramp->attack_length);
|
||||
dest->u.ramp.envelope.attack_level = CLAMP(ramp->attack_level);
|
||||
dest->u.ramp.envelope.fade_length = CLAMP(ramp->fade_length);
|
||||
@@ -891,18 +891,18 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *sr
|
||||
case SDL_HAPTIC_LEFTRIGHT:
|
||||
leftright = &src->leftright;
|
||||
|
||||
/* Header */
|
||||
// Header
|
||||
dest->type = FF_RUMBLE;
|
||||
dest->direction = 0;
|
||||
|
||||
/* Replay */
|
||||
// Replay
|
||||
dest->replay.length = (leftright->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(leftright->length);
|
||||
|
||||
/* Trigger */
|
||||
// Trigger
|
||||
dest->trigger.button = 0;
|
||||
dest->trigger.interval = 0;
|
||||
|
||||
/* Rumble (Linux expects 0-65535, so multiply by 2) */
|
||||
// Rumble (Linux expects 0-65535, so multiply by 2)
|
||||
dest->u.rumble.strong_magnitude = CLAMP(leftright->large_magnitude) * 2;
|
||||
dest->u.rumble.weak_magnitude = CLAMP(leftright->small_magnitude) * 2;
|
||||
|
||||
@@ -923,21 +923,21 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
{
|
||||
struct ff_effect *linux_effect;
|
||||
|
||||
/* Allocate the hardware effect */
|
||||
// Allocate the hardware effect
|
||||
effect->hweffect = (struct haptic_hweffect *)
|
||||
SDL_calloc(1, sizeof(struct haptic_hweffect));
|
||||
if (!effect->hweffect) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Prepare the ff_effect */
|
||||
// Prepare the ff_effect
|
||||
linux_effect = &effect->hweffect->effect;
|
||||
if (SDL_SYS_ToFFEffect(linux_effect, base) != 0) {
|
||||
goto new_effect_err;
|
||||
}
|
||||
linux_effect->id = -1; /* Have the kernel give it an id */
|
||||
linux_effect->id = -1; // Have the kernel give it an id
|
||||
|
||||
/* Upload the effect */
|
||||
// Upload the effect
|
||||
if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) {
|
||||
SDL_SetError("Haptic: Error uploading effect to the device: %s",
|
||||
strerror(errno));
|
||||
@@ -964,19 +964,19 @@ int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
|
||||
{
|
||||
struct ff_effect linux_effect;
|
||||
|
||||
/* Create the new effect */
|
||||
// Create the new effect
|
||||
if (SDL_SYS_ToFFEffect(&linux_effect, data) != 0) {
|
||||
return -1;
|
||||
}
|
||||
linux_effect.id = effect->hweffect->effect.id;
|
||||
|
||||
/* See if it can be uploaded. */
|
||||
// See if it can be uploaded.
|
||||
if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) {
|
||||
return SDL_SetError("Haptic: Error updating the effect: %s",
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
/* Copy the new effect into memory. */
|
||||
// Copy the new effect into memory.
|
||||
SDL_memcpy(&effect->hweffect->effect, &linux_effect,
|
||||
sizeof(struct ff_effect));
|
||||
|
||||
@@ -991,10 +991,10 @@ int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
{
|
||||
struct input_event run;
|
||||
|
||||
/* Prepare to run the effect */
|
||||
// Prepare to run the effect
|
||||
run.type = EV_FF;
|
||||
run.code = effect->hweffect->effect.id;
|
||||
/* We don't actually have infinity here, so we just do INT_MAX which is pretty damn close. */
|
||||
// We don't actually have infinity here, so we just do INT_MAX which is pretty damn close.
|
||||
run.value = (iterations > INT_MAX) ? INT_MAX : iterations;
|
||||
|
||||
if (write(haptic->hwdata->fd, (const void *)&run, sizeof(run)) < 0) {
|
||||
@@ -1042,7 +1042,7 @@ void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effec
|
||||
int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic,
|
||||
struct haptic_effect *effect)
|
||||
{
|
||||
#if 0 /* Not supported atm. */
|
||||
#if 0 // Not supported atm.
|
||||
struct input_event ie;
|
||||
|
||||
ie.type = EV_FF;
|
||||
@@ -1118,7 +1118,7 @@ int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
|
||||
{
|
||||
int i, ret;
|
||||
|
||||
/* Linux does not support this natively so we have to loop. */
|
||||
// Linux does not support this natively so we have to loop.
|
||||
for (i = 0; i < haptic->neffects; i++) {
|
||||
if (haptic->effects[i].hweffect != NULL) {
|
||||
ret = SDL_SYS_HapticStopEffect(haptic, &haptic->effects[i]);
|
||||
@@ -1130,4 +1130,4 @@ int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_HAPTIC_LINUX */
|
||||
#endif // SDL_HAPTIC_LINUX
|
||||
|
||||
@@ -58,7 +58,7 @@ static BOOL CALLBACK EnumHapticsCallback(const DIDEVICEINSTANCE *pdidInstance, V
|
||||
{
|
||||
(void)pContext;
|
||||
SDL_DINPUT_HapticMaybeAddDevice(pdidInstance);
|
||||
return DIENUM_CONTINUE; /* continue enumerating */
|
||||
return DIENUM_CONTINUE; // continue enumerating
|
||||
}
|
||||
|
||||
int SDL_DINPUT_HapticInit(void)
|
||||
@@ -67,12 +67,12 @@ int SDL_DINPUT_HapticInit(void)
|
||||
HINSTANCE instance;
|
||||
DWORD devClass;
|
||||
|
||||
if (dinput != NULL) { /* Already open. */
|
||||
if (dinput != NULL) { // Already open.
|
||||
return SDL_SetError("Haptic: SubSystem already open.");
|
||||
}
|
||||
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_DIRECTINPUT, SDL_TRUE)) {
|
||||
/* In some environments, IDirectInput8_Initialize / _EnumDevices can take a minute even with no controllers. */
|
||||
// In some environments, IDirectInput8_Initialize / _EnumDevices can take a minute even with no controllers.
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ int SDL_DINPUT_HapticInit(void)
|
||||
return DI_SetError("CoCreateInstance", ret);
|
||||
}
|
||||
|
||||
/* Because we used CoCreateInstance, we need to Initialize it, first. */
|
||||
// Because we used CoCreateInstance, we need to Initialize it, first.
|
||||
instance = GetModuleHandle(NULL);
|
||||
if (!instance) {
|
||||
SDL_SYS_HapticQuit();
|
||||
@@ -103,10 +103,10 @@ int SDL_DINPUT_HapticInit(void)
|
||||
return DI_SetError("Initializing DirectInput device", ret);
|
||||
}
|
||||
|
||||
/* Look for haptic devices. */
|
||||
// Look for haptic devices.
|
||||
for (devClass = DI8DEVCLASS_DEVICE; devClass <= DI8DEVCLASS_GAMECTRL; devClass++) {
|
||||
if (devClass == DI8DEVCLASS_GAMECTRL && SDL_WasInit(SDL_INIT_JOYSTICK)) {
|
||||
/* The joystick subsystem will manage adding DInput joystick haptic devices */
|
||||
// The joystick subsystem will manage adding DInput joystick haptic devices
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -134,35 +134,35 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance)
|
||||
SDL_hapticlist_item *item = NULL;
|
||||
|
||||
if (!dinput) {
|
||||
return -1; /* not initialized. We'll pick these up on enumeration if we init later. */
|
||||
return -1; // not initialized. We'll pick these up on enumeration if we init later.
|
||||
}
|
||||
|
||||
/* Make sure we don't already have it */
|
||||
// Make sure we don't already have it
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
if (SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0) {
|
||||
return -1; /* Already added */
|
||||
return -1; // Already added
|
||||
}
|
||||
}
|
||||
|
||||
/* Open the device */
|
||||
// Open the device
|
||||
ret = IDirectInput8_CreateDevice(dinput, &pdidInstance->guidInstance, &device, NULL);
|
||||
if (FAILED(ret)) {
|
||||
/* DI_SetError("Creating DirectInput device",ret); */
|
||||
// DI_SetError("Creating DirectInput device",ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Get capabilities. */
|
||||
// Get capabilities.
|
||||
SDL_zero(capabilities);
|
||||
capabilities.dwSize = sizeof(DIDEVCAPS);
|
||||
ret = IDirectInputDevice8_GetCapabilities(device, &capabilities);
|
||||
IDirectInputDevice8_Release(device);
|
||||
if (FAILED(ret)) {
|
||||
/* DI_SetError("Getting device capabilities",ret); */
|
||||
// DI_SetError("Getting device capabilities",ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((capabilities.dwFlags & needflags) != needflags) {
|
||||
return -1; /* not a device we can use. */
|
||||
return -1; // not a device we can use.
|
||||
}
|
||||
|
||||
item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
|
||||
@@ -177,7 +177,7 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Copy the instance over, useful for creating devices. */
|
||||
// Copy the instance over, useful for creating devices.
|
||||
SDL_memcpy(&item->instance, pdidInstance, sizeof(DIDEVICEINSTANCE));
|
||||
SDL_memcpy(&item->capabilities, &capabilities, sizeof(capabilities));
|
||||
|
||||
@@ -190,12 +190,12 @@ int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance)
|
||||
SDL_hapticlist_item *prev = NULL;
|
||||
|
||||
if (!dinput) {
|
||||
return -1; /* not initialized, ignore this. */
|
||||
return -1; // not initialized, ignore this.
|
||||
}
|
||||
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
if (SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0) {
|
||||
/* found it, remove it. */
|
||||
// found it, remove it.
|
||||
return SDL_SYS_RemoveHapticDevice(prev, item);
|
||||
}
|
||||
prev = item;
|
||||
@@ -226,13 +226,13 @@ static BOOL CALLBACK DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVO
|
||||
} else if (WIN_IsEqualGUID(guid, &GUID_RzAxis)) {
|
||||
offset = DIJOFS_RZ;
|
||||
} else {
|
||||
return DIENUM_CONTINUE; /* can't use this, go on. */
|
||||
return DIENUM_CONTINUE; // can't use this, go on.
|
||||
}
|
||||
|
||||
haptic->hwdata->axes[haptic->naxes] = offset;
|
||||
haptic->naxes++;
|
||||
|
||||
/* Currently using the artificial limit of 3 axes. */
|
||||
// Currently using the artificial limit of 3 axes.
|
||||
if (haptic->naxes >= 3) {
|
||||
return DIENUM_STOP;
|
||||
}
|
||||
@@ -249,10 +249,10 @@ static BOOL CALLBACK DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVO
|
||||
haptic->supported |= (s)
|
||||
static BOOL CALLBACK DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv)
|
||||
{
|
||||
/* Prepare the haptic device. */
|
||||
// Prepare the haptic device.
|
||||
SDL_Haptic *haptic = (SDL_Haptic *)pv;
|
||||
|
||||
/* Get supported. */
|
||||
// Get supported.
|
||||
EFFECT_TEST(GUID_Spring, SDL_HAPTIC_SPRING);
|
||||
EFFECT_TEST(GUID_Damper, SDL_HAPTIC_DAMPER);
|
||||
EFFECT_TEST(GUID_Inertia, SDL_HAPTIC_INERTIA);
|
||||
@@ -266,7 +266,7 @@ static BOOL CALLBACK DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv)
|
||||
EFFECT_TEST(GUID_SawtoothDown, SDL_HAPTIC_SAWTOOTHDOWN);
|
||||
EFFECT_TEST(GUID_RampForce, SDL_HAPTIC_RAMP);
|
||||
|
||||
/* Check for more. */
|
||||
// Check for more.
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -285,13 +285,13 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
||||
HRESULT ret;
|
||||
DIPROPDWORD dipdw;
|
||||
|
||||
/* Allocate the hwdata */
|
||||
// Allocate the hwdata
|
||||
haptic->hwdata = (struct haptic_hwdata *)SDL_calloc(1, sizeof(*haptic->hwdata));
|
||||
if (!haptic->hwdata) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* We'll use the device8 from now on. */
|
||||
// We'll use the device8 from now on.
|
||||
haptic->hwdata->device = device8;
|
||||
haptic->hwdata->is_joystick = is_joystick;
|
||||
|
||||
@@ -302,8 +302,8 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
||||
!!! FIXME: to work, and that's probably the common case. Still,
|
||||
!!! FIXME: ideally, We need to unify the opening code. */
|
||||
|
||||
if (!is_joystick) { /* if is_joystick, we already set this up elsewhere. */
|
||||
/* Grab it exclusively to use force feedback stuff. */
|
||||
if (!is_joystick) { // if is_joystick, we already set this up elsewhere.
|
||||
// Grab it exclusively to use force feedback stuff.
|
||||
ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device,
|
||||
SDL_HelperWindow,
|
||||
DISCL_EXCLUSIVE |
|
||||
@@ -313,7 +313,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
||||
goto acquire_err;
|
||||
}
|
||||
|
||||
/* Set data format. */
|
||||
// Set data format.
|
||||
ret = IDirectInputDevice8_SetDataFormat(haptic->hwdata->device,
|
||||
&SDL_c_dfDIJoystick2);
|
||||
if (FAILED(ret)) {
|
||||
@@ -321,7 +321,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
||||
goto acquire_err;
|
||||
}
|
||||
|
||||
/* Acquire the device. */
|
||||
// Acquire the device.
|
||||
ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Acquiring DirectInput device", ret);
|
||||
@@ -329,7 +329,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
||||
}
|
||||
}
|
||||
|
||||
/* Get number of axes. */
|
||||
// Get number of axes.
|
||||
ret = IDirectInputDevice8_EnumObjects(haptic->hwdata->device,
|
||||
DI_DeviceObjectCallback,
|
||||
haptic, DIDFT_AXIS);
|
||||
@@ -338,7 +338,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
||||
goto acquire_err;
|
||||
}
|
||||
|
||||
/* Reset all actuators - just in case. */
|
||||
// Reset all actuators - just in case.
|
||||
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
|
||||
DISFFC_RESET);
|
||||
if (FAILED(ret)) {
|
||||
@@ -346,7 +346,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
||||
goto acquire_err;
|
||||
}
|
||||
|
||||
/* Enabling actuators. */
|
||||
// Enabling actuators.
|
||||
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
|
||||
DISFFC_SETACTUATORSON);
|
||||
if (FAILED(ret)) {
|
||||
@@ -354,7 +354,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
||||
goto acquire_err;
|
||||
}
|
||||
|
||||
/* Get supported effects. */
|
||||
// Get supported effects.
|
||||
ret = IDirectInputDevice8_EnumEffects(haptic->hwdata->device,
|
||||
DI_EffectCallback, haptic,
|
||||
DIEFT_ALL);
|
||||
@@ -362,12 +362,12 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
||||
DI_SetError("Enumerating supported effects", ret);
|
||||
goto acquire_err;
|
||||
}
|
||||
if (haptic->supported == 0) { /* Error since device supports nothing. */
|
||||
if (haptic->supported == 0) { // Error since device supports nothing.
|
||||
SDL_SetError("Haptic: Internal error on finding supported effects.");
|
||||
goto acquire_err;
|
||||
}
|
||||
|
||||
/* Check autogain and autocenter. */
|
||||
// Check autogain and autocenter.
|
||||
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
|
||||
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||
dipdw.diph.dwObj = 0;
|
||||
@@ -375,7 +375,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
||||
dipdw.dwData = 10000;
|
||||
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
|
||||
DIPROP_FFGAIN, &dipdw.diph);
|
||||
if (!FAILED(ret)) { /* Gain is supported. */
|
||||
if (!FAILED(ret)) { // Gain is supported.
|
||||
haptic->supported |= SDL_HAPTIC_GAIN;
|
||||
}
|
||||
dipdw.diph.dwObj = 0;
|
||||
@@ -383,33 +383,33 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI
|
||||
dipdw.dwData = DIPROPAUTOCENTER_OFF;
|
||||
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
|
||||
DIPROP_AUTOCENTER, &dipdw.diph);
|
||||
if (!FAILED(ret)) { /* Autocenter is supported. */
|
||||
if (!FAILED(ret)) { // Autocenter is supported.
|
||||
haptic->supported |= SDL_HAPTIC_AUTOCENTER;
|
||||
}
|
||||
|
||||
/* Status is always supported. */
|
||||
// Status is always supported.
|
||||
haptic->supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
|
||||
|
||||
/* Check maximum effects. */
|
||||
// Check maximum effects.
|
||||
haptic->neffects = 128; /* This is not actually supported as thus under windows,
|
||||
there is no way to tell the number of EFFECTS that a
|
||||
device can hold, so we'll just use a "random" number
|
||||
instead and put warnings in SDL_haptic.h */
|
||||
haptic->nplaying = 128; /* Even more impossible to get this then neffects. */
|
||||
haptic->nplaying = 128; // Even more impossible to get this then neffects.
|
||||
|
||||
/* Prepare effects memory. */
|
||||
// Prepare effects memory.
|
||||
haptic->effects = (struct haptic_effect *)
|
||||
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
|
||||
if (!haptic->effects) {
|
||||
goto acquire_err;
|
||||
}
|
||||
/* Clear the memory */
|
||||
// Clear the memory
|
||||
SDL_memset(haptic->effects, 0,
|
||||
sizeof(struct haptic_effect) * haptic->neffects);
|
||||
|
||||
return 0;
|
||||
|
||||
/* Error handling */
|
||||
// Error handling
|
||||
acquire_err:
|
||||
IDirectInputDevice8_Unacquire(haptic->hwdata->device);
|
||||
return -1;
|
||||
@@ -420,7 +420,7 @@ int SDL_DINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item)
|
||||
HRESULT ret;
|
||||
LPDIRECTINPUTDEVICE8 device;
|
||||
|
||||
/* Open the device */
|
||||
// Open the device
|
||||
ret = IDirectInput8_CreateDevice(dinput, &item->instance.guidInstance,
|
||||
&device, NULL);
|
||||
if (FAILED(ret)) {
|
||||
@@ -443,7 +443,7 @@ int SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
hap_instance.dwSize = sizeof(DIDEVICEINSTANCE);
|
||||
joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);
|
||||
|
||||
/* Get the device instances. */
|
||||
// Get the device instances.
|
||||
ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device,
|
||||
&hap_instance);
|
||||
if (FAILED(ret)) {
|
||||
@@ -470,7 +470,7 @@ int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
|
||||
// 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; item = item->next) {
|
||||
if (WIN_IsEqualGUID(&item->instance.guidInstance, &joy_instance.guidInstance)) {
|
||||
haptic->instance_id = item->instance_id;
|
||||
@@ -486,7 +486,7 @@ void SDL_DINPUT_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
IDirectInputDevice8_Unacquire(haptic->hwdata->device);
|
||||
|
||||
/* Only release if isn't grabbed by a joystick. */
|
||||
// Only release if isn't grabbed by a joystick.
|
||||
if (haptic->hwdata->is_joystick == 0) {
|
||||
IDirectInputDevice8_Release(haptic->hwdata->device);
|
||||
}
|
||||
@@ -528,14 +528,14 @@ static int SDL_SYS_SetDirection(DIEFFECT *effect, const SDL_HapticDirection *dir
|
||||
{
|
||||
LONG *rglDir;
|
||||
|
||||
/* Handle no axes a part. */
|
||||
// Handle no axes a part.
|
||||
if (naxes == 0) {
|
||||
effect->dwFlags |= DIEFF_SPHERICAL; /* Set as default. */
|
||||
effect->dwFlags |= DIEFF_SPHERICAL; // Set as default.
|
||||
effect->rglDirection = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Has axes. */
|
||||
// Has axes.
|
||||
rglDir = (LONG *)SDL_malloc(sizeof(LONG) * naxes);
|
||||
if (!rglDir) {
|
||||
return -1;
|
||||
@@ -578,9 +578,9 @@ static int SDL_SYS_SetDirection(DIEFFECT *effect, const SDL_HapticDirection *dir
|
||||
}
|
||||
}
|
||||
|
||||
/* Clamps and converts. */
|
||||
// Clamps and converts.
|
||||
#define CCONVERT(x) (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
|
||||
/* Just converts. */
|
||||
// Just converts.
|
||||
#define CONVERT(x) (((x)*10000) / 0x7FFF)
|
||||
/*
|
||||
* Creates the DIEFFECT from a SDL_HapticEffect.
|
||||
@@ -591,7 +591,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
int i;
|
||||
DICONSTANTFORCE *constant;
|
||||
DIPERIODIC *periodic;
|
||||
DICONDITION *condition; /* Actually an array of conditions - one per axis. */
|
||||
DICONDITION *condition; // Actually an array of conditions - one per axis.
|
||||
DIRAMPFORCE *ramp;
|
||||
DICUSTOMFORCE *custom;
|
||||
DIENVELOPE *envelope;
|
||||
@@ -602,22 +602,22 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
const SDL_HapticCustom *hap_custom;
|
||||
DWORD *axes;
|
||||
|
||||
/* Set global stuff. */
|
||||
// Set global stuff.
|
||||
SDL_memset(dest, 0, sizeof(DIEFFECT));
|
||||
dest->dwSize = sizeof(DIEFFECT); /* Set the structure size. */
|
||||
dest->dwSamplePeriod = 0; /* Not used by us. */
|
||||
dest->dwGain = 10000; /* Gain is set globally, not locally. */
|
||||
dest->dwFlags = DIEFF_OBJECTOFFSETS; /* Seems obligatory. */
|
||||
dest->dwSize = sizeof(DIEFFECT); // Set the structure size.
|
||||
dest->dwSamplePeriod = 0; // Not used by us.
|
||||
dest->dwGain = 10000; // Gain is set globally, not locally.
|
||||
dest->dwFlags = DIEFF_OBJECTOFFSETS; // Seems obligatory.
|
||||
|
||||
/* Envelope. */
|
||||
// Envelope.
|
||||
envelope = (DIENVELOPE *)SDL_calloc(1, sizeof(DIENVELOPE));
|
||||
if (!envelope) {
|
||||
return -1;
|
||||
}
|
||||
dest->lpEnvelope = envelope;
|
||||
envelope->dwSize = sizeof(DIENVELOPE); /* Always should be this. */
|
||||
envelope->dwSize = sizeof(DIENVELOPE); // Always should be this.
|
||||
|
||||
/* Axes. */
|
||||
// Axes.
|
||||
if (src->constant.direction.type == SDL_HAPTIC_STEERING_AXIS) {
|
||||
dest->cAxes = 1;
|
||||
} else {
|
||||
@@ -628,7 +628,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
if (!axes) {
|
||||
return -1;
|
||||
}
|
||||
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
|
||||
axes[0] = haptic->hwdata->axes[0]; // Always at least one axis.
|
||||
if (dest->cAxes > 1) {
|
||||
axes[1] = haptic->hwdata->axes[1];
|
||||
}
|
||||
@@ -638,7 +638,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
dest->rgdwAxes = axes;
|
||||
}
|
||||
|
||||
/* The big type handling switch, even bigger than Linux's version. */
|
||||
// The big type handling switch, even bigger than Linux's version.
|
||||
switch (src->type) {
|
||||
case SDL_HAPTIC_CONSTANT:
|
||||
hap_constant = &src->constant;
|
||||
@@ -647,23 +647,23 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Specifics */
|
||||
// Specifics
|
||||
constant->lMagnitude = CONVERT(hap_constant->level);
|
||||
dest->cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
|
||||
dest->lpvTypeSpecificParams = constant;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_constant->length * 1000UL; /* In microseconds. */
|
||||
// Generics
|
||||
dest->dwDuration = hap_constant->length * 1000UL; // In microseconds.
|
||||
dest->dwTriggerButton = DIGetTriggerButton(hap_constant->button);
|
||||
dest->dwTriggerRepeatInterval = hap_constant->interval;
|
||||
dest->dwStartDelay = hap_constant->delay * 1000UL; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_constant->delay * 1000UL; // In microseconds.
|
||||
|
||||
/* Direction. */
|
||||
// Direction.
|
||||
if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Envelope */
|
||||
// Envelope
|
||||
if ((hap_constant->attack_length == 0) && (hap_constant->fade_length == 0)) {
|
||||
SDL_free(dest->lpEnvelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
@@ -687,7 +687,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Specifics */
|
||||
// Specifics
|
||||
periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude));
|
||||
periodic->lOffset = CONVERT(hap_periodic->offset);
|
||||
periodic->dwPhase =
|
||||
@@ -696,18 +696,18 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
dest->cbTypeSpecificParams = sizeof(DIPERIODIC);
|
||||
dest->lpvTypeSpecificParams = periodic;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_periodic->length * 1000UL; /* In microseconds. */
|
||||
// Generics
|
||||
dest->dwDuration = hap_periodic->length * 1000UL; // In microseconds.
|
||||
dest->dwTriggerButton = DIGetTriggerButton(hap_periodic->button);
|
||||
dest->dwTriggerRepeatInterval = hap_periodic->interval;
|
||||
dest->dwStartDelay = hap_periodic->delay * 1000UL; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_periodic->delay * 1000UL; // In microseconds.
|
||||
|
||||
/* Direction. */
|
||||
// Direction.
|
||||
if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Envelope */
|
||||
// Envelope
|
||||
if ((hap_periodic->attack_length == 0) && (hap_periodic->fade_length == 0)) {
|
||||
SDL_free(dest->lpEnvelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
@@ -730,7 +730,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Specifics */
|
||||
// Specifics
|
||||
for (i = 0; i < (int)dest->cAxes; i++) {
|
||||
condition[i].lOffset = CONVERT(hap_condition->center[i]);
|
||||
condition[i].lPositiveCoefficient =
|
||||
@@ -746,18 +746,18 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
dest->cbTypeSpecificParams = sizeof(DICONDITION) * dest->cAxes;
|
||||
dest->lpvTypeSpecificParams = condition;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_condition->length * 1000UL; /* In microseconds. */
|
||||
// Generics
|
||||
dest->dwDuration = hap_condition->length * 1000UL; // In microseconds.
|
||||
dest->dwTriggerButton = DIGetTriggerButton(hap_condition->button);
|
||||
dest->dwTriggerRepeatInterval = hap_condition->interval;
|
||||
dest->dwStartDelay = hap_condition->delay * 1000UL; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_condition->delay * 1000UL; // In microseconds.
|
||||
|
||||
/* Direction. */
|
||||
// Direction.
|
||||
if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Envelope - Not actually supported by most CONDITION implementations. */
|
||||
// Envelope - Not actually supported by most CONDITION implementations.
|
||||
SDL_free(dest->lpEnvelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
|
||||
@@ -770,24 +770,24 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Specifics */
|
||||
// Specifics
|
||||
ramp->lStart = CONVERT(hap_ramp->start);
|
||||
ramp->lEnd = CONVERT(hap_ramp->end);
|
||||
dest->cbTypeSpecificParams = sizeof(DIRAMPFORCE);
|
||||
dest->lpvTypeSpecificParams = ramp;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_ramp->length * 1000UL; /* In microseconds. */
|
||||
// Generics
|
||||
dest->dwDuration = hap_ramp->length * 1000UL; // In microseconds.
|
||||
dest->dwTriggerButton = DIGetTriggerButton(hap_ramp->button);
|
||||
dest->dwTriggerRepeatInterval = hap_ramp->interval;
|
||||
dest->dwStartDelay = hap_ramp->delay * 1000UL; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_ramp->delay * 1000UL; // In microseconds.
|
||||
|
||||
/* Direction. */
|
||||
// Direction.
|
||||
if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Envelope */
|
||||
// Envelope
|
||||
if ((hap_ramp->attack_length == 0) && (hap_ramp->fade_length == 0)) {
|
||||
SDL_free(dest->lpEnvelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
@@ -807,29 +807,29 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Specifics */
|
||||
// Specifics
|
||||
custom->cChannels = hap_custom->channels;
|
||||
custom->dwSamplePeriod = hap_custom->period * 1000UL;
|
||||
custom->cSamples = hap_custom->samples;
|
||||
custom->rglForceData = (LPLONG)SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
|
||||
for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) { /* Copy data. */
|
||||
for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) { // Copy data.
|
||||
custom->rglForceData[i] = CCONVERT(hap_custom->data[i]);
|
||||
}
|
||||
dest->cbTypeSpecificParams = sizeof(DICUSTOMFORCE);
|
||||
dest->lpvTypeSpecificParams = custom;
|
||||
|
||||
/* Generics */
|
||||
dest->dwDuration = hap_custom->length * 1000UL; /* In microseconds. */
|
||||
// Generics
|
||||
dest->dwDuration = hap_custom->length * 1000UL; // In microseconds.
|
||||
dest->dwTriggerButton = DIGetTriggerButton(hap_custom->button);
|
||||
dest->dwTriggerRepeatInterval = hap_custom->interval;
|
||||
dest->dwStartDelay = hap_custom->delay * 1000UL; /* In microseconds. */
|
||||
dest->dwStartDelay = hap_custom->delay * 1000UL; // In microseconds.
|
||||
|
||||
/* Direction. */
|
||||
// Direction.
|
||||
if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Envelope */
|
||||
// Envelope
|
||||
if ((hap_custom->attack_length == 0) && (hap_custom->fade_length == 0)) {
|
||||
SDL_free(dest->lpEnvelope);
|
||||
dest->lpEnvelope = NULL;
|
||||
@@ -861,7 +861,7 @@ static void SDL_SYS_HapticFreeDIEFFECT(DIEFFECT *effect, int type)
|
||||
SDL_free(effect->rgdwAxes);
|
||||
effect->rgdwAxes = NULL;
|
||||
if (effect->lpvTypeSpecificParams) {
|
||||
if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
|
||||
if (type == SDL_HAPTIC_CUSTOM) { // Must free the custom data.
|
||||
custom = (DICUSTOMFORCE *)effect->lpvTypeSpecificParams;
|
||||
SDL_free(custom->rglForceData);
|
||||
custom->rglForceData = NULL;
|
||||
@@ -876,7 +876,7 @@ static void SDL_SYS_HapticFreeDIEFFECT(DIEFFECT *effect, int type)
|
||||
/*
|
||||
* Gets the effect type from the generic SDL haptic effect wrapper.
|
||||
*/
|
||||
/* NOLINTNEXTLINE(readability-const-return-type): Can't fix Windows' headers */
|
||||
// NOLINTNEXTLINE(readability-const-return-type): Can't fix Windows' headers
|
||||
static REFGUID SDL_SYS_HapticEffectType(const SDL_HapticEffect *effect)
|
||||
{
|
||||
switch (effect->type) {
|
||||
@@ -929,12 +929,12 @@ int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
return SDL_SetError("Haptic: Unknown effect type.");
|
||||
}
|
||||
|
||||
/* Get the effect. */
|
||||
// Get the effect.
|
||||
if (SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base) < 0) {
|
||||
goto err_effectdone;
|
||||
}
|
||||
|
||||
/* Create the actual effect. */
|
||||
// Create the actual effect.
|
||||
ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type,
|
||||
&effect->hweffect->effect,
|
||||
&effect->hweffect->ref, NULL);
|
||||
@@ -956,7 +956,7 @@ int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effe
|
||||
DWORD flags;
|
||||
DIEFFECT temp;
|
||||
|
||||
/* Get the effect. */
|
||||
// Get the effect.
|
||||
SDL_memset(&temp, 0, sizeof(DIEFFECT));
|
||||
if (SDL_SYS_ToDIEFFECT(haptic, &temp, data) < 0) {
|
||||
goto err_update;
|
||||
@@ -971,7 +971,7 @@ int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effe
|
||||
DIEP_TRIGGERBUTTON |
|
||||
DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS;
|
||||
|
||||
/* Create the actual effect. */
|
||||
// Create the actual effect.
|
||||
ret =
|
||||
IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags);
|
||||
if (ret == DIERR_NOTEXCLUSIVEACQUIRED) {
|
||||
@@ -992,7 +992,7 @@ int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effe
|
||||
goto err_update;
|
||||
}
|
||||
|
||||
/* Copy it over. */
|
||||
// Copy it over.
|
||||
SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, data->type);
|
||||
SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(DIEFFECT));
|
||||
|
||||
@@ -1008,14 +1008,14 @@ int SDL_DINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
HRESULT ret;
|
||||
DWORD iter;
|
||||
|
||||
/* Check if it's infinite. */
|
||||
// Check if it's infinite.
|
||||
if (iterations == SDL_HAPTIC_INFINITY) {
|
||||
iter = INFINITE;
|
||||
} else {
|
||||
iter = iterations;
|
||||
}
|
||||
|
||||
/* Run the effect. */
|
||||
// Run the effect.
|
||||
ret = IDirectInputEffect_Start(effect->hweffect->ref, iter, 0);
|
||||
if (FAILED(ret)) {
|
||||
return DI_SetError("Running the effect", ret);
|
||||
@@ -1066,14 +1066,14 @@ int SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain)
|
||||
HRESULT ret;
|
||||
DIPROPDWORD dipdw;
|
||||
|
||||
/* Create the weird structure thingy. */
|
||||
// Create the weird structure thingy.
|
||||
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
|
||||
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||
dipdw.diph.dwObj = 0;
|
||||
dipdw.diph.dwHow = DIPH_DEVICE;
|
||||
dipdw.dwData = (DWORD)gain * 100; /* 0 to 10,000 */
|
||||
dipdw.dwData = (DWORD)gain * 100; // 0 to 10,000
|
||||
|
||||
/* Try to set the autocenter. */
|
||||
// Try to set the autocenter.
|
||||
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
|
||||
DIPROP_FFGAIN, &dipdw.diph);
|
||||
if (FAILED(ret)) {
|
||||
@@ -1087,14 +1087,14 @@ int SDL_DINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter)
|
||||
HRESULT ret;
|
||||
DIPROPDWORD dipdw;
|
||||
|
||||
/* Create the weird structure thingy. */
|
||||
// Create the weird structure thingy.
|
||||
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
|
||||
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||
dipdw.diph.dwObj = 0;
|
||||
dipdw.diph.dwHow = DIPH_DEVICE;
|
||||
dipdw.dwData = (autocenter == 0) ? DIPROPAUTOCENTER_OFF : DIPROPAUTOCENTER_ON;
|
||||
|
||||
/* Try to set the autocenter. */
|
||||
// Try to set the autocenter.
|
||||
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
|
||||
DIPROP_AUTOCENTER, &dipdw.diph);
|
||||
if (FAILED(ret)) {
|
||||
@@ -1107,7 +1107,7 @@ int SDL_DINPUT_HapticPause(SDL_Haptic *haptic)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
/* Pause the device. */
|
||||
// Pause the device.
|
||||
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
|
||||
DISFFC_PAUSE);
|
||||
if (FAILED(ret)) {
|
||||
@@ -1120,7 +1120,7 @@ int SDL_DINPUT_HapticUnpause(SDL_Haptic *haptic)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
/* Unpause the device. */
|
||||
// Unpause the device.
|
||||
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
|
||||
DISFFC_CONTINUE);
|
||||
if (FAILED(ret)) {
|
||||
@@ -1133,7 +1133,7 @@ int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
/* Try to stop the effects. */
|
||||
// Try to stop the effects.
|
||||
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
|
||||
DISFFC_STOPALL);
|
||||
if (FAILED(ret)) {
|
||||
@@ -1142,7 +1142,7 @@ int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* !SDL_HAPTIC_DINPUT */
|
||||
#else // !SDL_HAPTIC_DINPUT
|
||||
|
||||
typedef struct DIDEVICEINSTANCE DIDEVICEINSTANCE;
|
||||
typedef struct SDL_hapticlist_item SDL_hapticlist_item;
|
||||
@@ -1239,4 +1239,4 @@ int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic)
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
#endif /* SDL_HAPTIC_DINPUT */
|
||||
#endif // SDL_HAPTIC_DINPUT
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "SDL_windowshaptic_c.h"
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
// Set up for C function definitions, even when using C++
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -47,7 +47,7 @@ extern int SDL_DINPUT_HapticPause(SDL_Haptic *haptic);
|
||||
extern int SDL_DINPUT_HapticUnpause(SDL_Haptic *haptic);
|
||||
extern int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
// Ends C function definitions when using C++
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
#ifdef SDL_HAPTIC_DINPUT
|
||||
|
||||
#include "../SDL_syshaptic.h"
|
||||
#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
|
||||
#include "../../joystick/windows/SDL_windowsjoystick_c.h" /* For joystick hwdata */
|
||||
#include "../../joystick/windows/SDL_xinputjoystick_c.h" /* For xinput rumble */
|
||||
#include "../../joystick/SDL_sysjoystick.h" // For the real SDL_Joystick
|
||||
#include "../../joystick/windows/SDL_windowsjoystick_c.h" // For joystick hwdata
|
||||
#include "../../joystick/windows/SDL_xinputjoystick_c.h" // For xinput rumble
|
||||
|
||||
#include "SDL_windowshaptic_c.h"
|
||||
#include "SDL_dinputhaptic_c.h"
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
// Set up for C function definitions, even when using C++
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -74,7 +74,7 @@ int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item)
|
||||
SDL_hapticlist_tail = item;
|
||||
}
|
||||
|
||||
/* Device has been added. */
|
||||
// Device has been added.
|
||||
++numhaptics;
|
||||
|
||||
return numhaptics;
|
||||
@@ -93,7 +93,7 @@ int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *i
|
||||
SDL_hapticlist_tail = prev;
|
||||
}
|
||||
--numhaptics;
|
||||
/* !!! TODO: Send a haptic remove event? */
|
||||
// !!! TODO: Send a haptic remove event?
|
||||
SDL_free(item);
|
||||
return retval;
|
||||
}
|
||||
@@ -166,14 +166,14 @@ int SDL_SYS_HapticMouse(void)
|
||||
SDL_hapticlist_item *item;
|
||||
int index = 0;
|
||||
|
||||
/* Grab the first mouse haptic device we find. */
|
||||
// Grab the first mouse haptic device we find.
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
if (item->capabilities.dwDevType == DI8DEVCLASS_POINTER) {
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
#endif /* SDL_HAPTIC_DINPUT */
|
||||
#endif // SDL_HAPTIC_DINPUT
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -219,15 +219,15 @@ void SDL_SYS_HapticClose(SDL_Haptic *haptic)
|
||||
{
|
||||
if (haptic->hwdata) {
|
||||
|
||||
/* Free effects. */
|
||||
// Free effects.
|
||||
SDL_free(haptic->effects);
|
||||
haptic->effects = NULL;
|
||||
haptic->neffects = 0;
|
||||
|
||||
/* Clean up */
|
||||
// Clean up
|
||||
SDL_DINPUT_HapticClose(haptic);
|
||||
|
||||
/* Free */
|
||||
// Free
|
||||
SDL_free(haptic->hwdata);
|
||||
haptic->hwdata = NULL;
|
||||
}
|
||||
@@ -244,7 +244,7 @@ void SDL_SYS_HapticQuit(void)
|
||||
for (item = SDL_hapticlist; item; item = next) {
|
||||
/* Opened and not closed haptics are leaked, this is on purpose.
|
||||
* Close your haptic devices after usage. */
|
||||
/* !!! FIXME: (...is leaking on purpose a good idea?) - No, of course not. */
|
||||
// !!! FIXME: (...is leaking on purpose a good idea?) - No, of course not.
|
||||
next = item->next;
|
||||
SDL_free(item->name);
|
||||
SDL_free(item);
|
||||
@@ -265,7 +265,7 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
{
|
||||
int result;
|
||||
|
||||
/* Alloc the effect. */
|
||||
// Alloc the effect.
|
||||
effect->hweffect = (struct haptic_hweffect *) SDL_calloc(1, sizeof(struct haptic_hweffect));
|
||||
if (!effect->hweffect) {
|
||||
return -1;
|
||||
@@ -361,9 +361,9 @@ int SDL_SYS_HapticStopAll(SDL_Haptic *haptic)
|
||||
return SDL_DINPUT_HapticStopAll(haptic);
|
||||
}
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
// Ends C function definitions when using C++
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_HAPTIC_DINPUT */
|
||||
#endif // SDL_HAPTIC_DINPUT
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "../../core/windows/SDL_directx.h"
|
||||
#include "../../core/windows/SDL_xinput.h"
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
// Set up for C function definitions, even when using C++
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -40,8 +40,8 @@ struct haptic_hwdata
|
||||
#ifdef SDL_HAPTIC_DINPUT
|
||||
LPDIRECTINPUTDEVICE8 device;
|
||||
#endif
|
||||
DWORD axes[3]; /* Axes to use. */
|
||||
SDL_bool is_joystick; /* Device is loaded as joystick. */
|
||||
DWORD axes[3]; // Axes to use.
|
||||
SDL_bool is_joystick; // Device is loaded as joystick.
|
||||
SDL_Thread *thread;
|
||||
SDL_Mutex *mutex;
|
||||
Uint64 stopTicks;
|
||||
@@ -79,9 +79,9 @@ extern SDL_hapticlist_item *SDL_hapticlist;
|
||||
extern int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item);
|
||||
extern int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
// Ends C function definitions when using C++
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_windowshaptic_c_h_ */
|
||||
#endif // SDL_windowshaptic_c_h_
|
||||
|
||||
Reference in New Issue
Block a user