diff --git a/Source/Core/InputCommon/ControllerEmu/Control/Control.h b/Source/Core/InputCommon/ControllerEmu/Control/Control.h index bfdd54dd60..4a1bb585de 100644 --- a/Source/Core/InputCommon/ControllerEmu/Control/Control.h +++ b/Source/Core/InputCommon/ControllerEmu/Control/Control.h @@ -23,7 +23,7 @@ public: virtual ~Control(); template - T GetState() + T GetState() const { return control_ref->GetState(); } diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp index 881be39471..36733c9f7e 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp @@ -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); } diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h index ac0266f7c1..a5ea05a211 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h @@ -18,10 +18,10 @@ public: AnalogStick(const char* name, std::unique_ptr&& stick_gate); AnalogStick(const char* name, const char* ui_name, std::unique_ptr&& 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 m_stick_gate; diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h index b10677a615..707c93fa81 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h @@ -20,7 +20,7 @@ public: Buttons(const std::string& ini_name, const std::string& group_name); template - 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(); diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp index fa379624db..4dbb5a11ed 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp @@ -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(); diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h index 562313bb45..a6b38fb4bb 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h @@ -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. diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp index af9246c54d..457b36205b 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp @@ -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(); diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.h index ae9cabe340..983f668d78 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.h @@ -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; diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.cpp index bd70c64b53..d8aeea4eee 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.cpp @@ -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(); diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.h index de969f59b5..930241d7fe 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.h @@ -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 m_deadzone_setting; diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.cpp index 69739bc330..053d0bf429 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.cpp @@ -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); } diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.h index dc4c2364de..cb50c5eb73 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.h @@ -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; diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.cpp index bdfec69808..7aaac42b72 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.cpp @@ -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; diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.h index 8b72d6738b..5d75ff09bc 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.h @@ -26,7 +26,7 @@ public: explicit Triggers(const std::string& name); - StateData GetState(); + StateData GetState() const; private: SettingValue m_deadzone_setting; diff --git a/Source/Core/InputCommon/ControllerEmu/StickGate.cpp b/Source/Core/InputCommon/ControllerEmu/StickGate.cpp index 797d19aadf..d1b230c373 100644 --- a/Source/Core/InputCommon/ControllerEmu/StickGate.cpp +++ b/Source/Core/InputCommon/ControllerEmu/StickGate.cpp @@ -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; diff --git a/Source/Core/InputCommon/ControllerEmu/StickGate.h b/Source/Core/InputCommon/ControllerEmu/StickGate.h index 8a0a0ab100..015c77e9a4 100644 --- a/Source/Core/InputCommon/ControllerEmu/StickGate.h +++ b/Source/Core/InputCommon/ControllerEmu/StickGate.h @@ -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; diff --git a/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.cpp b/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.cpp index 75f69b8823..a749f83a01 100644 --- a/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.cpp @@ -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 diff --git a/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.h b/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.h index 2139c2e2ca..13b52bb989 100644 --- a/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.h +++ b/Source/Core/InputCommon/ControllerInterface/Touch/ButtonManager.h @@ -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 m_buttons; - std::map m_axises; + std::map m_axes; // Key is pad_id and ButtonType std::map, 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&); diff --git a/Source/Core/InputCommon/InputConfig.cpp b/Source/Core/InputCommon/InputConfig.cpp index 07a9b62daf..140e66e261 100644 --- a/Source/Core/InputCommon/InputConfig.cpp +++ b/Source/Core/InputCommon/InputConfig.cpp @@ -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(); } diff --git a/Source/Core/InputCommon/InputConfig.h b/Source/Core/InputCommon/InputConfig.h index 0eeeedaed8..a873e82503 100644 --- a/Source/Core/InputCommon/InputConfig.h +++ b/Source/Core/InputCommon/InputConfig.h @@ -34,7 +34,7 @@ public: m_controllers.emplace_back(std::make_unique(std::forward(args)...)); } - ControllerEmu::EmulatedController* GetController(int index); + ControllerEmu::EmulatedController* GetController(int index) const; void ClearControllers(); bool ControllersNeedToBeCreated() const; bool IsControllerControlledByGamepadDevice(int index) const;