src/haptic/darwin/SDL_syshaptic.c
changeset 9631 e015da7884df
parent 9619 b94b6d0bff0f
child 9633 3e742dd2c13d
equal deleted inserted replaced
9630:6c86d3216f6a 9631:e015da7884df
   769  */
   769  */
   770 static int
   770 static int
   771 SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
   771 SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
   772 {
   772 {
   773     int i;
   773     int i;
   774     FFCONSTANTFORCE *constant;
   774     FFCONSTANTFORCE *constant = NULL;
   775     FFPERIODIC *periodic;
   775     FFPERIODIC *periodic = NULL;
   776     FFCONDITION *condition;     /* Actually an array of conditions - one per axis. */
   776     FFCONDITION *condition = NULL;     /* Actually an array of conditions - one per axis. */
   777     FFRAMPFORCE *ramp;
   777     FFRAMPFORCE *ramp = NULL;
   778     FFCUSTOMFORCE *custom;
   778     FFCUSTOMFORCE *custom = NULL;
   779     FFENVELOPE *envelope;
   779     FFENVELOPE *envelope = NULL;
   780     SDL_HapticConstant *hap_constant;
   780     SDL_HapticConstant *hap_constant = NULL;
   781     SDL_HapticPeriodic *hap_periodic;
   781     SDL_HapticPeriodic *hap_periodic = NULL;
   782     SDL_HapticCondition *hap_condition;
   782     SDL_HapticCondition *hap_condition = NULL;
   783     SDL_HapticRamp *hap_ramp;
   783     SDL_HapticRamp *hap_ramp = NULL;
   784     SDL_HapticCustom *hap_custom;
   784     SDL_HapticCustom *hap_custom = NULL;
   785     DWORD *axes;
   785     DWORD *axes = NULL;
   786 
   786 
   787     /* Set global stuff. */
   787     /* Set global stuff. */
   788     SDL_memset(dest, 0, sizeof(FFEFFECT));
   788     SDL_memset(dest, 0, sizeof(FFEFFECT));
   789     dest->dwSize = sizeof(FFEFFECT);    /* Set the structure size. */
   789     dest->dwSize = sizeof(FFEFFECT);    /* Set the structure size. */
   790     dest->dwSamplePeriod = 0;   /* Not used by us. */
   790     dest->dwSamplePeriod = 0;   /* Not used by us. */
   909 
   909 
   910     case SDL_HAPTIC_SPRING:
   910     case SDL_HAPTIC_SPRING:
   911     case SDL_HAPTIC_DAMPER:
   911     case SDL_HAPTIC_DAMPER:
   912     case SDL_HAPTIC_INERTIA:
   912     case SDL_HAPTIC_INERTIA:
   913     case SDL_HAPTIC_FRICTION:
   913     case SDL_HAPTIC_FRICTION:
   914         hap_condition = &src->condition;
   914         if (dest->cAxes > 0) {
   915         condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
   915             hap_condition = &src->condition;
   916         if (condition == NULL) {
   916             condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
   917             return SDL_OutOfMemory();
   917             if (condition == NULL) {
   918         }
   918                 return SDL_OutOfMemory();
   919         SDL_memset(condition, 0, sizeof(FFCONDITION));
   919             }
   920 
   920             SDL_memset(condition, 0, sizeof(FFCONDITION));
   921         /* Specifics */
   921 
   922         for (i = 0; i < dest->cAxes; i++) {
   922             /* Specifics */
   923             condition[i].lOffset = CONVERT(hap_condition->center[i]);
   923             for (i = 0; i < dest->cAxes; i++) {
   924             condition[i].lPositiveCoefficient =
   924                 condition[i].lOffset = CONVERT(hap_condition->center[i]);
   925                 CONVERT(hap_condition->right_coeff[i]);
   925                 condition[i].lPositiveCoefficient =
   926             condition[i].lNegativeCoefficient =
   926                     CONVERT(hap_condition->right_coeff[i]);
   927                 CONVERT(hap_condition->left_coeff[i]);
   927                 condition[i].lNegativeCoefficient =
   928             condition[i].dwPositiveSaturation =
   928                     CONVERT(hap_condition->left_coeff[i]);
   929                 CCONVERT(hap_condition->right_sat[i] / 2);
   929                 condition[i].dwPositiveSaturation =
   930             condition[i].dwNegativeSaturation =
   930                     CCONVERT(hap_condition->right_sat[i] / 2);
   931                 CCONVERT(hap_condition->left_sat[i] / 2);
   931                 condition[i].dwNegativeSaturation =
   932             condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i] / 2);
   932                     CCONVERT(hap_condition->left_sat[i] / 2);
   933         }
   933                 condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i] / 2);
       
   934             }
       
   935         }
       
   936 
   934         dest->cbTypeSpecificParams = sizeof(FFCONDITION) * dest->cAxes;
   937         dest->cbTypeSpecificParams = sizeof(FFCONDITION) * dest->cAxes;
   935         dest->lpvTypeSpecificParams = condition;
   938         dest->lpvTypeSpecificParams = condition;
   936 
   939 
   937         /* Generics */
   940         /* Generics */
   938         dest->dwDuration = hap_condition->length * 1000;        /* In microseconds. */
   941         dest->dwDuration = hap_condition->length * 1000;        /* In microseconds. */