From b9975694ab133e964e84ae829e9ae93cca863cc4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 25 Oct 2015 22:28:15 -0400 Subject: [PATCH] InputConfig: Clean up controller management --- Source/Core/Core/HW/GCKeyboard.cpp | 26 ++--- Source/Core/Core/HW/GCKeyboard.h | 2 +- Source/Core/Core/HW/GCPad.cpp | 43 +++---- Source/Core/Core/HW/GCPad.h | 6 +- Source/Core/Core/HW/Wiimote.cpp | 110 +++++------------- Source/Core/Core/HW/WiimoteReal/IONix.cpp | 4 +- Source/Core/Core/HW/WiimoteReal/IOWin.cpp | 1 + Source/Core/Core/HW/WiimoteReal/IOdarwin.mm | 2 + .../Core/Core/HW/WiimoteReal/WiimoteReal.cpp | 6 +- Source/Core/Core/HW/WiimoteReal/WiimoteReal.h | 3 - Source/Core/Core/HotkeyManager.cpp | 16 +-- Source/Core/Core/HotkeyManager.h | 1 + Source/Core/DolphinWX/InputConfigDiag.cpp | 12 +- Source/Core/DolphinWX/InputConfigDiag.h | 2 +- Source/Core/DolphinWX/TASInputDlg.cpp | 2 +- Source/Core/InputCommon/InputConfig.cpp | 42 +++++-- Source/Core/InputCommon/InputConfig.h | 39 ++++--- 17 files changed, 146 insertions(+), 171 deletions(-) diff --git a/Source/Core/Core/HW/GCKeyboard.cpp b/Source/Core/Core/HW/GCKeyboard.cpp index 3170ac301d..d6c720cb47 100644 --- a/Source/Core/Core/HW/GCKeyboard.cpp +++ b/Source/Core/Core/HW/GCKeyboard.cpp @@ -22,26 +22,22 @@ InputConfig* GetConfig() void Shutdown() { - std::vector::const_iterator - i = s_config.controllers.begin(), - e = s_config.controllers.end(); - for ( ; i!=e; ++i ) - delete *i; - s_config.controllers.clear(); + s_config.ClearControllers(); g_controller_interface.Shutdown(); } -// if plugin isn't initialized, init and load config void Initialize(void* const hwnd) { - if (s_config.controllers.empty()) + if (s_config.ControllersNeedToBeCreated()) + { for (unsigned int i = 0; i < 4; ++i) - s_config.controllers.push_back(new GCKeyboard(i)); + s_config.CreateController(i); + } g_controller_interface.Initialize(hwnd); - // load the saved controller config + // Load the saved controller config s_config.LoadConfig(true); } @@ -50,13 +46,13 @@ void LoadConfig() s_config.LoadConfig(true); } -void GetStatus(u8 _port, KeyboardStatus* _pKeyboardStatus) +void GetStatus(u8 port, KeyboardStatus* keyboard_status) { - memset(_pKeyboardStatus, 0, sizeof(*_pKeyboardStatus)); - _pKeyboardStatus->err = PAD_ERR_NONE; + memset(keyboard_status, 0, sizeof(*keyboard_status)); + keyboard_status->err = PAD_ERR_NONE; - // get input - ((GCKeyboard*)s_config.controllers[_port])->GetInput(_pKeyboardStatus); + // Get input + static_cast(s_config.GetController(port))->GetInput(keyboard_status); } } diff --git a/Source/Core/Core/HW/GCKeyboard.h b/Source/Core/Core/HW/GCKeyboard.h index faef2adf75..8bf89fc1d4 100644 --- a/Source/Core/Core/HW/GCKeyboard.h +++ b/Source/Core/Core/HW/GCKeyboard.h @@ -18,6 +18,6 @@ void LoadConfig(); InputConfig* GetConfig(); -void GetStatus(u8 _port, KeyboardStatus* _pKeyboardStatus); +void GetStatus(u8 port, KeyboardStatus* keyboard_status); } diff --git a/Source/Core/Core/HW/GCPad.cpp b/Source/Core/Core/HW/GCPad.cpp index d83d54a0ff..e1021af2b9 100644 --- a/Source/Core/Core/HW/GCPad.cpp +++ b/Source/Core/Core/HW/GCPad.cpp @@ -23,27 +23,22 @@ InputConfig* GetConfig() void Shutdown() { - std::vector::const_iterator - i = s_config.controllers.begin(), - e = s_config.controllers.end(); - for ( ; i!=e; ++i ) - delete *i; - s_config.controllers.clear(); + s_config.ClearControllers(); g_controller_interface.Shutdown(); } -// if plugin isn't initialized, init and load config void Initialize(void* const hwnd) { - // add 4 gcpads - if (s_config.controllers.empty()) + if (s_config.ControllersNeedToBeCreated()) + { for (unsigned int i = 0; i < 4; ++i) - s_config.controllers.push_back(new GCPad(i)); + s_config.CreateController(i); + } g_controller_interface.Initialize(hwnd); - // load the saved controller config + // Load the saved controller config s_config.LoadConfig(true); } @@ -53,31 +48,31 @@ void LoadConfig() } -void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus) +void GetStatus(u8 pad_num, GCPadStatus* pad_status) { - memset(_pPADStatus, 0, sizeof(*_pPADStatus)); - _pPADStatus->err = PAD_ERR_NONE; + memset(pad_status, 0, sizeof(*pad_status)); + pad_status->err = PAD_ERR_NONE; - // if we are on the next input cycle, update output and input - static int _last_numPAD = 4; - if (_numPAD <= _last_numPAD) + // If we are on the next input cycle, update output and input + static int last_pad_num = 4; + if (pad_num <= last_pad_num) { g_controller_interface.UpdateInput(); } - _last_numPAD = _numPAD; + last_pad_num = pad_num; - // get input - ((GCPad*)s_config.controllers[_numPAD])->GetInput(_pPADStatus); + // Get input + static_cast(s_config.GetController(pad_num))->GetInput(pad_status); } -void Rumble(u8 _numPAD, const ControlState strength) +void Rumble(const u8 pad_num, const ControlState strength) { - ((GCPad*)s_config.controllers[ _numPAD ])->SetOutput(strength); + static_cast(s_config.GetController(pad_num))->SetOutput(strength); } -bool GetMicButton(u8 pad) +bool GetMicButton(const u8 pad_num) { - return ((GCPad*)s_config.controllers[pad])->GetMicButton(); + return static_cast(s_config.GetController(pad_num))->GetMicButton(); } } diff --git a/Source/Core/Core/HW/GCPad.h b/Source/Core/Core/HW/GCPad.h index e6b910ad70..cb9021ac2a 100644 --- a/Source/Core/Core/HW/GCPad.h +++ b/Source/Core/Core/HW/GCPad.h @@ -19,8 +19,8 @@ void LoadConfig(); InputConfig* GetConfig(); -void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus); -void Rumble(u8 _numPAD, const ControlState strength); +void GetStatus(u8 pad_num, GCPadStatus* pad_status); +void Rumble(u8 pad_num, ControlState strength); -bool GetMicButton(u8 pad); +bool GetMicButton(u8 pad_num); } diff --git a/Source/Core/Core/HW/Wiimote.cpp b/Source/Core/Core/HW/Wiimote.cpp index 2fafd852c6..8a95873047 100644 --- a/Source/Core/Core/HW/Wiimote.cpp +++ b/Source/Core/Core/HW/Wiimote.cpp @@ -25,24 +25,20 @@ InputConfig* GetConfig() void Shutdown() { - for (const ControllerEmu* i : s_config.controllers) - { - delete i; - } - s_config.controllers.clear(); + s_config.ClearControllers(); WiimoteReal::Stop(); g_controller_interface.Shutdown(); } -// if plugin isn't initialized, init and load config void Initialize(void* const hwnd, bool wait) { - // add 4 Wiimotes - if (s_config.controllers.empty()) + if (s_config.ControllersNeedToBeCreated()) + { for (unsigned int i = WIIMOTE_CHAN_0; i < MAX_BBMOTES; ++i) - s_config.controllers.push_back(new WiimoteEmu::Wiimote(i)); + s_config.CreateController(i); + } g_controller_interface.Initialize(hwnd); @@ -50,7 +46,7 @@ void Initialize(void* const hwnd, bool wait) WiimoteReal::Initialize(wait); - // reload Wiimotes with our settings + // Reload Wiimotes with our settings if (Movie::IsMovieActive()) Movie::ChangeWiiPads(); } @@ -72,104 +68,60 @@ void Pause() } -// __________________________________________________________________________________________________ -// Function: ControlChannel -// Purpose: An L2CAP packet is passed from the Core to the Wiimote, -// on the HID CONTROL channel. -// -// Inputs: _number [Description needed] -// _channelID [Description needed] -// _pData [Description needed] -// _Size [Description needed] -// -// Output: none -// -void ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size) +// An L2CAP packet is passed from the Core to the Wiimote on the HID CONTROL channel. +void ControlChannel(int number, u16 channel_id, const void* data, u32 size) { - if (WIIMOTE_SRC_HYBRID & g_wiimote_sources[_number]) - ((WiimoteEmu::Wiimote*)s_config.controllers[_number])->ControlChannel(_channelID, _pData, _Size); + if (WIIMOTE_SRC_HYBRID & g_wiimote_sources[number]) + static_cast(s_config.GetController(number))->ControlChannel(channel_id, data, size); } -// __________________________________________________________________________________________________ -// Function: InterruptChannel -// Purpose: An L2CAP packet is passed from the Core to the Wiimote, -// on the HID INTERRUPT channel. -// -// Inputs: _number [Description needed] -// _channelID [Description needed] -// _pData [Description needed] -// _Size [Description needed] -// -// Output: none -// -void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size) +// An L2CAP packet is passed from the Core to the Wiimote on the HID INTERRUPT channel. +void InterruptChannel(int number, u16 channel_id, const void* data, u32 size) { - if (WIIMOTE_SRC_HYBRID & g_wiimote_sources[_number]) - ((WiimoteEmu::Wiimote*)s_config.controllers[_number])->InterruptChannel(_channelID, _pData, _Size); + if (WIIMOTE_SRC_HYBRID & g_wiimote_sources[number]) + static_cast(s_config.GetController(number))->InterruptChannel(channel_id, data, size); } -// __________________________________________________________________________________________________ -// Function: Update -// Purpose: This function is called periodically by the Core. // TODO: Explain why. -// input: _number: [Description needed] -// output: none -// -void Update(int _number, bool _connected) +// This function is called periodically by the Core to update Wiimote state. +void Update(int number, bool connected) { - if (_connected) + if (connected) { - if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number]) - ((WiimoteEmu::Wiimote*)s_config.controllers[_number])->Update(); + if (WIIMOTE_SRC_EMU & g_wiimote_sources[number]) + static_cast(s_config.GetController(number))->Update(); else - WiimoteReal::Update(_number); + WiimoteReal::Update(number); } else { - if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number]) - ((WiimoteEmu::Wiimote*)s_config.controllers[_number])->ConnectOnInput(); - if (WIIMOTE_SRC_REAL & g_wiimote_sources[_number]) - WiimoteReal::ConnectOnInput(_number); + if (WIIMOTE_SRC_EMU & g_wiimote_sources[number]) + static_cast(s_config.GetController(number))->ConnectOnInput(); + + if (WIIMOTE_SRC_REAL & g_wiimote_sources[number]) + WiimoteReal::ConnectOnInput(number); } } -// __________________________________________________________________________________________________ -// Function: GetAttached -// Purpose: Get mask of attached pads (eg: controller 1 & 4 -> 0x9) -// input: none -// output: The number of attached pads -// +// Get a mask of attached the pads (eg: controller 1 & 4 -> 0x9) unsigned int GetAttached() { unsigned int attached = 0; - for (unsigned int i=0; iDoState(p); + for (int i = 0; i < MAX_BBMOTES; ++i) + static_cast(s_config.GetController(i))->DoState(p); } -// ___________________________________________________________________________ -// Function: EmuStateChange -// Purpose: Notifies the plugin of a change in emulation state -// input: newState - The new state for the Wiimote to change to. -// output: none -// +// Notifies the plugin of a change in emulation state void EmuStateChange(EMUSTATE_CHANGE newState) { - // TODO WiimoteReal::StateChange(newState); } diff --git a/Source/Core/Core/HW/WiimoteReal/IONix.cpp b/Source/Core/Core/HW/WiimoteReal/IONix.cpp index c72dbad8b6..f2abd830ea 100644 --- a/Source/Core/Core/HW/WiimoteReal/IONix.cpp +++ b/Source/Core/Core/HW/WiimoteReal/IONix.cpp @@ -10,7 +10,9 @@ #include #include -#include "Common/Common.h" +#include "Common/CommonTypes.h" +#include "Common/Logging/Log.h" +#include "Core/HW/WiimoteEmu/WiimoteHid.h" #include "Core/HW/WiimoteReal/WiimoteReal.h" namespace WiimoteReal diff --git a/Source/Core/Core/HW/WiimoteReal/IOWin.cpp b/Source/Core/Core/HW/WiimoteReal/IOWin.cpp index 1b24d19965..f9fce8f22c 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOWin.cpp +++ b/Source/Core/Core/HW/WiimoteReal/IOWin.cpp @@ -19,6 +19,7 @@ #include "Common/StringUtil.h" #include "Common/Thread.h" +#include "Core/HW/WiimoteEmu/WiimoteHid.h" #include "Core/HW/WiimoteReal/WiimoteReal.h" //#define AUTHENTICATE_WIIMOTES diff --git a/Source/Core/Core/HW/WiimoteReal/IOdarwin.mm b/Source/Core/Core/HW/WiimoteReal/IOdarwin.mm index 5f6271e82c..ed2e254732 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOdarwin.mm +++ b/Source/Core/Core/HW/WiimoteReal/IOdarwin.mm @@ -1,6 +1,8 @@ #define BLUETOOTH_VERSION_USE_CURRENT #include "Common/Common.h" +#include "Common/Logging/Log.h" +#include "Core/HW/WiimoteEmu/WiimoteHid.h" #include "Core/HW/WiimoteReal/WiimoteReal.h" @interface SearchBT: NSObject { diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp index 8022efff09..64082c5b21 100644 --- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp @@ -14,8 +14,10 @@ #include "Common/Timer.h" #include "Core/ConfigManager.h" #include "Core/Host.h" +#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteHid.h" #include "Core/HW/WiimoteReal/WiimoteReal.h" +#include "InputCommon/InputConfig.h" #include "SFML/Network.hpp" @@ -153,7 +155,7 @@ void Wiimote::InterruptChannel(const u16 channel, const void* const _data, const auto const data = static_cast(_data); Report rpt(data, data + size); - WiimoteEmu::Wiimote *const wm = (WiimoteEmu::Wiimote*)::Wiimote::GetConfig()->controllers[m_index]; + WiimoteEmu::Wiimote* const wm = static_cast(::Wiimote::GetConfig()->GetController(m_index)); // Convert output DATA packets to SET_REPORT packets. // Nintendo Wiimotes work without this translation, but 3rd @@ -382,7 +384,7 @@ void Wiimote::EmuStop() void Wiimote::EmuResume() { - WiimoteEmu::Wiimote *const wm = (WiimoteEmu::Wiimote*)::Wiimote::GetConfig()->controllers[m_index]; + WiimoteEmu::Wiimote* const wm = static_cast(::Wiimote::GetConfig()->GetController(m_index)); m_last_input_report.clear(); diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h index 931c9c811b..5d3a135787 100644 --- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h +++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h @@ -16,9 +16,7 @@ #include "Common/NonCopyable.h" #include "Common/Timer.h" #include "Core/HW/Wiimote.h" -#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteReal/WiimoteRealBase.h" -#include "InputCommon/InputConfig.h" class PointerWrap; @@ -29,7 +27,6 @@ namespace WiimoteReal class Wiimote : NonCopyable { -friend class WiimoteEmu::Wiimote; public: virtual ~Wiimote() {} // This needs to be called in derived destructors! diff --git a/Source/Core/Core/HotkeyManager.cpp b/Source/Core/Core/HotkeyManager.cpp index f992bef281..8a69f10e5b 100644 --- a/Source/Core/Core/HotkeyManager.cpp +++ b/Source/Core/Core/HotkeyManager.cpp @@ -8,6 +8,7 @@ #include "Common/Common.h" #include "Core/ConfigManager.h" #include "Core/HotkeyManager.h" +#include "InputCommon/GCPadStatus.h" const std::string hotkey_labels[] = { @@ -147,8 +148,8 @@ void GetStatus() { s_hotkey.err = PAD_ERR_NONE; - // get input - ((HotkeyManager*)s_config.controllers[0])->GetInput(&s_hotkey); + // Get input + static_cast(s_config.GetController(0))->GetInput(&s_hotkey); } bool IsEnabled() @@ -182,8 +183,8 @@ bool IsPressed(int Id, bool held) void Initialize(void* const hwnd) { - if (s_config.controllers.empty()) - s_config.controllers.push_back(new HotkeyManager()); + if (s_config.ControllersNeedToBeCreated()) + s_config.CreateController(); g_controller_interface.Initialize(hwnd); @@ -203,12 +204,7 @@ void LoadConfig() void Shutdown() { - std::vector::const_iterator - i = s_config.controllers.begin(), - e = s_config.controllers.end(); - for (; i != e; ++i) - delete *i; - s_config.controllers.clear(); + s_config.ClearControllers(); g_controller_interface.Shutdown(); } diff --git a/Source/Core/Core/HotkeyManager.h b/Source/Core/Core/HotkeyManager.h index 75da4450b9..95e5062067 100644 --- a/Source/Core/Core/HotkeyManager.h +++ b/Source/Core/Core/HotkeyManager.h @@ -5,6 +5,7 @@ #pragma once #include +#include "InputCommon/ControllerEmu.h" #include "InputCommon/InputConfig.h" enum Hotkey diff --git a/Source/Core/DolphinWX/InputConfigDiag.cpp b/Source/Core/DolphinWX/InputConfigDiag.cpp index e47e2776ed..215134526e 100644 --- a/Source/Core/DolphinWX/InputConfigDiag.cpp +++ b/Source/Core/DolphinWX/InputConfigDiag.cpp @@ -170,7 +170,7 @@ void InputConfigDialog::UpdateProfileComboBox() { std::string pname(File::GetUserPath(D_CONFIG_IDX)); pname += PROFILES_PATH; - pname += m_config.profile_name; + pname += m_config.GetProfileName(); std::vector sv = DoFileSearch({".ini"}, {pname}); @@ -652,7 +652,7 @@ void GamepadPage::GetProfilePath(std::string& path) path = File::GetUserPath(D_CONFIG_IDX); path += PROFILES_PATH; - path += m_config.profile_name; + path += m_config.GetProfileName(); path += '/'; path += WxStrToStr(profile_cbox->GetValue()); path += ".ini"; @@ -984,14 +984,14 @@ ControlGroupsSizer::ControlGroupsSizer(ControllerEmu* const controller, wxWindow Add(stacked_groups, 0, /*wxEXPAND|*/wxBOTTOM|wxRIGHT, 5); } -GamepadPage::GamepadPage(wxWindow* parent, InputConfig& config, const unsigned int pad_num, InputConfigDialog* const config_dialog) +GamepadPage::GamepadPage(wxWindow* parent, InputConfig& config, const int pad_num, InputConfigDialog* const config_dialog) : wxPanel(parent, wxID_ANY) - ,controller(config.controllers[pad_num]) + , controller(config.GetController(pad_num)) , m_config_dialog(config_dialog) , m_config(config) { - wxBoxSizer* control_group_sizer = new ControlGroupsSizer(m_config.controllers[pad_num], this, this, &control_groups); + wxBoxSizer* control_group_sizer = new ControlGroupsSizer(controller, this, this, &control_groups); wxStaticBoxSizer* profile_sbox = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Profile")); @@ -1060,7 +1060,7 @@ InputConfigDialog::InputConfigDialog(wxWindow* const parent, InputConfig& config m_pad_notebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_DEFAULT); GamepadPage* gp = new GamepadPage(m_pad_notebook, m_config, tab_num, this); m_padpages.push_back(gp); - m_pad_notebook->AddPage(gp, wxString::Format("%s [%u]", wxGetTranslation(StrToWxStr(m_config.gui_name)), 1 + tab_num)); + m_pad_notebook->AddPage(gp, wxString::Format("%s [%u]", wxGetTranslation(StrToWxStr(m_config.GetGUIName())), 1 + tab_num)); m_pad_notebook->SetSelection(0); diff --git a/Source/Core/DolphinWX/InputConfigDiag.h b/Source/Core/DolphinWX/InputConfigDiag.h index aa81fbd99d..9d85e2fb42 100644 --- a/Source/Core/DolphinWX/InputConfigDiag.h +++ b/Source/Core/DolphinWX/InputConfigDiag.h @@ -200,7 +200,7 @@ class GamepadPage : public wxPanel friend class ControlDialog; public: - GamepadPage(wxWindow* parent, InputConfig& config, const unsigned int pad_num, InputConfigDialog* const config_dialog); + GamepadPage(wxWindow* parent, InputConfig& config, const int pad_num, InputConfigDialog* const config_dialog); void UpdateGUI(); diff --git a/Source/Core/DolphinWX/TASInputDlg.cpp b/Source/Core/DolphinWX/TASInputDlg.cpp index 62753f6a4e..f8e77f8403 100644 --- a/Source/Core/DolphinWX/TASInputDlg.cpp +++ b/Source/Core/DolphinWX/TASInputDlg.cpp @@ -142,7 +142,7 @@ void TASInputDlg::CreateWiiLayout(int num) if (Core::IsRunning()) { - m_ext = ((WiimoteEmu::Wiimote*)Wiimote::GetConfig()->controllers[num])->CurrentExtension(); + m_ext = static_cast(Wiimote::GetConfig()->GetController(num))->CurrentExtension(); } else { diff --git a/Source/Core/InputCommon/InputConfig.cpp b/Source/Core/InputCommon/InputConfig.cpp index 6456e1e68f..f4a5900b96 100644 --- a/Source/Core/InputCommon/InputConfig.cpp +++ b/Source/Core/InputCommon/InputConfig.cpp @@ -2,10 +2,15 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include "Common/CommonPaths.h" +#include + +#include "Common/FileUtil.h" +#include "Common/IniFile.h" #include "Core/ConfigManager.h" #include "Core/HW/Wiimote.h" +#include "InputCommon/ControllerEmu.h" #include "InputCommon/InputConfig.h" +#include "InputCommon/ControllerInterface/ControllerInterface.h" bool InputConfig::LoadConfig(bool isGC) { @@ -52,25 +57,25 @@ bool InputConfig::LoadConfig(bool isGC) } } - if (inifile.Load(File::GetUserPath(D_CONFIG_IDX) + ini_name + ".ini")) + if (inifile.Load(File::GetUserPath(D_CONFIG_IDX) + m_ini_name + ".ini")) { int n = 0; - for (ControllerEmu* pad : controllers) + for (auto& controller : m_controllers) { // Load settings from ini if (useProfile[n]) { IniFile profile_ini; profile_ini.Load(File::GetUserPath(D_CONFIG_IDX) + path + profile[n] + ".ini"); - pad->LoadConfig(profile_ini.GetOrCreateSection("Profile")); + controller->LoadConfig(profile_ini.GetOrCreateSection("Profile")); } else { - pad->LoadConfig(inifile.GetOrCreateSection(pad->GetName())); + controller->LoadConfig(inifile.GetOrCreateSection(controller->GetName())); } // Update refs - pad->UpdateReferences(g_controller_interface); + controller->UpdateReferences(g_controller_interface); // Next profile n++; @@ -79,21 +84,36 @@ bool InputConfig::LoadConfig(bool isGC) } else { - controllers[0]->LoadDefaults(g_controller_interface); - controllers[0]->UpdateReferences(g_controller_interface); + m_controllers[0]->LoadDefaults(g_controller_interface); + m_controllers[0]->UpdateReferences(g_controller_interface); return false; } } void InputConfig::SaveConfig() { - std::string ini_filename = File::GetUserPath(D_CONFIG_IDX) + ini_name + ".ini"; + std::string ini_filename = File::GetUserPath(D_CONFIG_IDX) + m_ini_name + ".ini"; IniFile inifile; inifile.Load(ini_filename); - for (ControllerEmu* pad : controllers) - pad->SaveConfig(inifile.GetOrCreateSection(pad->GetName())); + for (auto& controller : m_controllers) + controller->SaveConfig(inifile.GetOrCreateSection(controller->GetName())); inifile.Save(ini_filename); } + +ControllerEmu* InputConfig::GetController(int index) +{ + return m_controllers.at(index).get(); +} + +void InputConfig::ClearControllers() +{ + m_controllers.clear(); +} + +bool InputConfig::ControllersNeedToBeCreated() const +{ + return m_controllers.empty(); +} diff --git a/Source/Core/InputCommon/InputConfig.h b/Source/Core/InputCommon/InputConfig.h index d827e25927..d8ebdd1a7e 100644 --- a/Source/Core/InputCommon/InputConfig.h +++ b/Source/Core/InputCommon/InputConfig.h @@ -4,29 +4,40 @@ #pragma once -#include +#include +#include +#include #include -#include "Common/FileUtil.h" -#include "Common/IniFile.h" -#include "Common/Thread.h" - -#include "InputCommon/ControllerEmu.h" -#include "InputCommon/ControllerInterface/ControllerInterface.h" +class ControllerEmu; class InputConfig { public: - InputConfig(const char* const _ini_name, const char* const _gui_name, - const char* const _profile_name) - : ini_name(_ini_name), gui_name(_gui_name), profile_name(_profile_name) {} + 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) + { + } bool LoadConfig(bool isGC); void SaveConfig(); - std::vector controllers; + template + void CreateController(Args&&... args) + { + m_controllers.emplace_back(std::make_unique(std::forward(args)...)); + } - const char* const ini_name; - const char* const gui_name; - const char* const profile_name; + ControllerEmu* GetController(int index); + void ClearControllers(); + bool ControllersNeedToBeCreated() const; + + std::string GetGUIName() const { return m_gui_name; } + std::string GetProfileName() const { return m_profile_name; } + +private: + std::vector> m_controllers; + const std::string m_ini_name; + const std::string m_gui_name; + const std::string m_profile_name; };