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.
This commit is contained in:
Lioncash 2017-02-06 14:48:09 -05:00
parent 0c7d9bbb73
commit ead076d335
5 changed files with 20 additions and 6 deletions

View File

@ -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()

View File

@ -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
{

View File

@ -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()));
}
}

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "DolphinWX/NetPlay/NetWindow.h"
#include <algorithm>
#include <cstddef>
#include <limits>
@ -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

View File

@ -8,6 +8,7 @@
#include <vector>
#include <wx/frame.h>
#include "Common/CommonTypes.h"
#include "Common/FifoQueue.h"
#include "Core/NetPlayClient.h"
#include "Core/NetPlayProto.h"