DolphinQt/ControllerEmu: Replace Input Radius/Shape settings with an input calibration "wizard".

This commit is contained in:
Jordan Woyak
2019-02-04 18:50:07 -06:00
parent 46918f420d
commit 0064f70c8a
13 changed files with 592 additions and 95 deletions

View File

@ -4,6 +4,11 @@
#pragma once
#include <optional>
#include <vector>
#include "Common/Matrix.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
@ -16,6 +21,10 @@ public:
// Angle is in radians and should be non-negative
virtual ControlState GetRadiusAtAngle(double ang) const = 0;
// This is provided purely as an optimization for ReshapableInput to produce a minimal amount of
// calibration points that are saved in our config.
virtual std::optional<u32> GetIdealCalibrationSampleCount() const;
virtual ~StickGate() = default;
};
@ -26,6 +35,7 @@ public:
// Radius of circumscribed circle
explicit OctagonStickGate(ControlState radius);
ControlState GetRadiusAtAngle(double ang) const override final;
std::optional<u32> GetIdealCalibrationSampleCount() const override final;
private:
const ControlState m_radius;
@ -48,6 +58,7 @@ class SquareStickGate : public StickGate
public:
explicit SquareStickGate(ControlState half_width);
ControlState GetRadiusAtAngle(double ang) const override final;
std::optional<u32> GetIdealCalibrationSampleCount() const override final;
private:
const ControlState m_half_width;
@ -56,37 +67,47 @@ private:
class ReshapableInput : public ControlGroup
{
public:
// This is the number of samples we generate but any number could be loaded from config.
static constexpr int CALIBRATION_SAMPLE_COUNT = 32;
// Contains input radius maximums at evenly-spaced angles.
using CalibrationData = std::vector<ControlState>;
ReshapableInput(std::string name, std::string ui_name, GroupType type);
struct ReshapeData
{
ControlState x{};
ControlState y{};
};
using ReshapeData = Common::DVec2;
enum
{
SETTING_INPUT_RADIUS,
SETTING_INPUT_SHAPE,
SETTING_DEADZONE,
SETTING_COUNT,
};
// Angle is in radians and should be non-negative
ControlState GetDeadzoneRadiusAtAngle(double ang) const;
ControlState GetInputRadiusAtAngle(double ang) const;
ControlState GetDeadzoneRadiusAtAngle(double angle) const;
ControlState GetInputRadiusAtAngle(double angle) const;
virtual ControlState GetGateRadiusAtAngle(double ang) const = 0;
virtual ControlState GetGateRadiusAtAngle(double angle) const = 0;
virtual ReshapeData GetReshapableState(bool adjusted) = 0;
virtual ControlState GetDefaultInputRadiusAtAngle(double ang) const;
void SetCalibrationToDefault();
void SetCalibrationFromGate(const StickGate& gate);
static void UpdateCalibrationData(CalibrationData& data, Common::DVec2 point);
static ControlState GetCalibrationDataRadiusAtAngle(const CalibrationData& data, double angle);
const CalibrationData& GetCalibrationData() const;
void SetCalibrationData(CalibrationData data);
protected:
void AddReshapingSettings(ControlState default_radius, ControlState default_shape,
int max_deadzone);
ReshapeData Reshape(ControlState x, ControlState y, ControlState modifier = 0.0);
private:
ControlState CalculateInputShapeRadiusAtAngle(double ang) const;
void LoadConfig(IniFile::Section*, const std::string&, const std::string&) override;
void SaveConfig(IniFile::Section*, const std::string&, const std::string&) override;
CalibrationData m_calibration;
};
} // namespace ControllerEmu