summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu/StickGate.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2020-03-15 15:06:54 +0100
committerGitHub <noreply@github.com>2020-03-15 15:06:54 +0100
commit4944e4b42972034db49691947bd7f9d0de0e3bbc (patch)
tree130287c8fde2abe42f6add799266c1dd4d951724 /Source/Core/InputCommon/ControllerEmu/StickGate.cpp
parent0bf05009d0923ba5012718c7cfb2c6992a20cf35 (diff)
parent2451a41a48ae283bc66bd85f8a34093233552a53 (diff)
Merge pull request #8647 from jordan-woyak/minor-input-cleanups
InputCommon: Minor ReshapableInput related cleanups.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/StickGate.cpp')
-rw-r--r--Source/Core/InputCommon/ControllerEmu/StickGate.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/StickGate.cpp b/Source/Core/InputCommon/ControllerEmu/StickGate.cpp
index 0b16103773..5e2acb3f5b 100644
--- a/Source/Core/InputCommon/ControllerEmu/StickGate.cpp
+++ b/Source/Core/InputCommon/ControllerEmu/StickGate.cpp
@@ -54,7 +54,7 @@ constexpr int ReshapableInput::CALIBRATION_SAMPLE_COUNT;
std::optional<u32> StickGate::GetIdealCalibrationSampleCount() const
{
- return {};
+ return std::nullopt;
}
OctagonStickGate::OctagonStickGate(ControlState radius) : m_radius(radius)
@@ -86,6 +86,12 @@ ControlState RoundStickGate::GetRadiusAtAngle(double) const
return m_radius;
}
+std::optional<u32> RoundStickGate::GetIdealCalibrationSampleCount() const
+{
+ // The "radius" is the same at every angle so a single sample is enough.
+ return 1;
+}
+
SquareStickGate::SquareStickGate(ControlState half_width) : m_half_width(half_width)
{
}
@@ -177,7 +183,8 @@ void ReshapableInput::UpdateCalibrationData(CalibrationData& data, Common::DVec2
auto& calibration_sample = data[calibration_index];
// Update closest sample from provided x,y.
- calibration_sample = std::max(calibration_sample, point.Length());
+ calibration_sample = std::clamp(point.Length(), calibration_sample,
+ SquareStickGate(1).GetRadiusAtAngle(calibration_angle));
// Here we update all other samples in our calibration vector to maintain
// a convex polygon containing our new calibration point.
@@ -275,10 +282,11 @@ void ReshapableInput::SaveConfig(IniFile::Section* section, const std::string& d
[](ControlState val) { return fmt::format("{:.2f}", val * CALIBRATION_CONFIG_SCALE); });
section->Set(group + CALIBRATION_CONFIG_NAME, JoinStrings(save_data, " "), "");
- const auto center_data = fmt::format("{:.2f} {:.2f}", m_center.x * CENTER_CONFIG_SCALE,
+ // Save center value.
+ static constexpr char center_format[] = "{:.2f} {:.2f}";
+ const auto center_data = fmt::format(center_format, m_center.x * CENTER_CONFIG_SCALE,
m_center.y * CENTER_CONFIG_SCALE);
-
- section->Set(group + CENTER_CONFIG_NAME, center_data, "");
+ section->Set(group + CENTER_CONFIG_NAME, center_data, fmt::format(center_format, 0.0, 0.0));
}
ReshapableInput::ReshapeData ReshapableInput::Reshape(ControlState x, ControlState y,