summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon
diff options
context:
space:
mode:
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).