diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2020-07-04 22:19:26 -0500 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2020-07-11 19:55:14 -0500 |
| commit | 5299e902aa7fe9f474b5e3dd37a5a04f9f3e6bbb (patch) | |
| tree | 7c8df15c1cabcd1590fffd09f54eb8d91d3e12b7 /Source/Core/InputCommon/ControllerEmu | |
| parent | ed32a2a1fe1d63f3ac1d9380b2328ebff39668e8 (diff) | |
ControllerInterface/Wiimote: Provide fallback values for extensions with bad calibration data.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu')
| -rw-r--r-- | Source/Core/InputCommon/ControllerEmu/ControllerEmu.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h index 3301672ccf..b6808f1c0b 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h +++ b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h @@ -14,6 +14,7 @@ #include "Common/BitUtils.h" #include "Common/Common.h" #include "Common/IniFile.h" +#include "Common/MathUtil.h" #include "InputCommon/ControlReference/ExpressionParser.h" #include "InputCommon/ControllerInterface/Device.h" @@ -37,6 +38,20 @@ struct TwoPointCalibration TwoPointCalibration() = default; TwoPointCalibration(const T& zero_, const T& max_) : zero{zero_}, max{max_} {} + // Sanity check is that max and zero are not equal. + constexpr bool IsSane() const + { + if constexpr (std::is_arithmetic_v<T>) + { + return max != zero; + } + else + { + return std::equal(std::begin(max.data), std::end(max.data), std::begin(zero.data), + std::not_equal_to<>()); + } + } + static constexpr size_t BITS_OF_PRECISION = Bits; T zero; @@ -53,6 +68,28 @@ struct ThreePointCalibration { } + // Sanity check is that min and max are on opposite sides of the zero value. + constexpr bool IsSane() const + { + if constexpr (std::is_arithmetic_v<T>) + { + return MathUtil::Sign(zero - min) * MathUtil::Sign(zero - max) == -1; + } + else + { + for (size_t i = 0; i != std::size(zero.data); ++i) + { + if (MathUtil::Sign(zero.data[i] - min.data[i]) * + MathUtil::Sign(zero.data[i] - max.data[i]) != + -1) + { + return false; + } + } + return true; + } + } + static constexpr size_t BITS_OF_PRECISION = Bits; T min; |
