From a05798b50ac7c5fc7d07520dfb99b37cc5cd34b4 Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Sat, 17 Aug 2024 22:24:45 +0200 Subject: [PATCH] Remove unused parameter and extract branching behaviour --- .../ControlGroup/IMUGyroscope.cpp | 26 ++++++++++--------- .../ControllerEmu/ControlGroup/IMUGyroscope.h | 4 ++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp index 2e8c4bb18c..98dd71307f 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp @@ -133,24 +133,18 @@ bool IMUGyroscope::CanCalibrate() const return ControlReference::GetInputGate(); } -std::optional IMUGyroscope::GetState(bool update) +std::optional IMUGyroscope::GetState() { - if (!AreInputsBound()) - { - if (update) - { - // Set calibration to zero. - m_calibration = {}; - RestartCalibration(); - } - return std::nullopt; - } + return AreInputsBound() ? GetStateInternal() : Reset(); +} +std::optional IMUGyroscope::GetStateInternal() +{ auto state = GetRawState(); // Alternatively we could open the control gate around GetRawState() while calibrating, // but that would imply background input would temporarily be treated differently for our controls - if (update && CanCalibrate()) + if (CanCalibrate()) UpdateCalibration(state); state -= m_calibration; @@ -162,6 +156,14 @@ std::optional IMUGyroscope::GetState(bool update) return state; } +std::nullopt_t IMUGyroscope::Reset() +{ + // Set calibration to zero. + m_calibration = {}; + RestartCalibration(); + return std::nullopt; +} + ControlState IMUGyroscope::GetDeadzone() const { return m_deadzone_setting.GetValue() / 360 * MathUtil::TAU; diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.h index 505ff93262..7cdca9146e 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.h @@ -23,7 +23,7 @@ public: StateData GetRawState() const; // Also updates the state by default - std::optional GetState(bool update = true); + std::optional GetState(); // Value is in rad/s. ControlState GetDeadzone() const; @@ -35,6 +35,8 @@ private: bool AreInputsBound() const; bool CanCalibrate() const; + std::nullopt_t Reset(); + std::optional GetStateInternal(); void RestartCalibration(); void UpdateCalibration(const StateData&);