Merge pull request #9688 from Filoppi/input_cleanup

Input cleanup
This commit is contained in:
Scott Mansell
2021-05-14 20:51:33 +12:00
committed by GitHub
47 changed files with 239 additions and 185 deletions

View File

@ -32,7 +32,7 @@ AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_,
AddInput(Translate, _trans("Modifier"));
}
AnalogStick::ReshapeData AnalogStick::GetReshapableState(bool adjusted)
AnalogStick::ReshapeData AnalogStick::GetReshapableState(bool adjusted) const
{
const ControlState y = controls[0]->GetState() - controls[1]->GetState();
const ControlState x = controls[3]->GetState() - controls[2]->GetState();
@ -46,7 +46,7 @@ AnalogStick::ReshapeData AnalogStick::GetReshapableState(bool adjusted)
return Reshape(x, y, modifier);
}
AnalogStick::StateData AnalogStick::GetState()
AnalogStick::StateData AnalogStick::GetState() const
{
return GetReshapableState(true);
}

View File

@ -18,10 +18,10 @@ public:
AnalogStick(const char* name, std::unique_ptr<StickGate>&& stick_gate);
AnalogStick(const char* name, const char* ui_name, std::unique_ptr<StickGate>&& stick_gate);
ReshapeData GetReshapableState(bool adjusted) final override;
ReshapeData GetReshapableState(bool adjusted) const final override;
ControlState GetGateRadiusAtAngle(double ang) const override;
StateData GetState();
StateData GetState() const;
private:
std::unique_ptr<StickGate> m_stick_gate;

View File

@ -10,6 +10,7 @@
#include <vector>
#include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/ExtensionPort.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
@ -34,7 +35,11 @@ public:
private:
SettingValue<int> m_selection_value;
NumericSetting<int> m_selection_setting = {&m_selection_value, {""}, 0, 0, 0};
// This is here and not added to the list of numeric_settings because it's serialized differently,
// by string (to be independent from the enum), and visualized differently in the UI.
// For the rest, it's treated similarly to other numeric_settings in the group.
NumericSetting<int> m_selection_setting = {
&m_selection_value, {""}, 0, 0, WiimoteEmu::ExtensionNumber::MAX - 1};
std::vector<std::unique_ptr<EmulatedController>> m_attachments;
};

View File

@ -20,7 +20,7 @@ public:
Buttons(const std::string& ini_name, const std::string& group_name);
template <typename C>
void GetState(C* const buttons, const C* bitmasks)
void GetState(C* const buttons, const C* bitmasks) const
{
for (auto& control : controls)
*buttons |= *(bitmasks++) * control->GetState<bool>();

View File

@ -44,7 +44,7 @@ void ControlGroup::AddDeadzoneSetting(SettingValue<double>* value, double maximu
// i18n: The percent symbol.
_trans("%"),
// i18n: Refers to the dead-zone setting of gamepad inputs.
_trans("Input strength to ignore.")},
_trans("Input strength to ignore and remap.")},
0, 0, maximum_deadzone);
}

View File

@ -64,7 +64,7 @@ Cursor::Cursor(std::string name_, std::string ui_name_)
AddSetting(&m_autohide_setting, {_trans("Auto-Hide")}, false);
}
Cursor::ReshapeData Cursor::GetReshapableState(bool adjusted)
Cursor::ReshapeData Cursor::GetReshapableState(bool adjusted) const
{
const ControlState y = controls[0]->GetState() - controls[1]->GetState();
const ControlState x = controls[3]->GetState() - controls[2]->GetState();

View File

@ -25,9 +25,10 @@ public:
Cursor(std::string name, std::string ui_name);
ReshapeData GetReshapableState(bool adjusted) final override;
ReshapeData GetReshapableState(bool adjusted) const final override;
ControlState GetGateRadiusAtAngle(double ang) const override;
// Modifies the state
StateData GetState(bool adjusted);
// Yaw movement in radians.

View File

@ -65,7 +65,7 @@ Force::Force(const std::string& name_) : ReshapableInput(name_, name_, GroupType
90, 1, 180);
}
Force::ReshapeData Force::GetReshapableState(bool adjusted)
Force::ReshapeData Force::GetReshapableState(bool adjusted) const
{
const ControlState y = controls[0]->GetState() - controls[1]->GetState();
const ControlState x = controls[3]->GetState() - controls[2]->GetState();
@ -77,7 +77,7 @@ Force::ReshapeData Force::GetReshapableState(bool adjusted)
return Reshape(x, y);
}
Force::StateData Force::GetState(bool adjusted)
Force::StateData Force::GetState(bool adjusted) const
{
const auto state = GetReshapableState(adjusted);
ControlState z = controls[4]->GetState() - controls[5]->GetState();

View File

@ -19,12 +19,12 @@ public:
explicit Force(const std::string& name);
ReshapeData GetReshapableState(bool adjusted) final override;
ReshapeData GetReshapableState(bool adjusted) const final override;
ControlState GetGateRadiusAtAngle(double ang) const final override;
ControlState GetDefaultInputRadiusAtAngle(double angle) const final override;
StateData GetState(bool adjusted = true);
StateData GetState(bool adjusted = true) const;
// Velocities returned in m/s.
ControlState GetSpeed() const;

View File

@ -40,7 +40,7 @@ IMUGyroscope::IMUGyroscope(std::string name_, std::string ui_name_)
// i18n: "°/s" is the symbol for degrees (angular measurement) divided by seconds.
_trans("°/s"),
// i18n: Refers to the dead-zone setting of gyroscope input.
_trans("Angular velocity to ignore.")},
_trans("Angular velocity to ignore and remap.")},
2, 0, 180);
AddSetting(&m_calibration_period_setting,

View File

@ -26,52 +26,52 @@ ModifySettingsButton::ModifySettingsButton(std::string button_name)
void ModifySettingsButton::AddInput(std::string button_name, bool toggle)
{
ControlGroup::AddInput(Translate, std::move(button_name));
threshold_exceeded.emplace_back(false);
associated_settings.emplace_back(false);
associated_settings_toggle.emplace_back(toggle);
m_threshold_exceeded.emplace_back(false);
m_associated_settings.emplace_back(false);
m_associated_settings_toggle.emplace_back(toggle);
}
void ModifySettingsButton::GetState()
void ModifySettingsButton::UpdateState()
{
for (size_t i = 0; i < controls.size(); ++i)
{
const bool state = controls[i]->GetState<bool>();
if (!associated_settings_toggle[i])
if (!m_associated_settings_toggle[i])
{
// not toggled
associated_settings[i] = state;
m_associated_settings[i] = state;
}
else
{
// toggle (loading savestates does not en-/disable toggle)
// after we passed the threshold, we en-/disable. but after that, we don't change it
// anymore
if (!threshold_exceeded[i] && state)
if (!m_threshold_exceeded[i] && state)
{
associated_settings[i] = !associated_settings[i];
m_associated_settings[i] = !m_associated_settings[i];
if (associated_settings[i])
if (m_associated_settings[i])
OSD::AddMessage(controls[i]->ui_name + ": on");
else
OSD::AddMessage(controls[i]->ui_name + ": off");
threshold_exceeded[i] = true;
m_threshold_exceeded[i] = true;
}
if (!state)
threshold_exceeded[i] = false;
m_threshold_exceeded[i] = false;
}
}
}
const std::vector<bool>& ModifySettingsButton::isSettingToggled() const
const std::vector<bool>& ModifySettingsButton::IsSettingToggled() const
{
return associated_settings_toggle;
return m_associated_settings_toggle;
}
const std::vector<bool>& ModifySettingsButton::getSettingsModifier() const
const std::vector<bool>& ModifySettingsButton::GetSettingsModifier() const
{
return associated_settings;
return m_associated_settings;
}
} // namespace ControllerEmu

View File

@ -18,14 +18,14 @@ public:
void AddInput(std::string button_name, bool toggle = false);
void GetState();
void UpdateState();
const std::vector<bool>& isSettingToggled() const;
const std::vector<bool>& getSettingsModifier() const;
const std::vector<bool>& IsSettingToggled() const;
const std::vector<bool>& GetSettingsModifier() const;
private:
std::vector<bool> threshold_exceeded; // internal calculation (if "state" was above threshold)
std::vector<bool> associated_settings_toggle; // is setting toggled or hold?
std::vector<bool> associated_settings; // result
std::vector<bool> m_threshold_exceeded; // internal calculation (if "state" was above threshold)
std::vector<bool> m_associated_settings_toggle; // is setting toggled or hold?
std::vector<bool> m_associated_settings; // result
};
} // namespace ControllerEmu

View File

@ -29,7 +29,7 @@ Slider::Slider(const std::string& name_) : Slider(name_, name_)
{
}
Slider::StateData Slider::GetState()
Slider::StateData Slider::GetState() const
{
const ControlState deadzone = m_deadzone_setting.GetValue() / 100;
const ControlState state = controls[1]->GetState() - controls[0]->GetState();

View File

@ -23,7 +23,7 @@ public:
Slider(const std::string& name_, const std::string& ui_name_);
explicit Slider(const std::string& name_);
StateData GetState();
StateData GetState() const;
private:
SettingValue<double> m_deadzone_setting;

View File

@ -42,7 +42,7 @@ Tilt::Tilt(const std::string& name_) : ReshapableInput(name_, name_, GroupType::
7, 1, 50);
}
Tilt::ReshapeData Tilt::GetReshapableState(bool adjusted)
Tilt::ReshapeData Tilt::GetReshapableState(bool adjusted) const
{
const ControlState y = controls[0]->GetState() - controls[1]->GetState();
const ControlState x = controls[3]->GetState() - controls[2]->GetState();
@ -56,7 +56,7 @@ Tilt::ReshapeData Tilt::GetReshapableState(bool adjusted)
return Reshape(x, y, modifier);
}
Tilt::StateData Tilt::GetState()
Tilt::StateData Tilt::GetState() const
{
return GetReshapableState(true);
}

View File

@ -19,14 +19,14 @@ public:
explicit Tilt(const std::string& name);
ReshapeData GetReshapableState(bool adjusted) final override;
ReshapeData GetReshapableState(bool adjusted) const final override;
ControlState GetGateRadiusAtAngle(double angle) const final override;
// Tilt is using the gate radius to adjust the tilt angle so we must provide an unadjusted value
// for the default input radius.
ControlState GetDefaultInputRadiusAtAngle(double angle) const final override;
StateData GetState();
StateData GetState() const;
// Return peak rotational velocity (for a complete turn) in radians/sec
ControlState GetMaxRotationalVelocity() const;

View File

@ -21,7 +21,7 @@ Triggers::Triggers(const std::string& name_) : ControlGroup(name_, GroupType::Tr
AddDeadzoneSetting(&m_deadzone_setting, 50);
}
Triggers::StateData Triggers::GetState()
Triggers::StateData Triggers::GetState() const
{
const size_t trigger_count = controls.size();
const ControlState deadzone = m_deadzone_setting.GetValue() / 100;

View File

@ -26,7 +26,7 @@ public:
explicit Triggers(const std::string& name);
StateData GetState();
StateData GetState() const;
private:
SettingValue<double> m_deadzone_setting;