From 6a75ea5653ec596b1a08e985e98fca0b05ccd6f7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 8 Feb 2017 22:15:43 -0500 Subject: [PATCH] ControllerEmu: Separate ControlGroup from ControllerEmu ControllerEmu, the class, is essentially acting like a namespace for ControlGroup. This makes it impossible to forward declare any of the internals. It also globs a bunch of classes together which is kind of a pain to manage. This splits ControlGroup and the classes it contains into their own source files and situates them all within a namespace, which gets them out of global scope. Since this allows forward declarations for the once-internal classes, it now requires significantly less files to be rebuilt if anything is changed in the ControllerEmu portion of code. It does not split out the settings classes yet, however, as it would be preferable to make a settings base class that all settings derive from, but this would be a functional change -- this commit only intends to move around existing code. Extracting the settings class will be done in another commit. --- Source/Core/Core/Analytics.cpp | 4 +- Source/Core/Core/Analytics.h | 1 + Source/Core/Core/HW/GCKeyboard.cpp | 6 +- Source/Core/Core/HW/GCKeyboard.h | 6 +- Source/Core/Core/HW/GCKeyboardEmu.cpp | 43 +- Source/Core/Core/HW/GCKeyboardEmu.h | 24 +- Source/Core/Core/HW/GCPad.cpp | 5 +- Source/Core/Core/HW/GCPad.h | 6 +- Source/Core/Core/HW/GCPadEmu.cpp | 56 ++- Source/Core/Core/HW/GCPadEmu.h | 28 +- Source/Core/Core/HW/Wiimote.cpp | 5 + Source/Core/Core/HW/Wiimote.h | 7 +- .../HW/WiimoteEmu/Attachment/Attachment.cpp | 8 +- .../HW/WiimoteEmu/Attachment/Attachment.h | 2 +- .../Core/HW/WiimoteEmu/Attachment/Classic.cpp | 26 +- .../Core/HW/WiimoteEmu/Attachment/Classic.h | 20 +- .../Core/HW/WiimoteEmu/Attachment/Drums.cpp | 17 +- .../Core/HW/WiimoteEmu/Attachment/Drums.h | 15 +- .../Core/HW/WiimoteEmu/Attachment/Guitar.cpp | 29 +- .../Core/HW/WiimoteEmu/Attachment/Guitar.h | 20 +- .../Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp | 28 +- .../Core/HW/WiimoteEmu/Attachment/Nunchuk.h | 21 +- .../HW/WiimoteEmu/Attachment/Turntable.cpp | 24 +- .../Core/HW/WiimoteEmu/Attachment/Turntable.h | 23 +- .../Core/HW/WiimoteEmu/EmuSubroutines.cpp | 1 + Source/Core/Core/HW/WiimoteEmu/Speaker.cpp | 2 + Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp | 91 ++-- Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h | 43 +- Source/Core/Core/HotkeyManager.cpp | 27 +- Source/Core/Core/HotkeyManager.h | 19 +- Source/Core/DolphinWX/Debugger/CodeWindow.cpp | 4 +- .../Core/DolphinWX/Input/InputConfigDiag.cpp | 50 +- Source/Core/DolphinWX/Input/InputConfigDiag.h | 14 +- .../Input/InputConfigDiagBitmaps.cpp | 44 +- Source/Core/InputCommon/CMakeLists.txt | 14 + .../ControllerEmu/Control/Control.cpp | 15 + .../ControllerEmu/Control/Control.h | 25 + .../ControllerEmu/Control/Input.cpp | 15 + .../InputCommon/ControllerEmu/Control/Input.h | 17 + .../ControllerEmu/Control/Output.cpp | 15 + .../ControllerEmu/Control/Output.h | 17 + .../ControlGroup/AnalogStick.cpp | 71 +++ .../ControllerEmu/ControlGroup/AnalogStick.h | 26 + .../ControllerEmu/ControlGroup/Buttons.cpp | 24 + .../ControllerEmu/ControlGroup/Buttons.h | 33 ++ .../ControlGroup/ControlGroup.cpp | 132 +++++ .../ControllerEmu/ControlGroup/ControlGroup.h | 117 +++++ .../ControllerEmu/ControlGroup/Cursor.cpp | 98 ++++ .../ControllerEmu/ControlGroup/Cursor.h | 29 ++ .../ControllerEmu/ControlGroup/Extension.cpp | 16 + .../ControllerEmu/ControlGroup/Extension.h | 31 ++ .../ControllerEmu/ControlGroup/Force.cpp | 51 ++ .../ControllerEmu/ControlGroup/Force.h | 22 + .../ControlGroup/MixedTriggers.cpp | 42 ++ .../ControlGroup/MixedTriggers.h | 19 + .../ControlGroup/ModifySettingsButton.cpp | 77 +++ .../ControlGroup/ModifySettingsButton.h | 31 ++ .../ControllerEmu/ControlGroup/Slider.cpp | 37 ++ .../ControllerEmu/ControlGroup/Slider.h | 19 + .../ControllerEmu/ControlGroup/Tilt.cpp | 99 ++++ .../ControllerEmu/ControlGroup/Tilt.h | 22 + .../ControllerEmu/ControlGroup/Triggers.cpp | 31 ++ .../ControllerEmu/ControlGroup/Triggers.h | 19 + .../ControllerEmu/ControllerEmu.cpp | 274 +--------- .../InputCommon/ControllerEmu/ControllerEmu.h | 474 +----------------- Source/Core/InputCommon/InputCommon.vcxproj | 28 ++ .../InputCommon/InputCommon.vcxproj.filters | 92 +++- Source/Core/InputCommon/InputConfig.cpp | 11 +- Source/Core/InputCommon/InputConfig.h | 16 +- 69 files changed, 1807 insertions(+), 971 deletions(-) create mode 100644 Source/Core/InputCommon/ControllerEmu/Control/Control.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/Control/Control.h create mode 100644 Source/Core/InputCommon/ControllerEmu/Control/Input.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/Control/Input.h create mode 100644 Source/Core/InputCommon/ControllerEmu/Control/Output.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/Control/Output.h create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.h create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.h create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.h create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.h create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.cpp create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.h diff --git a/Source/Core/Core/Analytics.cpp b/Source/Core/Core/Analytics.cpp index 6d628cd582..8638b79dba 100644 --- a/Source/Core/Core/Analytics.cpp +++ b/Source/Core/Core/Analytics.cpp @@ -1,3 +1,5 @@ +#include "Core/Analytics.h" + #include #include #include @@ -16,12 +18,10 @@ #include "Common/Common.h" #include "Common/CommonTypes.h" #include "Common/StringUtil.h" -#include "Core/Analytics.h" #include "Core/ConfigManager.h" #include "Core/HW/GCPad.h" #include "Core/Movie.h" #include "Core/NetPlayProto.h" -#include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/GCAdapter.h" #include "InputCommon/InputConfig.h" #include "VideoCommon/VideoBackendBase.h" diff --git a/Source/Core/Core/Analytics.h b/Source/Core/Core/Analytics.h index 11a555136f..d1900d4ae9 100644 --- a/Source/Core/Core/Analytics.h +++ b/Source/Core/Core/Analytics.h @@ -6,6 +6,7 @@ #include #include +#include #include "Common/Analytics.h" diff --git a/Source/Core/Core/HW/GCKeyboard.cpp b/Source/Core/Core/HW/GCKeyboard.cpp index 0f5014c3a3..300ed0608c 100644 --- a/Source/Core/Core/HW/GCKeyboard.cpp +++ b/Source/Core/Core/HW/GCKeyboard.cpp @@ -2,12 +2,16 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "Core/HW/GCKeyboard.h" + #include #include "Common/Common.h" #include "Common/CommonTypes.h" -#include "Core/HW/GCKeyboard.h" + #include "Core/HW/GCKeyboardEmu.h" + +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/InputConfig.h" #include "InputCommon/KeyboardStatus.h" diff --git a/Source/Core/Core/HW/GCKeyboard.h b/Source/Core/Core/HW/GCKeyboard.h index c968e2bae2..1cd8409015 100644 --- a/Source/Core/Core/HW/GCKeyboard.h +++ b/Source/Core/Core/HW/GCKeyboard.h @@ -5,12 +5,16 @@ #pragma once #include "Common/CommonTypes.h" -#include "InputCommon/ControllerEmu/ControllerEmu.h" class InputConfig; enum class KeyboardGroup; struct KeyboardStatus; +namespace ControllerEmu +{ +class ControlGroup; +} + namespace Keyboard { void Shutdown(); diff --git a/Source/Core/Core/HW/GCKeyboardEmu.cpp b/Source/Core/Core/HW/GCKeyboardEmu.cpp index 067cd996d3..e13ef5beaf 100644 --- a/Source/Core/Core/HW/GCKeyboardEmu.cpp +++ b/Source/Core/Core/HW/GCKeyboardEmu.cpp @@ -3,7 +3,12 @@ // Refer to the license.txt file included. #include "Core/HW/GCKeyboardEmu.h" + #include "Common/Common.h" +#include "Common/CommonTypes.h" +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" #include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/KeyboardStatus.h" @@ -48,36 +53,38 @@ static const char* const named_keys5[] = {"LEFT", "DOWN", "UP", "RIGHT", "ENTER" GCKeyboard::GCKeyboard(const unsigned int index) : m_index(index) { // buttons - groups.emplace_back(m_keys0x = new Buttons(_trans("Keys"))); + groups.emplace_back(m_keys0x = new ControllerEmu::Buttons(_trans("Keys"))); for (const char* key : named_keys0) - m_keys0x->controls.emplace_back(new ControlGroup::Input(key)); + m_keys0x->controls.emplace_back(new ControllerEmu::Input(key)); - groups.emplace_back(m_keys1x = new Buttons(_trans("Keys"))); + groups.emplace_back(m_keys1x = new ControllerEmu::Buttons(_trans("Keys"))); for (const char* key : named_keys1) - m_keys1x->controls.emplace_back(new ControlGroup::Input(key)); + m_keys1x->controls.emplace_back(new ControllerEmu::Input(key)); - groups.emplace_back(m_keys2x = new Buttons(_trans("Keys"))); + groups.emplace_back(m_keys2x = new ControllerEmu::Buttons(_trans("Keys"))); for (const char* key : named_keys2) - m_keys2x->controls.emplace_back(new ControlGroup::Input(key)); + m_keys2x->controls.emplace_back(new ControllerEmu::Input(key)); - groups.emplace_back(m_keys3x = new Buttons(_trans("Keys"))); + groups.emplace_back(m_keys3x = new ControllerEmu::Buttons(_trans("Keys"))); for (const char* key : named_keys3) - m_keys3x->controls.emplace_back(new ControlGroup::Input(key)); + m_keys3x->controls.emplace_back(new ControllerEmu::Input(key)); - groups.emplace_back(m_keys4x = new Buttons(_trans("Keys"))); + groups.emplace_back(m_keys4x = new ControllerEmu::Buttons(_trans("Keys"))); for (const char* key : named_keys4) - m_keys4x->controls.emplace_back(new ControlGroup::Input(key)); + m_keys4x->controls.emplace_back(new ControllerEmu::Input(key)); - groups.emplace_back(m_keys5x = new Buttons(_trans("Keys"))); + groups.emplace_back(m_keys5x = new ControllerEmu::Buttons(_trans("Keys"))); for (const char* key : named_keys5) - m_keys5x->controls.emplace_back(new ControlGroup::Input(key)); + m_keys5x->controls.emplace_back(new ControllerEmu::Input(key)); // options - groups.emplace_back(m_options = new ControlGroup(_trans("Options"))); + groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options"))); m_options->boolean_settings.emplace_back( - std::make_unique(_trans("Background Input"))); - m_options->boolean_settings.emplace_back(std::make_unique( - _trans("Iterative Input"), false, ControlGroup::SettingType::VIRTUAL)); + std::make_unique( + _trans("Background Input"))); + m_options->boolean_settings.emplace_back( + std::make_unique( + _trans("Iterative Input"), false, ControllerEmu::ControlGroup::SettingType::VIRTUAL)); } std::string GCKeyboard::GetName() const @@ -110,7 +117,7 @@ ControllerEmu::ControlGroup* GCKeyboard::GetGroup(KeyboardGroup group) KeyboardStatus GCKeyboard::GetInput() const { - auto lock = ControllerEmu::GetStateLock(); + const auto lock = GetStateLock(); KeyboardStatus kb = {}; @@ -126,7 +133,7 @@ KeyboardStatus GCKeyboard::GetInput() const void GCKeyboard::LoadDefaults(const ControllerInterface& ciface) { - ControllerEmu::LoadDefaults(ciface); + EmulatedController::LoadDefaults(ciface); // Buttons m_keys0x->SetControlExpression(5, "A"); diff --git a/Source/Core/Core/HW/GCKeyboardEmu.h b/Source/Core/Core/HW/GCKeyboardEmu.h index cf6cfd7e9d..ea347a51c7 100644 --- a/Source/Core/Core/HW/GCKeyboardEmu.h +++ b/Source/Core/Core/HW/GCKeyboardEmu.h @@ -10,6 +10,12 @@ struct KeyboardStatus; +namespace ControllerEmu +{ +class ControlGroup; +class Buttons; +} + enum class KeyboardGroup { Kb0x, @@ -22,23 +28,23 @@ enum class KeyboardGroup Options }; -class GCKeyboard : public ControllerEmu +class GCKeyboard : public ControllerEmu::EmulatedController { public: explicit GCKeyboard(unsigned int index); KeyboardStatus GetInput() const; std::string GetName() const override; - ControlGroup* GetGroup(KeyboardGroup group); + ControllerEmu::ControlGroup* GetGroup(KeyboardGroup group); void LoadDefaults(const ControllerInterface& ciface) override; private: - Buttons* m_keys0x; - Buttons* m_keys1x; - Buttons* m_keys2x; - Buttons* m_keys3x; - Buttons* m_keys4x; - Buttons* m_keys5x; - ControlGroup* m_options; + ControllerEmu::Buttons* m_keys0x; + ControllerEmu::Buttons* m_keys1x; + ControllerEmu::Buttons* m_keys2x; + ControllerEmu::Buttons* m_keys3x; + ControllerEmu::Buttons* m_keys4x; + ControllerEmu::Buttons* m_keys5x; + ControllerEmu::ControlGroup* m_options; const unsigned int m_index; }; diff --git a/Source/Core/Core/HW/GCPad.cpp b/Source/Core/Core/HW/GCPad.cpp index 6cb163780a..fcf9f524c5 100644 --- a/Source/Core/Core/HW/GCPad.cpp +++ b/Source/Core/Core/HW/GCPad.cpp @@ -2,11 +2,14 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "Core/HW/GCPad.h" + #include #include "Common/Common.h" -#include "Core/HW/GCPad.h" #include "Core/HW/GCPadEmu.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" +#include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/GCPadStatus.h" #include "InputCommon/InputConfig.h" diff --git a/Source/Core/Core/HW/GCPad.h b/Source/Core/Core/HW/GCPad.h index 28917da35e..728f68e7f9 100644 --- a/Source/Core/Core/HW/GCPad.h +++ b/Source/Core/Core/HW/GCPad.h @@ -5,13 +5,17 @@ #pragma once #include "Common/CommonTypes.h" -#include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerInterface/Device.h" class InputConfig; enum class PadGroup; struct GCPadStatus; +namespace ControllerEmu +{ +class ControlGroup; +} + namespace Pad { void Shutdown(); diff --git a/Source/Core/Core/HW/GCPadEmu.cpp b/Source/Core/Core/HW/GCPadEmu.cpp index 1dbed8adda..820932a2e3 100644 --- a/Source/Core/Core/HW/GCPadEmu.cpp +++ b/Source/Core/Core/HW/GCPadEmu.cpp @@ -3,9 +3,17 @@ // Refer to the license.txt file included. #include "Core/HW/GCPadEmu.h" + #include "Common/Common.h" #include "Common/CommonTypes.h" -#include "Core/Host.h" + +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "InputCommon/ControllerEmu/Control/Output.h" +#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h" +#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" +#include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h" +#include "InputCommon/GCPadStatus.h" static const u16 button_bitmasks[] = { PAD_BUTTON_A, @@ -39,40 +47,42 @@ static const char* const named_triggers[] = { GCPad::GCPad(const unsigned int index) : m_index(index) { // buttons - groups.emplace_back(m_buttons = new Buttons(_trans("Buttons"))); + groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons"))); for (unsigned int i = 0; i < sizeof(named_buttons) / sizeof(*named_buttons); ++i) - m_buttons->controls.emplace_back(new ControlGroup::Input(named_buttons[i])); + m_buttons->controls.emplace_back(new ControllerEmu::Input(named_buttons[i])); // sticks - groups.emplace_back(m_main_stick = new AnalogStick("Main Stick", _trans("Control Stick"), - DEFAULT_PAD_STICK_RADIUS)); - groups.emplace_back(m_c_stick = - new AnalogStick("C-Stick", _trans("C Stick"), DEFAULT_PAD_STICK_RADIUS)); + groups.emplace_back(m_main_stick = new ControllerEmu::AnalogStick( + "Main Stick", _trans("Control Stick"), DEFAULT_PAD_STICK_RADIUS)); + groups.emplace_back(m_c_stick = new ControllerEmu::AnalogStick("C-Stick", _trans("C Stick"), + DEFAULT_PAD_STICK_RADIUS)); // triggers - groups.emplace_back(m_triggers = new MixedTriggers(_trans("Triggers"))); + groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers"))); for (auto& named_trigger : named_triggers) - m_triggers->controls.emplace_back(new ControlGroup::Input(named_trigger)); + m_triggers->controls.emplace_back(new ControllerEmu::Input(named_trigger)); // rumble - groups.emplace_back(m_rumble = new ControlGroup(_trans("Rumble"))); - m_rumble->controls.emplace_back(new ControlGroup::Output(_trans("Motor"))); + groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble"))); + m_rumble->controls.emplace_back(new ControllerEmu::Output(_trans("Motor"))); // Microphone - groups.emplace_back(m_mic = new Buttons(_trans("Microphone"))); - m_mic->controls.emplace_back(new ControlGroup::Input(_trans("Button"))); + groups.emplace_back(m_mic = new ControllerEmu::Buttons(_trans("Microphone"))); + m_mic->controls.emplace_back(new ControllerEmu::Input(_trans("Button"))); // dpad - groups.emplace_back(m_dpad = new Buttons(_trans("D-Pad"))); + groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad"))); for (auto& named_direction : named_directions) - m_dpad->controls.emplace_back(new ControlGroup::Input(named_direction)); + m_dpad->controls.emplace_back(new ControllerEmu::Input(named_direction)); // options - groups.emplace_back(m_options = new ControlGroup(_trans("Options"))); + groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options"))); m_options->boolean_settings.emplace_back( - std::make_unique(_trans("Background Input"))); - m_options->boolean_settings.emplace_back(std::make_unique( - _trans("Iterative Input"), false, ControlGroup::SettingType::VIRTUAL)); + std::make_unique( + _trans("Background Input"))); + m_options->boolean_settings.emplace_back( + std::make_unique( + _trans("Iterative Input"), false, ControllerEmu::ControlGroup::SettingType::VIRTUAL)); } std::string GCPad::GetName() const @@ -107,7 +117,7 @@ ControllerEmu::ControlGroup* GCPad::GetGroup(PadGroup group) GCPadStatus GCPad::GetInput() const { - auto lock = ControllerEmu::GetStateLock(); + const auto lock = GetStateLock(); ControlState x, y, triggers[2]; GCPadStatus pad = {}; @@ -147,13 +157,13 @@ GCPadStatus GCPad::GetInput() const void GCPad::SetOutput(const ControlState strength) { - auto lock = ControllerEmu::GetStateLock(); + const auto lock = GetStateLock(); m_rumble->controls[0]->control_ref->State(strength); } void GCPad::LoadDefaults(const ControllerInterface& ciface) { - ControllerEmu::LoadDefaults(ciface); + EmulatedController::LoadDefaults(ciface); // Buttons m_buttons->SetControlExpression(0, "X"); // A @@ -222,6 +232,6 @@ void GCPad::LoadDefaults(const ControllerInterface& ciface) bool GCPad::GetMicButton() const { - auto lock = ControllerEmu::GetStateLock(); + const auto lock = GetStateLock(); return (0.0f != m_mic->controls.back()->control_ref->State()); } diff --git a/Source/Core/Core/HW/GCPadEmu.h b/Source/Core/Core/HW/GCPadEmu.h index cc51d60db0..ad3f3a48a2 100644 --- a/Source/Core/Core/HW/GCPadEmu.h +++ b/Source/Core/Core/HW/GCPadEmu.h @@ -8,7 +8,15 @@ #include "InputCommon/ControllerEmu/ControllerEmu.h" +struct GCPadStatus; + +namespace ControllerEmu +{ +class AnalogStick; +class Buttons; class ControlGroup; +class MixedTriggers; +} enum class PadGroup { @@ -22,7 +30,7 @@ enum class PadGroup Options }; -class GCPad : public ControllerEmu +class GCPad : public ControllerEmu::EmulatedController { public: explicit GCPad(unsigned int index); @@ -33,19 +41,19 @@ public: std::string GetName() const override; - ControlGroup* GetGroup(PadGroup group); + ControllerEmu::ControlGroup* GetGroup(PadGroup group); void LoadDefaults(const ControllerInterface& ciface) override; private: - Buttons* m_buttons; - AnalogStick* m_main_stick; - AnalogStick* m_c_stick; - Buttons* m_dpad; - MixedTriggers* m_triggers; - ControlGroup* m_rumble; - Buttons* m_mic; - ControlGroup* m_options; + ControllerEmu::Buttons* m_buttons; + ControllerEmu::AnalogStick* m_main_stick; + ControllerEmu::AnalogStick* m_c_stick; + ControllerEmu::Buttons* m_dpad; + ControllerEmu::MixedTriggers* m_triggers; + ControllerEmu::ControlGroup* m_rumble; + ControllerEmu::Buttons* m_mic; + ControllerEmu::ControlGroup* m_options; const unsigned int m_index; diff --git a/Source/Core/Core/HW/Wiimote.cpp b/Source/Core/Core/HW/Wiimote.cpp index 03590ea48c..c1f067fe42 100644 --- a/Source/Core/Core/HW/Wiimote.cpp +++ b/Source/Core/Core/HW/Wiimote.cpp @@ -3,10 +3,15 @@ // Refer to the license.txt file included. #include "Core/HW/Wiimote.h" + #include "Common/ChunkFile.h" +#include "Common/CommonTypes.h" + #include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteReal/WiimoteReal.h" #include "Core/Movie.h" + +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/InputConfig.h" diff --git a/Source/Core/Core/HW/Wiimote.h b/Source/Core/Core/HW/Wiimote.h index 668096265d..5e4cc2b0b0 100644 --- a/Source/Core/Core/HW/Wiimote.h +++ b/Source/Core/Core/HW/Wiimote.h @@ -6,10 +6,15 @@ #include "Common/Common.h" #include "Common/CommonTypes.h" -#include "InputCommon/ControllerEmu/ControllerEmu.h" class InputConfig; class PointerWrap; + +namespace ControllerEmu +{ +class ControlGroup; +} + namespace WiimoteEmu { enum class WiimoteGroup; diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp index f3294c0a92..ebc956fdc4 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp @@ -11,6 +11,7 @@ #include "Common/Common.h" #include "Common/CommonTypes.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h" +#include "InputCommon/ControllerEmu/ControlGroup/Extension.h" namespace WiimoteEmu { @@ -53,12 +54,14 @@ void Attachment::Reset() } } // namespace WiimoteEmu -void ControllerEmu::Extension::GetState(u8* const data) +namespace ControllerEmu +{ +void Extension::GetState(u8* const data) { ((WiimoteEmu::Attachment*)attachments[active_extension].get())->GetState(data); } -bool ControllerEmu::Extension::IsButtonPressed() const +bool Extension::IsButtonPressed() const { // Extension == 0 means no Extension, > 0 means one is connected // Since we want to use this to know if disconnected Wiimotes want to be connected, and @@ -71,3 +74,4 @@ bool ControllerEmu::Extension::IsButtonPressed() const return ((WiimoteEmu::Attachment*)attachments[switch_extension].get())->IsButtonPressed(); return false; } +} // namespace ControllerEmu diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.h b/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.h index caec32754a..dca1d23972 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.h +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.h @@ -13,7 +13,7 @@ namespace WiimoteEmu { struct ExtensionReg; -class Attachment : public ControllerEmu +class Attachment : public ControllerEmu::EmulatedController { public: Attachment(const char* const name, ExtensionReg& reg); diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.cpp index 76d35e63b1..1e6927fb86 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.cpp @@ -11,6 +11,12 @@ #include "Common/CommonTypes.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h" +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h" +#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" +#include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h" + namespace WiimoteEmu { constexpr std::array classic_id{{0x00, 0x00, 0xa4, 0x20, 0x01, 0x01}}; @@ -49,25 +55,25 @@ constexpr std::array classic_dpad_bitmasks{{ Classic::Classic(ExtensionReg& reg) : Attachment(_trans("Classic"), reg) { // buttons - groups.emplace_back(m_buttons = new Buttons("Buttons")); + groups.emplace_back(m_buttons = new ControllerEmu::Buttons("Buttons")); for (auto& classic_button_name : classic_button_names) - m_buttons->controls.emplace_back(new ControlGroup::Input(classic_button_name)); + m_buttons->controls.emplace_back(new ControllerEmu::Input(classic_button_name)); // sticks - groups.emplace_back(m_left_stick = - new AnalogStick(_trans("Left Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS)); - groups.emplace_back(m_right_stick = - new AnalogStick(_trans("Right Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS)); + groups.emplace_back(m_left_stick = new ControllerEmu::AnalogStick( + _trans("Left Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS)); + groups.emplace_back(m_right_stick = new ControllerEmu::AnalogStick( + _trans("Right Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS)); // triggers - groups.emplace_back(m_triggers = new MixedTriggers("Triggers")); + groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers("Triggers")); for (auto& classic_trigger_name : classic_trigger_names) - m_triggers->controls.emplace_back(new ControlGroup::Input(classic_trigger_name)); + m_triggers->controls.emplace_back(new ControllerEmu::Input(classic_trigger_name)); // dpad - groups.emplace_back(m_dpad = new Buttons("D-Pad")); + groups.emplace_back(m_dpad = new ControllerEmu::Buttons("D-Pad")); for (auto& named_direction : named_directions) - m_dpad->controls.emplace_back(new ControlGroup::Input(named_direction)); + m_dpad->controls.emplace_back(new ControllerEmu::Input(named_direction)); // Set up register m_calibration = classic_calibration; diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.h b/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.h index ac621859f6..9125667ebb 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.h +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.h @@ -6,6 +6,14 @@ #include "Core/HW/WiimoteEmu/Attachment/Attachment.h" +namespace ControllerEmu +{ +class AnalogStick; +class Buttons; +class ControlGroup; +class MixedTriggers; +} + namespace WiimoteEmu { enum class ClassicGroup; @@ -18,7 +26,7 @@ public: void GetState(u8* const data) override; bool IsButtonPressed() const override; - ControlGroup* GetGroup(ClassicGroup group); + ControllerEmu::ControlGroup* GetGroup(ClassicGroup group); enum { @@ -52,10 +60,10 @@ public: static const u8 RIGHT_TRIGGER_RANGE = 0x1F; private: - Buttons* m_buttons; - MixedTriggers* m_triggers; - Buttons* m_dpad; - AnalogStick* m_left_stick; - AnalogStick* m_right_stick; + ControllerEmu::Buttons* m_buttons; + ControllerEmu::MixedTriggers* m_triggers; + ControllerEmu::Buttons* m_dpad; + ControllerEmu::AnalogStick* m_left_stick; + ControllerEmu::AnalogStick* m_right_stick; }; } diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.cpp index 91672ddbfa..9c25382cd6 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.cpp @@ -11,6 +11,10 @@ #include "Common/CommonTypes.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h" +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h" +#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" + namespace WiimoteEmu { constexpr std::array drums_id{{0x01, 0x00, 0xa4, 0x20, 0x01, 0x03}}; @@ -32,17 +36,18 @@ constexpr std::array drum_button_bitmasks{{ Drums::Drums(ExtensionReg& reg) : Attachment(_trans("Drums"), reg) { // pads - groups.emplace_back(m_pads = new Buttons(_trans("Pads"))); + groups.emplace_back(m_pads = new ControllerEmu::Buttons(_trans("Pads"))); for (auto& drum_pad_name : drum_pad_names) - m_pads->controls.emplace_back(new ControlGroup::Input(drum_pad_name)); + m_pads->controls.emplace_back(new ControllerEmu::Input(drum_pad_name)); // stick - groups.emplace_back(m_stick = new AnalogStick("Stick", DEFAULT_ATTACHMENT_STICK_RADIUS)); + groups.emplace_back(m_stick = + new ControllerEmu::AnalogStick("Stick", DEFAULT_ATTACHMENT_STICK_RADIUS)); // buttons - groups.emplace_back(m_buttons = new Buttons("Buttons")); - m_buttons->controls.emplace_back(new ControlGroup::Input("-")); - m_buttons->controls.emplace_back(new ControlGroup::Input("+")); + groups.emplace_back(m_buttons = new ControllerEmu::Buttons("Buttons")); + m_buttons->controls.emplace_back(new ControllerEmu::Input("-")); + m_buttons->controls.emplace_back(new ControllerEmu::Input("+")); // set up register m_id = drums_id; diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.h b/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.h index 993a3e597b..83caa78814 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.h +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.h @@ -6,6 +6,13 @@ #include "Core/HW/WiimoteEmu/Attachment/Attachment.h" +namespace ControllerEmu +{ +class AnalogStick; +class Buttons; +class ControlGroup; +} + namespace WiimoteEmu { enum class DrumsGroup; @@ -18,7 +25,7 @@ public: void GetState(u8* const data) override; bool IsButtonPressed() const override; - ControlGroup* GetGroup(DrumsGroup group); + ControllerEmu::ControlGroup* GetGroup(DrumsGroup group); enum { @@ -34,8 +41,8 @@ public: }; private: - Buttons* m_buttons; - Buttons* m_pads; - AnalogStick* m_stick; + ControllerEmu::Buttons* m_buttons; + ControllerEmu::Buttons* m_pads; + ControllerEmu::AnalogStick* m_stick; }; } diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.cpp index 6bb6080dd2..e1a2dce8d6 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.cpp @@ -11,6 +11,12 @@ #include "Common/CommonTypes.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h" +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h" +#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" +#include "InputCommon/ControllerEmu/ControlGroup/Triggers.h" + namespace WiimoteEmu { constexpr std::array guitar_id{{0x00, 0x00, 0xa4, 0x20, 0x01, 0x03}}; @@ -35,26 +41,27 @@ constexpr std::array guitar_strum_bitmasks{{ Guitar::Guitar(ExtensionReg& reg) : Attachment(_trans("Guitar"), reg) { // frets - groups.emplace_back(m_frets = new Buttons(_trans("Frets"))); + groups.emplace_back(m_frets = new ControllerEmu::Buttons(_trans("Frets"))); for (auto& guitar_fret_name : guitar_fret_names) - m_frets->controls.emplace_back(new ControlGroup::Input(guitar_fret_name)); + m_frets->controls.emplace_back(new ControllerEmu::Input(guitar_fret_name)); // strum - groups.emplace_back(m_strum = new Buttons(_trans("Strum"))); - m_strum->controls.emplace_back(new ControlGroup::Input("Up")); - m_strum->controls.emplace_back(new ControlGroup::Input("Down")); + groups.emplace_back(m_strum = new ControllerEmu::Buttons(_trans("Strum"))); + m_strum->controls.emplace_back(new ControllerEmu::Input("Up")); + m_strum->controls.emplace_back(new ControllerEmu::Input("Down")); // buttons - groups.emplace_back(m_buttons = new Buttons("Buttons")); - m_buttons->controls.emplace_back(new ControlGroup::Input("-")); - m_buttons->controls.emplace_back(new ControlGroup::Input("+")); + groups.emplace_back(m_buttons = new ControllerEmu::Buttons("Buttons")); + m_buttons->controls.emplace_back(new ControllerEmu::Input("-")); + m_buttons->controls.emplace_back(new ControllerEmu::Input("+")); // stick - groups.emplace_back(m_stick = new AnalogStick(_trans("Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS)); + groups.emplace_back( + m_stick = new ControllerEmu::AnalogStick(_trans("Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS)); // whammy - groups.emplace_back(m_whammy = new Triggers(_trans("Whammy"))); - m_whammy->controls.emplace_back(new ControlGroup::Input(_trans("Bar"))); + groups.emplace_back(m_whammy = new ControllerEmu::Triggers(_trans("Whammy"))); + m_whammy->controls.emplace_back(new ControllerEmu::Input(_trans("Bar"))); // set up register m_id = guitar_id; diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.h b/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.h index 18549362c1..169818bff5 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.h +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.h @@ -6,6 +6,14 @@ #include "Core/HW/WiimoteEmu/Attachment/Attachment.h" +namespace ControllerEmu +{ +class AnalogStick; +class Buttons; +class ControlGroup; +class Triggers; +} + namespace WiimoteEmu { enum class GuitarGroup; @@ -18,7 +26,7 @@ public: void GetState(u8* const data) override; bool IsButtonPressed() const override; - ControlGroup* GetGroup(GuitarGroup group); + ControllerEmu::ControlGroup* GetGroup(GuitarGroup group); enum { @@ -35,10 +43,10 @@ public: }; private: - Buttons* m_buttons; - Buttons* m_frets; - Buttons* m_strum; - Triggers* m_whammy; - AnalogStick* m_stick; + ControllerEmu::Buttons* m_buttons; + ControllerEmu::Buttons* m_frets; + ControllerEmu::Buttons* m_strum; + ControllerEmu::Triggers* m_whammy; + ControllerEmu::AnalogStick* m_stick; }; } diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp index 61eb70adfe..98d5e1897f 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp @@ -12,6 +12,13 @@ #include "Common/MathUtil.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h" +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h" +#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" +#include "InputCommon/ControllerEmu/ControlGroup/Force.h" +#include "InputCommon/ControllerEmu/ControlGroup/Tilt.h" + namespace WiimoteEmu { constexpr std::array nunchuk_id{{0x00, 0x00, 0xa4, 0x20, 0x00, 0x00}}; @@ -23,24 +30,25 @@ constexpr std::array nunchuk_button_bitmasks{{ Nunchuk::Nunchuk(ExtensionReg& reg) : Attachment(_trans("Nunchuk"), reg) { // buttons - groups.emplace_back(m_buttons = new Buttons("Buttons")); - m_buttons->controls.emplace_back(new ControlGroup::Input("C")); - m_buttons->controls.emplace_back(new ControlGroup::Input("Z")); + groups.emplace_back(m_buttons = new ControllerEmu::Buttons("Buttons")); + m_buttons->controls.emplace_back(new ControllerEmu::Input("C")); + m_buttons->controls.emplace_back(new ControllerEmu::Input("Z")); // stick - groups.emplace_back(m_stick = new AnalogStick("Stick", DEFAULT_ATTACHMENT_STICK_RADIUS)); + groups.emplace_back(m_stick = + new ControllerEmu::AnalogStick("Stick", DEFAULT_ATTACHMENT_STICK_RADIUS)); // swing - groups.emplace_back(m_swing = new Force("Swing")); + groups.emplace_back(m_swing = new ControllerEmu::Force("Swing")); // tilt - groups.emplace_back(m_tilt = new Tilt("Tilt")); + groups.emplace_back(m_tilt = new ControllerEmu::Tilt("Tilt")); // shake - groups.emplace_back(m_shake = new Buttons("Shake")); - m_shake->controls.emplace_back(new ControlGroup::Input("X")); - m_shake->controls.emplace_back(new ControlGroup::Input("Y")); - m_shake->controls.emplace_back(new ControlGroup::Input("Z")); + groups.emplace_back(m_shake = new ControllerEmu::Buttons("Shake")); + m_shake->controls.emplace_back(new ControllerEmu::Input("X")); + m_shake->controls.emplace_back(new ControllerEmu::Input("Y")); + m_shake->controls.emplace_back(new ControllerEmu::Input("Z")); m_id = nunchuk_id; } diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.h b/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.h index 426d65afd2..48ec942672 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.h +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.h @@ -7,6 +7,15 @@ #include #include "Core/HW/WiimoteEmu/Attachment/Attachment.h" +namespace ControllerEmu +{ +class AnalogStick; +class Buttons; +class ControlGroup; +class Force; +class Tilt; +} + namespace WiimoteEmu { enum class NunchukGroup; @@ -20,7 +29,7 @@ public: void GetState(u8* const data) override; bool IsButtonPressed() const override; - ControlGroup* GetGroup(NunchukGroup group); + ControllerEmu::ControlGroup* GetGroup(NunchukGroup group); enum { @@ -44,13 +53,13 @@ public: void LoadDefaults(const ControllerInterface& ciface) override; private: - Tilt* m_tilt; - Force* m_swing; + ControllerEmu::Tilt* m_tilt; + ControllerEmu::Force* m_swing; - Buttons* m_shake; + ControllerEmu::Buttons* m_shake; - Buttons* m_buttons; - AnalogStick* m_stick; + ControllerEmu::Buttons* m_buttons; + ControllerEmu::AnalogStick* m_stick; std::array m_shake_step{}; }; diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.cpp b/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.cpp index f09cdcd0ab..a09521df78 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.cpp @@ -11,6 +11,13 @@ #include "Common/CommonTypes.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h" +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h" +#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" +#include "InputCommon/ControllerEmu/ControlGroup/Slider.h" +#include "InputCommon/ControllerEmu/ControlGroup/Triggers.h" + namespace WiimoteEmu { constexpr std::array turntable_id{{0x03, 0x00, 0xa4, 0x20, 0x01, 0x03}}; @@ -29,23 +36,24 @@ constexpr std::array turntable_button_names{{ Turntable::Turntable(ExtensionReg& reg) : Attachment(_trans("Turntable"), reg) { // buttons - groups.emplace_back(m_buttons = new Buttons("Buttons")); + groups.emplace_back(m_buttons = new ControllerEmu::Buttons("Buttons")); for (auto& turntable_button_name : turntable_button_names) - m_buttons->controls.emplace_back(new ControlGroup::Input(turntable_button_name)); + m_buttons->controls.emplace_back(new ControllerEmu::Input(turntable_button_name)); // turntables - groups.emplace_back(m_left_table = new Slider(_trans("Table Left"))); - groups.emplace_back(m_right_table = new Slider(_trans("Table Right"))); + groups.emplace_back(m_left_table = new ControllerEmu::Slider(_trans("Table Left"))); + groups.emplace_back(m_right_table = new ControllerEmu::Slider(_trans("Table Right"))); // stick - groups.emplace_back(m_stick = new AnalogStick("Stick", DEFAULT_ATTACHMENT_STICK_RADIUS)); + groups.emplace_back(m_stick = + new ControllerEmu::AnalogStick("Stick", DEFAULT_ATTACHMENT_STICK_RADIUS)); // effect dial - groups.emplace_back(m_effect_dial = new Triggers(_trans("Effect"))); - m_effect_dial->controls.emplace_back(new ControlGroup::Input(_trans("Dial"))); + groups.emplace_back(m_effect_dial = new ControllerEmu::Triggers(_trans("Effect"))); + m_effect_dial->controls.emplace_back(new ControllerEmu::Input(_trans("Dial"))); // crossfade - groups.emplace_back(m_crossfade = new Slider(_trans("Crossfade"))); + groups.emplace_back(m_crossfade = new ControllerEmu::Slider(_trans("Crossfade"))); // set up register m_id = turntable_id; diff --git a/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.h b/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.h index 7f917b3189..c97b68ccad 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.h +++ b/Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.h @@ -6,6 +6,15 @@ #include "Core/HW/WiimoteEmu/Attachment/Attachment.h" +namespace ControllerEmu +{ +class AnalogStick; +class Buttons; +class ControlGroup; +class Slider; +class Triggers; +} + namespace WiimoteEmu { enum class TurntableGroup; @@ -18,7 +27,7 @@ public: void GetState(u8* const data) override; bool IsButtonPressed() const override; - ControlGroup* GetGroup(TurntableGroup group); + ControllerEmu::ControlGroup* GetGroup(TurntableGroup group); enum { @@ -37,11 +46,11 @@ public: }; private: - Buttons* m_buttons; - AnalogStick* m_stick; - Triggers* m_effect_dial; - Slider* m_left_table; - Slider* m_right_table; - Slider* m_crossfade; + ControllerEmu::Buttons* m_buttons; + ControllerEmu::AnalogStick* m_stick; + ControllerEmu::Triggers* m_effect_dial; + ControllerEmu::Slider* m_left_table; + ControllerEmu::Slider* m_right_table; + ControllerEmu::Slider* m_crossfade; }; } diff --git a/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp b/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp index d673e3c046..af968ff143 100644 --- a/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp @@ -30,6 +30,7 @@ #include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteHid.h" #include "Core/HW/WiimoteReal/WiimoteReal.h" +#include "InputCommon/ControllerEmu/ControlGroup/Extension.h" namespace WiimoteEmu { diff --git a/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp b/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp index c5bec3fba8..bb0b6427a9 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp @@ -7,7 +7,9 @@ #include "AudioCommon/AudioCommon.h" #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" +#include "Core/ConfigManager.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" //#define WIIMOTE_SPEAKER_DUMP #ifdef WIIMOTE_SPEAKER_DUMP diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index 6fa9ab5802..46dab58c10 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "Core/HW/WiimoteEmu/WiimoteEmu.h" + #include #include #include @@ -10,6 +12,7 @@ #include "Common/CommonTypes.h" #include "Common/MathUtil.h" #include "Common/MsgHandler.h" + #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/HW/WiimoteEmu/Attachment/Classic.h" @@ -18,13 +21,22 @@ #include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h" #include "Core/HW/WiimoteEmu/Attachment/Turntable.h" #include "Core/HW/WiimoteEmu/MatrixMath.h" -#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteHid.h" #include "Core/HW/WiimoteReal/WiimoteReal.h" #include "Core/Host.h" #include "Core/Movie.h" #include "Core/NetPlayClient.h" +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "InputCommon/ControllerEmu/Control/Output.h" +#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" +#include "InputCommon/ControllerEmu/ControlGroup/Cursor.h" +#include "InputCommon/ControllerEmu/ControlGroup/Extension.h" +#include "InputCommon/ControllerEmu/ControlGroup/Force.h" +#include "InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h" +#include "InputCommon/ControllerEmu/ControlGroup/Tilt.h" + namespace { // :) @@ -239,27 +251,27 @@ Wiimote::Wiimote(const unsigned int index) // ---- set up all the controls ---- // buttons - groups.emplace_back(m_buttons = new Buttons("Buttons")); + groups.emplace_back(m_buttons = new ControllerEmu::Buttons("Buttons")); for (auto& named_button : named_buttons) - m_buttons->controls.emplace_back(new ControlGroup::Input(named_button)); + m_buttons->controls.emplace_back(new ControllerEmu::Input(named_button)); // ir - groups.emplace_back(m_ir = new Cursor(_trans("IR"))); + groups.emplace_back(m_ir = new ControllerEmu::Cursor(_trans("IR"))); // swing - groups.emplace_back(m_swing = new Force(_trans("Swing"))); + groups.emplace_back(m_swing = new ControllerEmu::Force(_trans("Swing"))); // tilt - groups.emplace_back(m_tilt = new Tilt(_trans("Tilt"))); + groups.emplace_back(m_tilt = new ControllerEmu::Tilt(_trans("Tilt"))); // shake - groups.emplace_back(m_shake = new Buttons(_trans("Shake"))); - m_shake->controls.emplace_back(new ControlGroup::Input("X")); - m_shake->controls.emplace_back(new ControlGroup::Input("Y")); - m_shake->controls.emplace_back(new ControlGroup::Input("Z")); + groups.emplace_back(m_shake = new ControllerEmu::Buttons(_trans("Shake"))); + m_shake->controls.emplace_back(new ControllerEmu::Input("X")); + m_shake->controls.emplace_back(new ControllerEmu::Input("Y")); + m_shake->controls.emplace_back(new ControllerEmu::Input("Z")); // extension - groups.emplace_back(m_extension = new Extension(_trans("Extension"))); + groups.emplace_back(m_extension = new ControllerEmu::Extension(_trans("Extension"))); m_extension->attachments.emplace_back(new WiimoteEmu::None(m_reg_ext)); m_extension->attachments.emplace_back(new WiimoteEmu::Nunchuk(m_reg_ext)); m_extension->attachments.emplace_back(new WiimoteEmu::Classic(m_reg_ext)); @@ -268,34 +280,40 @@ Wiimote::Wiimote(const unsigned int index) m_extension->attachments.emplace_back(new WiimoteEmu::Turntable(m_reg_ext)); m_extension->boolean_settings.emplace_back( - std::make_unique(_trans("Motion Plus"), false)); + std::make_unique(_trans("Motion Plus"), false)); // rumble - groups.emplace_back(m_rumble = new ControlGroup(_trans("Rumble"))); - m_rumble->controls.emplace_back(new ControlGroup::Output(_trans("Motor"))); + groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble"))); + m_rumble->controls.emplace_back(new ControllerEmu::Output(_trans("Motor"))); // dpad - groups.emplace_back(m_dpad = new Buttons("D-Pad")); + groups.emplace_back(m_dpad = new ControllerEmu::Buttons("D-Pad")); for (auto& named_direction : named_directions) - m_dpad->controls.emplace_back(new ControlGroup::Input(named_direction)); + m_dpad->controls.emplace_back(new ControllerEmu::Input(named_direction)); // options - groups.emplace_back(m_options = new ControlGroup(_trans("Options"))); + groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options"))); m_options->boolean_settings.emplace_back( - std::make_unique(_trans("Background Input"))); + std::make_unique( + _trans("Background Input"))); m_options->boolean_settings.emplace_back( - std::make_unique(_trans("Sideways Wii Remote"), false)); + std::make_unique(_trans("Sideways Wii Remote"), + false)); m_options->boolean_settings.emplace_back( - std::make_unique(_trans("Upright Wii Remote"), false)); - m_options->boolean_settings.emplace_back(std::make_unique( - _trans("Iterative Input"), false, ControlGroup::SettingType::VIRTUAL)); + std::make_unique(_trans("Upright Wii Remote"), + false)); + m_options->boolean_settings.emplace_back( + std::make_unique( + _trans("Iterative Input"), false, ControllerEmu::ControlGroup::SettingType::VIRTUAL)); m_options->numeric_settings.emplace_back( - std::make_unique(_trans("Speaker Pan"), 0, -127, 127)); + std::make_unique(_trans("Speaker Pan"), 0, -127, + 127)); m_options->numeric_settings.emplace_back( - std::make_unique(_trans("Battery"), 95.0 / 100, 0, 255)); + std::make_unique(_trans("Battery"), 95.0 / 100, + 0, 255)); // hotkeys - groups.emplace_back(m_hotkeys = new ModifySettingsButton(_trans("Hotkeys"))); + groups.emplace_back(m_hotkeys = new ControllerEmu::ModifySettingsButton(_trans("Hotkeys"))); // hotkeys to temporarily modify the Wii Remote orientation (sideways, upright) // this setting modifier is toggled m_hotkeys->AddInput(_trans("Sideways Toggle"), true); @@ -699,7 +717,7 @@ void Wiimote::Update() // returns true if a report was sent { - auto lock = ControllerEmu::GetStateLock(); + const auto lock = GetStateLock(); if (Step()) return; } @@ -724,7 +742,7 @@ void Wiimote::Update() data[0] = 0xA1; data[1] = m_reporting_mode; - auto lock = ControllerEmu::GetStateLock(); + const auto lock = GetStateLock(); // hotkey/settings modifier m_hotkeys->GetState(); // data is later accessed in UpdateButtonsStatus and GetAccelData @@ -959,7 +977,7 @@ void Wiimote::ConnectOnInput() } u16 buttons = 0; - auto lock = ControllerEmu::GetStateLock(); + const auto lock = GetStateLock(); m_buttons->GetState(&buttons, button_bitmasks); m_dpad->GetState(&buttons, dpad_bitmasks); @@ -974,7 +992,7 @@ void Wiimote::ConnectOnInput() void Wiimote::LoadDefaults(const ControllerInterface& ciface) { - ControllerEmu::LoadDefaults(ciface); + EmulatedController::LoadDefaults(ciface); // Buttons #if defined HAVE_X11 && HAVE_X11 @@ -1030,4 +1048,19 @@ void Wiimote::LoadDefaults(const ControllerInterface& ciface) // set nunchuk defaults m_extension->attachments[1]->LoadDefaults(ciface); } + +int Wiimote::CurrentExtension() const +{ + return m_extension->active_extension; } + +bool Wiimote::HaveExtension() const +{ + return m_extension->active_extension > 0; +} + +bool Wiimote::WantExtension() const +{ + return m_extension->switch_extension != 0; +} +} // namespace WiimoteEmu diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h index a32433ec44..31204766c5 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h @@ -20,6 +20,17 @@ class PointerWrap; +namespace ControllerEmu +{ +class Buttons; +class ControlGroup; +class Cursor; +class Extension; +class Force; +class ModifySettingsButton; +class Tilt; +} + namespace WiimoteReal { class Wiimote; @@ -152,7 +163,7 @@ enum ACCEL_RANGE = (ACCEL_ONE_G - ACCEL_ZERO_G), }; -class Wiimote : public ControllerEmu +class Wiimote : public ControllerEmu::EmulatedController { friend class WiimoteReal::Wiimote; @@ -175,8 +186,8 @@ public: Wiimote(const unsigned int index); std::string GetName() const override; - ControlGroup* GetWiimoteGroup(WiimoteGroup group); - ControlGroup* GetNunchukGroup(NunchukGroup group); + ControllerEmu::ControlGroup* GetWiimoteGroup(WiimoteGroup group); + ControllerEmu::ControlGroup* GetNunchukGroup(NunchukGroup group); ControllerEmu::ControlGroup* GetClassicGroup(ClassicGroup group); ControllerEmu::ControlGroup* GetGuitarGroup(GuitarGroup group); ControllerEmu::ControlGroup* GetDrumsGroup(DrumsGroup group); @@ -193,7 +204,8 @@ public: void LoadDefaults(const ControllerInterface& ciface) override; - int CurrentExtension() const { return m_extension->active_extension; } + int CurrentExtension() const; + protected: bool Step(); void HidOutputReport(const wm_report* const sr, const bool send_ack = true); @@ -205,8 +217,9 @@ protected: void GetIRData(u8* const data, bool use_accel); void GetExtData(u8* const data); - bool HaveExtension() const { return m_extension->active_extension > 0; } - bool WantExtension() const { return m_extension->switch_extension != 0; } + bool HaveExtension() const; + bool WantExtension() const; + private: struct ReadRequest { @@ -225,14 +238,16 @@ private: bool NetPlay_GetWiimoteData(int wiimote, u8* data, u8 size, u8 reporting_mode); // control groups - Buttons *m_buttons, *m_dpad, *m_shake; - Cursor* m_ir; - Tilt* m_tilt; - Force* m_swing; - ControlGroup* m_rumble; - Extension* m_extension; - ControlGroup* m_options; - ModifySettingsButton* m_hotkeys; + ControllerEmu::Buttons* m_buttons; + ControllerEmu::Buttons* m_dpad; + ControllerEmu::Buttons* m_shake; + ControllerEmu::Cursor* m_ir; + ControllerEmu::Tilt* m_tilt; + ControllerEmu::Force* m_swing; + ControllerEmu::ControlGroup* m_rumble; + ControllerEmu::Extension* m_extension; + ControllerEmu::ControlGroup* m_options; + ControllerEmu::ModifySettingsButton* m_hotkeys; // Wiimote accel data AccelData m_accel; diff --git a/Source/Core/Core/HotkeyManager.cpp b/Source/Core/Core/HotkeyManager.cpp index c1b5d7bfd8..07a34bf4b5 100644 --- a/Source/Core/Core/HotkeyManager.cpp +++ b/Source/Core/Core/HotkeyManager.cpp @@ -2,11 +2,17 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "Core/HotkeyManager.h" + #include #include #include "Common/Common.h" -#include "Core/HotkeyManager.h" +#include "Common/CommonTypes.h" + +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" #include "InputCommon/GCPadStatus.h" const std::string hotkey_labels[] = { @@ -255,19 +261,22 @@ HotkeyManager::HotkeyManager() { for (int group = 0; group < NUM_HOTKEY_GROUPS; group++) { - m_hotkey_groups[group] = (m_keys[group] = new Buttons("Keys", groups_info[group].name)); + m_hotkey_groups[group] = + (m_keys[group] = new ControllerEmu::Buttons("Keys", groups_info[group].name)); groups.emplace_back(m_hotkey_groups[group]); for (int key = groups_info[group].first; key <= groups_info[group].last; key++) { - m_keys[group]->controls.emplace_back(new ControlGroup::Input(hotkey_labels[key])); + m_keys[group]->controls.emplace_back(new ControllerEmu::Input(hotkey_labels[key])); } } - groups.emplace_back(m_options = new ControlGroup(_trans("Options"))); + groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options"))); m_options->boolean_settings.emplace_back( - std::make_unique(_trans("Background Input"))); - m_options->boolean_settings.emplace_back(std::make_unique( - _trans("Iterative Input"), false, ControlGroup::SettingType::VIRTUAL)); + std::make_unique( + _trans("Background Input"))); + m_options->boolean_settings.emplace_back( + std::make_unique( + _trans("Iterative Input"), false, ControllerEmu::ControlGroup::SettingType::VIRTUAL)); } HotkeyManager::~HotkeyManager() @@ -281,7 +290,7 @@ std::string HotkeyManager::GetName() const void HotkeyManager::GetInput(HotkeyStatus* const kb) { - auto lock = ControllerEmu::GetStateLock(); + const auto lock = GetStateLock(); for (int group = 0; group < NUM_HOTKEY_GROUPS; group++) { const int group_count = (groups_info[group].last - groups_info[group].first) + 1; @@ -319,7 +328,7 @@ int HotkeyManager::GetIndexForGroup(int group, int id) const void HotkeyManager::LoadDefaults(const ControllerInterface& ciface) { - ControllerEmu::LoadDefaults(ciface); + EmulatedController::LoadDefaults(ciface); #ifdef _WIN32 const std::string NON = "(!(LMENU | RMENU) & !(LSHIFT | RSHIFT) & !(LCONTROL | RCONTROL))"; diff --git a/Source/Core/Core/HotkeyManager.h b/Source/Core/Core/HotkeyManager.h index e002c48d54..443a3c0406 100644 --- a/Source/Core/Core/HotkeyManager.h +++ b/Source/Core/Core/HotkeyManager.h @@ -7,9 +7,16 @@ #include #include +#include "Common/CommonTypes.h" #include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/InputConfig.h" +namespace ControllerEmu +{ +class ControllerEmu; +class Buttons; +} + enum Hotkey { HK_OPEN, @@ -183,7 +190,7 @@ struct HotkeyStatus s8 err; }; -class HotkeyManager : public ControllerEmu +class HotkeyManager : public ControllerEmu::EmulatedController { public: HotkeyManager(); @@ -191,16 +198,16 @@ public: void GetInput(HotkeyStatus* const hk); std::string GetName() const override; - ControlGroup* GetHotkeyGroup(HotkeyGroup group) const; - ControlGroup* GetOptionsGroup() const; + ControllerEmu::ControlGroup* GetHotkeyGroup(HotkeyGroup group) const; + ControllerEmu::ControlGroup* GetOptionsGroup() const; int FindGroupByID(int id) const; int GetIndexForGroup(int group, int id) const; void LoadDefaults(const ControllerInterface& ciface) override; private: - Buttons* m_keys[NUM_HOTKEY_GROUPS]; - std::array m_hotkey_groups; - ControlGroup* m_options; + ControllerEmu::Buttons* m_keys[NUM_HOTKEY_GROUPS]; + std::array m_hotkey_groups; + ControllerEmu::ControlGroup* m_options; }; namespace HotkeyManagerEmu diff --git a/Source/Core/DolphinWX/Debugger/CodeWindow.cpp b/Source/Core/DolphinWX/Debugger/CodeWindow.cpp index 979d491c14..1bcd6f6928 100644 --- a/Source/Core/DolphinWX/Debugger/CodeWindow.cpp +++ b/Source/Core/DolphinWX/Debugger/CodeWindow.cpp @@ -28,13 +28,11 @@ #include "Common/CommonTypes.h" #include "Common/StringUtil.h" #include "Common/SymbolDB.h" +#include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/Debugger/Debugger_SymbolMap.h" #include "Core/Debugger/PPCDebugInterface.h" #include "Core/HW/CPU.h" -#include "Core/HW/Memmap.h" -#include "Core/HW/SystemTimers.h" -#include "Core/Host.h" #include "Core/PowerPC/BreakPoints.h" #include "Core/PowerPC/Gekko.h" #include "Core/PowerPC/JitInterface.h" diff --git a/Source/Core/DolphinWX/Input/InputConfigDiag.cpp b/Source/Core/DolphinWX/Input/InputConfigDiag.cpp index af218ff470..7763c2c76f 100644 --- a/Source/Core/DolphinWX/Input/InputConfigDiag.cpp +++ b/Source/Core/DolphinWX/Input/InputConfigDiag.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "DolphinWX/Input/InputConfigDiag.h" + #include #include #include @@ -38,21 +40,27 @@ #include "Common/FileUtil.h" #include "Common/IniFile.h" #include "Common/MsgHandler.h" + #include "Core/Core.h" #include "Core/HW/GCKeyboard.h" #include "Core/HW/GCPad.h" #include "Core/HW/Wiimote.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HotkeyManager.h" + #include "DolphinWX/DolphinSlider.h" #include "DolphinWX/Input/ClassicInputConfigDiag.h" #include "DolphinWX/Input/DrumsInputConfigDiag.h" #include "DolphinWX/Input/GuitarInputConfigDiag.h" -#include "DolphinWX/Input/InputConfigDiag.h" #include "DolphinWX/Input/NunchukInputConfigDiag.h" #include "DolphinWX/Input/TurntableInputConfigDiag.h" #include "DolphinWX/WxUtils.h" + +#include "InputCommon/ControlReference/ControlReference.h" #include "InputCommon/ControlReference/ExpressionParser.h" +#include "InputCommon/ControllerEmu/Control/Control.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" +#include "InputCommon/ControllerEmu/ControlGroup/Extension.h" #include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/Device.h" @@ -385,7 +393,7 @@ bool ControlDialog::Validate() { control_reference->expression = WxStrToStr(textctrl->GetValue()); - auto lock = ControllerEmu::GetStateLock(); + const auto lock = ControllerEmu::EmulatedController::GetStateLock(); control_reference->UpdateReference(g_controller_interface, m_parent->GetController()->default_device); @@ -424,7 +432,7 @@ void ControlDialog::ClearControl(wxCommandEvent&) { control_reference->expression.clear(); - auto lock = ControllerEmu::GetStateLock(); + const auto lock = ControllerEmu::EmulatedController::GetStateLock(); control_reference->UpdateReference(g_controller_interface, m_parent->GetController()->default_device); @@ -483,7 +491,7 @@ void ControlDialog::SetSelectedControl(wxCommandEvent&) textctrl->WriteText(expr); control_reference->expression = textctrl->GetValue(); - auto lock = ControllerEmu::GetStateLock(); + const auto lock = ControllerEmu::EmulatedController::GetStateLock(); control_reference->UpdateReference(g_controller_interface, m_parent->GetController()->default_device); @@ -519,7 +527,7 @@ void ControlDialog::AppendControl(wxCommandEvent& event) textctrl->WriteText(expr); control_reference->expression = textctrl->GetValue(); - auto lock = ControllerEmu::GetStateLock(); + const auto lock = ControllerEmu::EmulatedController::GetStateLock(); control_reference->UpdateReference(g_controller_interface, m_parent->GetController()->default_device); @@ -701,7 +709,7 @@ bool InputConfigDialog::DetectButton(ControlButton* button) wxString expr; GetExpressionForControl(expr, control_name); button->control_reference->expression = expr; - auto lock = ControllerEmu::GetStateLock(); + const auto lock = ControllerEmu::EmulatedController::GetStateLock(); button->control_reference->UpdateReference(g_controller_interface, controller->default_device); success = true; @@ -831,7 +839,7 @@ void InputConfigDialog::GetProfilePath(std::string& path) } } -ControllerEmu* InputConfigDialog::GetController() const +ControllerEmu::EmulatedController* InputConfigDialog::GetController() const { return controller; } @@ -930,8 +938,10 @@ ControlGroupBox::~ControlGroupBox() bool ControlGroupBox::HasBitmapHeading() const { - return control_group->type == GROUP_TYPE_STICK || control_group->type == GROUP_TYPE_TILT || - control_group->type == GROUP_TYPE_CURSOR || control_group->type == GROUP_TYPE_FORCE; + return control_group->type == ControllerEmu::GROUP_TYPE_STICK || + control_group->type == ControllerEmu::GROUP_TYPE_TILT || + control_group->type == ControllerEmu::GROUP_TYPE_CURSOR || + control_group->type == ControllerEmu::GROUP_TYPE_FORCE; } ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWindow* const parent, @@ -986,10 +996,10 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin switch (group->type) { - case GROUP_TYPE_STICK: - case GROUP_TYPE_TILT: - case GROUP_TYPE_CURSOR: - case GROUP_TYPE_FORCE: + case ControllerEmu::GROUP_TYPE_STICK: + case ControllerEmu::GROUP_TYPE_TILT: + case ControllerEmu::GROUP_TYPE_CURSOR: + case ControllerEmu::GROUP_TYPE_FORCE: { wxSize bitmap_size = parent->FromDIP(wxSize(64, 64)); m_scale = bitmap_size.GetWidth() / 64.0; @@ -1031,7 +1041,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin Add(h_szr, 0, wxEXPAND | wxLEFT | wxRIGHT, space3); } break; - case GROUP_TYPE_BUTTONS: + case ControllerEmu::GROUP_TYPE_BUTTONS: { // Draw buttons in rows of 8 unsigned int button_cols = group->controls.size() > 8 ? 8 : group->controls.size(); @@ -1069,17 +1079,17 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin Add(static_bitmap, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3); } break; - case GROUP_TYPE_MIXED_TRIGGERS: - case GROUP_TYPE_TRIGGERS: - case GROUP_TYPE_SLIDER: + case ControllerEmu::GROUP_TYPE_MIXED_TRIGGERS: + case ControllerEmu::GROUP_TYPE_TRIGGERS: + case ControllerEmu::GROUP_TYPE_SLIDER: { int height = (int)(12 * group->controls.size()); int width = 64; - if (GROUP_TYPE_MIXED_TRIGGERS == group->type) + if (ControllerEmu::GROUP_TYPE_MIXED_TRIGGERS == group->type) width = 64 + 12 + 1; - if (GROUP_TYPE_TRIGGERS != group->type) + if (ControllerEmu::GROUP_TYPE_TRIGGERS != group->type) height /= 2; height += 1; @@ -1113,7 +1123,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin Add(static_bitmap, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3); } break; - case GROUP_TYPE_EXTENSION: + case ControllerEmu::GROUP_TYPE_EXTENSION: { PadSettingExtension* const attachments = new PadSettingExtension(parent, (ControllerEmu::Extension*)group); diff --git a/Source/Core/DolphinWX/Input/InputConfigDiag.h b/Source/Core/DolphinWX/Input/InputConfigDiag.h index d89aae5481..068b5c48cb 100644 --- a/Source/Core/DolphinWX/Input/InputConfigDiag.h +++ b/Source/Core/DolphinWX/Input/InputConfigDiag.h @@ -23,10 +23,10 @@ #include #include -#include "InputCommon/ControlReference/ControlReference.h" -#include "InputCommon/ControllerEmu/ControllerEmu.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" #include "InputCommon/ControllerInterface/Device.h" +class ControlReference; class DolphinSlider; class InputConfig; class wxComboBox; @@ -35,6 +35,12 @@ class wxStaticBitmap; class wxStaticText; class wxTextCtrl; +namespace ControllerEmu +{ +class EmulatedController; +class Extension; +} + class PadSetting { protected: @@ -221,7 +227,7 @@ public: void AdjustBooleanSetting(wxCommandEvent& event); void GetProfilePath(std::string& path); - ControllerEmu* GetController() const; + ControllerEmu::EmulatedController* GetController() const; wxComboBox* profile_cbox = nullptr; wxComboBox* device_cbox = nullptr; @@ -234,7 +240,7 @@ protected: wxBoxSizer* CreaterResetGroupBox(wxOrientation orientation); wxBoxSizer* CreateProfileChooserGroupBox(); - ControllerEmu* const controller; + ControllerEmu::EmulatedController* const controller; wxTimer m_update_timer; diff --git a/Source/Core/DolphinWX/Input/InputConfigDiagBitmaps.cpp b/Source/Core/DolphinWX/Input/InputConfigDiagBitmaps.cpp index 57f2d892a2..a00cf0ab41 100644 --- a/Source/Core/DolphinWX/Input/InputConfigDiagBitmaps.cpp +++ b/Source/Core/DolphinWX/Input/InputConfigDiagBitmaps.cpp @@ -22,6 +22,15 @@ #include "DolphinWX/Input/InputConfigDiag.h" #include "DolphinWX/WxUtils.h" +#include "InputCommon/ControllerEmu/Control/Control.h" +#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h" +#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" +#include "InputCommon/ControllerEmu/ControlGroup/Cursor.h" +#include "InputCommon/ControllerEmu/ControlGroup/Force.h" +#include "InputCommon/ControllerEmu/ControlGroup/Slider.h" +#include "InputCommon/ControllerEmu/ControlGroup/Tilt.h" +#include "InputCommon/ControllerEmu/ControlGroup/Triggers.h" #include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/Device.h" @@ -150,9 +159,9 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g) switch (g->control_group->type) { - case GROUP_TYPE_TILT: - case GROUP_TYPE_STICK: - case GROUP_TYPE_CURSOR: + case ControllerEmu::GROUP_TYPE_TILT: + case ControllerEmu::GROUP_TYPE_STICK: + case ControllerEmu::GROUP_TYPE_CURSOR: { // this is starting to be a mess combining all these in one case @@ -160,19 +169,19 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g) switch (g->control_group->type) { - case GROUP_TYPE_STICK: + case ControllerEmu::GROUP_TYPE_STICK: ((ControllerEmu::AnalogStick*)g->control_group)->GetState(&x, &y); break; - case GROUP_TYPE_TILT: + case ControllerEmu::GROUP_TYPE_TILT: ((ControllerEmu::Tilt*)g->control_group)->GetState(&x, &y); break; - case GROUP_TYPE_CURSOR: + case ControllerEmu::GROUP_TYPE_CURSOR: ((ControllerEmu::Cursor*)g->control_group)->GetState(&x, &y, &z); break; } // ir cursor forward movement - if (GROUP_TYPE_CURSOR == g->control_group->type) + if (ControllerEmu::GROUP_TYPE_CURSOR == g->control_group->type) { gc->SetBrush(z ? *wxRED_BRUSH : *wxGREY_BRUSH); wxGraphicsPath path = gc->CreatePath(); @@ -182,7 +191,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g) // input zone gc->SetPen(*wxLIGHT_GREY_PEN); - if (GROUP_TYPE_STICK == g->control_group->type) + if (ControllerEmu::GROUP_TYPE_STICK == g->control_group->type) { gc->SetBrush(wxColour(0xDDDDDD)); // Light Gray @@ -222,9 +231,12 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g) gc->DrawRectangle(16, 16, 32, 32); } - if (GROUP_TYPE_CURSOR != g->control_group->type) + if (ControllerEmu::GROUP_TYPE_CURSOR != g->control_group->type) { - int deadzone_idx = g->control_group->type == GROUP_TYPE_STICK ? SETTING_DEADZONE : 0; + const int deadzone_idx = g->control_group->type == ControllerEmu::GROUP_TYPE_STICK ? + ControllerEmu::AnalogStick::SETTING_DEADZONE : + 0; + wxGraphicsPath path = gc->CreatePath(); path.AddCircle(VIS_BITMAP_SIZE / 2, VIS_BITMAP_SIZE / 2, g->control_group->numeric_settings[deadzone_idx]->GetValue() * @@ -255,7 +267,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g) } break; - case GROUP_TYPE_FORCE: + case ControllerEmu::GROUP_TYPE_FORCE: { ControlState raw_dot[3]; ControlState adj_dot[3]; @@ -320,7 +332,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g) } break; - case GROUP_TYPE_BUTTONS: + case ControllerEmu::GROUP_TYPE_BUTTONS: { const unsigned int button_count = static_cast(g->control_group->controls.size()); std::vector bitmasks(button_count); @@ -349,7 +361,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g) } break; - case GROUP_TYPE_TRIGGERS: + case ControllerEmu::GROUP_TYPE_TRIGGERS: { const unsigned int trigger_count = static_cast(g->control_group->controls.size()); std::vector trigs(trigger_count); @@ -391,7 +403,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g) } break; - case GROUP_TYPE_MIXED_TRIGGERS: + case ControllerEmu::GROUP_TYPE_MIXED_TRIGGERS: { const unsigned int trigger_count = ((unsigned int)(g->control_group->controls.size() / 2)); @@ -431,7 +443,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g) } break; - case GROUP_TYPE_SLIDER: + case ControllerEmu::GROUP_TYPE_SLIDER: { const ControlState deadzone = g->control_group->numeric_settings[0]->GetValue(); @@ -488,7 +500,7 @@ void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event)) g_controller_interface.UpdateInput(); wxMemoryDC dc; - auto lock = ControllerEmu::GetStateLock(); + const auto lock = ControllerEmu::EmulatedController::GetStateLock(); for (ControlGroupBox* g : control_groups) { // Only if this control group has a bitmap diff --git a/Source/Core/InputCommon/CMakeLists.txt b/Source/Core/InputCommon/CMakeLists.txt index 0c408a6567..b86c0500de 100644 --- a/Source/Core/InputCommon/CMakeLists.txt +++ b/Source/Core/InputCommon/CMakeLists.txt @@ -1,5 +1,19 @@ set(SRCS InputConfig.cpp ControllerEmu/ControllerEmu.cpp + ControllerEmu/Control/Control.cpp + ControllerEmu/Control/Input.cpp + ControllerEmu/Control/Output.cpp + ControllerEmu/ControlGroup/AnalogStick.cpp + ControllerEmu/ControlGroup/Buttons.cpp + ControllerEmu/ControlGroup/ControlGroup.cpp + ControllerEmu/ControlGroup/Cursor.cpp + ControllerEmu/ControlGroup/Extension.cpp + ControllerEmu/ControlGroup/Force.cpp + ControllerEmu/ControlGroup/MixedTriggers.cpp + ControllerEmu/ControlGroup/ModifySettingsButton.cpp + ControllerEmu/ControlGroup/Slider.cpp + ControllerEmu/ControlGroup/Tilt.cpp + ControllerEmu/ControlGroup/Triggers.cpp ControllerInterface/ControllerInterface.cpp ControllerInterface/Device.cpp ControlReference/ControlReference.cpp diff --git a/Source/Core/InputCommon/ControllerEmu/Control/Control.cpp b/Source/Core/InputCommon/ControllerEmu/Control/Control.cpp new file mode 100644 index 0000000000..00f9a71069 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/Control/Control.cpp @@ -0,0 +1,15 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/Control/Control.h" +#include "InputCommon/ControlReference/ControlReference.h" + +namespace ControllerEmu +{ +Control::Control(ControlReference* ref, const std::string& name_) : control_ref(ref), name(name_) +{ +} + +Control::~Control() = default; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/Control/Control.h b/Source/Core/InputCommon/ControllerEmu/Control/Control.h new file mode 100644 index 0000000000..ef88ebd328 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/Control/Control.h @@ -0,0 +1,25 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include + +class ControlReference; + +namespace ControllerEmu +{ +class Control +{ +public: + virtual ~Control(); + + std::unique_ptr const control_ref; + const std::string name; + +protected: + Control(ControlReference* ref, const std::string& name); +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/Control/Input.cpp b/Source/Core/InputCommon/ControllerEmu/Control/Input.cpp new file mode 100644 index 0000000000..0f2e400e56 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/Control/Input.cpp @@ -0,0 +1,15 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/Control/Input.h" + +#include +#include "InputCommon/ControlReference/ControlReference.h" + +namespace ControllerEmu +{ +Input::Input(const std::string& name_) : Control(new InputReference, name_) +{ +} +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/Control/Input.h b/Source/Core/InputCommon/ControllerEmu/Control/Input.h new file mode 100644 index 0000000000..678514736e --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/Control/Input.h @@ -0,0 +1,17 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include "InputCommon/ControllerEmu/Control/Control.h" + +namespace ControllerEmu +{ +class Input : public Control +{ +public: + explicit Input(const std::string& name); +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/Control/Output.cpp b/Source/Core/InputCommon/ControllerEmu/Control/Output.cpp new file mode 100644 index 0000000000..24d7b30499 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/Control/Output.cpp @@ -0,0 +1,15 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/Control/Output.h" + +#include +#include "InputCommon/ControlReference/ControlReference.h" + +namespace ControllerEmu +{ +Output::Output(const std::string& name_) : Control(new OutputReference, name_) +{ +} +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/Control/Output.h b/Source/Core/InputCommon/ControllerEmu/Control/Output.h new file mode 100644 index 0000000000..415c67f7d9 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/Control/Output.h @@ -0,0 +1,17 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include "InputCommon/ControllerEmu/Control/Control.h" + +namespace ControllerEmu +{ +class Output : public Control +{ +public: + explicit Output(const std::string& name); +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp new file mode 100644 index 0000000000..8ee7357963 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp @@ -0,0 +1,71 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h" + +#include +#include +#include + +#include "Common/Common.h" + +#include "InputCommon/ControlReference/ControlReference.h" +#include "InputCommon/ControllerEmu/Control/Control.h" +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "InputCommon/ControllerEmu/ControllerEmu.h" + +namespace ControllerEmu +{ +AnalogStick::AnalogStick(const char* const name_, ControlState default_radius) + : AnalogStick(name_, name_, default_radius) +{ +} + +AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_, + ControlState default_radius) + : ControlGroup(name_, ui_name_, GROUP_TYPE_STICK) +{ + for (auto& named_direction : named_directions) + controls.emplace_back(std::make_unique(named_direction)); + + controls.emplace_back(std::make_unique(_trans("Modifier"))); + numeric_settings.emplace_back( + std::make_unique(_trans("Radius"), default_radius, 0, 100)); + numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 50)); +} + +void AnalogStick::GetState(ControlState* const x, ControlState* const y) +{ + ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State(); + ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State(); + + ControlState radius = numeric_settings[SETTING_RADIUS]->GetValue(); + ControlState deadzone = numeric_settings[SETTING_DEADZONE]->GetValue(); + ControlState m = controls[4]->control_ref->State(); + + ControlState ang = atan2(yy, xx); + ControlState ang_sin = sin(ang); + ControlState ang_cos = cos(ang); + + ControlState dist = sqrt(xx * xx + yy * yy); + + // dead zone code + dist = std::max(0.0, dist - deadzone); + dist /= (1 - deadzone); + + // radius + dist *= radius; + + // The modifier halves the distance by 50%, which is useful + // for keyboard controls. + if (m) + dist *= 0.5; + + yy = std::max(-1.0, std::min(1.0, ang_sin * dist)); + xx = std::max(-1.0, std::min(1.0, ang_cos * dist)); + + *y = yy; + *x = xx; +} +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h new file mode 100644 index 0000000000..2d05b6baa4 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h @@ -0,0 +1,26 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" + +namespace ControllerEmu +{ +class AnalogStick : public ControlGroup +{ +public: + enum + { + SETTING_RADIUS, + SETTING_DEADZONE, + }; + + // The GameCube controller and Wiimote attachments have a different default radius + AnalogStick(const char* name, ControlState default_radius); + AnalogStick(const char* name, const char* ui_name, ControlState default_radius); + + void GetState(ControlState* x, ControlState* y); +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.cpp new file mode 100644 index 0000000000..55e4532e7a --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.cpp @@ -0,0 +1,24 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" + +#include +#include + +#include "Common/Common.h" + +namespace ControllerEmu +{ +Buttons::Buttons(const std::string& name_) : ControlGroup(name_, name_, GROUP_TYPE_BUTTONS) +{ + numeric_settings.emplace_back(std::make_unique(_trans("Threshold"), 0.5)); +} + +Buttons::Buttons(const std::string& ini_name, const std::string& group_name) + : ControlGroup(ini_name, group_name, GROUP_TYPE_BUTTONS) +{ + numeric_settings.emplace_back(std::make_unique(_trans("Threshold"), 0.5)); +} +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h new file mode 100644 index 0000000000..9b1acd866c --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Buttons.h @@ -0,0 +1,33 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +#include "InputCommon/ControlReference/ControlReference.h" +#include "InputCommon/ControllerEmu/Control/Control.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" + +namespace ControllerEmu +{ +class Buttons : public ControlGroup +{ +public: + explicit Buttons(const std::string& name_); + Buttons(const std::string& ini_name, const std::string& group_name); + + template + void GetState(C* const buttons, const C* bitmasks) + { + for (auto& control : controls) + { + if (control->control_ref->State() > numeric_settings[0]->GetValue()) // threshold + *buttons |= *bitmasks; + + bitmasks++; + } + } +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp new file mode 100644 index 0000000000..cd730697a5 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp @@ -0,0 +1,132 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" + +#include "Common/CommonTypes.h" +#include "Common/IniFile.h" + +#include "InputCommon/ControlReference/ControlReference.h" +#include "InputCommon/ControllerEmu/Control/Control.h" +#include "InputCommon/ControllerEmu/ControlGroup/Extension.h" +#include "InputCommon/ControllerEmu/ControllerEmu.h" + +namespace ControllerEmu +{ +ControlGroup::ControlGroup(const std::string& name_, const u32 type_) + : name(name_), ui_name(name_), type(type_) +{ +} + +ControlGroup::ControlGroup(const std::string& name_, const std::string& ui_name_, const u32 type_) + : name(name_), ui_name(ui_name_), type(type_) +{ +} + +ControlGroup::~ControlGroup() = default; + +ControlGroup::BooleanSetting::~BooleanSetting() = default; + +void ControlGroup::LoadConfig(IniFile::Section* sec, const std::string& defdev, + const std::string& base) +{ + std::string group(base + name + "/"); + + // settings + for (auto& s : numeric_settings) + { + if (s->m_type == SettingType::VIRTUAL) + continue; + + sec->Get(group + s->m_name, &s->m_value, s->m_default_value * 100); + s->m_value /= 100; + } + + for (auto& s : boolean_settings) + { + if (s->m_type == SettingType::VIRTUAL) + continue; + + sec->Get(group + s->m_name, &s->m_value, s->m_default_value); + } + + for (auto& c : controls) + { + // control expression + sec->Get(group + c->name, &c->control_ref->expression, ""); + + // range + sec->Get(group + c->name + "/Range", &c->control_ref->range, 100.0); + c->control_ref->range /= 100; + } + + // extensions + if (type == GROUP_TYPE_EXTENSION) + { + Extension* const ext = (Extension*)this; + + ext->switch_extension = 0; + u32 n = 0; + std::string extname; + sec->Get(base + name, &extname, ""); + + for (auto& ai : ext->attachments) + { + ai->default_device.FromString(defdev); + ai->LoadConfig(sec, base + ai->GetName() + "/"); + + if (ai->GetName() == extname) + ext->switch_extension = n; + + n++; + } + } +} + +void ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev, + const std::string& base) +{ + std::string group(base + name + "/"); + + for (auto& s : numeric_settings) + { + if (s->m_type == SettingType::VIRTUAL) + continue; + + sec->Set(group + s->m_name, s->m_value * 100.0, s->m_default_value * 100.0); + } + + for (auto& s : boolean_settings) + { + if (s->m_type == SettingType::VIRTUAL) + continue; + + sec->Set(group + s->m_name, s->m_value, s->m_default_value); + } + + for (auto& c : controls) + { + // control expression + sec->Set(group + c->name, c->control_ref->expression, ""); + + // range + sec->Set(group + c->name + "/Range", c->control_ref->range * 100.0, 100.0); + } + + // extensions + if (type == GROUP_TYPE_EXTENSION) + { + Extension* const ext = (Extension*)this; + sec->Set(base + name, ext->attachments[ext->switch_extension]->GetName(), "None"); + + for (auto& ai : ext->attachments) + ai->SaveConfig(sec, base + ai->GetName() + "/"); + } +} + +void ControlGroup::SetControlExpression(int index, const std::string& expression) +{ + controls.at(index)->control_ref->expression = expression; +} +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h new file mode 100644 index 0000000000..68eacb6e02 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h @@ -0,0 +1,117 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include + +#include "Common/CommonTypes.h" +#include "Common/IniFile.h" +#include "Core/ConfigManager.h" +#include "InputCommon/ControllerInterface/Device.h" + +namespace ControllerEmu +{ +class Control; + +enum +{ + GROUP_TYPE_OTHER, + GROUP_TYPE_STICK, + GROUP_TYPE_MIXED_TRIGGERS, + GROUP_TYPE_BUTTONS, + GROUP_TYPE_FORCE, + GROUP_TYPE_EXTENSION, + GROUP_TYPE_TILT, + GROUP_TYPE_CURSOR, + GROUP_TYPE_TRIGGERS, + GROUP_TYPE_SLIDER +}; + +class ControlGroup +{ +public: + enum class SettingType + { + NORMAL, // normal settings are saved to configuration files + VIRTUAL, // virtual settings are not saved at all + }; + + class NumericSetting + { + public: + NumericSetting(const std::string& setting_name, const ControlState default_value, + const u32 low = 0, const u32 high = 100, + const SettingType setting_type = SettingType::NORMAL) + : m_type(setting_type), m_name(setting_name), m_default_value(default_value), m_low(low), + m_high(high) + { + } + + ControlState GetValue() const { return m_value; } + void SetValue(ControlState value) { m_value = value; } + const SettingType m_type; + const std::string m_name; + const ControlState m_default_value; + const u32 m_low; + const u32 m_high; + ControlState m_value; + }; + + class BooleanSetting + { + public: + BooleanSetting(const std::string& setting_name, const bool default_value, + const SettingType setting_type = SettingType::NORMAL) + : m_type(setting_type), m_name(setting_name), m_default_value(default_value) + { + } + virtual ~BooleanSetting(); + + virtual bool GetValue() const { return m_value; } + virtual void SetValue(bool value) { m_value = value; } + const SettingType m_type; + const std::string m_name; + const bool m_default_value; + bool m_value; + }; + + class BackgroundInputSetting : public BooleanSetting + { + public: + BackgroundInputSetting(const std::string& setting_name) + : BooleanSetting(setting_name, false, SettingType::VIRTUAL) + { + } + + bool GetValue() const override { return SConfig::GetInstance().m_BackgroundInput; } + void SetValue(bool value) override + { + m_value = value; + SConfig::GetInstance().m_BackgroundInput = value; + } + }; + + explicit ControlGroup(const std::string& name, u32 type = GROUP_TYPE_OTHER); + ControlGroup(const std::string& name, const std::string& ui_name, u32 type = GROUP_TYPE_OTHER); + virtual ~ControlGroup(); + + virtual void LoadConfig(IniFile::Section* sec, const std::string& defdev = "", + const std::string& base = ""); + virtual void SaveConfig(IniFile::Section* sec, const std::string& defdev = "", + const std::string& base = ""); + + void SetControlExpression(int index, const std::string& expression); + + const std::string name; + const std::string ui_name; + const u32 type; + + std::vector> controls; + std::vector> numeric_settings; + std::vector> boolean_settings; +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp new file mode 100644 index 0000000000..1d0c55a8d5 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp @@ -0,0 +1,98 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/ControlGroup/Cursor.h" + +#include +#include +#include +#include + +#include "Common/Common.h" +#include "Common/MathUtil.h" + +#include "InputCommon/ControlReference/ControlReference.h" +#include "InputCommon/ControllerEmu/Control/Control.h" +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "InputCommon/ControllerEmu/ControllerEmu.h" + +namespace ControllerEmu +{ +Cursor::Cursor(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_CURSOR) +{ + for (auto& named_direction : named_directions) + controls.emplace_back(std::make_unique(named_direction)); + + controls.emplace_back(std::make_unique("Forward")); + controls.emplace_back(std::make_unique("Backward")); + controls.emplace_back(std::make_unique(_trans("Hide"))); + controls.emplace_back(std::make_unique("Recenter")); + + numeric_settings.emplace_back(std::make_unique(_trans("Center"), 0.5)); + numeric_settings.emplace_back(std::make_unique(_trans("Width"), 0.5)); + numeric_settings.emplace_back(std::make_unique(_trans("Height"), 0.5)); + numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 20)); + boolean_settings.emplace_back(std::make_unique(_trans("Relative Input"), false)); +} + +void Cursor::GetState(ControlState* const x, ControlState* const y, ControlState* const z, + const bool adjusted) +{ + const ControlState zz = controls[4]->control_ref->State() - controls[5]->control_ref->State(); + + // silly being here + if (zz > m_z) + m_z = std::min(m_z + 0.1, zz); + else if (zz < m_z) + m_z = std::max(m_z - 0.1, zz); + + *z = m_z; + + // hide + if (controls[6]->control_ref->State() > 0.5) + { + *x = 10000; + *y = 0; + } + else + { + ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State(); + ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State(); + + // adjust cursor according to settings + if (adjusted) + { + xx *= (numeric_settings[1]->GetValue() * 2); + yy *= (numeric_settings[2]->GetValue() * 2); + yy += (numeric_settings[0]->GetValue() - 0.5); + } + + // relative input + if (boolean_settings[0]->GetValue()) + { + const ControlState deadzone = numeric_settings[3]->GetValue(); + // deadzone to avoid the cursor slowly drifting + if (std::abs(xx) > deadzone) + m_x = MathUtil::Clamp(m_x + xx * SPEED_MULTIPLIER, -1.0, 1.0); + if (std::abs(yy) > deadzone) + m_y = MathUtil::Clamp(m_y + yy * SPEED_MULTIPLIER, -1.0, 1.0); + + // recenter + if (controls[7]->control_ref->State() > 0.5) + { + m_x = 0.0; + m_y = 0.0; + } + } + else + { + m_x = xx; + m_y = yy; + } + + *x = m_x; + *y = m_y; + } +} +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h new file mode 100644 index 0000000000..3520d95d13 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h @@ -0,0 +1,29 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" + +namespace ControllerEmu +{ +class Cursor : public ControlGroup +{ +public: + explicit Cursor(const std::string& name); + + void GetState(ControlState* x, ControlState* y, ControlState* z, bool adjusted = false); + + ControlState m_z = 0.0; + +private: + // This is used to reduce the cursor speed for relative input + // to something that makes sense with the default range. + static constexpr double SPEED_MULTIPLIER = 0.04; + + ControlState m_x = 0.0; + ControlState m_y = 0.0; +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.cpp new file mode 100644 index 0000000000..b35eb40bbd --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.cpp @@ -0,0 +1,16 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/ControlGroup/Extension.h" + +#include + +#include "InputCommon/ControllerEmu/ControllerEmu.h" + +namespace ControllerEmu +{ +Extension::Extension(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_EXTENSION) +{ +} +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.h new file mode 100644 index 0000000000..366e94f248 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.h @@ -0,0 +1,31 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include + +#include "Common/CommonTypes.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" + +namespace ControllerEmu +{ +class EmulatedController; + +class Extension : public ControlGroup +{ +public: + explicit Extension(const std::string& name); + + void GetState(u8* data); + bool IsButtonPressed() const; + + std::vector> attachments; + + int switch_extension = 0; + int active_extension = 0; +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp new file mode 100644 index 0000000000..29413ada2c --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp @@ -0,0 +1,51 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/ControlGroup/Force.h" + +#include +#include +#include +#include + +#include "Common/Common.h" +#include "Common/CommonTypes.h" +#include "InputCommon/ControlReference/ControlReference.h" +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "InputCommon/ControllerEmu/ControllerEmu.h" + +namespace ControllerEmu +{ +Force::Force(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_FORCE) +{ + memset(m_swing, 0, sizeof(m_swing)); + + controls.emplace_back(std::make_unique(_trans("Up"))); + controls.emplace_back(std::make_unique(_trans("Down"))); + controls.emplace_back(std::make_unique(_trans("Left"))); + controls.emplace_back(std::make_unique(_trans("Right"))); + controls.emplace_back(std::make_unique(_trans("Forward"))); + controls.emplace_back(std::make_unique(_trans("Backward"))); + + numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 50)); +} + +void Force::GetState(ControlState* axis) +{ + const ControlState deadzone = numeric_settings[0]->GetValue(); + + for (u32 i = 0; i < 6; i += 2) + { + ControlState tmpf = 0; + const ControlState state = + controls[i + 1]->control_ref->State() - controls[i]->control_ref->State(); + if (fabs(state) > deadzone) + tmpf = ((state - (deadzone * sign(state))) / (1 - deadzone)); + + ControlState& ax = m_swing[i >> 1]; + *axis++ = (tmpf - ax); + ax = tmpf; + } +} +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.h new file mode 100644 index 0000000000..767009a1f8 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.h @@ -0,0 +1,22 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" + +namespace ControllerEmu +{ +class Force : public ControlGroup +{ +public: + explicit Force(const std::string& name); + + void GetState(ControlState* axis); + +private: + ControlState m_swing[3]; +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.cpp new file mode 100644 index 0000000000..db8efc48a5 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.cpp @@ -0,0 +1,42 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h" + +#include +#include +#include + +#include "Common/Common.h" +#include "Common/CommonTypes.h" + +#include "InputCommon/ControlReference/ControlReference.h" +#include "InputCommon/ControllerEmu/Control/Control.h" + +namespace ControllerEmu +{ +MixedTriggers::MixedTriggers(const std::string& name_) + : ControlGroup(name_, GROUP_TYPE_MIXED_TRIGGERS) +{ + numeric_settings.emplace_back(std::make_unique(_trans("Threshold"), 0.9)); +} + +void MixedTriggers::GetState(u16* const digital, const u16* bitmasks, ControlState* analog) +{ + const size_t trigger_count = controls.size() / 2; + + for (size_t i = 0; i < trigger_count; ++i, ++bitmasks, ++analog) + { + if (controls[i]->control_ref->State() > numeric_settings[0]->GetValue()) // threshold + { + *analog = 1.0; + *digital |= *bitmasks; + } + else + { + *analog = controls[i + trigger_count]->control_ref->State(); + } + } +} +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h new file mode 100644 index 0000000000..7cd606e53a --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h @@ -0,0 +1,19 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" + +namespace ControllerEmu +{ +class MixedTriggers : public ControlGroup +{ +public: + explicit MixedTriggers(const std::string& name); + + void GetState(u16* digital, const u16* bitmasks, ControlState* analog); +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp new file mode 100644 index 0000000000..b71b1ea2c1 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp @@ -0,0 +1,77 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h" + +#include +#include +#include +#include + +#include "Common/Common.h" +#include "InputCommon/ControlReference/ControlReference.h" +#include "InputCommon/ControllerEmu/Control/Control.h" +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "VideoCommon/OnScreenDisplay.h" + +namespace ControllerEmu +{ +ModifySettingsButton::ModifySettingsButton(std::string button_name) + : Buttons(std::move(button_name)) +{ + numeric_settings.emplace_back(std::make_unique(_trans("Threshold"), 0.5)); +} + +void ModifySettingsButton::AddInput(std::string button_name, bool toggle) +{ + controls.emplace_back(new Input(std::move(button_name))); + threshold_exceeded.emplace_back(false); + associated_settings.emplace_back(false); + associated_settings_toggle.emplace_back(toggle); +} + +void ModifySettingsButton::GetState() +{ + for (size_t i = 0; i < controls.size(); ++i) + { + ControlState state = controls[i]->control_ref->State(); + + if (!associated_settings_toggle[i]) + { + // not toggled + associated_settings[i] = state > numeric_settings[0]->GetValue(); + } + 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 > numeric_settings[0]->GetValue()) + { + associated_settings[i] = !associated_settings[i]; + + if (associated_settings[i]) + OSD::AddMessage(controls[i]->name + ": " + _trans("on")); + else + OSD::AddMessage(controls[i]->name + ": " + _trans("off")); + + threshold_exceeded[i] = true; + } + + if (state < numeric_settings[0]->GetValue()) + threshold_exceeded[i] = false; + } + } +} + +const std::vector& ModifySettingsButton::isSettingToggled() const +{ + return associated_settings_toggle; +} + +const std::vector& ModifySettingsButton::getSettingsModifier() const +{ + return associated_settings; +} +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h new file mode 100644 index 0000000000..667f3e5c7a --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h @@ -0,0 +1,31 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include + +#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" + +namespace ControllerEmu +{ +class ModifySettingsButton : public Buttons +{ +public: + explicit ModifySettingsButton(std::string button_name); + + void AddInput(std::string button_name, bool toggle = false); + + void GetState(); + + 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 +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.cpp new file mode 100644 index 0000000000..5fdf349bba --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.cpp @@ -0,0 +1,37 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/ControlGroup/Slider.h" + +#include +#include +#include + +#include "Common/Common.h" +#include "InputCommon/ControlReference/ControlReference.h" +#include "InputCommon/ControllerEmu/Control/Control.h" +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "InputCommon/ControllerEmu/ControllerEmu.h" + +namespace ControllerEmu +{ +Slider::Slider(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_SLIDER) +{ + controls.emplace_back(std::make_unique("Left")); + controls.emplace_back(std::make_unique("Right")); + + numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 50)); +} + +void Slider::GetState(ControlState* const slider) +{ + const ControlState deadzone = numeric_settings[0]->GetValue(); + const ControlState state = controls[1]->control_ref->State() - controls[0]->control_ref->State(); + + if (fabs(state) > deadzone) + *slider = (state - (deadzone * sign(state))) / (1 - deadzone); + else + *slider = 0; +} +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.h new file mode 100644 index 0000000000..3d6f7f5a02 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Slider.h @@ -0,0 +1,19 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" + +namespace ControllerEmu +{ +class Slider : public ControlGroup +{ +public: + explicit Slider(const std::string& name); + + void GetState(ControlState* slider); +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.cpp new file mode 100644 index 0000000000..5481d92606 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.cpp @@ -0,0 +1,99 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/ControlGroup/Tilt.h" + +#include +#include +#include +#include +#include + +#include "Common/Common.h" +#include "InputCommon/ControlReference/ControlReference.h" +#include "InputCommon/ControllerEmu/Control/Control.h" +#include "InputCommon/ControllerEmu/Control/Input.h" + +namespace ControllerEmu +{ +Tilt::Tilt(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_TILT) +{ + memset(m_tilt, 0, sizeof(m_tilt)); + + controls.emplace_back(std::make_unique("Forward")); + controls.emplace_back(std::make_unique("Backward")); + controls.emplace_back(std::make_unique("Left")); + controls.emplace_back(std::make_unique("Right")); + + controls.emplace_back(std::make_unique(_trans("Modifier"))); + + numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 50)); + numeric_settings.emplace_back(std::make_unique(_trans("Circle Stick"), 0)); + numeric_settings.emplace_back(std::make_unique(_trans("Angle"), 0.9, 0, 180)); +} + +void Tilt::GetState(ControlState* const x, ControlState* const y, const bool step) +{ + // this is all a mess + + ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State(); + ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State(); + + ControlState deadzone = numeric_settings[0]->GetValue(); + ControlState circle = numeric_settings[1]->GetValue(); + auto const angle = numeric_settings[2]->GetValue() / 1.8; + ControlState m = controls[4]->control_ref->State(); + + // deadzone / circle stick code + // this section might be all wrong, but its working good enough, I think + + ControlState ang = atan2(yy, xx); + ControlState ang_sin = sin(ang); + ControlState ang_cos = cos(ang); + + // the amt a full square stick would have at current angle + ControlState square_full = + std::min(ang_sin ? 1 / fabs(ang_sin) : 2, ang_cos ? 1 / fabs(ang_cos) : 2); + + // the amt a full stick would have that was (user setting circular) at current angle + // I think this is more like a pointed circle rather than a rounded square like it should be + ControlState stick_full = (square_full * (1 - circle)) + (circle); + + ControlState dist = sqrt(xx * xx + yy * yy); + + // dead zone code + dist = std::max(0.0, dist - deadzone * stick_full); + dist /= (1 - deadzone); + + // circle stick code + ControlState amt = dist / stick_full; + dist += (square_full - 1) * amt * circle; + + if (m) + dist *= 0.5; + + yy = std::max(-1.0, std::min(1.0, ang_sin * dist)); + xx = std::max(-1.0, std::min(1.0, ang_cos * dist)); + + // this is kinda silly here + // gui being open will make this happen 2x as fast, o well + + // silly + if (step) + { + if (xx > m_tilt[0]) + m_tilt[0] = std::min(m_tilt[0] + 0.1, xx); + else if (xx < m_tilt[0]) + m_tilt[0] = std::max(m_tilt[0] - 0.1, xx); + + if (yy > m_tilt[1]) + m_tilt[1] = std::min(m_tilt[1] + 0.1, yy); + else if (yy < m_tilt[1]) + m_tilt[1] = std::max(m_tilt[1] - 0.1, yy); + } + + *y = m_tilt[1] * angle; + *x = m_tilt[0] * angle; +} +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.h new file mode 100644 index 0000000000..940d7d9722 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Tilt.h @@ -0,0 +1,22 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" + +namespace ControllerEmu +{ +class Tilt : public ControlGroup +{ +public: + explicit Tilt(const std::string& name); + + void GetState(ControlState* x, ControlState* y, bool step = true); + +private: + ControlState m_tilt[2]; +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.cpp new file mode 100644 index 0000000000..3e13b0b504 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.cpp @@ -0,0 +1,31 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/ControlGroup/Triggers.h" + +#include +#include +#include +#include + +#include "Common/Common.h" +#include "InputCommon/ControlReference/ControlReference.h" +#include "InputCommon/ControllerEmu/Control/Control.h" + +namespace ControllerEmu +{ +Triggers::Triggers(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_TRIGGERS) +{ + numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 50)); +} + +void Triggers::GetState(ControlState* analog) +{ + const size_t trigger_count = controls.size(); + const ControlState deadzone = numeric_settings[0]->GetValue(); + + for (size_t i = 0; i < trigger_count; ++i, ++analog) + *analog = std::max(controls[i]->control_ref->State() - deadzone, 0.0) / (1 - deadzone); +} +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.h new file mode 100644 index 0000000000..5562e5c694 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Triggers.h @@ -0,0 +1,19 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" + +namespace ControllerEmu +{ +class Triggers : public ControlGroup +{ +public: + explicit Triggers(const std::string& name); + + void GetState(ControlState* analog); +}; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.cpp b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.cpp index 62501494e6..2aa65b3d42 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.cpp @@ -3,23 +3,36 @@ // Refer to the license.txt file included. #include "InputCommon/ControllerEmu/ControllerEmu.h" + #include -#include "Common/Common.h" -#include "VideoCommon/OnScreenDisplay.h" +#include +#include + +#include "Common/IniFile.h" + +#include "InputCommon/ControlReference/ControlReference.h" +#include "InputCommon/ControllerEmu/Control/Control.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" +#include "InputCommon/ControllerEmu/ControlGroup/Extension.h" + +namespace ControllerEmu +{ +static std::recursive_mutex s_get_state_mutex; + +EmulatedController::~EmulatedController() = default; // This should be called before calling GetState() or State() on a control reference // to prevent a race condition. // This is a recursive mutex because UpdateReferences is recursive. -static std::recursive_mutex s_get_state_mutex; -std::unique_lock ControllerEmu::GetStateLock() +std::unique_lock EmulatedController::GetStateLock() { std::unique_lock lock(s_get_state_mutex); return lock; } -void ControllerEmu::UpdateReferences(ControllerInterface& devi) +void EmulatedController::UpdateReferences(ControllerInterface& devi) { - auto lock = ControllerEmu::GetStateLock(); + const auto lock = GetStateLock(); for (auto& ctrlGroup : groups) { for (auto& control : ctrlGroup->controls) @@ -34,7 +47,7 @@ void ControllerEmu::UpdateReferences(ControllerInterface& devi) } } -void ControllerEmu::UpdateDefaultDevice() +void EmulatedController::UpdateDefaultDevice() { for (auto& ctrlGroup : groups) { @@ -50,62 +63,7 @@ void ControllerEmu::UpdateDefaultDevice() } } -void ControllerEmu::ControlGroup::LoadConfig(IniFile::Section* sec, const std::string& defdev, - const std::string& base) -{ - std::string group(base + name + "/"); - - // settings - for (auto& s : numeric_settings) - { - if (s->m_type == SettingType::VIRTUAL) - continue; - sec->Get(group + s->m_name, &s->m_value, s->m_default_value * 100); - s->m_value /= 100; - } - for (auto& s : boolean_settings) - { - if (s->m_type == SettingType::VIRTUAL) - continue; - sec->Get(group + s->m_name, &s->m_value, s->m_default_value); - } - - for (auto& c : controls) - { - // control expression - sec->Get(group + c->name, &c->control_ref->expression, ""); - - // range - sec->Get(group + c->name + "/Range", &c->control_ref->range, 100.0); - c->control_ref->range /= 100; - } - - // extensions - if (type == GROUP_TYPE_EXTENSION) - { - Extension* const ext = (Extension*)this; - - ext->switch_extension = 0; - unsigned int n = 0; - std::string extname; - sec->Get(base + name, &extname, ""); - - for (auto& ai : ext->attachments) - { - ai->default_device.FromString(defdev); - ai->LoadConfig(sec, base + ai->GetName() + "/"); - - if (ai->GetName() == extname) - ext->switch_extension = n; - - n++; - } - } -} - -ControllerEmu::ControlGroup::BooleanSetting::~BooleanSetting() = default; - -void ControllerEmu::LoadConfig(IniFile::Section* sec, const std::string& base) +void EmulatedController::LoadConfig(IniFile::Section* sec, const std::string& base) { std::string defdev = default_device.ToString(); if (base.empty()) @@ -118,45 +76,7 @@ void ControllerEmu::LoadConfig(IniFile::Section* sec, const std::string& base) cg->LoadConfig(sec, defdev, base); } -void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev, - const std::string& base) -{ - std::string group(base + name + "/"); - - for (auto& s : numeric_settings) - { - if (s->m_type == SettingType::VIRTUAL) - continue; - sec->Set(group + s->m_name, s->m_value * 100.0, s->m_default_value * 100.0); - } - for (auto& s : boolean_settings) - { - if (s->m_type == SettingType::VIRTUAL) - continue; - sec->Set(group + s->m_name, s->m_value, s->m_default_value); - } - - for (auto& c : controls) - { - // control expression - sec->Set(group + c->name, c->control_ref->expression, ""); - - // range - sec->Set(group + c->name + "/Range", c->control_ref->range * 100.0, 100.0); - } - - // extensions - if (type == GROUP_TYPE_EXTENSION) - { - Extension* const ext = (Extension*)this; - sec->Set(base + name, ext->attachments[ext->switch_extension]->GetName(), "None"); - - for (auto& ai : ext->attachments) - ai->SaveConfig(sec, base + ai->GetName() + "/"); - } -} - -void ControllerEmu::SaveConfig(IniFile::Section* sec, const std::string& base) +void EmulatedController::SaveConfig(IniFile::Section* sec, const std::string& base) { const std::string defdev = default_device.ToString(); if (base.empty()) @@ -166,154 +86,7 @@ void ControllerEmu::SaveConfig(IniFile::Section* sec, const std::string& base) ctrlGroup->SaveConfig(sec, defdev, base); } -void ControllerEmu::ControlGroup::SetControlExpression(int index, const std::string& expression) -{ - controls.at(index)->control_ref->expression = expression; -} - -ControllerEmu::AnalogStick::AnalogStick(const char* const _name, ControlState default_radius) - : AnalogStick(_name, _name, default_radius) -{ -} - -ControllerEmu::AnalogStick::AnalogStick(const char* const _name, const char* const _ui_name, - ControlState default_radius) - : ControlGroup(_name, _ui_name, GROUP_TYPE_STICK) -{ - for (auto& named_direction : named_directions) - controls.emplace_back(std::make_unique(named_direction)); - - controls.emplace_back(std::make_unique(_trans("Modifier"))); - numeric_settings.emplace_back( - std::make_unique(_trans("Radius"), default_radius, 0, 100)); - numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 50)); -} - -ControllerEmu::Buttons::Buttons(const std::string& _name) - : ControlGroup(_name, _name, GROUP_TYPE_BUTTONS) -{ - numeric_settings.emplace_back(std::make_unique(_trans("Threshold"), 0.5)); -} - -ControllerEmu::Buttons::Buttons(const std::string& ini_name, const std::string& group_name) - : ControlGroup(ini_name, group_name, GROUP_TYPE_BUTTONS) -{ - numeric_settings.emplace_back(std::make_unique(_trans("Threshold"), 0.5)); -} - -ControllerEmu::ModifySettingsButton::ModifySettingsButton(std::string button_name) - : Buttons(std::move(button_name)) -{ - numeric_settings.emplace_back(std::make_unique(_trans("Threshold"), 0.5)); -} - -void ControllerEmu::ModifySettingsButton::AddInput(std::string button_name, bool toggle) -{ - controls.emplace_back(new ControlGroup::Input(std::move(button_name))); - threshold_exceeded.emplace_back(false); - associated_settings.emplace_back(false); - associated_settings_toggle.emplace_back(toggle); -} - -void ControllerEmu::ModifySettingsButton::GetState() -{ - for (size_t i = 0; i < controls.size(); ++i) - { - ControlState state = controls[i]->control_ref->State(); - - if (!associated_settings_toggle[i]) - { - // not toggled - associated_settings[i] = state > numeric_settings[0]->GetValue(); - } - 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 > numeric_settings[0]->GetValue()) - { - associated_settings[i] = !associated_settings[i]; - if (associated_settings[i]) - OSD::AddMessage(controls[i]->name + ": " + _trans("on")); - else - OSD::AddMessage(controls[i]->name + ": " + _trans("off")); - threshold_exceeded[i] = true; - } - if (state < numeric_settings[0]->GetValue()) - threshold_exceeded[i] = false; - } - } -} - -ControllerEmu::MixedTriggers::MixedTriggers(const std::string& _name) - : ControlGroup(_name, GROUP_TYPE_MIXED_TRIGGERS) -{ - numeric_settings.emplace_back(std::make_unique(_trans("Threshold"), 0.9)); -} - -ControllerEmu::Triggers::Triggers(const std::string& _name) - : ControlGroup(_name, GROUP_TYPE_TRIGGERS) -{ - numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 50)); -} - -ControllerEmu::Slider::Slider(const std::string& _name) : ControlGroup(_name, GROUP_TYPE_SLIDER) -{ - controls.emplace_back(std::make_unique("Left")); - controls.emplace_back(std::make_unique("Right")); - - numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 50)); -} - -ControllerEmu::Force::Force(const std::string& _name) : ControlGroup(_name, GROUP_TYPE_FORCE) -{ - memset(m_swing, 0, sizeof(m_swing)); - - controls.emplace_back(std::make_unique(_trans("Up"))); - controls.emplace_back(std::make_unique(_trans("Down"))); - controls.emplace_back(std::make_unique(_trans("Left"))); - controls.emplace_back(std::make_unique(_trans("Right"))); - controls.emplace_back(std::make_unique(_trans("Forward"))); - controls.emplace_back(std::make_unique(_trans("Backward"))); - - numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 50)); -} - -ControllerEmu::Tilt::Tilt(const std::string& _name) : ControlGroup(_name, GROUP_TYPE_TILT) -{ - memset(m_tilt, 0, sizeof(m_tilt)); - - controls.emplace_back(std::make_unique("Forward")); - controls.emplace_back(std::make_unique("Backward")); - controls.emplace_back(std::make_unique("Left")); - controls.emplace_back(std::make_unique("Right")); - - controls.emplace_back(std::make_unique(_trans("Modifier"))); - - numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 50)); - numeric_settings.emplace_back(std::make_unique(_trans("Circle Stick"), 0)); - numeric_settings.emplace_back(std::make_unique(_trans("Angle"), 0.9, 0, 180)); -} - -ControllerEmu::Cursor::Cursor(const std::string& _name) - : ControlGroup(_name, GROUP_TYPE_CURSOR), m_z(0) -{ - for (auto& named_direction : named_directions) - controls.emplace_back(std::make_unique(named_direction)); - controls.emplace_back(std::make_unique("Forward")); - controls.emplace_back(std::make_unique("Backward")); - controls.emplace_back(std::make_unique(_trans("Hide"))); - controls.emplace_back(std::make_unique("Recenter")); - - numeric_settings.emplace_back(std::make_unique(_trans("Center"), 0.5)); - numeric_settings.emplace_back(std::make_unique(_trans("Width"), 0.5)); - numeric_settings.emplace_back(std::make_unique(_trans("Height"), 0.5)); - numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 20)); - boolean_settings.emplace_back(std::make_unique(_trans("Relative Input"), false)); -} - -void ControllerEmu::LoadDefaults(const ControllerInterface& ciface) +void EmulatedController::LoadDefaults(const ControllerInterface& ciface) { // load an empty inifile section, clears everything IniFile::Section sec; @@ -326,3 +99,4 @@ void ControllerEmu::LoadDefaults(const ControllerInterface& ciface) UpdateDefaultDevice(); } } +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h index 65332ac87f..24f4434dcb 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h +++ b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h @@ -4,488 +4,27 @@ #pragma once -#include -#include #include #include #include #include #include "Common/IniFile.h" -#include "Common/MathUtil.h" -#include "Core/ConfigManager.h" #include "InputCommon/ControlReference/ControlReference.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" -#include "InputCommon/GCPadStatus.h" #define sign(x) ((x) ? (x) < 0 ? -1 : 1 : 0) -enum -{ - GROUP_TYPE_OTHER, - GROUP_TYPE_STICK, - GROUP_TYPE_MIXED_TRIGGERS, - GROUP_TYPE_BUTTONS, - GROUP_TYPE_FORCE, - GROUP_TYPE_EXTENSION, - GROUP_TYPE_TILT, - GROUP_TYPE_CURSOR, - GROUP_TYPE_TRIGGERS, - GROUP_TYPE_SLIDER -}; - -enum -{ - SETTING_RADIUS, - SETTING_DEADZONE, -}; - const char* const named_directions[] = {"Up", "Down", "Left", "Right"}; -class ControllerEmu +namespace ControllerEmu +{ +class ControlGroup; + +class EmulatedController { public: - class ControlGroup - { - public: - class Control - { - protected: - Control(ControlReference* const _ref, const std::string& _name) - : control_ref(_ref), name(_name) - { - } - - public: - virtual ~Control() {} - std::unique_ptr const control_ref; - const std::string name; - }; - - class Input : public Control - { - public: - Input(const std::string& _name) : Control(new InputReference, _name) {} - }; - - class Output : public Control - { - public: - Output(const std::string& _name) : Control(new OutputReference, _name) {} - }; - - enum class SettingType - { - NORMAL, // normal settings are saved to configuration files - VIRTUAL, // virtual settings are not saved at all - }; - - class NumericSetting - { - public: - NumericSetting(const std::string& setting_name, const ControlState default_value, - const unsigned int low = 0, const unsigned int high = 100, - const SettingType setting_type = SettingType::NORMAL) - : m_type(setting_type), m_name(setting_name), m_default_value(default_value), m_low(low), - m_high(high) - { - } - - ControlState GetValue() const { return m_value; } - void SetValue(ControlState value) { m_value = value; } - const SettingType m_type; - const std::string m_name; - const ControlState m_default_value; - const unsigned int m_low, m_high; - ControlState m_value; - }; - - class BooleanSetting - { - public: - BooleanSetting(const std::string& setting_name, const bool default_value, - const SettingType setting_type = SettingType::NORMAL) - : m_type(setting_type), m_name(setting_name), m_default_value(default_value) - { - } - virtual ~BooleanSetting(); - - virtual bool GetValue() const { return m_value; } - virtual void SetValue(bool value) { m_value = value; } - const SettingType m_type; - const std::string m_name; - const bool m_default_value; - bool m_value; - }; - - class BackgroundInputSetting : public BooleanSetting - { - public: - BackgroundInputSetting(const std::string& setting_name) - : BooleanSetting(setting_name, false, SettingType::VIRTUAL) - { - } - - bool GetValue() const override { return SConfig::GetInstance().m_BackgroundInput; } - void SetValue(bool value) override - { - m_value = value; - SConfig::GetInstance().m_BackgroundInput = value; - } - }; - - ControlGroup(const std::string& _name, const unsigned int _type = GROUP_TYPE_OTHER) - : name(_name), ui_name(_name), type(_type) - { - } - ControlGroup(const std::string& _name, const std::string& _ui_name, - const unsigned int _type = GROUP_TYPE_OTHER) - : name(_name), ui_name(_ui_name), type(_type) - { - } - virtual ~ControlGroup() {} - virtual void LoadConfig(IniFile::Section* sec, const std::string& defdev = "", - const std::string& base = ""); - virtual void SaveConfig(IniFile::Section* sec, const std::string& defdev = "", - const std::string& base = ""); - - void SetControlExpression(int index, const std::string& expression); - - const std::string name; - const std::string ui_name; - const unsigned int type; - - std::vector> controls; - std::vector> numeric_settings; - std::vector> boolean_settings; - }; - - class AnalogStick : public ControlGroup - { - public: - // The GameCube controller and Wiimote attachments have a different default radius - AnalogStick(const char* const _name, ControlState default_radius); - AnalogStick(const char* const _name, const char* const _ui_name, ControlState default_radius); - - void GetState(ControlState* const x, ControlState* const y) - { - ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State(); - ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State(); - - ControlState radius = numeric_settings[SETTING_RADIUS]->GetValue(); - ControlState deadzone = numeric_settings[SETTING_DEADZONE]->GetValue(); - ControlState m = controls[4]->control_ref->State(); - - ControlState ang = atan2(yy, xx); - ControlState ang_sin = sin(ang); - ControlState ang_cos = cos(ang); - - ControlState dist = sqrt(xx * xx + yy * yy); - - // dead zone code - dist = std::max(0.0, dist - deadzone); - dist /= (1 - deadzone); - - // radius - dist *= radius; - - // The modifier halves the distance by 50%, which is useful - // for keyboard controls. - if (m) - dist *= 0.5; - - yy = std::max(-1.0, std::min(1.0, ang_sin * dist)); - xx = std::max(-1.0, std::min(1.0, ang_cos * dist)); - - *y = yy; - *x = xx; - } - }; - - class Buttons : public ControlGroup - { - public: - Buttons(const std::string& _name); - Buttons(const std::string& ini_name, const std::string& group_name); - - template - void GetState(C* const buttons, const C* bitmasks) - { - for (auto& control : controls) - { - if (control->control_ref->State() > numeric_settings[0]->GetValue()) // threshold - *buttons |= *bitmasks; - - bitmasks++; - } - } - }; - - class ModifySettingsButton : public Buttons - { - public: - ModifySettingsButton(std::string button_name); - void AddInput(std::string button_name, bool toggle = false); - - void GetState(); - - const std::vector& isSettingToggled() const { return associated_settings_toggle; } - const std::vector& getSettingsModifier() const { return associated_settings; } - 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 - }; - - class MixedTriggers : public ControlGroup - { - public: - MixedTriggers(const std::string& _name); - - void GetState(u16* const digital, const u16* bitmasks, ControlState* analog) - { - const unsigned int trig_count = ((unsigned int)(controls.size() / 2)); - for (unsigned int i = 0; i < trig_count; ++i, ++bitmasks, ++analog) - { - if (controls[i]->control_ref->State() > numeric_settings[0]->GetValue()) // threshold - { - *analog = 1.0; - *digital |= *bitmasks; - } - else - { - *analog = controls[i + trig_count]->control_ref->State(); - } - } - } - }; - - class Triggers : public ControlGroup - { - public: - Triggers(const std::string& _name); - - void GetState(ControlState* analog) - { - const unsigned int trig_count = ((unsigned int)(controls.size())); - const ControlState deadzone = numeric_settings[0]->GetValue(); - for (unsigned int i = 0; i < trig_count; ++i, ++analog) - *analog = std::max(controls[i]->control_ref->State() - deadzone, 0.0) / (1 - deadzone); - } - }; - - class Slider : public ControlGroup - { - public: - Slider(const std::string& _name); - - void GetState(ControlState* const slider) - { - const ControlState deadzone = numeric_settings[0]->GetValue(); - const ControlState state = - controls[1]->control_ref->State() - controls[0]->control_ref->State(); - - if (fabs(state) > deadzone) - *slider = (state - (deadzone * sign(state))) / (1 - deadzone); - else - *slider = 0; - } - }; - - class Force : public ControlGroup - { - public: - Force(const std::string& _name); - - void GetState(ControlState* axis) - { - const ControlState deadzone = numeric_settings[0]->GetValue(); - for (unsigned int i = 0; i < 6; i += 2) - { - ControlState tmpf = 0; - const ControlState state = - controls[i + 1]->control_ref->State() - controls[i]->control_ref->State(); - if (fabs(state) > deadzone) - tmpf = ((state - (deadzone * sign(state))) / (1 - deadzone)); - - ControlState& ax = m_swing[i >> 1]; - *axis++ = (tmpf - ax); - ax = tmpf; - } - } - - private: - ControlState m_swing[3]; - }; - - class Tilt : public ControlGroup - { - public: - Tilt(const std::string& _name); - - void GetState(ControlState* const x, ControlState* const y, const bool step = true) - { - // this is all a mess - - ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State(); - ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State(); - - ControlState deadzone = numeric_settings[0]->GetValue(); - ControlState circle = numeric_settings[1]->GetValue(); - auto const angle = numeric_settings[2]->GetValue() / 1.8; - ControlState m = controls[4]->control_ref->State(); - - // deadzone / circle stick code - // this section might be all wrong, but its working good enough, I think - - ControlState ang = atan2(yy, xx); - ControlState ang_sin = sin(ang); - ControlState ang_cos = cos(ang); - - // the amt a full square stick would have at current angle - ControlState square_full = - std::min(ang_sin ? 1 / fabs(ang_sin) : 2, ang_cos ? 1 / fabs(ang_cos) : 2); - - // the amt a full stick would have that was (user setting circular) at current angle - // I think this is more like a pointed circle rather than a rounded square like it should be - ControlState stick_full = (square_full * (1 - circle)) + (circle); - - ControlState dist = sqrt(xx * xx + yy * yy); - - // dead zone code - dist = std::max(0.0, dist - deadzone * stick_full); - dist /= (1 - deadzone); - - // circle stick code - ControlState amt = dist / stick_full; - dist += (square_full - 1) * amt * circle; - - if (m) - dist *= 0.5; - - yy = std::max(-1.0, std::min(1.0, ang_sin * dist)); - xx = std::max(-1.0, std::min(1.0, ang_cos * dist)); - - // this is kinda silly here - // gui being open will make this happen 2x as fast, o well - - // silly - if (step) - { - if (xx > m_tilt[0]) - m_tilt[0] = std::min(m_tilt[0] + 0.1, xx); - else if (xx < m_tilt[0]) - m_tilt[0] = std::max(m_tilt[0] - 0.1, xx); - - if (yy > m_tilt[1]) - m_tilt[1] = std::min(m_tilt[1] + 0.1, yy); - else if (yy < m_tilt[1]) - m_tilt[1] = std::max(m_tilt[1] - 0.1, yy); - } - - *y = m_tilt[1] * angle; - *x = m_tilt[0] * angle; - } - - private: - ControlState m_tilt[2]; - }; - - class Cursor : public ControlGroup - { - public: - Cursor(const std::string& _name); - - void GetState(ControlState* const x, ControlState* const y, ControlState* const z, - const bool adjusted = false) - { - const ControlState zz = controls[4]->control_ref->State() - controls[5]->control_ref->State(); - - // silly being here - if (zz > m_z) - m_z = std::min(m_z + 0.1, zz); - else if (zz < m_z) - m_z = std::max(m_z - 0.1, zz); - - *z = m_z; - - // hide - if (controls[6]->control_ref->State() > 0.5) - { - *x = 10000; - *y = 0; - } - else - { - ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State(); - ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State(); - - // adjust cursor according to settings - if (adjusted) - { - xx *= (numeric_settings[1]->GetValue() * 2); - yy *= (numeric_settings[2]->GetValue() * 2); - yy += (numeric_settings[0]->GetValue() - 0.5); - } - - // relative input - if (boolean_settings[0]->GetValue()) - { - const ControlState deadzone = numeric_settings[3]->GetValue(); - // deadzone to avoid the cursor slowly drifting - if (std::abs(xx) > deadzone) - m_x = MathUtil::Clamp(m_x + xx * SPEED_MULTIPLIER, -1.0, 1.0); - if (std::abs(yy) > deadzone) - m_y = MathUtil::Clamp(m_y + yy * SPEED_MULTIPLIER, -1.0, 1.0); - - // recenter - if (controls[7]->control_ref->State() > 0.5) - { - m_x = 0.0; - m_y = 0.0; - } - } - else - { - m_x = xx; - m_y = yy; - } - - *x = m_x; - *y = m_y; - } - } - - ControlState m_z; - - private: - // This is used to reduce the cursor speed for relative input - // to something that makes sense with the default range. - static constexpr double SPEED_MULTIPLIER = 0.04; - - ControlState m_x = 0.0; - ControlState m_y = 0.0; - }; - - class Extension : public ControlGroup - { - public: - Extension(const std::string& _name) - : ControlGroup(_name, GROUP_TYPE_EXTENSION), switch_extension(0), active_extension(0) - { - } - - ~Extension() {} - void GetState(u8* const data); - bool IsButtonPressed() const; - - std::vector> attachments; - - int switch_extension; - int active_extension; - }; - - virtual ~ControllerEmu() {} + virtual ~EmulatedController(); virtual std::string GetName() const = 0; virtual void LoadDefaults(const ControllerInterface& ciface); @@ -506,3 +45,4 @@ public: ciface::Core::DeviceQualifier default_device; }; +} // namespace ControllerEmu diff --git a/Source/Core/InputCommon/InputCommon.vcxproj b/Source/Core/InputCommon/InputCommon.vcxproj index 0f961839d7..954110646b 100644 --- a/Source/Core/InputCommon/InputCommon.vcxproj +++ b/Source/Core/InputCommon/InputCommon.vcxproj @@ -36,6 +36,20 @@ + + + + + + + + + + + + + + @@ -57,6 +71,20 @@ + + + + + + + + + + + + + + diff --git a/Source/Core/InputCommon/InputCommon.vcxproj.filters b/Source/Core/InputCommon/InputCommon.vcxproj.filters index 1287497f01..4302e1233d 100644 --- a/Source/Core/InputCommon/InputCommon.vcxproj.filters +++ b/Source/Core/InputCommon/InputCommon.vcxproj.filters @@ -16,6 +16,12 @@ {4c839215-4085-4e34-a960-7960986ad015} + + {19ddd862-a1e3-479b-b638-bb31700c5171} + + + {e805231c-dc4e-4540-8bf8-8c567f3d00ae} + @@ -23,6 +29,48 @@ ControllerEmu + + ControllerEmu\Control + + + ControllerEmu\Control + + + ControllerEmu\Control + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + ControllerInterface\DInput @@ -61,6 +109,48 @@ ControllerEmu + + ControllerEmu\Control + + + ControllerEmu\Control + + + ControllerEmu\Control + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + + + ControllerEmu\ControlGroup + ControllerInterface\DInput @@ -98,4 +188,4 @@ - + \ No newline at end of file diff --git a/Source/Core/InputCommon/InputConfig.cpp b/Source/Core/InputCommon/InputConfig.cpp index 1a723c5fbb..86bda0189f 100644 --- a/Source/Core/InputCommon/InputConfig.cpp +++ b/Source/Core/InputCommon/InputConfig.cpp @@ -9,10 +9,19 @@ #include "Common/MsgHandler.h" #include "Core/ConfigManager.h" #include "Core/HW/Wiimote.h" +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" #include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/InputConfig.h" +InputConfig::InputConfig(const std::string& ini_name, const std::string& gui_name, + const std::string& profile_name) + : m_ini_name(ini_name), m_gui_name(gui_name), m_profile_name(profile_name) +{ +} + +InputConfig::~InputConfig() = default; + bool InputConfig::LoadConfig(bool isGC) { IniFile inifile; @@ -104,7 +113,7 @@ void InputConfig::SaveConfig() inifile.Save(ini_filename); } -ControllerEmu* InputConfig::GetController(int index) +ControllerEmu::EmulatedController* InputConfig::GetController(int index) { return m_controllers.at(index).get(); } diff --git a/Source/Core/InputCommon/InputConfig.h b/Source/Core/InputCommon/InputConfig.h index 27cc70198e..fcbd8a59f9 100644 --- a/Source/Core/InputCommon/InputConfig.h +++ b/Source/Core/InputCommon/InputConfig.h @@ -9,16 +9,18 @@ #include #include -class ControllerEmu; +namespace ControllerEmu +{ +class EmulatedController; +} class InputConfig { public: InputConfig(const std::string& ini_name, const std::string& gui_name, - const std::string& profile_name) - : m_ini_name(ini_name), m_gui_name(gui_name), m_profile_name(profile_name) - { - } + const std::string& profile_name); + + ~InputConfig(); bool LoadConfig(bool isGC); void SaveConfig(); @@ -29,7 +31,7 @@ public: m_controllers.emplace_back(std::make_unique(std::forward(args)...)); } - ControllerEmu* GetController(int index); + ControllerEmu::EmulatedController* GetController(int index); void ClearControllers(); bool ControllersNeedToBeCreated() const; bool IsControllerControlledByGamepadDevice(int index) const; @@ -37,7 +39,7 @@ public: std::string GetGUIName() const { return m_gui_name; } std::string GetProfileName() const { return m_profile_name; } private: - std::vector> m_controllers; + std::vector> m_controllers; const std::string m_ini_name; const std::string m_gui_name; const std::string m_profile_name;