summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2021-03-21 22:42:33 +0100
committerJosJuice <josjuice@gmail.com>2022-10-03 22:04:09 +0200
commitb296248b49d3cfe130756feda5941d717fdba75d (patch)
tree7610e534e8780530a3e103ede860725420091bdd /Source/Core/InputCommon
parent8fd25259ee27240b0993e9f348ba2431799437af (diff)
DolphinQt: Use input override system for TAS input windows
This lets the TAS input code use a higher-level interface for overriding inputs instead of having to fiddle with raw bits. WiiTASInputWindow in particular was messy with how much controller code it had to re-implement.
Diffstat (limited to 'Source/Core/InputCommon')
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControllerEmu.h26
1 files changed, 23 insertions, 3 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h
index b0e514d20a..e7e957e608 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h
+++ b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h
@@ -20,8 +20,13 @@
class ControllerInterface;
-const char* const named_directions[] = {_trans("Up"), _trans("Down"), _trans("Left"),
- _trans("Right")};
+constexpr const char* DIRECTION_UP = _trans("Up");
+constexpr const char* DIRECTION_DOWN = _trans("Down");
+constexpr const char* DIRECTION_LEFT = _trans("Left");
+constexpr const char* DIRECTION_RIGHT = _trans("Right");
+
+constexpr const char* named_directions[] = {DIRECTION_UP, DIRECTION_DOWN, DIRECTION_LEFT,
+ DIRECTION_RIGHT};
class ControlReference;
@@ -204,7 +209,7 @@ public:
std::vector<std::unique_ptr<ControlGroup>> groups;
- // Maps a float from -1.0..+1.0 to an integer of the provided values.
+ // Maps a float from -1.0..+1.0 to an integer in the provided range.
template <typename T, typename F>
static T MapFloat(F input_value, T zero_value, T neg_1_value = std::numeric_limits<T>::min(),
T pos_1_value = std::numeric_limits<T>::max())
@@ -227,6 +232,21 @@ public:
return T(std::llround((zero_value - neg_1_value) * input_value + zero_value));
}
+ // The inverse of the function above.
+ // Maps an integer in the provided range to a float in the range -1.0..1.0.
+ template <typename F, typename T>
+ static F MapToFloat(T input_value, T zero_value, T neg_1_value = std::numeric_limits<T>::min(),
+ T pos_1_value = std::numeric_limits<T>::max())
+ {
+ static_assert(std::is_integral<T>(), "T is only sane for int types.");
+ static_assert(std::is_floating_point<F>(), "F is only sane for float types.");
+
+ if (input_value >= zero_value)
+ return F(input_value - zero_value) / F(pos_1_value - zero_value);
+ else
+ return -F(zero_value - input_value) / F(zero_value - neg_1_value);
+ }
+
protected:
// TODO: Wiimote attachments actually end up using their parent controller value for this,
// so theirs won't be used (and thus shouldn't even exist).