Haptic: Fix clamping bugs on Windows, by using the Darwin haptics code.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 16 Aug 2014 16:49:00 -0400
changeset 90718e04e17c7af3
parent 9070 8973a237f360
child 9072 0c1a46c018aa
Haptic: Fix clamping bugs on Windows, by using the Darwin haptics code.

Thanks, Elias!

Partially fixes Bugzilla #2686.
src/haptic/windows/SDL_dinputhaptic.c
     1.1 --- a/src/haptic/windows/SDL_dinputhaptic.c	Sat Aug 16 16:47:42 2014 -0400
     1.2 +++ b/src/haptic/windows/SDL_dinputhaptic.c	Sat Aug 16 16:49:00 2014 -0400
     1.3 @@ -602,7 +602,10 @@
     1.4      }
     1.5  }
     1.6  
     1.7 -#define CONVERT(x)   (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
     1.8 +/* Clamps and converts. */
     1.9 +#define CCONVERT(x)   (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
    1.10 +/* Just converts. */
    1.11 +#define CONVERT(x)    (((x)*10000) / 0x7FFF)
    1.12  /*
    1.13   * Creates the DIEFFECT from a SDL_HapticEffect.
    1.14   */
    1.15 @@ -689,9 +692,9 @@
    1.16              SDL_free(dest->lpEnvelope);
    1.17              dest->lpEnvelope = NULL;
    1.18          } else {
    1.19 -            envelope->dwAttackLevel = CONVERT(hap_constant->attack_level);
    1.20 +            envelope->dwAttackLevel = CCONVERT(hap_constant->attack_level);
    1.21              envelope->dwAttackTime = hap_constant->attack_length * 1000;
    1.22 -            envelope->dwFadeLevel = CONVERT(hap_constant->fade_level);
    1.23 +            envelope->dwFadeLevel = CCONVERT(hap_constant->fade_level);
    1.24              envelope->dwFadeTime = hap_constant->fade_length * 1000;
    1.25          }
    1.26  
    1.27 @@ -736,9 +739,9 @@
    1.28              SDL_free(dest->lpEnvelope);
    1.29              dest->lpEnvelope = NULL;
    1.30          } else {
    1.31 -            envelope->dwAttackLevel = CONVERT(hap_periodic->attack_level);
    1.32 +            envelope->dwAttackLevel = CCONVERT(hap_periodic->attack_level);
    1.33              envelope->dwAttackTime = hap_periodic->attack_length * 1000;
    1.34 -            envelope->dwFadeLevel = CONVERT(hap_periodic->fade_level);
    1.35 +            envelope->dwFadeLevel = CCONVERT(hap_periodic->fade_level);
    1.36              envelope->dwFadeTime = hap_periodic->fade_length * 1000;
    1.37          }
    1.38  
    1.39 @@ -763,10 +766,10 @@
    1.40              condition[i].lNegativeCoefficient =
    1.41                  CONVERT(hap_condition->left_coeff[i]);
    1.42              condition[i].dwPositiveSaturation =
    1.43 -                CONVERT(hap_condition->right_sat[i] / 2);
    1.44 +                CCONVERT(hap_condition->right_sat[i] / 2);
    1.45              condition[i].dwNegativeSaturation =
    1.46 -                CONVERT(hap_condition->left_sat[i] / 2);
    1.47 -            condition[i].lDeadBand = CONVERT(hap_condition->deadband[i] / 2);
    1.48 +                CCONVERT(hap_condition->left_sat[i] / 2);
    1.49 +            condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i] / 2);
    1.50          }
    1.51          dest->cbTypeSpecificParams = sizeof(DICONDITION) * dest->cAxes;
    1.52          dest->lpvTypeSpecificParams = condition;
    1.53 @@ -819,9 +822,9 @@
    1.54              SDL_free(dest->lpEnvelope);
    1.55              dest->lpEnvelope = NULL;
    1.56          } else {
    1.57 -            envelope->dwAttackLevel = CONVERT(hap_ramp->attack_level);
    1.58 +            envelope->dwAttackLevel = CCONVERT(hap_ramp->attack_level);
    1.59              envelope->dwAttackTime = hap_ramp->attack_length * 1000;
    1.60 -            envelope->dwFadeLevel = CONVERT(hap_ramp->fade_level);
    1.61 +            envelope->dwFadeLevel = CCONVERT(hap_ramp->fade_level);
    1.62              envelope->dwFadeTime = hap_ramp->fade_length * 1000;
    1.63          }
    1.64  
    1.65 @@ -842,7 +845,7 @@
    1.66          custom->rglForceData =
    1.67              SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
    1.68          for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) {      /* Copy data. */
    1.69 -            custom->rglForceData[i] = CONVERT(hap_custom->data[i]);
    1.70 +            custom->rglForceData[i] = CCONVERT(hap_custom->data[i]);
    1.71          }
    1.72          dest->cbTypeSpecificParams = sizeof(DICUSTOMFORCE);
    1.73          dest->lpvTypeSpecificParams = custom;
    1.74 @@ -864,9 +867,9 @@
    1.75              SDL_free(dest->lpEnvelope);
    1.76              dest->lpEnvelope = NULL;
    1.77          } else {
    1.78 -            envelope->dwAttackLevel = CONVERT(hap_custom->attack_level);
    1.79 +            envelope->dwAttackLevel = CCONVERT(hap_custom->attack_level);
    1.80              envelope->dwAttackTime = hap_custom->attack_length * 1000;
    1.81 -            envelope->dwFadeLevel = CONVERT(hap_custom->fade_level);
    1.82 +            envelope->dwFadeLevel = CCONVERT(hap_custom->fade_level);
    1.83              envelope->dwFadeTime = hap_custom->fade_length * 1000;
    1.84          }
    1.85