Improved correctiveness in CreateEffect. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Sun, 20 Jul 2008 14:12:52 +0000
branchgsoc2008_force_feedback
changeset 25381f9c20580ab4
parent 2537 8d92ec01f92f
child 2539 b4c41a7eea04
Improved correctiveness in CreateEffect.
Added UpdateEffect support to darwin.
src/haptic/darwin/SDL_syshaptic.c
     1.1 --- a/src/haptic/darwin/SDL_syshaptic.c	Sat Jul 19 17:05:30 2008 +0000
     1.2 +++ b/src/haptic/darwin/SDL_syshaptic.c	Sun Jul 20 14:12:52 2008 +0000
     1.3 @@ -833,13 +833,13 @@
     1.4     }
     1.5  
     1.6     /* Get the effect. */
     1.7 -   if (SDL_SYS_ToFFEFFECT(haptic, &effect->hweffect->effect, &effect->effect ) < 0) {
     1.8 +   if (SDL_SYS_ToFFEFFECT(haptic, &effect->hweffect->effect, base) < 0) {
     1.9        goto err_effectdone;
    1.10     }
    1.11  
    1.12     /* Create the actual effect. */
    1.13 -   ret = FFDeviceCreateEffect( haptic->hwdata->device, type,
    1.14 -         &effect->hweffect->effect, &effect->hweffect->ref );
    1.15 +   ret = FFDeviceCreateEffect(haptic->hwdata->device, type,
    1.16 +         &effect->hweffect->effect, &effect->hweffect->ref);
    1.17  
    1.18     if (ret != FF_OK) {
    1.19        SDL_SetError("Haptic: Unable to create effect.");
    1.20 @@ -849,7 +849,7 @@
    1.21     return 0;
    1.22  
    1.23  err_effectdone:
    1.24 -   SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, effect->effect.type);
    1.25 +   SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, base->type);
    1.26  err_hweffect:
    1.27     if (effect->hweffect != NULL) {
    1.28        SDL_free(effect->hweffect);
    1.29 @@ -866,7 +866,37 @@
    1.30  SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
    1.31        struct haptic_effect * effect, SDL_HapticEffect * data)
    1.32  {
    1.33 -   /* TODO */
    1.34 +   HRESULT ret;
    1.35 +   FFEffectParameterFlag flags;
    1.36 +   FFEFFECT temp;
    1.37 +
    1.38 +   /* Get the effect. */
    1.39 +   SDL_memset(&temp, 0, sizeof(FFEFFECT));
    1.40 +   if (SDL_SYS_ToFFEFFECT(haptic, &temp, data) < 0) {
    1.41 +      goto err_update;
    1.42 +   }
    1.43 +
    1.44 +   /* Set the flags.  Might be worthwhile to diff temp with loaded effect and
    1.45 +    *  only change those parameters. */
    1.46 +   flags = FFEP_ALLPARAMS;
    1.47 +
    1.48 +   /* Create the actual effect. */
    1.49 +   ret = FFEffectSetParameters(haptic->hwdata->device, effect->hweffect->ref,
    1.50 +                               &temp, flags);
    1.51 +
    1.52 +   if (ret != FF_OK) {
    1.53 +      SDL_SetError("Haptic: Unable to update effect.");
    1.54 +      goto err_update;
    1.55 +   }
    1.56 +
    1.57 +   /* Copy it over. */
    1.58 +   SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, data->type);
    1.59 +   SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(FFEFFECT));
    1.60 +
    1.61 +   return 0;
    1.62 +
    1.63 +err_update:
    1.64 +   SDL_SYS_HapticFreeFFEFFECT(&temp, data->type);
    1.65     return -1;
    1.66  }
    1.67