InputCommon: Add types to ControllerEmu that represent raw controller inputs and calibration data to calculate normalized input values.

This commit is contained in:
Jordan Woyak 2020-01-21 18:32:03 -06:00
parent 259a7191d2
commit 8343dadd58
2 changed files with 118 additions and 0 deletions

View file

@ -300,6 +300,12 @@ void SetBit(T& value, size_t bit_number, bool bit_value)
value &= ~(T{1} << bit_number);
}
template <size_t bit_number, typename T>
void SetBit(T& value, bool bit_value)
{
SetBit(value, bit_number, bit_value);
}
template <typename T>
class FlagBit
{
@ -340,4 +346,15 @@ public:
std::underlying_type_t<T> m_hex = 0;
};
// Left-shift a value and set new LSBs to that of the supplied LSB.
// Converts a value from a N-bit range to an (N+X)-bit range. e.g. 0x101 -> 0x10111
template <typename T>
T ExpandValue(T value, size_t left_shift_amount)
{
static_assert(std::is_unsigned<T>(), "ExpandValue is only sane on unsigned types.");
return (value << left_shift_amount) |
(T(-ExtractBit<0>(value)) >> (BitSize<T>() - left_shift_amount));
}
} // namespace Common