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.
This commit is contained in:
JosJuice
2021-03-21 22:42:33 +01:00
parent 8fd25259ee
commit b296248b49
21 changed files with 557 additions and 507 deletions

View File

@ -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).