|
36 | 36 |
|
37 | 37 | namespace WebCore {
|
38 | 38 |
|
| 39 | +static double magnitudeToIntensity(double magnitude) |
| 40 | +{ |
| 41 | + if (magnitude <= 0) |
| 42 | + return 0; |
| 43 | + |
| 44 | + // Magnitude is a value in the [0; 1] range. Intensity has the same range but with |
| 45 | + // GameController, intensities below 0.1 don't register. To address this, we scale |
| 46 | + // the magnitude to be in the [0.1; 1] range. |
| 47 | + constexpr double newRange = 0.9; |
| 48 | + constexpr double newMinimum = 0.1; |
| 49 | + return (std::min(magnitude, 1.0) * newRange) + newMinimum; |
| 50 | +} |
| 51 | + |
39 | 52 | std::unique_ptr<GameControllerHapticEffect> GameControllerHapticEffect::create(GameControllerHapticEngines& engines, const GamepadEffectParameters& parameters, CompletionHandler<void(bool)>&& completionHandler)
|
40 | 53 | {
|
41 |
| - auto createPlayer = [&](CHHapticEngine *engine, double intensity) -> RetainPtr<id> { |
| 54 | + auto createPlayer = [&](CHHapticEngine *engine, double magnitude) -> RetainPtr<id> { |
42 | 55 | NSDictionary* hapticDict = @{
|
43 | 56 | CHHapticPatternKeyPattern: @[
|
44 | 57 | @{ CHHapticPatternKeyEvent: @{
|
|
47 | 60 | CHHapticPatternKeyEventDuration: [NSNumber numberWithDouble:std::clamp<double>(parameters.duration / 1000., 0, GamepadEffectParameters::maximumDuration.seconds())],
|
48 | 61 | CHHapticPatternKeyEventParameters: @[ @{
|
49 | 62 | CHHapticPatternKeyParameterID: CHHapticEventParameterIDHapticIntensity,
|
50 |
| - CHHapticPatternKeyParameterValue: [NSNumber numberWithDouble:std::clamp<double>(intensity, 0, 1)], |
| 63 | + CHHapticPatternKeyParameterValue: [NSNumber numberWithDouble:magnitudeToIntensity(magnitude)], |
51 | 64 | } ]
|
52 | 65 | }, },
|
53 | 66 | ],
|
|
0 commit comments