From a082e9324fce217378915fa2946fda5cfccf8c8d Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Tue, 11 Oct 2016 12:54:35 -0700 Subject: [PATCH] HW: Don't be responsible for g_controller_interface Currently, `g_controller_interface` is initialized and shut down by each of `GCKeyboard`, `GCPad`, `Wiimote`, and `HotkeyManager`. This 1) is weird conceptually, because it necessitates passing a pointer to the native window to each of those classes, which don't need it, and 2) can cause issues when controller backends are initialized or shutdown multiple times in succession. --- Source/Core/Core/Core.cpp | 12 +++++++----- Source/Core/Core/HW/GCKeyboard.cpp | 5 +---- Source/Core/Core/HW/GCKeyboard.h | 2 +- Source/Core/Core/HW/GCPad.cpp | 5 +---- Source/Core/Core/HW/GCPad.h | 2 +- Source/Core/Core/HW/Wiimote.cpp | 5 +---- Source/Core/Core/HW/Wiimote.h | 2 +- Source/Core/Core/HotkeyManager.cpp | 5 +---- Source/Core/Core/HotkeyManager.h | 2 +- Source/Core/DolphinWX/Frame.cpp | 20 +++++++++----------- 10 files changed, 24 insertions(+), 36 deletions(-) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 816811d4cb..e12a7fe14f 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -510,8 +510,9 @@ void EmuThread() bool init_controllers = false; if (!g_controller_interface.IsInit()) { - Pad::Initialize(s_window_handle); - Keyboard::Initialize(s_window_handle); + g_controller_interface.Initialize(s_window_handle); + Pad::Initialize(); + Keyboard::Initialize(); init_controllers = true; } else @@ -525,9 +526,9 @@ void EmuThread() if (core_parameter.bWii && !SConfig::GetInstance().m_bt_passthrough_enabled) { if (init_controllers) - Wiimote::Initialize(s_window_handle, !s_state_filename.empty() ? - Wiimote::InitializeMode::DO_WAIT_FOR_WIIMOTES : - Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES); + Wiimote::Initialize(!s_state_filename.empty() ? + Wiimote::InitializeMode::DO_WAIT_FOR_WIIMOTES : + Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES); else Wiimote::LoadConfig(); @@ -651,6 +652,7 @@ void EmuThread() Wiimote::Shutdown(); Keyboard::Shutdown(); Pad::Shutdown(); + g_controller_interface.Shutdown(); init_controllers = false; } diff --git a/Source/Core/Core/HW/GCKeyboard.cpp b/Source/Core/Core/HW/GCKeyboard.cpp index 37fde7c574..e01b2eb6a9 100644 --- a/Source/Core/Core/HW/GCKeyboard.cpp +++ b/Source/Core/Core/HW/GCKeyboard.cpp @@ -23,11 +23,9 @@ InputConfig* GetConfig() void Shutdown() { s_config.ClearControllers(); - - g_controller_interface.Shutdown(); } -void Initialize(void* const hwnd) +void Initialize() { if (s_config.ControllersNeedToBeCreated()) { @@ -35,7 +33,6 @@ void Initialize(void* const hwnd) s_config.CreateController(i); } - g_controller_interface.Initialize(hwnd); g_controller_interface.RegisterHotplugCallback(LoadConfig); // Load the saved controller config diff --git a/Source/Core/Core/HW/GCKeyboard.h b/Source/Core/Core/HW/GCKeyboard.h index 73f0bd50cb..0547dcfa2f 100644 --- a/Source/Core/Core/HW/GCKeyboard.h +++ b/Source/Core/Core/HW/GCKeyboard.h @@ -12,7 +12,7 @@ struct KeyboardStatus; namespace Keyboard { void Shutdown(); -void Initialize(void* const hwnd); +void Initialize(); void LoadConfig(); InputConfig* GetConfig(); diff --git a/Source/Core/Core/HW/GCPad.cpp b/Source/Core/Core/HW/GCPad.cpp index 6050e1a560..034d546557 100644 --- a/Source/Core/Core/HW/GCPad.cpp +++ b/Source/Core/Core/HW/GCPad.cpp @@ -22,11 +22,9 @@ InputConfig* GetConfig() void Shutdown() { s_config.ClearControllers(); - - g_controller_interface.Shutdown(); } -void Initialize(void* const hwnd) +void Initialize() { if (s_config.ControllersNeedToBeCreated()) { @@ -34,7 +32,6 @@ void Initialize(void* const hwnd) s_config.CreateController(i); } - g_controller_interface.Initialize(hwnd); g_controller_interface.RegisterHotplugCallback(LoadConfig); // Load the saved controller config diff --git a/Source/Core/Core/HW/GCPad.h b/Source/Core/Core/HW/GCPad.h index f4b9d8e449..fab5609e0d 100644 --- a/Source/Core/Core/HW/GCPad.h +++ b/Source/Core/Core/HW/GCPad.h @@ -13,7 +13,7 @@ struct GCPadStatus; namespace Pad { void Shutdown(); -void Initialize(void* const hwnd); +void Initialize(); void LoadConfig(); InputConfig* GetConfig(); diff --git a/Source/Core/Core/HW/Wiimote.cpp b/Source/Core/Core/HW/Wiimote.cpp index ea63468a31..0d91fb926c 100644 --- a/Source/Core/Core/HW/Wiimote.cpp +++ b/Source/Core/Core/HW/Wiimote.cpp @@ -24,11 +24,9 @@ void Shutdown() s_config.ClearControllers(); WiimoteReal::Stop(); - - g_controller_interface.Shutdown(); } -void Initialize(void* const hwnd, InitializeMode init_mode) +void Initialize(InitializeMode init_mode) { if (s_config.ControllersNeedToBeCreated()) { @@ -36,7 +34,6 @@ void Initialize(void* const hwnd, InitializeMode init_mode) s_config.CreateController(i); } - g_controller_interface.Initialize(hwnd); g_controller_interface.RegisterHotplugCallback(LoadConfig); s_config.LoadConfig(false); diff --git a/Source/Core/Core/HW/Wiimote.h b/Source/Core/Core/HW/Wiimote.h index 1c77042342..9dee32ffb7 100644 --- a/Source/Core/Core/HW/Wiimote.h +++ b/Source/Core/Core/HW/Wiimote.h @@ -42,7 +42,7 @@ enum class InitializeMode }; void Shutdown(); -void Initialize(void* const hwnd, InitializeMode init_mode); +void Initialize(InitializeMode init_mode); void ResetAllWiimotes(); void LoadConfig(); void Resume(); diff --git a/Source/Core/Core/HotkeyManager.cpp b/Source/Core/Core/HotkeyManager.cpp index a97c87ae25..c33c24e2d5 100644 --- a/Source/Core/Core/HotkeyManager.cpp +++ b/Source/Core/Core/HotkeyManager.cpp @@ -182,12 +182,11 @@ bool IsPressed(int Id, bool held) return false; } -void Initialize(void* const hwnd) +void Initialize() { if (s_config.ControllersNeedToBeCreated()) s_config.CreateController(); - g_controller_interface.Initialize(hwnd); g_controller_interface.RegisterHotplugCallback(LoadConfig); // load the saved controller config @@ -207,8 +206,6 @@ void LoadConfig() void Shutdown() { s_config.ClearControllers(); - - g_controller_interface.Shutdown(); } } diff --git a/Source/Core/Core/HotkeyManager.h b/Source/Core/Core/HotkeyManager.h index 45dfc6474f..a53f57bb14 100644 --- a/Source/Core/Core/HotkeyManager.h +++ b/Source/Core/Core/HotkeyManager.h @@ -155,7 +155,7 @@ private: namespace HotkeyManagerEmu { -void Initialize(void* const hwnd); +void Initialize(); void Shutdown(); void LoadConfig(); diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index 2253297bb6..401451b666 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -333,19 +333,16 @@ bool CFrame::InitControllers() if (!g_controller_interface.IsInit()) { #if defined(HAVE_X11) && HAVE_X11 - Window win = X11Utils::XWindowFromHandle(GetHandle()); - Pad::Initialize(reinterpret_cast(win)); - Keyboard::Initialize(reinterpret_cast(win)); - Wiimote::Initialize(reinterpret_cast(win), - Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES); - HotkeyManagerEmu::Initialize(reinterpret_cast(win)); + void* win = reinterpret_cast(X11Utils::XWindowFromHandle(GetHandle())); #else - Pad::Initialize(reinterpret_cast(GetHandle())); - Keyboard::Initialize(reinterpret_cast(GetHandle())); - Wiimote::Initialize(reinterpret_cast(GetHandle()), - Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES); - HotkeyManagerEmu::Initialize(reinterpret_cast(GetHandle())); + void* win = reinterpret_cast(GetHandle()); #endif + g_controller_interface.Initialize(win); + Pad::Initialize(); + Keyboard::Initialize(); + Wiimote::Initialize(Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES); + HotkeyManagerEmu::Initialize(); + return true; } return false; @@ -547,6 +544,7 @@ CFrame::~CFrame() Keyboard::Shutdown(); Pad::Shutdown(); HotkeyManagerEmu::Shutdown(); + g_controller_interface.Shutdown(); drives.clear();