diff options
| author | JosJuice <josjuice@gmail.com> | 2021-03-21 20:27:00 +0100 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2022-10-03 22:00:21 +0200 |
| commit | cb16d20f2d4ed1ebf150b6ba4d64fe469c1263f1 (patch) | |
| tree | 4cf6bf751dd1cdea3d199f5885571598325d44d7 /Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp | |
| parent | cb6d476538afe85c25d30e8679b6f15abe5d1760 (diff) | |
ControllerEmu: Add new "input override" system
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp index 539e02b449..0f30b50f63 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp @@ -4,6 +4,7 @@ #include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h" #include <cmath> +#include <optional> #include "Common/Common.h" #include "Common/MathUtil.h" @@ -48,6 +49,34 @@ AnalogStick::StateData AnalogStick::GetState() const return GetReshapableState(true); } +AnalogStick::StateData AnalogStick::GetState(const InputOverrideFunction& override_func) const +{ + bool override_occurred = false; + return GetState(override_func, &override_occurred); +} + +AnalogStick::StateData AnalogStick::GetState(const InputOverrideFunction& override_func, + bool* override_occurred) const +{ + StateData state = GetState(); + if (!override_func) + return state; + + if (const std::optional<ControlState> x_override = override_func(name, X_INPUT_OVERRIDE, state.x)) + { + state.x = *x_override; + *override_occurred = true; + } + + if (const std::optional<ControlState> y_override = override_func(name, Y_INPUT_OVERRIDE, state.y)) + { + state.y = *y_override; + *override_occurred = true; + } + + return state; +} + ControlState AnalogStick::GetGateRadiusAtAngle(double ang) const { return m_stick_gate->GetRadiusAtAngle(ang); |
