summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2022-10-03 16:25:40 -0400
committerGitHub <noreply@github.com>2022-10-03 16:25:40 -0400
commit052c7395fbc0789147703a4c5cc754ae28f8f8bd (patch)
treec6e206df257937e8373aeeb012e29ea74f0d0fc7 /Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp
parentcb6d476538afe85c25d30e8679b6f15abe5d1760 (diff)
parent51ee05cb35f401c82adf815cbb4f4c3133e7ea84 (diff)
Merge pull request #9624 from JosJuice/input-override
Add new "input override" system for TAS input and Android touch controls
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp')
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp29
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);