From ead076d335a88f4fccb520a00f9d618b72f28826 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 6 Feb 2017 14:48:09 -0500 Subject: [PATCH 1/2] NetWindow: Get rid of direct use of the main_window global Utilizes the event system (which is what should have been done here initially), in order to prevent coupling between two different window frames. This also makes booting games more versatile using the UI event system, as the event can just act as a carrier for the filename, making directly calling boot functions unnecessary. All that's needed is for the event to propagate to the frame. --- Source/Core/DolphinWX/Frame.cpp | 4 ++++ Source/Core/DolphinWX/Frame.h | 2 ++ Source/Core/DolphinWX/FrameTools.cpp | 4 ++-- Source/Core/DolphinWX/NetPlay/NetWindow.cpp | 15 +++++++++++---- Source/Core/DolphinWX/NetPlay/NetWindow.h | 1 + 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index 1648163752..f35e964706 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -229,6 +229,8 @@ wxDEFINE_EVENT(wxEVT_HOST_COMMAND, wxCommandEvent); wxDEFINE_EVENT(DOLPHIN_EVT_LOCAL_INI_CHANGED, wxCommandEvent); wxDEFINE_EVENT(DOLPHIN_EVT_RELOAD_THEME_BITMAPS, wxCommandEvent); wxDEFINE_EVENT(DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM, wxCommandEvent); +wxDEFINE_EVENT(DOLPHIN_EVT_BOOT_SOFTWARE, wxCommandEvent); +wxDEFINE_EVENT(DOLPHIN_EVT_STOP_SOFTWARE, wxCommandEvent); // Event tables BEGIN_EVENT_TABLE(CFrame, CRenderFrame) @@ -495,6 +497,8 @@ void CFrame::BindEvents() Bind(DOLPHIN_EVT_RELOAD_THEME_BITMAPS, &CFrame::OnReloadThemeBitmaps, this); Bind(DOLPHIN_EVT_RELOAD_GAMELIST, &CFrame::OnReloadGameList, this); Bind(DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM, &CFrame::OnUpdateLoadWiiMenuItem, this); + Bind(DOLPHIN_EVT_BOOT_SOFTWARE, &CFrame::OnPlay, this); + Bind(DOLPHIN_EVT_STOP_SOFTWARE, &CFrame::OnStop, this); } bool CFrame::RendererIsFullscreen() diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h index 98f60c200a..1ee82ed621 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -62,6 +62,8 @@ private: wxDECLARE_EVENT(DOLPHIN_EVT_RELOAD_THEME_BITMAPS, wxCommandEvent); wxDECLARE_EVENT(DOLPHIN_EVT_UPDATE_LOAD_WII_MENU_ITEM, wxCommandEvent); +wxDECLARE_EVENT(DOLPHIN_EVT_BOOT_SOFTWARE, wxCommandEvent); +wxDECLARE_EVENT(DOLPHIN_EVT_STOP_SOFTWARE, wxCommandEvent); class CFrame : public CRenderFrame { diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index fb69f6ac0c..c40e6d0916 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -501,7 +501,7 @@ void CFrame::OnRecordExport(wxCommandEvent& WXUNUSED(event)) DoRecordingSave(); } -void CFrame::OnPlay(wxCommandEvent& WXUNUSED(event)) +void CFrame::OnPlay(wxCommandEvent& event) { if (Core::IsRunning()) { @@ -526,7 +526,7 @@ void CFrame::OnPlay(wxCommandEvent& WXUNUSED(event)) else { // Core is uninitialized, start the game - BootGame(""); + BootGame(WxStrToStr(event.GetString())); } } diff --git a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp index 75cf03885e..bd78185e7e 100644 --- a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "DolphinWX/NetPlay/NetWindow.h" + #include #include #include @@ -43,9 +45,7 @@ #include "DolphinWX/Frame.h" #include "DolphinWX/GameListCtrl.h" #include "DolphinWX/ISOFile.h" -#include "DolphinWX/Main.h" #include "DolphinWX/NetPlay/ChangeGameDialog.h" -#include "DolphinWX/NetPlay/NetWindow.h" #include "DolphinWX/NetPlay/PadMapDialog.h" #include "DolphinWX/WxUtils.h" #include "MD5Dialog.h" @@ -369,12 +369,19 @@ void NetPlayDialog::OnStart(wxCommandEvent&) void NetPlayDialog::BootGame(const std::string& filename) { - main_frame->BootGame(filename); + wxCommandEvent play_event{DOLPHIN_EVT_BOOT_SOFTWARE, GetId()}; + play_event.SetString(StrToWxStr(filename)); + play_event.SetEventObject(this); + + AddPendingEvent(play_event); } void NetPlayDialog::StopGame() { - main_frame->DoStop(); + wxCommandEvent stop_event{DOLPHIN_EVT_STOP_SOFTWARE, GetId()}; + stop_event.SetEventObject(this); + + AddPendingEvent(stop_event); } // NetPlayUI methods called from ---NETPLAY--- thread diff --git a/Source/Core/DolphinWX/NetPlay/NetWindow.h b/Source/Core/DolphinWX/NetPlay/NetWindow.h index bc199c2581..a579de2f40 100644 --- a/Source/Core/DolphinWX/NetPlay/NetWindow.h +++ b/Source/Core/DolphinWX/NetPlay/NetWindow.h @@ -8,6 +8,7 @@ #include #include +#include "Common/CommonTypes.h" #include "Common/FifoQueue.h" #include "Core/NetPlayClient.h" #include "Core/NetPlayProto.h" From c41f587c291cc8216c1d9c40254eea5d776d2699 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 6 Feb 2017 17:26:30 -0500 Subject: [PATCH 2/2] Frame: Hide functions that don't need to be exposed Any functions left exposed are used elsewhere through the main_window global. May as well prevent any more functions from being used in that manner where possible. --- Source/Core/DolphinWX/Frame.h | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h index 1ee82ed621..e679bed2c7 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -90,29 +90,16 @@ public: wxCheatsWindow* g_CheatsWindow = nullptr; TASInputDlg* g_TASInputDlg[8]; - void DoPause(); void DoStop(); - bool TriggerSTMPowerEvent(); - void OnStopped(); - void DoRecordingSave(); void UpdateGUI(); void UpdateGameList(); void ToggleLogWindow(bool bShow); void ToggleLogConfigWindow(bool bShow); - void PostEvent(wxCommandEvent& event); void StatusBarMessage(const char* Text, ...); void ClearStatusBar(); - void OnRenderWindowSizeRequest(int width, int height); void BootGame(const std::string& filename); - void OnRenderParentClose(wxCloseEvent& event); - void OnRenderParentMove(wxMoveEvent& event); bool RendererHasFocus(); bool RendererIsFullscreen(); - void DoFullscreen(bool enable_fullscreen); - void DoExclusiveFullscreen(bool enable_fullscreen); - void ToggleDisplayMode(bool bFullscreen); - static void ConnectWiimote(int wm_idx, bool connect); - void UpdateTitle(const std::string& str); void OpenGeneralConfiguration(wxWindowID tab_id = wxID_ANY); const CGameListCtrl* GetGameListCtrl() const; @@ -234,7 +221,25 @@ private: // Override window proc for tricks like screensaver disabling WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); #endif + + void DoOpen(bool Boot); + void DoPause(); + void DoToggleToolbar(bool); + void DoRecordingSave(); + void DoFullscreen(bool enable_fullscreen); + void DoExclusiveFullscreen(bool enable_fullscreen); + void ToggleDisplayMode(bool bFullscreen); + bool TriggerSTMPowerEvent(); + void OnStopped(); + void OnRenderWindowSizeRequest(int width, int height); + void UpdateTitle(const std::string& str); + static void ConnectWiimote(int wm_idx, bool connect); + // Event functions + void PostEvent(wxCommandEvent& event); + void OnRenderParentClose(wxCloseEvent& event); + void OnRenderParentMove(wxMoveEvent& event); + void OnQuit(wxCommandEvent& event); void OnHelp(wxCommandEvent& event); @@ -247,7 +252,6 @@ private: void UpdateLoadWiiMenuItem() const; void OnOpen(wxCommandEvent& event); // File menu - void DoOpen(bool Boot); void OnRefresh(wxCommandEvent& event); void OnBootDrive(wxCommandEvent& event); @@ -293,7 +297,6 @@ private: void OnMove(wxMoveEvent& event); void OnResize(wxSizeEvent& event); void OnToggleToolbar(wxCommandEvent& event); - void DoToggleToolbar(bool); void OnToggleStatusbar(wxCommandEvent& event); void OnToggleWindow(wxCommandEvent& event);