Merge pull request #8647 from jordan-woyak/minor-input-cleanups

InputCommon: Minor ReshapableInput related cleanups.
This commit is contained in:
Léo Lam
2020-03-15 15:06:54 +01:00
committed by GitHub
4 changed files with 41 additions and 29 deletions

View File

@ -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,

View File

@ -48,6 +48,7 @@ class RoundStickGate : public StickGate
public:
explicit RoundStickGate(ControlState radius);
ControlState GetRadiusAtAngle(double ang) const override final;
std::optional<u32> GetIdealCalibrationSampleCount() const override final;
private:
const ControlState m_radius;