diff options
| author | 2020-10-10 09:03:47 -0400 | |
|---|---|---|
| committer | 2020-11-15 23:33:20 -0500 | |
| commit | 9b501af8e3d0f6457fafb0fdfbcc11f6da4f0e8a (patch) | |
| tree | 3a9cc70c7caa50eb7f3c5ede1bdddd4fa928c118 /src/core | |
| parent | configure_input: Hook up the vibration percentage spinbox (diff) | |
| download | yuzu-9b501af8e3d0f6457fafb0fdfbcc11f6da4f0e8a.tar.gz yuzu-9b501af8e3d0f6457fafb0fdfbcc11f6da4f0e8a.tar.xz yuzu-9b501af8e3d0f6457fafb0fdfbcc11f6da4f0e8a.zip | |
controllers/npad: Add heuristics to reduce rumble state changes
Sending too many state changes in a short period of time can cause massive performance issues.
As a result, we have to use several heuristics to reduce the number of state changes to minimize/eliminate this performance impact while maintaining the quality of these vibrations as much as possible.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/frontend/input.h | 2 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 51 |
2 files changed, 47 insertions, 6 deletions
diff --git a/src/core/frontend/input.h b/src/core/frontend/input.h index 277b70e53..fb2ce2514 100644 --- a/src/core/frontend/input.h +++ b/src/core/frontend/input.h | |||
| @@ -33,7 +33,7 @@ public: | |||
| 33 | virtual bool GetAnalogDirectionStatus(AnalogDirection direction) const { | 33 | virtual bool GetAnalogDirectionStatus(AnalogDirection direction) const { |
| 34 | return {}; | 34 | return {}; |
| 35 | } | 35 | } |
| 36 | virtual bool SetRumblePlay(f32 amp_high, f32 amp_low, f32 freq_high, f32 freq_low) const { | 36 | virtual bool SetRumblePlay(f32 amp_low, f32 freq_low, f32 amp_high, f32 freq_high) const { |
| 37 | return {}; | 37 | return {}; |
| 38 | } | 38 | } |
| 39 | }; | 39 | }; |
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 924f209c0..cc54b164d 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -698,16 +698,57 @@ void Controller_NPad::VibrateController(const std::vector<DeviceHandle>& vibrati | |||
| 698 | continue; | 698 | continue; |
| 699 | } | 699 | } |
| 700 | 700 | ||
| 701 | // Filter out vibrations with equivalent values to reduce unnecessary state changes. | ||
| 702 | if (vibration_values[i].amp_low == | ||
| 703 | latest_vibration_values[npad_index][device_index].amp_low && | ||
| 704 | vibration_values[i].amp_high == | ||
| 705 | latest_vibration_values[npad_index][device_index].amp_high) { | ||
| 706 | continue; | ||
| 707 | } | ||
| 708 | |||
| 709 | // Filter out non-zero vibrations that are within 0.015625 absolute amplitude of each other. | ||
| 710 | if ((vibration_values[i].amp_low != 0.0f || vibration_values[i].amp_high != 0.0f) && | ||
| 711 | (latest_vibration_values[npad_index][device_index].amp_low != 0.0f || | ||
| 712 | latest_vibration_values[npad_index][device_index].amp_high != 0.0f) && | ||
| 713 | (abs(vibration_values[i].amp_low - | ||
| 714 | latest_vibration_values[npad_index][device_index].amp_low) < 0.015625f && | ||
| 715 | abs(vibration_values[i].amp_high - | ||
| 716 | latest_vibration_values[npad_index][device_index].amp_high) < 0.015625f)) { | ||
| 717 | continue; | ||
| 718 | } | ||
| 719 | |||
| 701 | using namespace Settings::NativeButton; | 720 | using namespace Settings::NativeButton; |
| 702 | const auto& button_state = buttons[npad_index]; | 721 | const auto& button_state = buttons[npad_index]; |
| 703 | 722 | ||
| 704 | // TODO: Vibrate left/right vibration motors independently if possible. | 723 | // TODO: Vibrate left/right vibration motors independently if possible. |
| 705 | button_state[A - BUTTON_HID_BEGIN]->SetRumblePlay( | 724 | const bool success = button_state[A - BUTTON_HID_BEGIN]->SetRumblePlay( |
| 706 | vibration_values[i].amp_high * Settings::values.vibration_strength.GetValue() / 100, | ||
| 707 | vibration_values[i].amp_low * Settings::values.vibration_strength.GetValue() / 100, | 725 | vibration_values[i].amp_low * Settings::values.vibration_strength.GetValue() / 100, |
| 708 | vibration_values[i].freq_high, vibration_values[i].freq_low); | 726 | vibration_values[i].freq_low, |
| 709 | 727 | vibration_values[i].amp_high * Settings::values.vibration_strength.GetValue() / 100, | |
| 710 | latest_vibration_values[npad_index][device_index] = vibration_values[i]; | 728 | vibration_values[i].freq_high); |
| 729 | |||
| 730 | if (success) { | ||
| 731 | switch (connected_controllers[npad_index].type) { | ||
| 732 | case NPadControllerType::None: | ||
| 733 | UNREACHABLE(); | ||
| 734 | break; | ||
| 735 | case NPadControllerType::ProController: | ||
| 736 | case NPadControllerType::Handheld: | ||
| 737 | case NPadControllerType::JoyDual: | ||
| 738 | // Since we can't vibrate motors independently yet, we can reduce state changes by | ||
| 739 | // assigning all 3 device indices the current vibration value. | ||
| 740 | latest_vibration_values[npad_index][0] = vibration_values[i]; | ||
| 741 | latest_vibration_values[npad_index][1] = vibration_values[i]; | ||
| 742 | latest_vibration_values[npad_index][2] = vibration_values[i]; | ||
| 743 | break; | ||
| 744 | case NPadControllerType::JoyLeft: | ||
| 745 | case NPadControllerType::JoyRight: | ||
| 746 | case NPadControllerType::Pokeball: | ||
| 747 | default: | ||
| 748 | latest_vibration_values[npad_index][device_index] = vibration_values[i]; | ||
| 749 | break; | ||
| 750 | } | ||
| 751 | } | ||
| 711 | } | 752 | } |
| 712 | } | 753 | } |
| 713 | 754 | ||