mirror of
https://github.com/yuzu-emu/yuzu-android
synced 2024-11-25 14:18:51 +00:00
Merge pull request #13154 from german77/vibration-filter
core: hid: Reintroduce vibration filter
This commit is contained in:
commit
8416d1c028
4 changed files with 23 additions and 2 deletions
|
@ -2,6 +2,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <common/scope_exit.h>
|
||||
|
||||
#include "common/polyfill_ranges.h"
|
||||
|
@ -1287,6 +1288,22 @@ bool EmulatedController::SetVibration(DeviceIndex device_index, const VibrationV
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!Settings::values.enable_accurate_vibrations.GetValue()) {
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::milliseconds;
|
||||
using std::chrono::steady_clock;
|
||||
|
||||
const auto now = steady_clock::now();
|
||||
|
||||
// Filter out non-zero vibrations that are within 15ms of each other.
|
||||
if ((vibration.low_amplitude != 0.0f || vibration.high_amplitude != 0.0f) &&
|
||||
duration_cast<milliseconds>(now - last_vibration_timepoint[index]) < milliseconds(15)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
last_vibration_timepoint[index] = now;
|
||||
}
|
||||
|
||||
// Exponential amplification is too strong at low amplitudes. Switch to a linear
|
||||
// amplification if strength is set below 0.7f
|
||||
const Common::Input::VibrationAmplificationType type =
|
||||
|
|
|
@ -583,6 +583,7 @@ private:
|
|||
std::size_t nfc_handles{0};
|
||||
std::array<VibrationValue, 2> last_vibration_value{DEFAULT_VIBRATION_VALUE,
|
||||
DEFAULT_VIBRATION_VALUE};
|
||||
std::array<std::chrono::steady_clock::time_point, 2> last_vibration_timepoint{};
|
||||
|
||||
// Temporary values to avoid doing changes while the controller is in configuring mode
|
||||
NpadStyleIndex tmp_npad_type{NpadStyleIndex::None};
|
||||
|
|
|
@ -638,7 +638,11 @@ struct VibrationValue {
|
|||
if (low_amplitude != b.low_amplitude || high_amplitude != b.high_amplitude) {
|
||||
return false;
|
||||
}
|
||||
if (low_frequency != b.low_amplitude || high_frequency != b.high_frequency) {
|
||||
// Changes in frequency without amplitude don't have any effect
|
||||
if (low_amplitude == 0 && high_amplitude == 0) {
|
||||
return true;
|
||||
}
|
||||
if (low_frequency != b.low_frequency || high_frequency != b.high_frequency) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
|
||||
#include "common/assert.h"
|
||||
|
|
Loading…
Reference in a new issue