Merge pull request #3202 from lioncash/input

InputConfig: Clean up controller management
This commit is contained in:
Markus Wick 2015-11-19 09:10:36 +01:00
commit 1f4b16dacf
17 changed files with 146 additions and 171 deletions

View File

@ -22,26 +22,22 @@ InputConfig* GetConfig()
void Shutdown() void Shutdown()
{ {
std::vector<ControllerEmu*>::const_iterator s_config.ClearControllers();
i = s_config.controllers.begin(),
e = s_config.controllers.end();
for ( ; i!=e; ++i )
delete *i;
s_config.controllers.clear();
g_controller_interface.Shutdown(); g_controller_interface.Shutdown();
} }
// if plugin isn't initialized, init and load config
void Initialize(void* const hwnd) void Initialize(void* const hwnd)
{ {
if (s_config.controllers.empty()) if (s_config.ControllersNeedToBeCreated())
{
for (unsigned int i = 0; i < 4; ++i) for (unsigned int i = 0; i < 4; ++i)
s_config.controllers.push_back(new GCKeyboard(i)); s_config.CreateController<GCKeyboard>(i);
}
g_controller_interface.Initialize(hwnd); g_controller_interface.Initialize(hwnd);
// load the saved controller config // Load the saved controller config
s_config.LoadConfig(true); s_config.LoadConfig(true);
} }
@ -50,13 +46,13 @@ void LoadConfig()
s_config.LoadConfig(true); s_config.LoadConfig(true);
} }
void GetStatus(u8 _port, KeyboardStatus* _pKeyboardStatus) void GetStatus(u8 port, KeyboardStatus* keyboard_status)
{ {
memset(_pKeyboardStatus, 0, sizeof(*_pKeyboardStatus)); memset(keyboard_status, 0, sizeof(*keyboard_status));
_pKeyboardStatus->err = PAD_ERR_NONE; keyboard_status->err = PAD_ERR_NONE;
// get input // Get input
((GCKeyboard*)s_config.controllers[_port])->GetInput(_pKeyboardStatus); static_cast<GCKeyboard*>(s_config.GetController(port))->GetInput(keyboard_status);
} }
} }

View File

@ -18,6 +18,6 @@ void LoadConfig();
InputConfig* GetConfig(); InputConfig* GetConfig();
void GetStatus(u8 _port, KeyboardStatus* _pKeyboardStatus); void GetStatus(u8 port, KeyboardStatus* keyboard_status);
} }

View File

@ -23,27 +23,22 @@ InputConfig* GetConfig()
void Shutdown() void Shutdown()
{ {
std::vector<ControllerEmu*>::const_iterator s_config.ClearControllers();
i = s_config.controllers.begin(),
e = s_config.controllers.end();
for ( ; i!=e; ++i )
delete *i;
s_config.controllers.clear();
g_controller_interface.Shutdown(); g_controller_interface.Shutdown();
} }
// if plugin isn't initialized, init and load config
void Initialize(void* const hwnd) void Initialize(void* const hwnd)
{ {
// add 4 gcpads if (s_config.ControllersNeedToBeCreated())
if (s_config.controllers.empty()) {
for (unsigned int i = 0; i < 4; ++i) for (unsigned int i = 0; i < 4; ++i)
s_config.controllers.push_back(new GCPad(i)); s_config.CreateController<GCPad>(i);
}
g_controller_interface.Initialize(hwnd); g_controller_interface.Initialize(hwnd);
// load the saved controller config // Load the saved controller config
s_config.LoadConfig(true); 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)); memset(pad_status, 0, sizeof(*pad_status));
_pPADStatus->err = PAD_ERR_NONE; pad_status->err = PAD_ERR_NONE;
// if we are on the next input cycle, update output and input // If we are on the next input cycle, update output and input
static int _last_numPAD = 4; static int last_pad_num = 4;
if (_numPAD <= _last_numPAD) if (pad_num <= last_pad_num)
{ {
g_controller_interface.UpdateInput(); g_controller_interface.UpdateInput();
} }
_last_numPAD = _numPAD; last_pad_num = pad_num;
// get input // Get input
((GCPad*)s_config.controllers[_numPAD])->GetInput(_pPADStatus); static_cast<GCPad*>(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<GCPad*>(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<GCPad*>(s_config.GetController(pad_num))->GetMicButton();
} }
} }

View File

@ -19,8 +19,8 @@ void LoadConfig();
InputConfig* GetConfig(); InputConfig* GetConfig();
void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus); void GetStatus(u8 pad_num, GCPadStatus* pad_status);
void Rumble(u8 _numPAD, const ControlState strength); void Rumble(u8 pad_num, ControlState strength);
bool GetMicButton(u8 pad); bool GetMicButton(u8 pad_num);
} }

View File

@ -25,24 +25,20 @@ InputConfig* GetConfig()
void Shutdown() void Shutdown()
{ {
for (const ControllerEmu* i : s_config.controllers) s_config.ClearControllers();
{
delete i;
}
s_config.controllers.clear();
WiimoteReal::Stop(); WiimoteReal::Stop();
g_controller_interface.Shutdown(); g_controller_interface.Shutdown();
} }
// if plugin isn't initialized, init and load config
void Initialize(void* const hwnd, bool wait) void Initialize(void* const hwnd, bool wait)
{ {
// add 4 Wiimotes if (s_config.ControllersNeedToBeCreated())
if (s_config.controllers.empty()) {
for (unsigned int i = WIIMOTE_CHAN_0; i < MAX_BBMOTES; ++i) for (unsigned int i = WIIMOTE_CHAN_0; i < MAX_BBMOTES; ++i)
s_config.controllers.push_back(new WiimoteEmu::Wiimote(i)); s_config.CreateController<WiimoteEmu::Wiimote>(i);
}
g_controller_interface.Initialize(hwnd); g_controller_interface.Initialize(hwnd);
@ -50,7 +46,7 @@ void Initialize(void* const hwnd, bool wait)
WiimoteReal::Initialize(wait); WiimoteReal::Initialize(wait);
// reload Wiimotes with our settings // Reload Wiimotes with our settings
if (Movie::IsMovieActive()) if (Movie::IsMovieActive())
Movie::ChangeWiiPads(); Movie::ChangeWiiPads();
} }
@ -72,72 +68,41 @@ void Pause()
} }
// __________________________________________________________________________________________________ // An L2CAP packet is passed from the Core to the Wiimote on the HID CONTROL channel.
// Function: ControlChannel void ControlChannel(int number, u16 channel_id, const void* data, u32 size)
// 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)
{ {
if (WIIMOTE_SRC_HYBRID & g_wiimote_sources[_number]) if (WIIMOTE_SRC_HYBRID & g_wiimote_sources[number])
((WiimoteEmu::Wiimote*)s_config.controllers[_number])->ControlChannel(_channelID, _pData, _Size); static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->ControlChannel(channel_id, data, size);
} }
// __________________________________________________________________________________________________ // An L2CAP packet is passed from the Core to the Wiimote on the HID INTERRUPT channel.
// Function: InterruptChannel void InterruptChannel(int number, u16 channel_id, const void* data, u32 size)
// 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)
{ {
if (WIIMOTE_SRC_HYBRID & g_wiimote_sources[_number]) if (WIIMOTE_SRC_HYBRID & g_wiimote_sources[number])
((WiimoteEmu::Wiimote*)s_config.controllers[_number])->InterruptChannel(_channelID, _pData, _Size); static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->InterruptChannel(channel_id, data, size);
} }
// __________________________________________________________________________________________________ // This function is called periodically by the Core to update Wiimote state.
// Function: Update void Update(int number, bool connected)
// Purpose: This function is called periodically by the Core. // TODO: Explain why.
// input: _number: [Description needed]
// output: none
//
void Update(int _number, bool _connected)
{ {
if (_connected) if (connected)
{ {
if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number]) if (WIIMOTE_SRC_EMU & g_wiimote_sources[number])
((WiimoteEmu::Wiimote*)s_config.controllers[_number])->Update(); static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->Update();
else else
WiimoteReal::Update(_number); WiimoteReal::Update(number);
} }
else else
{ {
if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number]) if (WIIMOTE_SRC_EMU & g_wiimote_sources[number])
((WiimoteEmu::Wiimote*)s_config.controllers[_number])->ConnectOnInput(); static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->ConnectOnInput();
if (WIIMOTE_SRC_REAL & g_wiimote_sources[_number])
WiimoteReal::ConnectOnInput(_number); if (WIIMOTE_SRC_REAL & g_wiimote_sources[number])
WiimoteReal::ConnectOnInput(number);
} }
} }
// __________________________________________________________________________________________________ // Get a mask of attached the pads (eg: controller 1 & 4 -> 0x9)
// Function: GetAttached
// Purpose: Get mask of attached pads (eg: controller 1 & 4 -> 0x9)
// input: none
// output: The number of attached pads
//
unsigned int GetAttached() unsigned int GetAttached()
{ {
unsigned int attached = 0; unsigned int attached = 0;
@ -147,29 +112,16 @@ unsigned int GetAttached()
return attached; return attached;
} }
// ___________________________________________________________________________ // Save/Load state
// Function: DoState
// Purpose: Saves/load state
// input/output: ptr: [Description Needed]
// input: mode [Description needed]
//
void DoState(PointerWrap& p) void DoState(PointerWrap& p)
{ {
// TODO: for (int i = 0; i < MAX_BBMOTES; ++i)
static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(i))->DoState(p);
for (unsigned int i=0; i<MAX_BBMOTES; ++i)
((WiimoteEmu::Wiimote*)s_config.controllers[i])->DoState(p);
} }
// ___________________________________________________________________________ // Notifies the plugin of a change in emulation state
// 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
//
void EmuStateChange(EMUSTATE_CHANGE newState) void EmuStateChange(EMUSTATE_CHANGE newState)
{ {
// TODO
WiimoteReal::StateChange(newState); WiimoteReal::StateChange(newState);
} }

View File

@ -10,7 +10,9 @@
#include <bluetooth/hci_lib.h> #include <bluetooth/hci_lib.h>
#include <bluetooth/l2cap.h> #include <bluetooth/l2cap.h>
#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" #include "Core/HW/WiimoteReal/WiimoteReal.h"
namespace WiimoteReal namespace WiimoteReal

View File

@ -19,6 +19,7 @@
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Common/Thread.h" #include "Common/Thread.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h" #include "Core/HW/WiimoteReal/WiimoteReal.h"
//#define AUTHENTICATE_WIIMOTES //#define AUTHENTICATE_WIIMOTES

View File

@ -1,6 +1,8 @@
#define BLUETOOTH_VERSION_USE_CURRENT #define BLUETOOTH_VERSION_USE_CURRENT
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/Logging/Log.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h" #include "Core/HW/WiimoteReal/WiimoteReal.h"
@interface SearchBT: NSObject { @interface SearchBT: NSObject {

View File

@ -14,8 +14,10 @@
#include "Common/Timer.h" #include "Common/Timer.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Host.h" #include "Core/Host.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h" #include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h" #include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "InputCommon/InputConfig.h"
#include "SFML/Network.hpp" #include "SFML/Network.hpp"
@ -153,7 +155,7 @@ void Wiimote::InterruptChannel(const u16 channel, const void* const _data, const
auto const data = static_cast<const u8*>(_data); auto const data = static_cast<const u8*>(_data);
Report rpt(data, data + size); Report rpt(data, data + size);
WiimoteEmu::Wiimote *const wm = (WiimoteEmu::Wiimote*)::Wiimote::GetConfig()->controllers[m_index]; WiimoteEmu::Wiimote* const wm = static_cast<WiimoteEmu::Wiimote*>(::Wiimote::GetConfig()->GetController(m_index));
// Convert output DATA packets to SET_REPORT packets. // Convert output DATA packets to SET_REPORT packets.
// Nintendo Wiimotes work without this translation, but 3rd // Nintendo Wiimotes work without this translation, but 3rd
@ -382,7 +384,7 @@ void Wiimote::EmuStop()
void Wiimote::EmuResume() void Wiimote::EmuResume()
{ {
WiimoteEmu::Wiimote *const wm = (WiimoteEmu::Wiimote*)::Wiimote::GetConfig()->controllers[m_index]; WiimoteEmu::Wiimote* const wm = static_cast<WiimoteEmu::Wiimote*>(::Wiimote::GetConfig()->GetController(m_index));
m_last_input_report.clear(); m_last_input_report.clear();

View File

@ -16,9 +16,7 @@
#include "Common/NonCopyable.h" #include "Common/NonCopyable.h"
#include "Common/Timer.h" #include "Common/Timer.h"
#include "Core/HW/Wiimote.h" #include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteReal/WiimoteRealBase.h" #include "Core/HW/WiimoteReal/WiimoteRealBase.h"
#include "InputCommon/InputConfig.h"
class PointerWrap; class PointerWrap;
@ -29,7 +27,6 @@ namespace WiimoteReal
class Wiimote : NonCopyable class Wiimote : NonCopyable
{ {
friend class WiimoteEmu::Wiimote;
public: public:
virtual ~Wiimote() {} virtual ~Wiimote() {}
// This needs to be called in derived destructors! // This needs to be called in derived destructors!

View File

@ -8,6 +8,7 @@
#include "Common/Common.h" #include "Common/Common.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/HotkeyManager.h" #include "Core/HotkeyManager.h"
#include "InputCommon/GCPadStatus.h"
const std::string hotkey_labels[] = const std::string hotkey_labels[] =
{ {
@ -147,8 +148,8 @@ void GetStatus()
{ {
s_hotkey.err = PAD_ERR_NONE; s_hotkey.err = PAD_ERR_NONE;
// get input // Get input
((HotkeyManager*)s_config.controllers[0])->GetInput(&s_hotkey); static_cast<HotkeyManager*>(s_config.GetController(0))->GetInput(&s_hotkey);
} }
bool IsEnabled() bool IsEnabled()
@ -182,8 +183,8 @@ bool IsPressed(int Id, bool held)
void Initialize(void* const hwnd) void Initialize(void* const hwnd)
{ {
if (s_config.controllers.empty()) if (s_config.ControllersNeedToBeCreated())
s_config.controllers.push_back(new HotkeyManager()); s_config.CreateController<HotkeyManager>();
g_controller_interface.Initialize(hwnd); g_controller_interface.Initialize(hwnd);
@ -203,12 +204,7 @@ void LoadConfig()
void Shutdown() void Shutdown()
{ {
std::vector<ControllerEmu*>::const_iterator s_config.ClearControllers();
i = s_config.controllers.begin(),
e = s_config.controllers.end();
for (; i != e; ++i)
delete *i;
s_config.controllers.clear();
g_controller_interface.Shutdown(); g_controller_interface.Shutdown();
} }

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include "InputCommon/ControllerEmu.h"
#include "InputCommon/InputConfig.h" #include "InputCommon/InputConfig.h"
enum Hotkey enum Hotkey

View File

@ -170,7 +170,7 @@ void InputConfigDialog::UpdateProfileComboBox()
{ {
std::string pname(File::GetUserPath(D_CONFIG_IDX)); std::string pname(File::GetUserPath(D_CONFIG_IDX));
pname += PROFILES_PATH; pname += PROFILES_PATH;
pname += m_config.profile_name; pname += m_config.GetProfileName();
std::vector<std::string> sv = DoFileSearch({".ini"}, {pname}); std::vector<std::string> sv = DoFileSearch({".ini"}, {pname});
@ -652,7 +652,7 @@ void GamepadPage::GetProfilePath(std::string& path)
path = File::GetUserPath(D_CONFIG_IDX); path = File::GetUserPath(D_CONFIG_IDX);
path += PROFILES_PATH; path += PROFILES_PATH;
path += m_config.profile_name; path += m_config.GetProfileName();
path += '/'; path += '/';
path += WxStrToStr(profile_cbox->GetValue()); path += WxStrToStr(profile_cbox->GetValue());
path += ".ini"; path += ".ini";
@ -984,14 +984,14 @@ ControlGroupsSizer::ControlGroupsSizer(ControllerEmu* const controller, wxWindow
Add(stacked_groups, 0, /*wxEXPAND|*/wxBOTTOM|wxRIGHT, 5); 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) : wxPanel(parent, wxID_ANY)
,controller(config.controllers[pad_num]) , controller(config.GetController(pad_num))
, m_config_dialog(config_dialog) , m_config_dialog(config_dialog)
, m_config(config) , 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")); 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); m_pad_notebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_DEFAULT);
GamepadPage* gp = new GamepadPage(m_pad_notebook, m_config, tab_num, this); GamepadPage* gp = new GamepadPage(m_pad_notebook, m_config, tab_num, this);
m_padpages.push_back(gp); 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); m_pad_notebook->SetSelection(0);

View File

@ -200,7 +200,7 @@ class GamepadPage : public wxPanel
friend class ControlDialog; friend class ControlDialog;
public: 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(); void UpdateGUI();

View File

@ -142,7 +142,7 @@ void TASInputDlg::CreateWiiLayout(int num)
if (Core::IsRunning()) if (Core::IsRunning())
{ {
m_ext = ((WiimoteEmu::Wiimote*)Wiimote::GetConfig()->controllers[num])->CurrentExtension(); m_ext = static_cast<WiimoteEmu::Wiimote*>(Wiimote::GetConfig()->GetController(num))->CurrentExtension();
} }
else else
{ {

View File

@ -2,10 +2,15 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Common/CommonPaths.h" #include <vector>
#include "Common/FileUtil.h"
#include "Common/IniFile.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/HW/Wiimote.h" #include "Core/HW/Wiimote.h"
#include "InputCommon/ControllerEmu.h"
#include "InputCommon/InputConfig.h" #include "InputCommon/InputConfig.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
bool InputConfig::LoadConfig(bool isGC) 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; int n = 0;
for (ControllerEmu* pad : controllers) for (auto& controller : m_controllers)
{ {
// Load settings from ini // Load settings from ini
if (useProfile[n]) if (useProfile[n])
{ {
IniFile profile_ini; IniFile profile_ini;
profile_ini.Load(File::GetUserPath(D_CONFIG_IDX) + path + profile[n] + ".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 else
{ {
pad->LoadConfig(inifile.GetOrCreateSection(pad->GetName())); controller->LoadConfig(inifile.GetOrCreateSection(controller->GetName()));
} }
// Update refs // Update refs
pad->UpdateReferences(g_controller_interface); controller->UpdateReferences(g_controller_interface);
// Next profile // Next profile
n++; n++;
@ -79,21 +84,36 @@ bool InputConfig::LoadConfig(bool isGC)
} }
else else
{ {
controllers[0]->LoadDefaults(g_controller_interface); m_controllers[0]->LoadDefaults(g_controller_interface);
controllers[0]->UpdateReferences(g_controller_interface); m_controllers[0]->UpdateReferences(g_controller_interface);
return false; return false;
} }
} }
void InputConfig::SaveConfig() 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 inifile;
inifile.Load(ini_filename); inifile.Load(ini_filename);
for (ControllerEmu* pad : controllers) for (auto& controller : m_controllers)
pad->SaveConfig(inifile.GetOrCreateSection(pad->GetName())); controller->SaveConfig(inifile.GetOrCreateSection(controller->GetName()));
inifile.Save(ini_filename); 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();
}

View File

@ -4,29 +4,40 @@
#pragma once #pragma once
#include <map> #include <memory>
#include <string>
#include <utility>
#include <vector> #include <vector>
#include "Common/FileUtil.h" class ControllerEmu;
#include "Common/IniFile.h"
#include "Common/Thread.h"
#include "InputCommon/ControllerEmu.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
class InputConfig class InputConfig
{ {
public: public:
InputConfig(const char* const _ini_name, const char* const _gui_name, InputConfig(const std::string& ini_name, const std::string& gui_name, const std::string& profile_name)
const char* const _profile_name) : m_ini_name(ini_name), m_gui_name(gui_name), m_profile_name(profile_name)
: ini_name(_ini_name), gui_name(_gui_name), profile_name(_profile_name) {} {
}
bool LoadConfig(bool isGC); bool LoadConfig(bool isGC);
void SaveConfig(); void SaveConfig();
std::vector<ControllerEmu*> controllers; template <typename T, typename... Args>
void CreateController(Args&&... args)
{
m_controllers.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
}
const char* const ini_name; ControllerEmu* GetController(int index);
const char* const gui_name; void ClearControllers();
const char* const profile_name; bool ControllersNeedToBeCreated() const;
std::string GetGUIName() const { return m_gui_name; }
std::string GetProfileName() const { return m_profile_name; }
private:
std::vector<std::unique_ptr<ControllerEmu>> m_controllers;
const std::string m_ini_name;
const std::string m_gui_name;
const std::string m_profile_name;
}; };