diff --git a/Source/Core/Common/Logging/Log.h b/Source/Core/Common/Logging/Log.h index ce136b2c0b..9e45881b1c 100644 --- a/Source/Core/Common/Logging/Log.h +++ b/Source/Core/Common/Logging/Log.h @@ -20,6 +20,7 @@ enum LOG_TYPE COMMANDPROCESSOR, COMMON, CONSOLE, + CONTROLLERINTERFACE, CORE, DISCIO, DSPHLE, diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index b03255ca9e..2c58148fb2 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -123,6 +123,7 @@ LogManager::LogManager() m_log[COMMANDPROCESSOR] = {"CP", "Command Processor"}; m_log[COMMON] = {"COMMON", "Common"}; m_log[CONSOLE] = {"CONSOLE", "Dolphin Console"}; + m_log[CONTROLLERINTERFACE] = {"CI", "Controller Interface"}; m_log[CORE] = {"CORE", "Core"}; m_log[DISCIO] = {"DIO", "Disc IO"}; m_log[DSPHLE] = {"DSPHLE", "DSP HLE"}; diff --git a/Source/Core/Core/HW/GCPadEmu.cpp b/Source/Core/Core/HW/GCPadEmu.cpp index 1ad70afac9..ffcf3f556b 100644 --- a/Source/Core/Core/HW/GCPadEmu.cpp +++ b/Source/Core/Core/HW/GCPadEmu.cpp @@ -93,10 +93,15 @@ GCPad::GCPad(const unsigned int index) : m_index(index) // options groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options"))); - m_options->AddSetting(&m_always_connected_setting, - // i18n: Treat a controller as always being connected regardless of what - // devices the user actually has plugged in - _trans("Always Connected"), false); + m_options->AddSetting( + &m_always_connected_setting, + // i18n: Treat a controller as always being connected regardless of what + // devices the user actually has plugged in + {_trans("Always Connected"), _trans(""), + _trans("Always connected if checked.\n" + "If unchecked, it will link the emulated controller connection state\n" + "to the real default device connection state (if there is one).")}, + false); } std::string GCPad::GetName() const @@ -181,17 +186,17 @@ void GCPad::LoadDefaults(const ControllerInterface& ciface) EmulatedController::LoadDefaults(ciface); // Buttons - m_buttons->SetControlExpression(0, "X"); // A - m_buttons->SetControlExpression(1, "Z"); // B - m_buttons->SetControlExpression(2, "C"); // X - m_buttons->SetControlExpression(3, "S"); // Y - m_buttons->SetControlExpression(4, "D"); // Z + m_buttons->SetControlExpression(0, "`X`"); // A + m_buttons->SetControlExpression(1, "`Z`"); // B + m_buttons->SetControlExpression(2, "`C`"); // X + m_buttons->SetControlExpression(3, "`S`"); // Y + m_buttons->SetControlExpression(4, "`D`"); // Z #ifdef _WIN32 - m_buttons->SetControlExpression(5, "RETURN"); // Start + m_buttons->SetControlExpression(5, "`RETURN`"); // Start #else // OS X/Linux // Start - m_buttons->SetControlExpression(5, "Return"); + m_buttons->SetControlExpression(5, "`Return`"); #endif // stick modifiers to 50 % @@ -199,46 +204,46 @@ void GCPad::LoadDefaults(const ControllerInterface& ciface) m_c_stick->controls[4]->control_ref->range = 0.5f; // D-Pad - m_dpad->SetControlExpression(0, "T"); // Up - m_dpad->SetControlExpression(1, "G"); // Down - m_dpad->SetControlExpression(2, "F"); // Left - m_dpad->SetControlExpression(3, "H"); // Right + m_dpad->SetControlExpression(0, "`T`"); // Up + m_dpad->SetControlExpression(1, "`G`"); // Down + m_dpad->SetControlExpression(2, "`F`"); // Left + m_dpad->SetControlExpression(3, "`H`"); // Right // C Stick - m_c_stick->SetControlExpression(0, "I"); // Up - m_c_stick->SetControlExpression(1, "K"); // Down - m_c_stick->SetControlExpression(2, "J"); // Left - m_c_stick->SetControlExpression(3, "L"); // Right + m_c_stick->SetControlExpression(0, "`I`"); // Up + m_c_stick->SetControlExpression(1, "`K`"); // Down + m_c_stick->SetControlExpression(2, "`J`"); // Left + m_c_stick->SetControlExpression(3, "`L`"); // Right // Modifier - m_c_stick->SetControlExpression(4, "Ctrl"); + m_c_stick->SetControlExpression(4, "`Ctrl`"); // Control Stick #ifdef _WIN32 - m_main_stick->SetControlExpression(0, "UP"); // Up - m_main_stick->SetControlExpression(1, "DOWN"); // Down - m_main_stick->SetControlExpression(2, "LEFT"); // Left - m_main_stick->SetControlExpression(3, "RIGHT"); // Right + m_main_stick->SetControlExpression(0, "`UP`"); // Up + m_main_stick->SetControlExpression(1, "`DOWN`"); // Down + m_main_stick->SetControlExpression(2, "`LEFT`"); // Left + m_main_stick->SetControlExpression(3, "`RIGHT`"); // Right #elif __APPLE__ m_main_stick->SetControlExpression(0, "`Up Arrow`"); // Up m_main_stick->SetControlExpression(1, "`Down Arrow`"); // Down m_main_stick->SetControlExpression(2, "`Left Arrow`"); // Left m_main_stick->SetControlExpression(3, "`Right Arrow`"); // Right #else - m_main_stick->SetControlExpression(0, "Up"); // Up - m_main_stick->SetControlExpression(1, "Down"); // Down - m_main_stick->SetControlExpression(2, "Left"); // Left - m_main_stick->SetControlExpression(3, "Right"); // Right + m_main_stick->SetControlExpression(0, "`Up`"); // Up + m_main_stick->SetControlExpression(1, "`Down`"); // Down + m_main_stick->SetControlExpression(2, "`Left`"); // Left + m_main_stick->SetControlExpression(3, "`Right`"); // Right #endif // Modifier - m_main_stick->SetControlExpression(4, "Shift"); + m_main_stick->SetControlExpression(4, "`Shift`"); // Because our defaults use keyboard input, set calibration shapes to squares. m_c_stick->SetCalibrationFromGate(ControllerEmu::SquareStickGate(1.0)); m_main_stick->SetCalibrationFromGate(ControllerEmu::SquareStickGate(1.0)); // Triggers - m_triggers->SetControlExpression(0, "Q"); // L - m_triggers->SetControlExpression(1, "W"); // R + m_triggers->SetControlExpression(0, "`Q`"); // L + m_triggers->SetControlExpression(1, "`W`"); // R } bool GCPad::GetMicButton() const diff --git a/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp b/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp index bf71f7e6f6..391b0f2136 100644 --- a/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp @@ -19,7 +19,6 @@ #include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteReal/WiimoteReal.h" #include "InputCommon/ControllerEmu/ControlGroup/Attachments.h" -#include "InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h" namespace WiimoteEmu { diff --git a/Source/Core/Core/HW/WiimoteEmu/ExtensionPort.cpp b/Source/Core/Core/HW/WiimoteEmu/ExtensionPort.cpp index 8a9c6de766..c94242da4a 100644 --- a/Source/Core/Core/HW/WiimoteEmu/ExtensionPort.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/ExtensionPort.cpp @@ -23,7 +23,6 @@ void ExtensionPort::AttachExtension(Extension* ext) m_extension = ext; m_i2c_bus.AddSlave(m_extension); - ; } } // namespace WiimoteEmu diff --git a/Source/Core/Core/HW/WiimoteEmu/ExtensionPort.h b/Source/Core/Core/HW/WiimoteEmu/ExtensionPort.h index 3a266bcc07..5cfa0cbbcd 100644 --- a/Source/Core/Core/HW/WiimoteEmu/ExtensionPort.h +++ b/Source/Core/Core/HW/WiimoteEmu/ExtensionPort.h @@ -22,6 +22,8 @@ enum ExtensionNumber : u8 UDRAW_TABLET, DRAWSOME_TABLET, TATACON, + + MAX }; // FYI: An extension must be attached. diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index bb88790eca..4198ba3095 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -428,7 +428,7 @@ void Wiimote::Update() // Hotkey / settings modifier // Data is later accessed in IsSideways and IsUpright - m_hotkeys->GetState(); + m_hotkeys->UpdateState(); // Update our motion simulations. StepDynamics(); @@ -700,15 +700,15 @@ EncryptionKey Wiimote::GetExtensionEncryptionKey() const bool Wiimote::IsSideways() const { - const bool sideways_modifier_toggle = m_hotkeys->getSettingsModifier()[0]; - const bool sideways_modifier_switch = m_hotkeys->getSettingsModifier()[2]; + const bool sideways_modifier_toggle = m_hotkeys->GetSettingsModifier()[0]; + const bool sideways_modifier_switch = m_hotkeys->GetSettingsModifier()[2]; return m_sideways_setting.GetValue() ^ sideways_modifier_toggle ^ sideways_modifier_switch; } bool Wiimote::IsUpright() const { - const bool upright_modifier_toggle = m_hotkeys->getSettingsModifier()[1]; - const bool upright_modifier_switch = m_hotkeys->getSettingsModifier()[3]; + const bool upright_modifier_toggle = m_hotkeys->GetSettingsModifier()[1]; + const bool upright_modifier_switch = m_hotkeys->GetSettingsModifier()[3]; return m_upright_setting.GetValue() ^ upright_modifier_toggle ^ upright_modifier_switch; } diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingNumeric.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingNumeric.cpp index d84310ffa7..bfebe78341 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingNumeric.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/MappingNumeric.cpp @@ -75,6 +75,9 @@ void MappingDouble::Update() MappingBool::MappingBool(MappingWidget* parent, ControllerEmu::NumericSetting* setting) : QCheckBox(parent), m_setting(*setting) { + if (const auto ui_description = m_setting.GetUIDescription()) + setToolTip(tr(ui_description)); + connect(this, &QCheckBox::stateChanged, this, [this, parent](int value) { m_setting.SetValue(value != 0); ConfigChanged(); diff --git a/Source/Core/DolphinQt/Config/ToolTipControls/ToolTipWidget.h b/Source/Core/DolphinQt/Config/ToolTipControls/ToolTipWidget.h index 8b5ffe5518..2aea3e0b29 100644 --- a/Source/Core/DolphinQt/Config/ToolTipControls/ToolTipWidget.h +++ b/Source/Core/DolphinQt/Config/ToolTipControls/ToolTipWidget.h @@ -10,6 +10,8 @@ #include "DolphinQt/Config/Graphics/BalloonTip.h" +constexpr int TOOLTIP_DELAY = 300; + template class ToolTipWidget : public Derived { @@ -25,7 +27,7 @@ private: { if (m_timer_id) return; - m_timer_id = this->startTimer(300); + m_timer_id = this->startTimer(TOOLTIP_DELAY); } void leaveEvent(QEvent* event) override diff --git a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp index c96ea0599c..1a7ca5a8ef 100644 --- a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp +++ b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp @@ -247,22 +247,18 @@ ParseStatus Lexer::Tokenize(std::vector& tokens) class ControlExpression : public Expression { public: - // Keep a shared_ptr to the device so the control pointer doesn't become invalid. - std::shared_ptr m_device; - - explicit ControlExpression(ControlQualifier qualifier_) : qualifier(qualifier_) {} + explicit ControlExpression(ControlQualifier qualifier) : m_qualifier(qualifier) {} ControlState GetValue() const override { - if (s_hotkey_suppressions.IsSuppressed(input)) + if (s_hotkey_suppressions.IsSuppressed(m_input)) return 0; - else - return GetValueIgnoringSuppression(); + return GetValueIgnoringSuppression(); } ControlState GetValueIgnoringSuppression() const { - if (!input) + if (!m_input) return 0.0; // Note: Inputs may return negative values in situations where opposing directions are @@ -271,27 +267,29 @@ public: // FYI: Clamping values greater than 1.0 is purposely not done to support unbounded values in // the future. (e.g. raw accelerometer/gyro data) - return std::max(0.0, input->GetState()); + return std::max(0.0, m_input->GetState()); } void SetValue(ControlState value) override { - if (output) - output->SetState(value); + if (m_output) + m_output->SetState(value); } - int CountNumControls() const override { return (input || output) ? 1 : 0; } + int CountNumControls() const override { return (m_input || m_output) ? 1 : 0; } void UpdateReferences(ControlEnvironment& env) override { - m_device = env.FindDevice(qualifier); - input = env.FindInput(qualifier); - output = env.FindOutput(qualifier); + m_device = env.FindDevice(m_qualifier); + m_input = env.FindInput(m_qualifier); + m_output = env.FindOutput(m_qualifier); } - Device::Input* GetInput() const { return input; }; + Device::Input* GetInput() const { return m_input; }; private: - ControlQualifier qualifier; - Device::Input* input = nullptr; - Device::Output* output = nullptr; + // Keep a shared_ptr to the device so the control pointer doesn't become invalid. + std::shared_ptr m_device; + ControlQualifier m_qualifier; + Device::Input* m_input = nullptr; + Device::Output* m_output = nullptr; }; bool HotkeySuppressions::IsSuppressedIgnoringModifiers(Device::Input* input, @@ -371,6 +369,7 @@ public: } case TOK_ASSIGN: { + // Use this carefully as it's extremely powerful and can end up in unforeseen situations lhs->SetValue(rhs->GetValue()); return lhs->GetValue(); } @@ -565,6 +564,9 @@ private: // This class proxies all methods to its either left-hand child if it has bound controls, or its // right-hand child. Its intended use is for supporting old-style barewords expressions. +// Note that if you have a keyboard device as default device and the expression is a single digit +// number, this will usually resolve in a numerical key instead of a numerical value. +// Though if this expression belongs to NumericSetting, it will likely be simplifed back to a value. class CoalesceExpression : public Expression { public: @@ -945,6 +947,7 @@ static std::unique_ptr ParseBarewordExpression(const std::string& st qualifier.control_name = str; qualifier.has_device = false; + // This control expression will only work (find the specified control) with the default device. return std::make_unique(qualifier); } diff --git a/Source/Core/InputCommon/ControlReference/ExpressionParser.h b/Source/Core/InputCommon/ControlReference/ExpressionParser.h index 9789e9afe0..14670848ae 100644 --- a/Source/Core/InputCommon/ControlReference/ExpressionParser.h +++ b/Source/Core/InputCommon/ControlReference/ExpressionParser.h @@ -63,7 +63,9 @@ public: enum class ParseStatus { Successful, + // Note that the expression could still work in this case (be valid and return a value) SyntaxError, + // Will return the default value EmptyExpression, }; @@ -107,6 +109,7 @@ class ControlQualifier public: bool has_device; Core::DeviceQualifier device_qualifier; + // Makes no distinction between input and output std::string control_name; ControlQualifier() : has_device(false) {} 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/Attachments.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h index f92bd8b1fd..77d44df093 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h @@ -10,6 +10,7 @@ #include #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 m_selection_value; - NumericSetting 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 m_selection_setting = { + &m_selection_value, {""}, 0, 0, WiimoteEmu::ExtensionNumber::MAX - 1}; std::vector> m_attachments; }; 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/ControlGroup.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp index 2862445392..22f2973d32 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp @@ -44,7 +44,7 @@ void ControlGroup::AddDeadzoneSetting(SettingValue* 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); } 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/IMUGyroscope.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp index b5408cfe34..95c74b1896 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp @@ -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, diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp index 6dc200d1e1..1cf2b5a579 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp @@ -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(); - 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& ModifySettingsButton::isSettingToggled() const +const std::vector& ModifySettingsButton::IsSettingToggled() const { - return associated_settings_toggle; + return m_associated_settings_toggle; } -const std::vector& ModifySettingsButton::getSettingsModifier() const +const std::vector& ModifySettingsButton::GetSettingsModifier() const { - return associated_settings; + return m_associated_settings; } } // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h index 667f3e5c7a..b060aa0caa 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h @@ -18,14 +18,14 @@ public: void AddInput(std::string button_name, bool toggle = false); - void GetState(); + void UpdateState(); - const std::vector& isSettingToggled() const; - const std::vector& getSettingsModifier() const; + const std::vector& IsSettingToggled() const; + const std::vector& GetSettingsModifier() const; private: - std::vector threshold_exceeded; // internal calculation (if "state" was above threshold) - std::vector associated_settings_toggle; // is setting toggled or hold? - std::vector associated_settings; // result + std::vector m_threshold_exceeded; // internal calculation (if "state" was above threshold) + std::vector m_associated_settings_toggle; // is setting toggled or hold? + std::vector m_associated_settings; // result }; } // namespace ControllerEmu 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..d57a2402cf 100644 --- a/Source/Core/InputCommon/ControllerEmu/StickGate.cpp +++ b/Source/Core/InputCommon/ControllerEmu/StickGate.cpp @@ -128,6 +128,7 @@ std::optional SquareStickGate::GetIdealCalibrationSampleCount() const ReshapableInput::ReshapableInput(std::string name_, std::string ui_name_, GroupType type_) : ControlGroup(std::move(name_), std::move(ui_name_), type_) { + // 50 is not always enough but users can set it to more with an expression AddDeadzoneSetting(&m_deadzone_setting, 50); } @@ -280,11 +281,16 @@ void ReshapableInput::SaveConfig(IniFile::Section* section, const std::string& d } ReshapableInput::ReshapeData ReshapableInput::Reshape(ControlState x, ControlState y, - ControlState modifier) + ControlState modifier, + ControlState clamp) const { x -= m_center.x; y -= m_center.y; + // We run this even if both x and y will be zero. + // In that case, std::atan2(0, 0) returns a valid non-NaN value, but the exact value + // (which depends on the signs of x and y) does not matter here as dist is zero + // TODO: make the AtAngle functions work with negative angles: ControlState angle = std::atan2(y, x) + MathUtil::TAU; @@ -321,8 +327,8 @@ ReshapableInput::ReshapeData ReshapableInput::Reshape(ControlState x, ControlSta // Scale to the gate shape/radius: dist *= gate_max_dist; - return {std::clamp(std::cos(angle) * dist, -1.0, 1.0), - std::clamp(std::sin(angle) * dist, -1.0, 1.0)}; + return {std::clamp(std::cos(angle) * dist, -clamp, clamp), + std::clamp(std::sin(angle) * dist, -clamp, clamp)}; } } // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/StickGate.h b/Source/Core/InputCommon/ControllerEmu/StickGate.h index 8a0a0ab100..c2b2f7b183 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,8 @@ 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, + ControlState clamp = 1.0) const; private: void LoadConfig(IniFile::Section*, const std::string&, const std::string&) override; diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index fe176ce7f7..0cae47c741 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -237,7 +237,7 @@ void ControllerInterface::AddDevice(std::shared_ptr device device->SetId(id); } - NOTICE_LOG_FMT(SERIALINTERFACE, "Added device: {}", device->GetQualifiedName()); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "Added device: {}", device->GetQualifiedName()); m_devices.emplace_back(std::move(device)); } @@ -252,7 +252,7 @@ void ControllerInterface::RemoveDevice(std::functionGetQualifiedName()); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "Removed device: {}", dev->GetQualifiedName()); return true; } return false; diff --git a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp index 99767dee4c..ea855632c9 100644 --- a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPClient.cpp @@ -205,7 +205,7 @@ static bool IsSameController(const Proto::MessageType::PortInfo& a, static void HotplugThreadFunc() { Common::SetCurrentThreadName("DualShockUDPClient Hotplug Thread"); - INFO_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient hotplug thread started"); + INFO_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient hotplug thread started"); while (s_hotplug_thread_running.IsSet()) { @@ -225,7 +225,7 @@ static void HotplugThreadFunc() if (server.m_socket.send(&list_ports, sizeof list_ports, server.m_address, server.m_port) != sf::Socket::Status::Done) { - ERROR_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient HotplugThreadFunc send failed"); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient HotplugThreadFunc send failed"); } } } @@ -277,7 +277,7 @@ static void HotplugThreadFunc() } } } - INFO_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient hotplug thread stopped"); + INFO_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient hotplug thread stopped"); } static void StartHotplugThread() @@ -310,7 +310,7 @@ static void StopHotplugThread() static void Restart() { - INFO_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient Restart"); + INFO_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient Restart"); StopHotplugThread(); @@ -394,7 +394,7 @@ void Init() void PopulateDevices() { - INFO_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient PopulateDevices"); + INFO_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient PopulateDevices"); // s_servers has already been updated so we can't use it to know which devices we removed, // also it's good to remove all of them before adding new ones so that their id will be set @@ -510,7 +510,7 @@ void Device::UpdateInput() if (m_socket.send(&data_req, sizeof(data_req), m_server_address, m_server_port) != sf::Socket::Status::Done) { - ERROR_LOG_FMT(SERIALINTERFACE, "DualShockUDPClient UpdateInput send failed"); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "DualShockUDPClient UpdateInput send failed"); } } diff --git a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h index 582b483555..5d445e11da 100644 --- a/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h +++ b/Source/Core/InputCommon/ControllerInterface/DualShockUDPClient/DualShockUDPProto.h @@ -249,7 +249,7 @@ struct Message if (crc32_in_header != crc32_calculated) { NOTICE_LOG_FMT( - SERIALINTERFACE, + CONTROLLERINTERFACE, "DualShockUDPClient Received message with bad CRC in header: got {:08x}, expected {:08x}", crc32_in_header, crc32_calculated); return std::nullopt; diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm index de878b6a3e..63bddf499e 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm @@ -178,11 +178,11 @@ void Init(void* window) HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); if (!HIDManager) - ERROR_LOG_FMT(SERIALINTERFACE, "Failed to create HID Manager reference"); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "Failed to create HID Manager reference"); IOHIDManagerSetDeviceMatching(HIDManager, nullptr); if (IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) - ERROR_LOG_FMT(SERIALINTERFACE, "Failed to open HID Manager"); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "Failed to open HID Manager"); // Callbacks for acquisition or loss of a matching device IOHIDManagerRegisterDeviceMatchingCallback(HIDManager, DeviceMatchingCallback, nullptr); @@ -198,7 +198,7 @@ void Init(void* window) // Enable hotplugging s_hotplug_thread = std::thread([] { Common::SetCurrentThreadName("IOHIDManager Hotplug Thread"); - NOTICE_LOG_FMT(SERIALINTERFACE, "IOHIDManager hotplug thread started"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "IOHIDManager hotplug thread started"); IOHIDManagerScheduleWithRunLoop(HIDManager, CFRunLoopGetCurrent(), OurRunLoop); s_stopper.AddToRunLoop(CFRunLoopGetCurrent(), OurRunLoop); @@ -206,7 +206,7 @@ void Init(void* window) s_stopper.RemoveFromRunLoop(CFRunLoopGetCurrent(), OurRunLoop); IOHIDManagerUnscheduleFromRunLoop(HIDManager, CFRunLoopGetCurrent(), OurRunLoop); - NOTICE_LOG_FMT(SERIALINTERFACE, "IOHIDManager hotplug thread stopped"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "IOHIDManager hotplug thread stopped"); }); } diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm index 39794426a8..f08f704275 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm @@ -109,8 +109,9 @@ void Joystick::AddElements(CFArrayRef elements, std::set& co break; } - NOTICE_LOG_FMT(SERIALINTERFACE, "Unknown IOHIDElement, ignoring (Usage: {:x}, Type: {:x})", - usage, IOHIDElementGetType(e)); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, + "Unknown IOHIDElement, ignoring (Usage: {:x}, Type: {:x})", usage, + IOHIDElementGetType(e)); break; } diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index e232fd6ee7..f908181c8d 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -81,7 +81,7 @@ void Init() { #if !SDL_VERSION_ATLEAST(2, 0, 0) if (SDL_Init(SDL_INIT_JOYSTICK) != 0) - ERROR_LOG_FMT(SERIALINTERFACE, "SDL failed to initialize"); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "SDL failed to initialize"); return; #else s_hotplug_thread = std::thread([] { @@ -95,14 +95,14 @@ void Init() if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) != 0) { - ERROR_LOG_FMT(SERIALINTERFACE, "SDL failed to initialize"); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "SDL failed to initialize"); return; } const Uint32 custom_events_start = SDL_RegisterEvents(2); if (custom_events_start == static_cast(-1)) { - ERROR_LOG_FMT(SERIALINTERFACE, "SDL failed to register custom events"); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "SDL failed to register custom events"); return; } s_stop_event_type = custom_events_start; 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/ControllerInterface/Win32/Win32.cpp b/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp index 096ad31827..b7cf19a13d 100644 --- a/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp @@ -53,7 +53,7 @@ void ciface::Win32::Init(void* hwnd) if (FAILED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED))) { - ERROR_LOG_FMT(SERIALINTERFACE, "CoInitializeEx failed: {}", GetLastError()); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "CoInitializeEx failed: {}", GetLastError()); return; } Common::ScopeGuard uninit([] { CoUninitialize(); }); @@ -67,12 +67,12 @@ void ciface::Win32::Init(void* hwnd) ATOM window_class = RegisterClassEx(&window_class_info); if (!window_class) { - NOTICE_LOG_FMT(SERIALINTERFACE, "RegisterClassEx failed: {}", GetLastError()); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "RegisterClassEx failed: {}", GetLastError()); return; } Common::ScopeGuard unregister([&window_class] { if (!UnregisterClass(MAKEINTATOM(window_class), GetModuleHandle(nullptr))) - ERROR_LOG_FMT(SERIALINTERFACE, "UnregisterClass failed: {}", GetLastError()); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "UnregisterClass failed: {}", GetLastError()); }); message_window = CreateWindowEx(0, L"Message", nullptr, 0, 0, 0, 0, 0, HWND_MESSAGE, nullptr, @@ -80,12 +80,12 @@ void ciface::Win32::Init(void* hwnd) promise_guard.Exit(); if (!message_window) { - ERROR_LOG_FMT(SERIALINTERFACE, "CreateWindowEx failed: {}", GetLastError()); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "CreateWindowEx failed: {}", GetLastError()); return; } Common::ScopeGuard destroy([&] { if (!DestroyWindow(message_window)) - ERROR_LOG_FMT(SERIALINTERFACE, "DestroyWindow failed: {}", GetLastError()); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "DestroyWindow failed: {}", GetLastError()); }); std::array devices; @@ -103,7 +103,7 @@ void ciface::Win32::Init(void* hwnd) if (!RegisterRawInputDevices(devices.data(), static_cast(devices.size()), static_cast(sizeof(decltype(devices)::value_type)))) { - ERROR_LOG_FMT(SERIALINTERFACE, "RegisterRawInputDevices failed: {}", GetLastError()); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "RegisterRawInputDevices failed: {}", GetLastError()); return; } @@ -128,18 +128,18 @@ void ciface::Win32::PopulateDevices(void* hwnd) s_done_populating.Reset(); PostMessage(s_message_window, WM_INPUT_DEVICE_CHANGE, 0, 0); if (!s_done_populating.WaitFor(std::chrono::seconds(10))) - ERROR_LOG_FMT(SERIALINTERFACE, "win32 timed out when trying to populate devices"); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "win32 timed out when trying to populate devices"); } else { - ERROR_LOG_FMT(SERIALINTERFACE, + ERROR_LOG_FMT(CONTROLLERINTERFACE, "win32 asked to populate devices, but device thread isn't running"); } } void ciface::Win32::DeInit() { - NOTICE_LOG_FMT(SERIALINTERFACE, "win32 DeInit"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "win32 DeInit"); if (s_thread.joinable()) { PostMessage(s_message_window, WM_DOLPHIN_STOP, 0, 0); diff --git a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp index 214dd323ac..265d81ad40 100644 --- a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp +++ b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp @@ -253,7 +253,7 @@ static void AddDeviceNode(const char* devnode) auto evdev_device = FindDeviceWithUniqueIDAndPhysicalLocation(uniq, phys); if (evdev_device) { - NOTICE_LOG_FMT(SERIALINTERFACE, + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "evdev combining devices with unique id: {}, physical location: {}", uniq, phys); evdev_device->AddNode(devnode, fd, dev); @@ -282,7 +282,7 @@ static void AddDeviceNode(const char* devnode) static void HotplugThreadFunc() { Common::SetCurrentThreadName("evdev Hotplug Thread"); - NOTICE_LOG_FMT(SERIALINTERFACE, "evdev hotplug thread started"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "evdev hotplug thread started"); udev* const udev = udev_new(); Common::ScopeGuard udev_guard([udev] { udev_unref(udev); }); @@ -337,7 +337,7 @@ static void HotplugThreadFunc() AddDeviceNode(devnode); } } - NOTICE_LOG_FMT(SERIALINTERFACE, "evdev hotplug thread stopped"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "evdev hotplug thread stopped"); } static void StartHotplugThread() diff --git a/Source/Core/InputCommon/GCAdapter.cpp b/Source/Core/InputCommon/GCAdapter.cpp index cf16d06b0c..6041defaa3 100644 --- a/Source/Core/InputCommon/GCAdapter.cpp +++ b/Source/Core/InputCommon/GCAdapter.cpp @@ -88,7 +88,8 @@ static void Read() int err = libusb_interrupt_transfer(s_handle, s_endpoint_in, s_controller_payload_swap, sizeof(s_controller_payload_swap), &payload_size, 16); if (err) - ERROR_LOG_FMT(SERIALINTERFACE, "adapter libusb read failed: err={}", libusb_error_name(err)); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "adapter libusb read failed: err={}", + libusb_error_name(err)); { std::lock_guard lk(s_mutex); @@ -121,7 +122,8 @@ static void Write() const int err = libusb_interrupt_transfer(s_handle, s_endpoint_out, payload, sizeof(payload), &size, 16); if (err != 0) - ERROR_LOG_FMT(SERIALINTERFACE, "adapter libusb write failed: err={}", libusb_error_name(err)); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "adapter libusb write failed: err={}", + libusb_error_name(err)); } } @@ -154,7 +156,7 @@ static int HotplugCallback(libusb_context* ctx, libusb_device* dev, libusb_hotpl static void ScanThreadFunc() { Common::SetCurrentThreadName("GC Adapter Scanning Thread"); - NOTICE_LOG_FMT(SERIALINTERFACE, "GC Adapter scanning thread started"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter scanning thread started"); #if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102 #ifndef __FreeBSD__ @@ -170,7 +172,7 @@ static void ScanThreadFunc() nullptr, &s_hotplug_handle) != LIBUSB_SUCCESS) s_libusb_hotplug_enabled = false; if (s_libusb_hotplug_enabled) - NOTICE_LOG_FMT(SERIALINTERFACE, "Using libUSB hotplug detection"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "Using libUSB hotplug detection"); } #endif @@ -187,7 +189,7 @@ static void ScanThreadFunc() else Common::SleepCurrentThread(500); } - NOTICE_LOG_FMT(SERIALINTERFACE, "GC Adapter scanning thread stopped"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter scanning thread stopped"); } void SetAdapterCallback(std::function func) @@ -265,7 +267,7 @@ static bool CheckDeviceAccess(libusb_device* device) if (ret != 0) { // could not acquire the descriptor, no point in trying to use it. - ERROR_LOG_FMT(SERIALINTERFACE, "libusb_get_device_descriptor failed with error: {}", ret); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "libusb_get_device_descriptor failed with error: {}", ret); return false; } @@ -275,7 +277,7 @@ static bool CheckDeviceAccess(libusb_device* device) return false; } - NOTICE_LOG_FMT(SERIALINTERFACE, "Found GC Adapter with Vendor: {:X} Product: {:X} Devnum: {}", + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "Found GC Adapter with Vendor: {:X} Product: {:X} Devnum: {}", desc.idVendor, desc.idProduct, 1); // In case of failure, capture the libusb error code into the adapter status @@ -287,14 +289,14 @@ static bool CheckDeviceAccess(libusb_device* device) if (ret == LIBUSB_ERROR_ACCESS) { ERROR_LOG_FMT( - SERIALINTERFACE, + CONTROLLERINTERFACE, "Dolphin does not have access to this device: Bus {:03d} Device {:03d}: ID {:04X}:{:04X}.", bus, port, desc.idVendor, desc.idProduct); return false; } if (ret != 0) { - ERROR_LOG_FMT(SERIALINTERFACE, "libusb_open failed to open device with error = {}", ret); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "libusb_open failed to open device with error = {}", ret); return false; } @@ -303,14 +305,14 @@ static bool CheckDeviceAccess(libusb_device* device) { ret = libusb_detach_kernel_driver(s_handle, 0); if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) - ERROR_LOG_FMT(SERIALINTERFACE, "libusb_detach_kernel_driver failed with error: {}", ret); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "libusb_detach_kernel_driver failed with error: {}", ret); } // This call makes Nyko-brand (and perhaps other) adapters work. // However it returns LIBUSB_ERROR_PIPE with Mayflash adapters. const int transfer = libusb_control_transfer(s_handle, 0x21, 11, 0x0001, 0, nullptr, 0, 1000); if (transfer < 0) - WARN_LOG_FMT(SERIALINTERFACE, "libusb_control_transfer failed with error: {}", transfer); + WARN_LOG_FMT(CONTROLLERINTERFACE, "libusb_control_transfer failed with error: {}", transfer); // this split is needed so that we don't avoid claiming the interface when // detaching the kernel driver is successful @@ -324,7 +326,7 @@ static bool CheckDeviceAccess(libusb_device* device) ret = libusb_claim_interface(s_handle, 0); if (ret != 0) { - ERROR_LOG_FMT(SERIALINTERFACE, "libusb_claim_interface failed with error: {}", ret); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "libusb_claim_interface failed with error: {}", ret); libusb_close(s_handle); s_handle = nullptr; return false; @@ -410,7 +412,7 @@ static void Reset() } if (s_detect_callback != nullptr) s_detect_callback(); - NOTICE_LOG_FMT(SERIALINTERFACE, "GC Adapter detached"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter detached"); } GCPadStatus Input(int chan) @@ -436,8 +438,8 @@ GCPadStatus Input(int chan) controller_payload_copy[0] != LIBUSB_DT_HID) { // This can occur for a few frames on initialization. - ERROR_LOG_FMT(SERIALINTERFACE, "error reading payload (size: {}, type: {:02x})", payload_size, - controller_payload_copy[0]); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "error reading payload (size: {}, type: {:02x})", + payload_size, controller_payload_copy[0]); } else { @@ -446,8 +448,8 @@ GCPadStatus Input(int chan) if (type != ControllerTypes::CONTROLLER_NONE && s_controller_type[chan] == ControllerTypes::CONTROLLER_NONE) { - NOTICE_LOG_FMT(SERIALINTERFACE, "New device connected to Port {} of Type: {:02x}", chan + 1, - controller_payload_copy[1 + (9 * chan)]); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "New device connected to Port {} of Type: {:02x}", + chan + 1, controller_payload_copy[1 + (9 * chan)]); get_origin = true; } @@ -551,7 +553,7 @@ static void ResetRumbleLockNeeded() int size = 0; libusb_interrupt_transfer(s_handle, s_endpoint_out, rumble, sizeof(rumble), &size, 16); - INFO_LOG_FMT(SERIALINTERFACE, "Rumble state reset"); + INFO_LOG_FMT(CONTROLLERINTERFACE, "Rumble state reset"); } void Output(int chan, u8 rumble_command) diff --git a/Source/Core/InputCommon/GCAdapter_Android.cpp b/Source/Core/InputCommon/GCAdapter_Android.cpp index a2b169abda..88888b345a 100644 --- a/Source/Core/InputCommon/GCAdapter_Android.cpp +++ b/Source/Core/InputCommon/GCAdapter_Android.cpp @@ -64,7 +64,7 @@ static u64 s_last_init = 0; static void ScanThreadFunc() { Common::SetCurrentThreadName("GC Adapter Scanning Thread"); - NOTICE_LOG_FMT(SERIALINTERFACE, "GC Adapter scanning thread started"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter scanning thread started"); JNIEnv* env = IDCache::GetEnvForThread(); @@ -78,13 +78,13 @@ static void ScanThreadFunc() Common::SleepCurrentThread(1000); } - NOTICE_LOG_FMT(SERIALINTERFACE, "GC Adapter scanning thread stopped"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter scanning thread stopped"); } static void Write() { Common::SetCurrentThreadName("GC Adapter Write Thread"); - NOTICE_LOG_FMT(SERIALINTERFACE, "GC Adapter write thread started"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter write thread started"); JNIEnv* env = IDCache::GetEnvForThread(); jmethodID output_func = env->GetStaticMethodID(s_adapter_class, "Output", "([B)I"); @@ -108,7 +108,7 @@ static void Write() // Netplay sends invalid data which results in size = 0x00. Ignore it. if (size != write_size && size != 0x00) { - ERROR_LOG_FMT(SERIALINTERFACE, "error writing rumble (size: {})", size); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "error writing rumble (size: {})", size); Reset(); } } @@ -116,13 +116,13 @@ static void Write() Common::YieldCPU(); } - NOTICE_LOG_FMT(SERIALINTERFACE, "GC Adapter write thread stopped"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter write thread stopped"); } static void Read() { Common::SetCurrentThreadName("GC Adapter Read Thread"); - NOTICE_LOG_FMT(SERIALINTERFACE, "GC Adapter read thread started"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter read thread started"); bool first_read = true; JNIEnv* env = IDCache::GetEnvForThread(); @@ -179,7 +179,7 @@ static void Read() s_fd = 0; s_detected = false; - NOTICE_LOG_FMT(SERIALINTERFACE, "GC Adapter read thread stopped"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter read thread stopped"); } void Init() @@ -229,7 +229,7 @@ static void Reset() s_detected = false; s_fd = 0; - NOTICE_LOG_FMT(SERIALINTERFACE, "GC Adapter detached"); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter detached"); } void Shutdown() @@ -270,8 +270,8 @@ GCPadStatus Input(int chan) GCPadStatus pad = {}; if (payload_size != controller_payload_copy.size()) { - ERROR_LOG_FMT(SERIALINTERFACE, "error reading payload (size: {}, type: {:02x})", payload_size, - controller_payload_copy[0]); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "error reading payload (size: {}, type: {:02x})", + payload_size, controller_payload_copy[0]); Reset(); } else @@ -281,8 +281,8 @@ GCPadStatus Input(int chan) if (type != ControllerTypes::CONTROLLER_NONE && s_controller_type[chan] == ControllerTypes::CONTROLLER_NONE) { - ERROR_LOG_FMT(SERIALINTERFACE, "New device connected to Port {} of Type: {:02x}", chan + 1, - controller_payload_copy[1 + (9 * chan)]); + ERROR_LOG_FMT(CONTROLLERINTERFACE, "New device connected to Port {} of Type: {:02x}", + chan + 1, controller_payload_copy[1 + (9 * chan)]); get_origin = true; } diff --git a/Source/Core/InputCommon/InputConfig.cpp b/Source/Core/InputCommon/InputConfig.cpp index 07a9b62daf..3b9fb7f809 100644 --- a/Source/Core/InputCommon/InputConfig.cpp +++ b/Source/Core/InputCommon/InputConfig.cpp @@ -133,7 +133,6 @@ bool InputConfig::LoadConfig(bool isGC) } #endif controller->LoadConfig(&config); - // Update refs controller->UpdateReferences(g_controller_interface); controller_names.push_back(controller->GetName()); @@ -171,7 +170,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; diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 9eac785c5a..710e8c5e75 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -776,6 +776,7 @@ void Renderer::UpdateDrawRectangle() const float win_width = static_cast(m_backbuffer_width); const float win_height = static_cast(m_backbuffer_height); + // FIXME: this breaks at very low widget sizes // Make ControllerInterface aware of the render window region actually being used // to adjust mouse cursor inputs. g_controller_interface.SetAspectRatioAdjustment(draw_aspect_ratio / (win_width / win_height));