8000 [GameController] Correctly handle magnitude values passed to GamepadH… · WebKit/WebKit@7ad0df2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ad0df2

Browse files
committed
[GameController] Correctly handle magnitude values passed to GamepadHapticActuator.playEffect()
https://bugs.webkit.org/show_bug.cgi?id=250616 Reviewed by Youenn Fablet. Correctly handle magnitude values passed to GamepadHapticActuator.playEffect() when passing them to the GameController framework. We noticed different Gamepad vibration results between Safari and Chrome for the same magnitude values. One obvious difference was that values below 0.1 didn't result in any vibration in Safari but did in Chrome. In 258874@main, I made an attempt to address this by scaling the input magnitude (in the range [0; 1]) to be in the range [0.1; 1] in order to always get a vibration if the magnitude value is not zero. However, I have since heard back from GameController developers who have indicating that we should be using the square root of the magnitude, instead of the raw magnitude value. This is due to the fact that the GameController framework doesn't use the input value as-is internally. I am therefore updating our code to use the suggested approach. I have validated on XBox Cloud that the level of vibration feels similar between Safari and Chrome. * Source/WebCore/platform/gamepad/cocoa/GameControllerHapticEffect.mm: (WebCore::magnitudeToIntensity): Canonical link: https://commits.webkit.org/258988@main
1 parent ddc1672 commit 7ad0df2

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

Source/WebCore/platform/gamepad/cocoa/GameControllerHapticEffect.mm

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,18 @@
3131
#import "GameControllerHapticEngines.h"
3232
#import "GamepadEffectParameters.h"
3333
#import "Logging.h"
34+
#import <cmath>
3435

3536
#import "CoreHapticsSoftLink.h"
3637

3738
namespace WebCore {
3839

3940
static double magnitudeToIntensity(double magnitude)
4041
{
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;
42+
// GameController doesn't use the intensity as-is and values below 0.1 would end up
43+
// not triggering any gamepad vibration. Per GameController developers, we should
44+
// pass sqrt(magnitude) to address this issue.
45+
return std::sqrt(std::clamp<double>(magnitude, 0, 1));
5046
}
5147

5248
std::unique_ptr<GameControllerHapticEffect> GameControllerHapticEffect::create(GameControllerHapticEngines& engines, const GamepadEffectParameters& parameters, CompletionHandler<void(bool)>&& completionHandler)

0 commit comments

Comments
 (0)
0