2018-12-21 22:11:00 +00:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-02-05 00:50:07 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Common/Matrix.h"
|
|
|
|
|
2018-12-21 22:11:00 +00:00
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
2018-12-29 22:06:03 +00:00
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
2019-03-27 00:31:03 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
2018-12-21 22:11:00 +00:00
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
|
|
|
// An abstract class representing the plastic shell that limits an analog stick's movement.
|
|
|
|
class StickGate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Angle is in radians and should be non-negative
|
|
|
|
virtual ControlState GetRadiusAtAngle(double ang) const = 0;
|
|
|
|
|
2019-02-05 00:50:07 +00:00
|
|
|
// 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;
|
|
|
|
|
2018-12-21 22:11:00 +00:00
|
|
|
virtual ~StickGate() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
// An octagon-shaped stick gate is found on most Nintendo GC/Wii analog sticks.
|
|
|
|
class OctagonStickGate : public StickGate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Radius of circumscribed circle
|
|
|
|
explicit OctagonStickGate(ControlState radius);
|
|
|
|
ControlState GetRadiusAtAngle(double ang) const override final;
|
2019-02-05 00:50:07 +00:00
|
|
|
std::optional<u32> GetIdealCalibrationSampleCount() const override final;
|
2018-12-21 22:11:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const ControlState m_radius;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A round-shaped stick gate. Possibly found on 3rd-party accessories.
|
|
|
|
class RoundStickGate : public StickGate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit RoundStickGate(ControlState radius);
|
|
|
|
ControlState GetRadiusAtAngle(double ang) const override final;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const ControlState m_radius;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A square-shaped stick gate. e.g. keyboard input.
|
|
|
|
class SquareStickGate : public StickGate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit SquareStickGate(ControlState half_width);
|
|
|
|
ControlState GetRadiusAtAngle(double ang) const override final;
|
2019-02-05 00:50:07 +00:00
|
|
|
std::optional<u32> GetIdealCalibrationSampleCount() const override final;
|
2018-12-21 22:11:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const ControlState m_half_width;
|
|
|
|
};
|
|
|
|
|
2018-12-29 22:06:03 +00:00
|
|
|
class ReshapableInput : public ControlGroup
|
|
|
|
{
|
|
|
|
public:
|
2019-02-05 00:50:07 +00:00
|
|
|
// 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>;
|
|
|
|
|
2018-12-29 22:06:03 +00:00
|
|
|
ReshapableInput(std::string name, std::string ui_name, GroupType type);
|
|
|
|
|
2019-02-05 00:50:07 +00:00
|
|
|
using ReshapeData = Common::DVec2;
|
2018-12-29 22:06:03 +00:00
|
|
|
|
|
|
|
// Angle is in radians and should be non-negative
|
2019-02-05 00:50:07 +00:00
|
|
|
ControlState GetDeadzoneRadiusAtAngle(double angle) const;
|
|
|
|
ControlState GetInputRadiusAtAngle(double angle) const;
|
2018-12-29 22:06:03 +00:00
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
ControlState GetDeadzonePercentage() const;
|
|
|
|
|
2019-02-05 00:50:07 +00:00
|
|
|
virtual ControlState GetGateRadiusAtAngle(double angle) const = 0;
|
2018-12-30 15:10:32 +00:00
|
|
|
virtual ReshapeData GetReshapableState(bool adjusted) = 0;
|
2019-02-05 00:50:07 +00:00
|
|
|
virtual ControlState GetDefaultInputRadiusAtAngle(double ang) const;
|
2018-12-29 22:06:03 +00:00
|
|
|
|
2019-02-05 00:50:07 +00:00
|
|
|
void SetCalibrationToDefault();
|
|
|
|
void SetCalibrationFromGate(const StickGate& gate);
|
|
|
|
|
|
|
|
static void UpdateCalibrationData(CalibrationData& data, Common::DVec2 point);
|
|
|
|
static ControlState GetCalibrationDataRadiusAtAngle(const CalibrationData& data, double angle);
|
2018-12-29 22:06:03 +00:00
|
|
|
|
2019-02-05 00:50:07 +00:00
|
|
|
const CalibrationData& GetCalibrationData() const;
|
|
|
|
void SetCalibrationData(CalibrationData data);
|
|
|
|
|
|
|
|
protected:
|
2018-12-30 15:10:32 +00:00
|
|
|
ReshapeData Reshape(ControlState x, ControlState y, ControlState modifier = 0.0);
|
2018-12-29 22:06:03 +00:00
|
|
|
|
|
|
|
private:
|
2019-02-05 00:50:07 +00:00
|
|
|
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;
|
2019-03-27 00:31:03 +00:00
|
|
|
SettingValue<double> m_deadzone_setting;
|
2018-12-29 22:06:03 +00:00
|
|
|
};
|
|
|
|
|
2018-12-21 22:11:00 +00:00
|
|
|
} // namespace ControllerEmu
|