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
|
|
|
|
{
|
2020-10-29 22:11:34 +00:00
|
|
|
// Minimum stick distance from the center before virtual notches are applied.
|
|
|
|
constexpr ControlState MINIMUM_NOTCH_DISTANCE = 0.9;
|
|
|
|
|
2018-12-21 22:11:00 +00:00
|
|
|
// 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;
|
2020-02-24 22:55:44 +00:00
|
|
|
std::optional<u32> GetIdealCalibrationSampleCount() const override final;
|
2018-12-21 22:11:00 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2020-10-29 22:11:34 +00:00
|
|
|
virtual ControlState GetVirtualNotchSize() const { return 0.0; };
|
|
|
|
|
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);
|
|
|
|
|
2020-09-19 13:40:36 +00:00
|
|
|
static void UpdateCalibrationData(CalibrationData& data, Common::DVec2 point1,
|
|
|
|
Common::DVec2 point2);
|
2019-02-05 00:50:07 +00:00
|
|
|
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);
|
|
|
|
|
2019-04-12 20:26:34 +00:00
|
|
|
const ReshapeData& GetCenter() const;
|
|
|
|
void SetCenter(ReshapeData center);
|
|
|
|
|
2019-02-05 00:50:07 +00:00
|
|
|
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;
|
2019-04-12 20:26:34 +00:00
|
|
|
ReshapeData m_center;
|
2018-12-29 22:06:03 +00:00
|
|
|
};
|
|
|
|
|
2018-12-21 22:11:00 +00:00
|
|
|
} // namespace ControllerEmu
|