diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index f4190aa72c..113ac0e553 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -427,11 +427,20 @@ void EmuThread() Keyboard::Initialize(s_window_handle); init_controllers = true; } + else + { + // Update references in case controllers were refreshed + Pad::LoadConfig(); + Keyboard::LoadConfig(); + } // Load and Init Wiimotes - only if we are booting in Wii mode if (core_parameter.bWii) { - Wiimote::Initialize(s_window_handle, !s_state_filename.empty()); + if (init_controllers) + Wiimote::Initialize(s_window_handle, !s_state_filename.empty()); + else + Wiimote::LoadConfig(); // Activate Wiimotes which don't have source set to "None" for (unsigned int i = 0; i != MAX_BBMOTES; ++i) diff --git a/Source/Core/Core/HW/GCKeyboard.cpp b/Source/Core/Core/HW/GCKeyboard.cpp index 1e57e8e802..d6ac24e637 100644 --- a/Source/Core/Core/HW/GCKeyboard.cpp +++ b/Source/Core/Core/HW/GCKeyboard.cpp @@ -45,6 +45,11 @@ void Initialize(void* const hwnd) s_config.LoadConfig(true); } +void LoadConfig() +{ + s_config.LoadConfig(true); +} + void GetStatus(u8 _port, KeyboardStatus* _pKeyboardStatus) { memset(_pKeyboardStatus, 0, sizeof(*_pKeyboardStatus)); @@ -52,19 +57,6 @@ void GetStatus(u8 _port, KeyboardStatus* _pKeyboardStatus) std::unique_lock lk(s_config.controls_lock, std::try_to_lock); - if (!lk.owns_lock()) - { - // if gui has lock (messing with controls), skip this input cycle - // center axes and return - _pKeyboardStatus->key0x = 0; - _pKeyboardStatus->key1x = 0; - _pKeyboardStatus->key2x = 0; - _pKeyboardStatus->key3x = 0; - _pKeyboardStatus->key4x = 0; - _pKeyboardStatus->key5x = 0; - return; - } - // get input ((GCKeyboard*)s_config.controllers[_port])->GetInput(_pKeyboardStatus); } diff --git a/Source/Core/Core/HW/GCKeyboard.h b/Source/Core/Core/HW/GCKeyboard.h index 407b822db1..f535567381 100644 --- a/Source/Core/Core/HW/GCKeyboard.h +++ b/Source/Core/Core/HW/GCKeyboard.h @@ -13,6 +13,7 @@ namespace Keyboard void Shutdown(); void Initialize(void* const hwnd); +void LoadConfig(); InputConfig* GetConfig(); diff --git a/Source/Core/Core/HW/GCPad.cpp b/Source/Core/Core/HW/GCPad.cpp index 34ae9ea618..b57a6d02f2 100644 --- a/Source/Core/Core/HW/GCPad.cpp +++ b/Source/Core/Core/HW/GCPad.cpp @@ -46,6 +46,12 @@ void Initialize(void* const hwnd) s_config.LoadConfig(true); } +void LoadConfig() +{ + s_config.LoadConfig(true); +} + + void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus) { memset(_pPADStatus, 0, sizeof(*_pPADStatus)); @@ -53,16 +59,6 @@ void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus) std::unique_lock lk(s_config.controls_lock, std::try_to_lock); - if (!lk.owns_lock()) - { - // if gui has lock (messing with controls), skip this input cycle - // center axes and return - _pPADStatus->stickX = GCPadStatus::MAIN_STICK_CENTER_X; - _pPADStatus->stickY = GCPadStatus::MAIN_STICK_CENTER_Y; - _pPADStatus->substickX = GCPadStatus::C_STICK_CENTER_X; - _pPADStatus->substickY = GCPadStatus::C_STICK_CENTER_Y; - return; - } // get input ((GCPad*)s_config.controllers[_numPAD])->GetInput(_pPADStatus); @@ -72,9 +68,6 @@ void Rumble(u8 _numPAD, const ControlState strength) { std::unique_lock lk(s_config.controls_lock, std::try_to_lock); - if (!lk.owns_lock()) - return; - ((GCPad*)s_config.controllers[ _numPAD ])->SetOutput(strength); } @@ -83,8 +76,6 @@ bool GetMicButton(u8 pad) std::unique_lock lk(s_config.controls_lock, std::try_to_lock); - if (!lk.owns_lock()) - return false; return ((GCPad*)s_config.controllers[pad])->GetMicButton(); } diff --git a/Source/Core/Core/HW/GCPad.h b/Source/Core/Core/HW/GCPad.h index d9da72e9fc..5d70f9274c 100644 --- a/Source/Core/Core/HW/GCPad.h +++ b/Source/Core/Core/HW/GCPad.h @@ -13,6 +13,7 @@ namespace Pad void Shutdown(); void Initialize(void* const hwnd); +void LoadConfig(); InputConfig* GetConfig(); diff --git a/Source/Core/Core/HW/Wiimote.cpp b/Source/Core/Core/HW/Wiimote.cpp index 357b3b1fea..756384ca30 100644 --- a/Source/Core/Core/HW/Wiimote.cpp +++ b/Source/Core/Core/HW/Wiimote.cpp @@ -55,6 +55,12 @@ void Initialize(void* const hwnd, bool wait) Movie::ChangeWiiPads(); } +void LoadConfig() +{ + s_config.LoadConfig(true); +} + + void Resume() { WiimoteReal::Resume(); @@ -113,7 +119,7 @@ void Update(int _number) //PanicAlert( "Wiimote_Update" ); // TODO: change this to a try_to_lock, and make it give empty input on failure - std::lock_guard lk(s_config.controls_lock); + std::unique_lock lk(s_config.controls_lock, std::try_to_lock); if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number]) ((WiimoteEmu::Wiimote*)s_config.controllers[_number])->Update(); diff --git a/Source/Core/Core/HW/Wiimote.h b/Source/Core/Core/HW/Wiimote.h index 71fa2d28b6..81f2e83c5c 100644 --- a/Source/Core/Core/HW/Wiimote.h +++ b/Source/Core/Core/HW/Wiimote.h @@ -36,6 +36,7 @@ namespace Wiimote void Shutdown(); void Initialize(void* const hwnd, bool wait = false); +void LoadConfig(); void Resume(); void Pause(); diff --git a/Source/Core/Core/HotkeyManager.cpp b/Source/Core/Core/HotkeyManager.cpp index 9fc7208ddb..fd25108a5e 100644 --- a/Source/Core/Core/HotkeyManager.cpp +++ b/Source/Core/Core/HotkeyManager.cpp @@ -157,6 +157,7 @@ static u32 hotkeyDown[3]; static HotkeyStatus hotkey; static InputConfig s_config("Hotkeys", _trans("Hotkeys"), "Hotkeys"); + InputConfig* GetConfig() { return &s_config; @@ -170,10 +171,14 @@ void GetStatus() ((HotkeyManager*)s_config.controllers[0])->GetInput(&hotkey); } -bool IsReady() +bool IsEnabled() { - std::unique_lock lk(s_config.controls_lock, std::try_to_lock); - return lk.owns_lock(); + return enabled; +} + +void Enable(bool enable_toggle) +{ + enabled = enable_toggle; } bool IsPressed(int Id, bool held) @@ -209,6 +214,13 @@ void Initialize(void* const hwnd) for (unsigned int i = 0; i < 3; ++i) hotkeyDown[i] = 0; + + enabled = true; +} + +void LoadConfig() +{ + s_config.LoadConfig(true); } void Shutdown() diff --git a/Source/Core/Core/HotkeyManager.h b/Source/Core/Core/HotkeyManager.h index 6095db4906..bd76395046 100644 --- a/Source/Core/Core/HotkeyManager.h +++ b/Source/Core/Core/HotkeyManager.h @@ -32,9 +32,13 @@ namespace HotkeyManagerEmu { void Initialize(void* const hwnd); void Shutdown(); + void LoadConfig(); InputConfig* GetConfig(); void GetStatus(); - bool IsReady(); + bool IsEnabled(); + void Enable(bool enable_toggle); bool IsPressed(int Id, bool held); + + static bool enabled; } diff --git a/Source/Core/DolphinWX/ControllerConfigDiag.cpp b/Source/Core/DolphinWX/ControllerConfigDiag.cpp index 909f70b1b1..6f3ae906f5 100644 --- a/Source/Core/DolphinWX/ControllerConfigDiag.cpp +++ b/Source/Core/DolphinWX/ControllerConfigDiag.cpp @@ -23,6 +23,7 @@ #include "Common/SysConf.h" #include "Core/ConfigManager.h" #include "Core/Core.h" +#include "Core/HotkeyManager.h" #include "Core/Movie.h" #include "Core/NetPlayProto.h" #include "Core/HW/GCKeyboard.h" @@ -207,12 +208,13 @@ wxStaticBoxSizer* ControllerConfigDiag::CreateWiimoteConfigSizer() wiimote_configure_bt[i]->Bind(wxEVT_BUTTON, &ControllerConfigDiag::ConfigEmulatedWiimote, this); // Disable controller type selection for certain circumstances. - if (NetPlay::IsNetPlayRunning() || Movie::IsMovieActive()) + bool wii_game_started = SConfig::GetInstance().m_LocalCoreStartupParameter.bWii || Core::GetState() == Core::CORE_UNINITIALIZED; + if (NetPlay::IsNetPlayRunning() || Movie::IsMovieActive() || !wii_game_started) wiimote_source_ch[i]->Disable(); m_orig_wiimote_sources[i] = g_wiimote_sources[i]; wiimote_source_ch[i]->Select(m_orig_wiimote_sources[i]); - if (m_orig_wiimote_sources[i] != WIIMOTE_SRC_EMU && m_orig_wiimote_sources[i] != WIIMOTE_SRC_HYBRID) + if (!wii_game_started || (m_orig_wiimote_sources[i] != WIIMOTE_SRC_EMU && m_orig_wiimote_sources[i] != WIIMOTE_SRC_HYBRID)) wiimote_configure_bt[i]->Disable(); } @@ -390,28 +392,13 @@ wxStaticBoxSizer* ControllerConfigDiag::CreateGeneralWiimoteSettingsSizer() void ControllerConfigDiag::ConfigEmulatedWiimote(wxCommandEvent& ev) { InputConfig* const wiimote_plugin = Wiimote::GetConfig(); - bool was_init = false; - if (g_controller_interface.IsInit()) // check if game is running - { - was_init = true; - } - else - { -#if defined(HAVE_X11) && HAVE_X11 - Window win = X11Utils::XWindowFromHandle(GetHandle()); - Wiimote::Initialize(reinterpret_cast(win)); -#else - Wiimote::Initialize(reinterpret_cast(GetHandle())); -#endif - } + + HotkeyManagerEmu::Enable(false); InputConfigDialog m_ConfigFrame(this, *wiimote_plugin, _("Dolphin Emulated Wiimote Configuration"), m_wiimote_index_from_conf_bt_id[ev.GetId()]); m_ConfigFrame.ShowModal(); - if (!was_init) // if game isn't running - { - Wiimote::Shutdown(); - } + HotkeyManagerEmu::Enable(true); } void ControllerConfigDiag::RefreshRealWiimotes(wxCommandEvent&) @@ -535,24 +522,7 @@ void ControllerConfigDiag::OnGameCubeConfigButton(wxCommandEvent& event) InputConfig* const key_plugin = Keyboard::GetConfig(); const int port_num = m_gc_port_config_ids[event.GetId()]; - bool was_init = false; - - // check if game is running - if (g_controller_interface.IsInit()) - { - was_init = true; - } - else - { -#if defined(HAVE_X11) && HAVE_X11 - Window win = X11Utils::XWindowFromHandle(GetHandle()); - Pad::Initialize(reinterpret_cast(win)); - Keyboard::Initialize(reinterpret_cast(win)); -#else - Pad::Initialize(reinterpret_cast(GetHandle())); - Keyboard::Initialize(reinterpret_cast(GetHandle())); -#endif - } + HotkeyManagerEmu::Enable(false); if (SConfig::GetInstance().m_SIDevice[port_num] == SIDEVICE_GC_KEYBOARD) { @@ -565,10 +535,5 @@ void ControllerConfigDiag::OnGameCubeConfigButton(wxCommandEvent& event) m_ConfigFrame.ShowModal(); } - // if game isn't running - if (!was_init) - { - Keyboard::Shutdown(); - Pad::Shutdown(); - } + HotkeyManagerEmu::Enable(true); } diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index 9352dcb367..b6b28a57f2 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -1263,7 +1263,7 @@ const CGameListCtrl *CFrame::GetGameListCtrl() const void CFrame::PollHotkeys(wxTimerEvent& event) { - if (!HotkeyManagerEmu::IsReady()) + if (!HotkeyManagerEmu::IsEnabled()) return; if (Core::GetState() == Core::CORE_UNINITIALIZED || Core::GetState() == Core::CORE_PAUSE) diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 7ab7e9523c..04534a48fb 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -51,6 +51,7 @@ #include "Core/State.h" #include "Core/HW/CPU.h" #include "Core/HW/DVDInterface.h" +#include "Core/HW/GCKeyboard.h" #include "Core/HW/GCPad.h" #include "Core/HW/ProcessorInterface.h" #include "Core/HW/SI_Device.h" @@ -1366,27 +1367,31 @@ void CFrame::OnConfigHotkey(wxCommandEvent& WXUNUSED (event)) InputConfig* const hotkey_plugin = HotkeyManagerEmu::GetConfig(); // check if game is running - if (g_controller_interface.IsInit()) + bool game_running = false; + if (Core::GetState() == Core::CORE_RUN) { - was_init = true; - } - else - { -#if defined(HAVE_X11) && HAVE_X11 - Window win = X11Utils::XWindowFromHandle(GetHandle()); - HotkeyManagerEmu::Initialize(reinterpret_cast(win)); -#else - HotkeyManagerEmu::Initialize(reinterpret_cast(GetHandle())); -#endif + Core::SetState(Core::CORE_PAUSE); + game_running = true; } + HotkeyManagerEmu::Enable(false); + InputConfigDialog m_ConfigFrame(this, *hotkey_plugin, _("Dolphin Hotkeys")); m_ConfigFrame.ShowModal(); + // Update references in case controllers were refreshed + if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) + Wiimote::LoadConfig(); + Keyboard::LoadConfig(); + Pad::LoadConfig(); + HotkeyManagerEmu::LoadConfig(); + + HotkeyManagerEmu::Enable(true); + // if game isn't running - if (!was_init) + if (game_running) { - HotkeyManagerEmu::Shutdown(); + Core::SetState(Core::CORE_RUN); } // Update the GUI in case menu accelerators were changed diff --git a/Source/Core/DolphinWX/InputConfigDiag.cpp b/Source/Core/DolphinWX/InputConfigDiag.cpp index 653f92ea11..d45458535a 100644 --- a/Source/Core/DolphinWX/InputConfigDiag.cpp +++ b/Source/Core/DolphinWX/InputConfigDiag.cpp @@ -44,6 +44,10 @@ #include "Common/FileUtil.h" #include "Common/IniFile.h" #include "Common/MsgHandler.h" +#include "Core/Core.h" +#include "Core/HotkeyManager.h" +#include "Core/HW/GCKeyboard.h" +#include "Core/HW/GCPad.h" #include "Core/HW/Wiimote.h" #include "DolphinWX/InputConfigDiag.h" #include "DolphinWX/WxUtils.h" @@ -740,6 +744,8 @@ void InputConfigDialog::UpdateDeviceComboBox() void GamepadPage::RefreshDevices(wxCommandEvent&) { + bool was_unpaused = Core::PauseAndLock(true); + std::lock_guard lk(m_config.controls_lock); // refresh devices @@ -750,6 +756,14 @@ void GamepadPage::RefreshDevices(wxCommandEvent&) // update device cbox m_config_dialog->UpdateDeviceComboBox(); + + //if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) + Wiimote::LoadConfig(); + Keyboard::LoadConfig(); + Pad::LoadConfig(); + HotkeyManagerEmu::LoadConfig(); + + Core::PauseAndLock(false, was_unpaused); } ControlGroupBox::~ControlGroupBox() diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 3eb1b95ff2..1330cb1e0a 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -136,9 +136,6 @@ void ControllerInterface::UpdateInput() { std::unique_lock lk(update_lock, std::defer_lock); - if (!lk.try_lock()) - return; - for (ciface::Core::Device* d : m_devices) d->UpdateInput(); } diff --git a/Source/Core/InputCommon/InputConfig.cpp b/Source/Core/InputCommon/InputConfig.cpp index da5bb5081a..ef517d407d 100644 --- a/Source/Core/InputCommon/InputConfig.cpp +++ b/Source/Core/InputCommon/InputConfig.cpp @@ -7,13 +7,6 @@ #include "Core/HW/Wiimote.h" #include "InputCommon/InputConfig.h" -InputConfig::~InputConfig() -{ - // delete pads - for (ControllerEmu* pad : controllers) - delete pad; -} - bool InputConfig::LoadConfig(bool isGC) { IniFile inifile; diff --git a/Source/Core/InputCommon/InputConfig.h b/Source/Core/InputCommon/InputConfig.h index e6e80c83fc..a234cdf167 100644 --- a/Source/Core/InputCommon/InputConfig.h +++ b/Source/Core/InputCommon/InputConfig.h @@ -21,8 +21,6 @@ public: const char* const _profile_name) : ini_name(_ini_name), gui_name(_gui_name), profile_name(_profile_name) {} - ~InputConfig(); - bool LoadConfig(bool isGC); void SaveConfig();