src/haptic/darwin/SDL_syshaptic.c
branchgsoc2008_force_feedback
changeset 2535 f0ed8471497d
parent 2534 e597de8dccd5
child 2537 8d92ec01f92f
     1.1 --- a/src/haptic/darwin/SDL_syshaptic.c	Fri Jul 18 19:22:56 2008 +0000
     1.2 +++ b/src/haptic/darwin/SDL_syshaptic.c	Sat Jul 19 15:57:07 2008 +0000
     1.3 @@ -69,7 +69,7 @@
     1.4  /*
     1.5   * Prototypes.
     1.6   */
     1.7 -static void SDL_SYS_HapticFreeFFEFFECT( FFEFFECT * effect );
     1.8 +static void SDL_SYS_HapticFreeFFEFFECT( FFEFFECT * effect, int type );
     1.9  
    1.10  
    1.11  /*
    1.12 @@ -314,7 +314,8 @@
    1.13        /* Free the effects. */
    1.14        for (i=0; i<haptic->neffects; i++) {        
    1.15           if (haptic->effects[i].hweffect != NULL) {
    1.16 -            SDL_SYS_HapticFreeFFEFFECT(&haptic->effects[i].hweffect->effect);
    1.17 +            SDL_SYS_HapticFreeFFEFFECT(&haptic->effects[i].hweffect->effect,
    1.18 +                                       haptic->effects[i].effect.type);
    1.19              SDL_free(haptic->effects[i].hweffect);
    1.20           } 
    1.21        }    
    1.22 @@ -414,6 +415,7 @@
    1.23     SDL_HapticPeriodic *hap_periodic;
    1.24     SDL_HapticCondition *hap_condition;
    1.25     SDL_HapticRamp *hap_ramp;
    1.26 +   SDL_HapticCustom *hap_custom;
    1.27     DWORD *axes;
    1.28  
    1.29     /* Set global stuff. */
    1.30 @@ -460,6 +462,7 @@
    1.31              SDL_OutOfMemory();
    1.32              return -1;
    1.33           }
    1.34 +         SDL_memset(constant, 0, sizeof(FFCONSTANTFORCE));
    1.35  
    1.36           /* Specifics */
    1.37           constant->lMagnitude = CONVERT(hap_constant->level);
    1.38 @@ -496,6 +499,7 @@
    1.39              SDL_OutOfMemory();
    1.40              return -1;
    1.41           }
    1.42 +         SDL_memset(periodic, 0, sizeof(FFPERIODIC));
    1.43  
    1.44           /* Specifics */
    1.45           periodic->dwMagnitude = CONVERT(hap_periodic->magnitude);
    1.46 @@ -534,6 +538,7 @@
    1.47              SDL_OutOfMemory();
    1.48              return -1;
    1.49           }
    1.50 +         SDL_memset(condition, 0, sizeof(FFCONDITION));
    1.51  
    1.52           /* Specifics */
    1.53           for (i=0; i<dest->cAxes; i++) {
    1.54 @@ -575,10 +580,13 @@
    1.55              SDL_OutOfMemory();
    1.56              return -1;
    1.57           }
    1.58 +         SDL_memset(ramp, 0, sizeof(FFRAMPFORCE));
    1.59  
    1.60           /* Specifics */
    1.61           ramp->lStart = CONVERT(hap_ramp->start);
    1.62           ramp->lEnd = CONVERT(hap_ramp->end);
    1.63 +         dest->cbTypeSpecificParams = sizeof(FFRAMPFORCE);
    1.64 +         dest->lpvTypeSpecificParams = ramp;
    1.65  
    1.66           /* Generics */
    1.67           dest->dwDuration = hap_ramp->length * 1000; /* In microseconds. */
    1.68 @@ -599,6 +607,45 @@
    1.69  
    1.70           break;
    1.71  
    1.72 +      case SDL_HAPTIC_CUSTOM:
    1.73 +         hap_custom = &src->custom;
    1.74 +         custom = SDL_malloc(sizeof(FFCUSTOMFORCE));
    1.75 +         if (custom == NULL) {
    1.76 +            SDL_OutOfMemory();
    1.77 +            return -1;
    1.78 +         }
    1.79 +         SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE));
    1.80 +
    1.81 +         /* Specifics */
    1.82 +         custom->cChannels = hap_custom->channels;
    1.83 +         custom->dwSamplePeriod = hap_custom->period * 1000;
    1.84 +         custom->cSamples = hap_custom->samples;
    1.85 +         custom->rglForceData = SDL_malloc(sizeof(LONG)*custom->cSamples*custom->cChannels);
    1.86 +         for (i=0; i<hap_custom->samples*hap_custom->channels; i++) { /* Copy data. */
    1.87 +            custom->rglForceData[i] = CONVERT(hap_custom->data[i]);
    1.88 +         }
    1.89 +         dest->cbTypeSpecificParams = sizeof(FFCUSTOMFORCE);
    1.90 +         dest->lpvTypeSpecificParams = custom;
    1.91 +
    1.92 +         /* Generics */
    1.93 +         dest->dwDuration = hap_custom->length * 1000; /* In microseconds. */
    1.94 +         dest->dwTriggerButton = FFJOFS_BUTTON(hap_custom->button);
    1.95 +         dest->dwTriggerRepeatInterval = hap_custom->interval;
    1.96 +         dest->dwStartDelay = hap_custom->delay * 1000; /* In microseconds. */
    1.97 +
    1.98 +         /* Direction. */
    1.99 +         if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) < 0) {
   1.100 +            return -1;
   1.101 +         }
   1.102 +         
   1.103 +         /* Envelope */
   1.104 +         envelope->dwAttackLevel = CONVERT(hap_custom->attack_level);
   1.105 +         envelope->dwAttackTime = hap_custom->attack_length * 1000;
   1.106 +         envelope->dwFadeLevel = CONVERT(hap_custom->fade_level);
   1.107 +         envelope->dwFadeTime = hap_custom->fade_length * 1000;
   1.108 +
   1.109 +         break;
   1.110 +
   1.111  
   1.112        default:
   1.113           SDL_SetError("Haptic: Unknown effect type.");
   1.114 @@ -613,8 +660,10 @@
   1.115   * Frees an FFEFFECT allocated by SDL_SYS_ToFFEFFECT.
   1.116   */
   1.117  static void
   1.118 -SDL_SYS_HapticFreeFFEFFECT( FFEFFECT * effect )
   1.119 +SDL_SYS_HapticFreeFFEFFECT( FFEFFECT * effect, int type )
   1.120  {
   1.121 +   FFCUSTOMFORCE *custom;
   1.122 +
   1.123     if (effect->lpEnvelope != NULL) {
   1.124        SDL_free(effect->lpEnvelope);
   1.125        effect->lpEnvelope = NULL;
   1.126 @@ -624,6 +673,11 @@
   1.127        effect->rgdwAxes = NULL;
   1.128     }
   1.129     if (effect->lpvTypeSpecificParams != NULL) {
   1.130 +      if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
   1.131 +         custom = (FFCUSTOMFORCE*) effect->lpvTypeSpecificParams;
   1.132 +         SDL_free(custom->rglForceData);
   1.133 +         custom->rglForceData = NULL;
   1.134 +      }
   1.135        SDL_free(effect->lpvTypeSpecificParams);
   1.136        effect->lpvTypeSpecificParams = NULL;
   1.137     }
   1.138 @@ -725,7 +779,7 @@
   1.139     return 0;
   1.140  
   1.141  err_effectdone:
   1.142 -   SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect);
   1.143 +   SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, effect->effect.type);
   1.144  err_hweffect:
   1.145     if (effect->hweffect != NULL) {
   1.146        SDL_free(effect->hweffect);