mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2025-08-17 16:46:31 +00:00
Improvements to haptic error handling
- Move gamepad index check to the JS side to simplify the code - Handle gamepads that don't support haptics
This commit is contained in:
parent
ce52398dc5
commit
a191915b9d
@ -132,14 +132,6 @@ void MoonlightInstance::PollGamepads() {
|
|||||||
|
|
||||||
void MoonlightInstance::ClControllerRumble(unsigned short controllerNumber, unsigned short lowFreqMotor, unsigned short highFreqMotor)
|
void MoonlightInstance::ClControllerRumble(unsigned short controllerNumber, unsigned short lowFreqMotor, unsigned short highFreqMotor)
|
||||||
{
|
{
|
||||||
PP_GamepadsSampleData gamepadData;
|
|
||||||
g_Instance->m_GamepadApi->Sample(g_Instance->pp_instance(), &gamepadData);
|
|
||||||
|
|
||||||
// We must determine which gamepads are connected before sending rumble events.
|
|
||||||
const unsigned short activeGamepadMask = static_cast<unsigned short>(GetActiveGamepadMask(gamepadData));
|
|
||||||
if ((activeGamepadMask & (1 << controllerNumber)) == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const float weakMagnitude = static_cast<float>(highFreqMotor) / static_cast<float>(UINT16_MAX);
|
const float weakMagnitude = static_cast<float>(highFreqMotor) / static_cast<float>(UINT16_MAX);
|
||||||
const float strongMagnitude = static_cast<float>(lowFreqMotor) / static_cast<float>(UINT16_MAX);
|
const float strongMagnitude = static_cast<float>(lowFreqMotor) / static_cast<float>(UINT16_MAX);
|
||||||
|
|
||||||
|
@ -87,7 +87,10 @@ function handleMessage(msg) {
|
|||||||
const weakMagnitude = parseFloat(eventData[1]);
|
const weakMagnitude = parseFloat(eventData[1]);
|
||||||
const strongMagnitude = parseFloat(eventData[2]);
|
const strongMagnitude = parseFloat(eventData[2]);
|
||||||
console.log("Playing rumble on gamepad " + gamepadIdx + " with weakMagnitude " + weakMagnitude + " and strongMagnitude " + strongMagnitude);
|
console.log("Playing rumble on gamepad " + gamepadIdx + " with weakMagnitude " + weakMagnitude + " and strongMagnitude " + strongMagnitude);
|
||||||
navigator.getGamepads()[gamepadIdx].vibrationActuator.playEffect('dual-rumble', {
|
|
||||||
|
// We may not actually have a gamepad at this index.
|
||||||
|
// Even if we do have a gamepad, it may not have a vibrationActuator associated with it.
|
||||||
|
navigator.getGamepads()[gamepadIdx]?.vibrationActuator?.playEffect('dual-rumble', {
|
||||||
startDelay: 0,
|
startDelay: 0,
|
||||||
duration: 5000, // Moonlight should be sending another rumble event when stopping.
|
duration: 5000, // Moonlight should be sending another rumble event when stopping.
|
||||||
weakMagnitude: weakMagnitude,
|
weakMagnitude: weakMagnitude,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user