/* * Creates a new haptic effect. */ int SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base) { HRESULT ret; REFGUID type = SDL_SYS_HapticEffectType(base); if (type == NULL) { goto err_hweffect; } /* Alloc the effect. */ effect->hweffect = (struct haptic_hweffect *) SDL_malloc(sizeof(struct haptic_hweffect)); if (effect->hweffect == NULL) { SDL_OutOfMemory(); goto err_hweffect; } SDL_zerop(effect->hweffect); if (haptic->hwdata->bXInputHaptic) { SDL_assert(base->type == SDL_HAPTIC_SINE); /* should catch this at higher level */ return SDL_SYS_HapticUpdateEffect(haptic, effect, base); } /* Get the effect. */ if (SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base) < 0) { goto err_effectdone; } /* Create the actual effect. */ ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type, &effect->hweffect->effect, &effect->hweffect->ref, NULL); if (FAILED(ret)) { DI_SetError("Unable to create effect", ret); goto err_effectdone; } return 0; err_effectdone: SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, base->type); err_hweffect: if (effect->hweffect != NULL) { SDL_free(effect->hweffect); effect->hweffect = NULL; } return -1; }
/* * Updates an effect. */ int SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data) { if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) { return -1; } /* 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 */ if (SDL_SYS_HapticUpdateEffect(haptic, &haptic->effects[effect], data) < 0) { return -1; } SDL_memcpy(&haptic->effects[effect].effect, data, sizeof(SDL_HapticEffect)); return 0; }