Make SDL_SetError and friends unconditionally return -1.
This lets us change things like this... if (Failed) { SDL_SetError("We failed"); return -1; } ...into this... if (Failed) { return SDL_SetError("We failed"); } Fixes Bugzilla #1778.
This commit is contained in:
parent
8c6b9f4743
commit
4f438b70a2
106 changed files with 616 additions and 1189 deletions
|
@ -447,8 +447,7 @@ SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
|
|||
|
||||
/* Check to see if effect is supported */
|
||||
if (SDL_HapticEffectSupported(haptic, effect) == SDL_FALSE) {
|
||||
SDL_SetError("Haptic: Effect not supported by haptic device.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Effect not supported by haptic device.");
|
||||
}
|
||||
|
||||
/* See if there's a free slot */
|
||||
|
@ -467,8 +466,7 @@ SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
|
|||
}
|
||||
}
|
||||
|
||||
SDL_SetError("Haptic: Device has no free space left.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Device has no free space left.");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -497,8 +495,7 @@ SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect,
|
|||
|
||||
/* Can't change type dynamically. */
|
||||
if (data->type != haptic->effects[effect].effect.type) {
|
||||
SDL_SetError("Haptic: Updating effect type is illegal.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Updating effect type is illegal.");
|
||||
}
|
||||
|
||||
/* Updates the effect */
|
||||
|
@ -579,8 +576,7 @@ SDL_HapticGetEffectStatus(SDL_Haptic * haptic, int effect)
|
|||
}
|
||||
|
||||
if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) {
|
||||
SDL_SetError("Haptic: Device does not support status queries.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Device does not support status queries.");
|
||||
}
|
||||
|
||||
return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]);
|
||||
|
@ -600,13 +596,11 @@ SDL_HapticSetGain(SDL_Haptic * haptic, int gain)
|
|||
}
|
||||
|
||||
if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) {
|
||||
SDL_SetError("Haptic: Device does not support setting gain.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Device does not support setting gain.");
|
||||
}
|
||||
|
||||
if ((gain < 0) || (gain > 100)) {
|
||||
SDL_SetError("Haptic: Gain must be between 0 and 100.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Gain must be between 0 and 100.");
|
||||
}
|
||||
|
||||
/* We use the envvar to get the maximum gain. */
|
||||
|
@ -644,13 +638,11 @@ SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
|||
}
|
||||
|
||||
if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) {
|
||||
SDL_SetError("Haptic: Device does not support setting autocenter.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Device does not support setting autocenter.");
|
||||
}
|
||||
|
||||
if ((autocenter < 0) || (autocenter > 100)) {
|
||||
SDL_SetError("Haptic: Autocenter must be between 0 and 100.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Autocenter must be between 0 and 100.");
|
||||
}
|
||||
|
||||
if (SDL_SYS_HapticSetAutocenter(haptic, autocenter) < 0) {
|
||||
|
@ -671,8 +663,7 @@ SDL_HapticPause(SDL_Haptic * haptic)
|
|||
}
|
||||
|
||||
if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) {
|
||||
SDL_SetError("Haptic: Device does not support setting pausing.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Device does not support setting pausing.");
|
||||
}
|
||||
|
||||
return SDL_SYS_HapticPause(haptic);
|
||||
|
@ -773,8 +764,7 @@ SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length)
|
|||
}
|
||||
|
||||
if (haptic->rumble_id < 0) {
|
||||
SDL_SetError("Haptic: Rumble effect not initialized on haptic device");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Rumble effect not initialized on haptic device");
|
||||
}
|
||||
|
||||
/* Clamp strength. */
|
||||
|
@ -805,8 +795,7 @@ SDL_HapticRumbleStop(SDL_Haptic * haptic)
|
|||
}
|
||||
|
||||
if (haptic->rumble_id < 0) {
|
||||
SDL_SetError("Haptic: Rumble effect not initialized on haptic device");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Rumble effect not initialized on haptic device");
|
||||
}
|
||||
|
||||
return SDL_HapticStopEffect(haptic, haptic->rumble_id);
|
||||
|
|
|
@ -160,15 +160,13 @@ SDL_SYS_HapticInit(void)
|
|||
/* Get HID devices. */
|
||||
match = IOServiceMatching(kIOHIDDeviceKey);
|
||||
if (match == NULL) {
|
||||
SDL_SetError("Haptic: Failed to get IOServiceMatching.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Failed to get IOServiceMatching.");
|
||||
}
|
||||
|
||||
/* Now search I/O Registry for matching devices. */
|
||||
result = IOServiceGetMatchingServices(kIOMasterPortDefault, match, &iter);
|
||||
if (result != kIOReturnSuccess) {
|
||||
SDL_SetError("Haptic: Couldn't create a HID object iterator.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Couldn't create a HID object iterator.");
|
||||
}
|
||||
/* IOServiceGetMatchingServices consumes dictionary. */
|
||||
|
||||
|
@ -257,8 +255,7 @@ HIDGetDeviceProduct(io_service_t dev, char *name)
|
|||
ret = IORegistryEntryCreateCFProperties(dev, &hidProperties,
|
||||
kCFAllocatorDefault, kNilOptions);
|
||||
if ((ret != KERN_SUCCESS) || !hidProperties) {
|
||||
SDL_SetError("Haptic: Unable to create CFProperties.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unable to create CFProperties.");
|
||||
}
|
||||
|
||||
/* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also
|
||||
|
@ -289,17 +286,15 @@ HIDGetDeviceProduct(io_service_t dev, char *name)
|
|||
if (refCF) {
|
||||
if (!CFStringGetCString(refCF, name, 256,
|
||||
CFStringGetSystemEncoding())) {
|
||||
SDL_SetError
|
||||
return SDL_SetError
|
||||
("Haptic: CFStringGetCString error retrieving pDevice->product.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(usbProperties);
|
||||
} else {
|
||||
SDL_SetError
|
||||
return SDL_SetError
|
||||
("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Release stuff. */
|
||||
|
@ -310,8 +305,7 @@ HIDGetDeviceProduct(io_service_t dev, char *name)
|
|||
SDL_SetError("Haptic: IOObjectRelease error with parent1.");
|
||||
}
|
||||
} else {
|
||||
SDL_SetError("Haptic: Error getting registry entries.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Error getting registry entries.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -336,8 +330,7 @@ GetSupportedFeatures(SDL_Haptic * haptic)
|
|||
|
||||
ret = FFDeviceGetForceFeedbackCapabilities(device, &features);
|
||||
if (ret != FF_OK) {
|
||||
SDL_SetError("Haptic: Unable to get device's supported features.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unable to get device's supported features.");
|
||||
}
|
||||
|
||||
supported = 0;
|
||||
|
@ -366,9 +359,8 @@ GetSupportedFeatures(SDL_Haptic * haptic)
|
|||
if (ret == FF_OK)
|
||||
supported |= SDL_HAPTIC_GAIN;
|
||||
else if (ret != FFERR_UNSUPPORTED) {
|
||||
SDL_SetError("Haptic: Unable to get if device supports gain: %s.",
|
||||
FFStrError(ret));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unable to get if device supports gain: %s.",
|
||||
FFStrError(ret));
|
||||
}
|
||||
|
||||
/* Checks if supports autocenter. */
|
||||
|
@ -377,10 +369,9 @@ GetSupportedFeatures(SDL_Haptic * haptic)
|
|||
if (ret == FF_OK)
|
||||
supported |= SDL_HAPTIC_AUTOCENTER;
|
||||
else if (ret != FFERR_UNSUPPORTED) {
|
||||
SDL_SetError
|
||||
return SDL_SetError
|
||||
("Haptic: Unable to get if device supports autocenter: %s.",
|
||||
FFStrError(ret));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check for axes, we have an artificial limit on axes */
|
||||
|
@ -625,8 +616,7 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes)
|
|||
/* Has axes. */
|
||||
rglDir = SDL_malloc(sizeof(LONG) * naxes);
|
||||
if (rglDir == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
|
||||
effect->rglDirection = rglDir;
|
||||
|
@ -654,8 +644,7 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes)
|
|||
return 0;
|
||||
|
||||
default:
|
||||
SDL_SetError("Haptic: Unknown direction type.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unknown direction type.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -695,8 +684,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
|
|||
/* Envelope. */
|
||||
envelope = SDL_malloc(sizeof(FFENVELOPE));
|
||||
if (envelope == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(envelope, 0, sizeof(FFENVELOPE));
|
||||
dest->lpEnvelope = envelope;
|
||||
|
@ -707,8 +695,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
|
|||
if (dest->cAxes > 0) {
|
||||
axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
|
||||
if (axes == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
|
||||
if (dest->cAxes > 1) {
|
||||
|
@ -727,8 +714,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
|
|||
hap_constant = &src->constant;
|
||||
constant = SDL_malloc(sizeof(FFCONSTANTFORCE));
|
||||
if (constant == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(constant, 0, sizeof(FFCONSTANTFORCE));
|
||||
|
||||
|
@ -771,8 +757,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
|
|||
hap_periodic = &src->periodic;
|
||||
periodic = SDL_malloc(sizeof(FFPERIODIC));
|
||||
if (periodic == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(periodic, 0, sizeof(FFPERIODIC));
|
||||
|
||||
|
@ -817,8 +802,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
|
|||
hap_condition = &src->condition;
|
||||
condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
|
||||
if (condition == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(condition, 0, sizeof(FFCONDITION));
|
||||
|
||||
|
@ -860,8 +844,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
|
|||
hap_ramp = &src->ramp;
|
||||
ramp = SDL_malloc(sizeof(FFRAMPFORCE));
|
||||
if (ramp == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(ramp, 0, sizeof(FFRAMPFORCE));
|
||||
|
||||
|
@ -899,8 +882,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
|
|||
hap_custom = &src->custom;
|
||||
custom = SDL_malloc(sizeof(FFCUSTOMFORCE));
|
||||
if (custom == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE));
|
||||
|
||||
|
@ -944,8 +926,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
|
|||
|
||||
|
||||
default:
|
||||
SDL_SetError("Haptic: Unknown effect type.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unknown effect type.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1150,9 +1131,8 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
/* Run the effect. */
|
||||
ret = FFEffectStart(effect->hweffect->ref, iter, 0);
|
||||
if (ret != FF_OK) {
|
||||
SDL_SetError("Haptic: Unable to run the effect: %s.",
|
||||
FFStrError(ret));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unable to run the effect: %s.",
|
||||
FFStrError(ret));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1169,9 +1149,8 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
|||
|
||||
ret = FFEffectStop(effect->hweffect->ref);
|
||||
if (ret != FF_OK) {
|
||||
SDL_SetError("Haptic: Unable to stop the effect: %s.",
|
||||
FFStrError(ret));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unable to stop the effect: %s.",
|
||||
FFStrError(ret));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1236,8 +1215,7 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
|
|||
FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
|
||||
FFPROP_FFGAIN, &val);
|
||||
if (ret != FF_OK) {
|
||||
SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1262,9 +1240,8 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
|||
ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
|
||||
FFPROP_AUTOCENTER, &val);
|
||||
if (ret != FF_OK) {
|
||||
SDL_SetError("Haptic: Error setting autocenter: %s.",
|
||||
FFStrError(ret));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Error setting autocenter: %s.",
|
||||
FFStrError(ret));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1282,8 +1259,7 @@ SDL_SYS_HapticPause(SDL_Haptic * haptic)
|
|||
ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
|
||||
FFSFFC_PAUSE);
|
||||
if (ret != FF_OK) {
|
||||
SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1301,8 +1277,7 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
|
|||
ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
|
||||
FFSFFC_CONTINUE);
|
||||
if (ret != FF_OK) {
|
||||
SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1320,8 +1295,7 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
|
|||
ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
|
||||
FFSFFC_STOPALL);
|
||||
if (ret != FF_OK) {
|
||||
SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -92,9 +92,8 @@ EV_IsHaptic(int fd)
|
|||
/* Ask device for what it has. */
|
||||
ret = 0;
|
||||
if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(features)), features) < 0) {
|
||||
SDL_SetError("Haptic: Unable to get device's features: %s",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unable to get device's features: %s",
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
/* Convert supported features to SDL_HAPTIC platform-neutral features. */
|
||||
|
@ -309,9 +308,8 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic)
|
|||
/* Open the character device */
|
||||
fd = open(SDL_hapticlist[haptic->index].fname, O_RDWR, 0);
|
||||
if (fd < 0) {
|
||||
SDL_SetError("Haptic: Unable to open %s: %s",
|
||||
SDL_hapticlist[haptic->index], strerror(errno));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unable to open %s: %s",
|
||||
SDL_hapticlist[haptic->index], strerror(errno));
|
||||
}
|
||||
|
||||
/* Try to create the haptic. */
|
||||
|
@ -340,9 +338,8 @@ SDL_SYS_HapticMouse(void)
|
|||
/* Open the device. */
|
||||
fd = open(SDL_hapticlist[i].fname, O_RDWR, 0);
|
||||
if (fd < 0) {
|
||||
SDL_SetError("Haptic: Unable to open %s: %s",
|
||||
SDL_hapticlist[i], strerror(errno));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unable to open %s: %s",
|
||||
SDL_hapticlist[i], strerror(errno));
|
||||
}
|
||||
|
||||
/* Is it a mouse? */
|
||||
|
@ -405,15 +402,13 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||
}
|
||||
}
|
||||
if (i >= MAX_HAPTICS) {
|
||||
SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities");
|
||||
}
|
||||
|
||||
fd = open(joystick->hwdata->fname, O_RDWR, 0);
|
||||
if (fd < 0) {
|
||||
SDL_SetError("Haptic: Unable to open %s: %s",
|
||||
joystick->hwdata->fname, strerror(errno));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unable to open %s: %s",
|
||||
joystick->hwdata->fname, strerror(errno));
|
||||
}
|
||||
ret = SDL_SYS_HapticOpenFromFD(haptic, fd); /* Already closes on error. */
|
||||
if (ret < 0) {
|
||||
|
@ -544,8 +539,7 @@ SDL_SYS_ToDirection(SDL_HapticDirection * dir)
|
|||
return (Uint16) tmp;
|
||||
|
||||
default:
|
||||
SDL_SetError("Haptic: Unsupported direction type.");
|
||||
return (Uint16) - 1;
|
||||
return (Uint16) SDL_SetError("Haptic: Unsupported direction type.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -733,8 +727,7 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
|
|||
|
||||
|
||||
default:
|
||||
SDL_SetError("Haptic: Unknown effect type.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unknown effect type.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -754,8 +747,7 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
effect->hweffect = (struct haptic_hweffect *)
|
||||
SDL_malloc(sizeof(struct haptic_hweffect));
|
||||
if (effect->hweffect == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
/* Prepare the ff_effect */
|
||||
|
@ -802,9 +794,8 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
|
|||
|
||||
/* See if it can be uploaded. */
|
||||
if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) {
|
||||
SDL_SetError("Haptic: Error updating the effect: %s",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Error updating the effect: %s",
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
/* Copy the new effect into memory. */
|
||||
|
@ -831,8 +822,7 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
run.value = (iterations > INT_MAX) ? INT_MAX : iterations;
|
||||
|
||||
if (write(haptic->hwdata->fd, (const void *) &run, sizeof(run)) < 0) {
|
||||
SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -852,9 +842,8 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
|||
stop.value = 0;
|
||||
|
||||
if (write(haptic->hwdata->fd, (const void *) &stop, sizeof(stop)) < 0) {
|
||||
SDL_SetError("Haptic: Unable to stop the effect: %s",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unable to stop the effect: %s",
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -891,8 +880,7 @@ SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
|
|||
ie.code = effect->hweffect->effect.id;
|
||||
|
||||
if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
|
||||
SDL_SetError("Haptic: Error getting device status.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Error getting device status.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -915,8 +903,7 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
|
|||
ie.value = (0xFFFFUL * gain) / 100;
|
||||
|
||||
if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
|
||||
SDL_SetError("Haptic: Error setting gain: %s", strerror(errno));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Error setting gain: %s", strerror(errno));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -936,8 +923,7 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
|||
ie.value = (0xFFFFUL * autocenter) / 100;
|
||||
|
||||
if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
|
||||
SDL_SetError("Haptic: Error setting autocenter: %s", strerror(errno));
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Error setting autocenter: %s", strerror(errno));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -977,9 +963,8 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
|
|||
if (haptic->effects[i].hweffect != NULL) {
|
||||
ret = SDL_SYS_HapticStopEffect(haptic, &haptic->effects[i]);
|
||||
if (ret < 0) {
|
||||
SDL_SetError
|
||||
return SDL_SetError
|
||||
("Haptic: Error while trying to stop all playing effects.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ extern HWND SDL_HelperWindow;
|
|||
/*
|
||||
* Prototypes.
|
||||
*/
|
||||
static void DI_SetError(const char *str, HRESULT err);
|
||||
static int DI_SetError(const char *str, HRESULT err);
|
||||
static int DI_GUIDIsSame(const GUID * a, const GUID * b);
|
||||
static int SDL_SYS_HapticOpenFromInstance(SDL_Haptic * haptic,
|
||||
DIDEVICEINSTANCE instance);
|
||||
|
@ -110,14 +110,14 @@ static BOOL CALLBACK DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv);
|
|||
/*
|
||||
* Like SDL_SetError but for DX error codes.
|
||||
*/
|
||||
static void
|
||||
static int
|
||||
DI_SetError(const char *str, HRESULT err)
|
||||
{
|
||||
/*
|
||||
SDL_SetError("Haptic: %s - %s: %s", str,
|
||||
DXGetErrorString8A(err), DXGetErrorDescription8A(err));
|
||||
*/
|
||||
SDL_SetError("Haptic error %s", str);
|
||||
return SDL_SetError("Haptic error %s", str);
|
||||
}
|
||||
|
||||
|
||||
|
@ -142,8 +142,7 @@ SDL_SYS_HapticInit(void)
|
|||
HINSTANCE instance;
|
||||
|
||||
if (dinput != NULL) { /* Already open. */
|
||||
SDL_SetError("Haptic: SubSystem already open.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: SubSystem already open.");
|
||||
}
|
||||
|
||||
/* Clear all the memory. */
|
||||
|
@ -153,8 +152,7 @@ SDL_SYS_HapticInit(void)
|
|||
|
||||
ret = WIN_CoInitialize();
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Coinitialize", ret);
|
||||
return -1;
|
||||
return DI_SetError("Coinitialize", ret);
|
||||
}
|
||||
|
||||
coinitialized = SDL_TRUE;
|
||||
|
@ -163,23 +161,20 @@ SDL_SYS_HapticInit(void)
|
|||
&IID_IDirectInput8, (LPVOID) & dinput);
|
||||
if (FAILED(ret)) {
|
||||
SDL_SYS_HapticQuit();
|
||||
DI_SetError("CoCreateInstance", ret);
|
||||
return -1;
|
||||
return DI_SetError("CoCreateInstance", ret);
|
||||
}
|
||||
|
||||
/* Because we used CoCreateInstance, we need to Initialize it, first. */
|
||||
instance = GetModuleHandle(NULL);
|
||||
if (instance == NULL) {
|
||||
SDL_SYS_HapticQuit();
|
||||
SDL_SetError("GetModuleHandle() failed with error code %d.",
|
||||
GetLastError());
|
||||
return -1;
|
||||
return SDL_SetError("GetModuleHandle() failed with error code %d.",
|
||||
GetLastError());
|
||||
}
|
||||
ret = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION);
|
||||
if (FAILED(ret)) {
|
||||
SDL_SYS_HapticQuit();
|
||||
DI_SetError("Initializing DirectInput device", ret);
|
||||
return -1;
|
||||
return DI_SetError("Initializing DirectInput device", ret);
|
||||
}
|
||||
|
||||
/* Look for haptic devices. */
|
||||
|
@ -191,8 +186,7 @@ SDL_SYS_HapticInit(void)
|
|||
DIEDFL_ATTACHEDONLY);
|
||||
if (FAILED(ret)) {
|
||||
SDL_SYS_HapticQuit();
|
||||
DI_SetError("Enumerating DirectInput devices", ret);
|
||||
return -1;
|
||||
return DI_SetError("Enumerating DirectInput devices", ret);
|
||||
}
|
||||
|
||||
if (!env || SDL_atoi(env)) {
|
||||
|
@ -411,8 +405,7 @@ SDL_SYS_HapticOpenFromXInput(SDL_Haptic * haptic, Uint8 userid)
|
|||
haptic->effects = (struct haptic_effect *)
|
||||
SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
|
||||
if (haptic->effects == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
/* Clear the memory */
|
||||
SDL_memset(haptic->effects, 0,
|
||||
|
@ -422,8 +415,7 @@ SDL_SYS_HapticOpenFromXInput(SDL_Haptic * haptic, Uint8 userid)
|
|||
if (haptic->hwdata == NULL) {
|
||||
SDL_free(haptic->effects);
|
||||
haptic->effects = NULL;
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
|
||||
|
||||
|
@ -690,8 +682,7 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||
haptic->hwdata = (struct haptic_hwdata *)
|
||||
SDL_malloc(sizeof(*haptic->hwdata));
|
||||
if (haptic->hwdata == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
|
||||
|
||||
|
@ -809,8 +800,7 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes)
|
|||
/* Has axes. */
|
||||
rglDir = SDL_malloc(sizeof(LONG) * naxes);
|
||||
if (rglDir == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
|
||||
effect->rglDirection = rglDir;
|
||||
|
@ -838,8 +828,7 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes)
|
|||
return 0;
|
||||
|
||||
default:
|
||||
SDL_SetError("Haptic: Unknown direction type.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unknown direction type.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -875,8 +864,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
/* Envelope. */
|
||||
envelope = SDL_malloc(sizeof(DIENVELOPE));
|
||||
if (envelope == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(envelope, 0, sizeof(DIENVELOPE));
|
||||
dest->lpEnvelope = envelope;
|
||||
|
@ -887,8 +875,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
if (dest->cAxes > 0) {
|
||||
axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
|
||||
if (axes == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
|
||||
if (dest->cAxes > 1) {
|
||||
|
@ -907,8 +894,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
hap_constant = &src->constant;
|
||||
constant = SDL_malloc(sizeof(DICONSTANTFORCE));
|
||||
if (constant == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(constant, 0, sizeof(DICONSTANTFORCE));
|
||||
|
||||
|
@ -951,8 +937,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
hap_periodic = &src->periodic;
|
||||
periodic = SDL_malloc(sizeof(DIPERIODIC));
|
||||
if (periodic == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(periodic, 0, sizeof(DIPERIODIC));
|
||||
|
||||
|
@ -997,8 +982,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
hap_condition = &src->condition;
|
||||
condition = SDL_malloc(sizeof(DICONDITION) * dest->cAxes);
|
||||
if (condition == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(condition, 0, sizeof(DICONDITION));
|
||||
|
||||
|
@ -1040,8 +1024,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
hap_ramp = &src->ramp;
|
||||
ramp = SDL_malloc(sizeof(DIRAMPFORCE));
|
||||
if (ramp == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(ramp, 0, sizeof(DIRAMPFORCE));
|
||||
|
||||
|
@ -1079,8 +1062,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
hap_custom = &src->custom;
|
||||
custom = SDL_malloc(sizeof(DICUSTOMFORCE));
|
||||
if (custom == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(custom, 0, sizeof(DICUSTOMFORCE));
|
||||
|
||||
|
@ -1124,8 +1106,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
|||
|
||||
|
||||
default:
|
||||
SDL_SetError("Haptic: Unknown effect type.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unknown effect type.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1358,8 +1339,7 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
/* Run the effect. */
|
||||
ret = IDirectInputEffect_Start(effect->hweffect->ref, iter, 0);
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Running the effect", ret);
|
||||
return -1;
|
||||
return DI_SetError("Running the effect", ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1381,8 +1361,7 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
|
|||
|
||||
ret = IDirectInputEffect_Stop(effect->hweffect->ref);
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Unable to stop effect", ret);
|
||||
return -1;
|
||||
return DI_SetError("Unable to stop effect", ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1424,8 +1403,7 @@ SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
|
|||
|
||||
ret = IDirectInputEffect_GetEffectStatus(effect->hweffect->ref, &status);
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Getting effect status", ret);
|
||||
return -1;
|
||||
return DI_SetError("Getting effect status", ret);
|
||||
}
|
||||
|
||||
if (status == 0)
|
||||
|
@ -1454,8 +1432,7 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
|
|||
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
|
||||
DIPROP_FFGAIN, &dipdw.diph);
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Setting gain", ret);
|
||||
return -1;
|
||||
return DI_SetError("Setting gain", ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1483,8 +1460,7 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
|
|||
ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
|
||||
DIPROP_AUTOCENTER, &dipdw.diph);
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Setting autocenter", ret);
|
||||
return -1;
|
||||
return DI_SetError("Setting autocenter", ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1503,8 +1479,7 @@ SDL_SYS_HapticPause(SDL_Haptic * haptic)
|
|||
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
|
||||
DISFFC_PAUSE);
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Pausing the device", ret);
|
||||
return -1;
|
||||
return DI_SetError("Pausing the device", ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1523,8 +1498,7 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
|
|||
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
|
||||
DISFFC_CONTINUE);
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Pausing the device", ret);
|
||||
return -1;
|
||||
return DI_SetError("Pausing the device", ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1548,8 +1522,7 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
|
|||
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
|
||||
DISFFC_STOPALL);
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Stopping the device", ret);
|
||||
return -1;
|
||||
return DI_SetError("Stopping the device", ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue