summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/hid
diff options
context:
space:
mode:
authorMorph <39850852+Morph1984@users.noreply.github.com>2020-10-10 15:03:47 +0200
committerMorph <39850852+Morph1984@users.noreply.github.com>2020-11-16 05:33:20 +0100
commit9b501af8e3d0f6457fafb0fdfbcc11f6da4f0e8a (patch)
tree3a9cc70c7caa50eb7f3c5ede1bdddd4fa928c118 /src/core/hle/service/hid
parentconfigure_input: Hook up the vibration percentage spinbox (diff)
downloadyuzu-9b501af8e3d0f6457fafb0fdfbcc11f6da4f0e8a.tar
yuzu-9b501af8e3d0f6457fafb0fdfbcc11f6da4f0e8a.tar.gz
yuzu-9b501af8e3d0f6457fafb0fdfbcc11f6da4f0e8a.tar.bz2
yuzu-9b501af8e3d0f6457fafb0fdfbcc11f6da4f0e8a.tar.lz
yuzu-9b501af8e3d0f6457fafb0fdfbcc11f6da4f0e8a.tar.xz
yuzu-9b501af8e3d0f6457fafb0fdfbcc11f6da4f0e8a.tar.zst
yuzu-9b501af8e3d0f6457fafb0fdfbcc11f6da4f0e8a.zip
Diffstat (limited to 'src/core/hle/service/hid')
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp51
1 files changed, 46 insertions, 5 deletions
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
continue;
}
+ // Filter out vibrations with equivalent values to reduce unnecessary state changes.
+ if (vibration_values[i].amp_low ==
+ latest_vibration_values[npad_index][device_index].amp_low &&
+ vibration_values[i].amp_high ==
+ latest_vibration_values[npad_index][device_index].amp_high) {
+ continue;
+ }
+
+ // Filter out non-zero vibrations that are within 0.015625 absolute amplitude of each other.
+ if ((vibration_values[i].amp_low != 0.0f || vibration_values[i].amp_high != 0.0f) &&
+ (latest_vibration_values[npad_index][device_index].amp_low != 0.0f ||
+ latest_vibration_values[npad_index][device_index].amp_high != 0.0f) &&
+ (abs(vibration_values[i].amp_low -
+ latest_vibration_values[npad_index][device_index].amp_low) < 0.015625f &&
+ abs(vibration_values[i].amp_high -
+ latest_vibration_values[npad_index][device_index].amp_high) < 0.015625f)) {
+ continue;
+ }
+
using namespace Settings::NativeButton;
const auto& button_state = buttons[npad_index];
// TODO: Vibrate left/right vibration motors independently if possible.
- button_state[A - BUTTON_HID_BEGIN]->SetRumblePlay(
- vibration_values[i].amp_high * Settings::values.vibration_strength.GetValue() / 100,
+ const bool success = button_state[A - BUTTON_HID_BEGIN]->SetRumblePlay(
vibration_values[i].amp_low * Settings::values.vibration_strength.GetValue() / 100,
- vibration_values[i].freq_high, vibration_values[i].freq_low);
-
- latest_vibration_values[npad_index][device_index] = vibration_values[i];
+ vibration_values[i].freq_low,
+ vibration_values[i].amp_high * Settings::values.vibration_strength.GetValue() / 100,
+ vibration_values[i].freq_high);
+
+ if (success) {
+ switch (connected_controllers[npad_index].type) {
+ case NPadControllerType::None:
+ UNREACHABLE();
+ break;
+ case NPadControllerType::ProController:
+ case NPadControllerType::Handheld:
+ case NPadControllerType::JoyDual:
+ // Since we can't vibrate motors independently yet, we can reduce state changes by
+ // assigning all 3 device indices the current vibration value.
+ latest_vibration_values[npad_index][0] = vibration_values[i];
+ latest_vibration_values[npad_index][1] = vibration_values[i];
+ latest_vibration_values[npad_index][2] = vibration_values[i];
+ break;
+ case NPadControllerType::JoyLeft:
+ case NPadControllerType::JoyRight:
+ case NPadControllerType::Pokeball:
+ default:
+ latest_vibration_values[npad_index][device_index] = vibration_values[i];
+ break;
+ }
+ }
}
}