summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2021-03-21 20:27:00 +0100
committerJosJuice <josjuice@gmail.com>2022-10-03 22:00:21 +0200
commitcb16d20f2d4ed1ebf150b6ba4d64fe469c1263f1 (patch)
tree4cf6bf751dd1cdea3d199f5885571598325d44d7 /Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h
parentcb6d476538afe85c25d30e8679b6f15abe5d1760 (diff)
ControllerEmu: Add new "input override" system
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h')
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h
index 2d02adabf1..652f64ae5f 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h
@@ -3,6 +3,7 @@
#pragma once
+#include <cmath>
#include <string>
#include "InputCommon/ControlReference/ControlReference.h"
@@ -24,5 +25,21 @@ public:
for (auto& control : controls)
*buttons |= *(bitmasks++) * control->GetState<bool>();
}
+
+ template <typename C>
+ void GetState(C* const buttons, const C* bitmasks,
+ const InputOverrideFunction& override_func) const
+ {
+ if (!override_func)
+ return GetState(buttons, bitmasks);
+
+ for (auto& control : controls)
+ {
+ ControlState state = control->GetState();
+ if (std::optional<ControlState> state_override = override_func(name, control->name, state))
+ state = *state_override;
+ *buttons |= *(bitmasks++) * (std::lround(state) > 0);
+ }
+ }
};
} // namespace ControllerEmu