InputCommon: add a ton of missing consts
fix some related grammar errors only the ButtonManager required code changes
This commit is contained in:
parent
d586163e38
commit
a261e61e9e
|
@ -23,7 +23,7 @@ public:
|
|||
virtual ~Control();
|
||||
|
||||
template <typename T = ControlState>
|
||||
T GetState()
|
||||
T GetState() const
|
||||
{
|
||||
return control_ref->GetState<T>();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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>();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
|
||||
explicit Triggers(const std::string& name);
|
||||
|
||||
StateData GetState();
|
||||
StateData GetState() const;
|
||||
|
||||
private:
|
||||
SettingValue<double> m_deadzone_setting;
|
||||
|
|
|
@ -280,7 +280,7 @@ void ReshapableInput::SaveConfig(IniFile::Section* section, const std::string& d
|
|||
}
|
||||
|
||||
ReshapableInput::ReshapeData ReshapableInput::Reshape(ControlState x, ControlState y,
|
||||
ControlState modifier)
|
||||
ControlState modifier) const
|
||||
{
|
||||
x -= m_center.x;
|
||||
y -= m_center.y;
|
||||
|
|
|
@ -91,7 +91,7 @@ public:
|
|||
virtual ControlState GetVirtualNotchSize() const { return 0.0; };
|
||||
|
||||
virtual ControlState GetGateRadiusAtAngle(double angle) const = 0;
|
||||
virtual ReshapeData GetReshapableState(bool adjusted) = 0;
|
||||
virtual ReshapeData GetReshapableState(bool adjusted) const = 0;
|
||||
virtual ControlState GetDefaultInputRadiusAtAngle(double ang) const;
|
||||
|
||||
void SetCalibrationToDefault();
|
||||
|
@ -108,7 +108,7 @@ public:
|
|||
void SetCenter(ReshapeData center);
|
||||
|
||||
protected:
|
||||
ReshapeData Reshape(ControlState x, ControlState y, ControlState modifier = 0.0);
|
||||
ReshapeData Reshape(ControlState x, ControlState y, ControlState modifier = 0.0) const;
|
||||
|
||||
private:
|
||||
void LoadConfig(IniFile::Section*, const std::string&, const std::string&) override;
|
||||
|
|
|
@ -766,7 +766,7 @@ bool InputDevice::PressEvent(int button, int action)
|
|||
if (binding.second->m_bind_type == BIND_BUTTON)
|
||||
m_buttons[binding.second->m_button_type] = action == BUTTON_PRESSED ? true : false;
|
||||
else
|
||||
m_axises[binding.second->m_button_type] = action == BUTTON_PRESSED ? 1.0f : 0.0f;
|
||||
m_axes[binding.second->m_button_type] = action == BUTTON_PRESSED ? 1.0f : 0.0f;
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
|
@ -780,34 +780,54 @@ void InputDevice::AxisEvent(int axis, float value)
|
|||
if (binding.second->m_bind == axis)
|
||||
{
|
||||
if (binding.second->m_bind_type == BIND_AXIS)
|
||||
m_axises[binding.second->m_button_type] = value;
|
||||
m_axes[binding.second->m_button_type] = value;
|
||||
else
|
||||
m_buttons[binding.second->m_button_type] = value > 0.5f ? true : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool InputDevice::ButtonValue(int pad_id, ButtonType button)
|
||||
bool InputDevice::ButtonValue(int pad_id, ButtonType button) const
|
||||
{
|
||||
const auto& binding = m_input_binds.find(std::make_pair(pad_id, button));
|
||||
const auto binding = m_input_binds.find(std::make_pair(pad_id, button));
|
||||
if (binding == m_input_binds.end())
|
||||
return false;
|
||||
|
||||
if (binding->second->m_bind_type == BIND_BUTTON)
|
||||
return m_buttons[binding->second->m_button_type];
|
||||
{
|
||||
const auto button = m_buttons.find(binding->second->m_button_type);
|
||||
if (button == m_buttons.end())
|
||||
return false;
|
||||
return button->second;
|
||||
}
|
||||
else
|
||||
return (m_axises[binding->second->m_button_type] * binding->second->m_neg) > 0.5f;
|
||||
{
|
||||
const auto axis = m_axes.find(binding->second->m_button_type);
|
||||
if (axis == m_axes.end())
|
||||
return false;
|
||||
return (axis->second * binding->second->m_neg) > 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
float InputDevice::AxisValue(int pad_id, ButtonType axis)
|
||||
float InputDevice::AxisValue(int pad_id, ButtonType axis) const
|
||||
{
|
||||
const auto& binding = m_input_binds.find(std::make_pair(pad_id, axis));
|
||||
const auto binding = m_input_binds.find(std::make_pair(pad_id, axis));
|
||||
if (binding == m_input_binds.end())
|
||||
return 0.0f;
|
||||
|
||||
if (binding->second->m_bind_type == BIND_AXIS)
|
||||
return m_axises[binding->second->m_button_type] * binding->second->m_neg;
|
||||
{
|
||||
const auto axis = m_axes.find(binding->second->m_button_type);
|
||||
if (axis == m_axes.end())
|
||||
return 0.0f;
|
||||
return axis->second * binding->second->m_neg;
|
||||
}
|
||||
else
|
||||
return m_buttons[binding->second->m_button_type] == BUTTON_PRESSED ? 1.0f : 0.0f;
|
||||
{
|
||||
const auto button = m_buttons.find(binding->second->m_button_type);
|
||||
if (button == m_buttons.end())
|
||||
return 0.0f;
|
||||
return button->second == BUTTON_PRESSED ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
} // namespace ButtonManager
|
||||
|
|
|
@ -210,7 +210,7 @@ private:
|
|||
public:
|
||||
Button() : m_state(BUTTON_RELEASED) {}
|
||||
void SetState(ButtonState state) { m_state = state; }
|
||||
bool Pressed() { return m_state == BUTTON_PRESSED; }
|
||||
bool Pressed() const { return m_state == BUTTON_PRESSED; }
|
||||
~Button() {}
|
||||
};
|
||||
class Axis
|
||||
|
@ -221,7 +221,7 @@ private:
|
|||
public:
|
||||
Axis() : m_value(0.0f) {}
|
||||
void SetValue(float value) { m_value = value; }
|
||||
float AxisValue() { return m_value; }
|
||||
float AxisValue() const { return m_value; }
|
||||
~Axis() {}
|
||||
};
|
||||
|
||||
|
@ -244,7 +244,7 @@ class InputDevice
|
|||
private:
|
||||
const std::string m_dev;
|
||||
std::map<ButtonType, bool> m_buttons;
|
||||
std::map<ButtonType, float> m_axises;
|
||||
std::map<ButtonType, float> m_axes;
|
||||
|
||||
// Key is pad_id and ButtonType
|
||||
std::map<std::pair<int, ButtonType>, sBind*> m_input_binds;
|
||||
|
@ -263,8 +263,8 @@ public:
|
|||
}
|
||||
bool PressEvent(int button, int action);
|
||||
void AxisEvent(int axis, float value);
|
||||
bool ButtonValue(int pad_id, ButtonType button);
|
||||
float AxisValue(int pad_id, ButtonType axis);
|
||||
bool ButtonValue(int pad_id, ButtonType button) const;
|
||||
float AxisValue(int pad_id, ButtonType axis) const;
|
||||
};
|
||||
|
||||
void Init(const std::string&);
|
||||
|
|
|
@ -171,7 +171,7 @@ void InputConfig::SaveConfig()
|
|||
inifile.Save(ini_filename);
|
||||
}
|
||||
|
||||
ControllerEmu::EmulatedController* InputConfig::GetController(int index)
|
||||
ControllerEmu::EmulatedController* InputConfig::GetController(int index) const
|
||||
{
|
||||
return m_controllers.at(index).get();
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
m_controllers.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
ControllerEmu::EmulatedController* GetController(int index);
|
||||
ControllerEmu::EmulatedController* GetController(int index) const;
|
||||
void ClearControllers();
|
||||
bool ControllersNeedToBeCreated() const;
|
||||
bool IsControllerControlledByGamepadDevice(int index) const;
|
||||
|
|
Loading…
Reference in New Issue