From 217ee430630aad61d6012d621134919173dc4559 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Sun, 27 Feb 2011 02:27:43 +0000 Subject: [PATCH] Fix a memory leak in the breakpoint window. Parent message alerts by the active window. This way if another window is open it isn't pushed behind the main window. We probably should parent the message alerts by the calling window instead, but this may be good enough. Make sure there is only one instance of some modeless windows (Cheats Manager and Net Play). git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7257 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Core/Src/NetPlay.cpp | 42 +++++----- Source/Core/Core/Src/NetPlay.h | 3 - Source/Core/Core/Src/PowerPC/SignatureDB.cpp | 2 +- Source/Core/DolphinWX/Src/CheatsWindow.cpp | 7 ++ Source/Core/DolphinWX/Src/CheatsWindow.h | 1 + .../Src/Debugger/BreakpointWindow.cpp | 5 +- Source/Core/DolphinWX/Src/Frame.cpp | 4 +- Source/Core/DolphinWX/Src/Frame.h | 4 + Source/Core/DolphinWX/Src/FrameTools.cpp | 20 +++-- Source/Core/DolphinWX/Src/Main.cpp | 2 +- Source/Core/DolphinWX/Src/NetWindow.cpp | 82 ++++++++++--------- Source/Core/DolphinWX/Src/NetWindow.h | 4 + 12 files changed, 98 insertions(+), 78 deletions(-) diff --git a/Source/Core/Core/Src/NetPlay.cpp b/Source/Core/Core/Src/NetPlay.cpp index 7aa77d3fb6..650adc34d5 100644 --- a/Source/Core/Core/Src/NetPlay.cpp +++ b/Source/Core/Core/Src/NetPlay.cpp @@ -42,21 +42,21 @@ NetPlay::NetPlay(NetPlayUI* dialog) void NetPlay_Enable(NetPlay* const np) { - CritLocker crit(::crit_netplay_ptr); // probably safe without a lock - ::netplay_ptr = np; + CritLocker crit(crit_netplay_ptr); // probably safe without a lock + netplay_ptr = np; } void NetPlay_Disable() { - CritLocker crit(::crit_netplay_ptr); - ::netplay_ptr = NULL; + CritLocker crit(crit_netplay_ptr); + netplay_ptr = NULL; } // called from ---GUI--- thread NetPlay::~NetPlay() { CritLocker crit(crit_netplay_ptr); - ::netplay_ptr = NULL; + netplay_ptr = NULL; // not perfect if (m_is_running) @@ -288,9 +288,9 @@ u8 NetPlay::GetPadNum(u8 numPAD) // Actual Core function which is called on every frame bool CSIDevice_GCController::NetPlay_GetInput(u8 numPAD, SPADStatus PadStatus, u32 *PADStatus) { - CritLocker crit(::crit_netplay_ptr); + CritLocker crit(crit_netplay_ptr); - if (::netplay_ptr) + if (netplay_ptr) return netplay_ptr->GetNetPads(numPAD, &PadStatus, (NetPad*)PADStatus); else return false; @@ -300,9 +300,9 @@ bool CSIDevice_GCController::NetPlay_GetInput(u8 numPAD, SPADStatus PadStatus, u // so all players' games get the same time u32 CEXIIPL::NetPlay_GetGCTime() { - CritLocker crit(::crit_netplay_ptr); + CritLocker crit(crit_netplay_ptr); - if (::netplay_ptr) + if (netplay_ptr) return 1272737767; // watev else return 0; @@ -312,10 +312,10 @@ u32 CEXIIPL::NetPlay_GetGCTime() // return the local pad num that should rumble given a ingame pad num u8 CSIDevice_GCController::NetPlay_GetPadNum(u8 numPAD) { - CritLocker crit(::crit_netplay_ptr); + CritLocker crit(crit_netplay_ptr); - if (::netplay_ptr) - return ::netplay_ptr->GetPadNum(numPAD); + if (netplay_ptr) + return netplay_ptr->GetPadNum(numPAD); else return numPAD; } @@ -325,20 +325,20 @@ u8 CSIDevice_GCController::NetPlay_GetPadNum(u8 numPAD) //void CWII_IPC_HLE_Device_usb_oh1_57e_305::NetPlay_WiimoteUpdate(int _number) void CWII_IPC_HLE_Device_usb_oh1_57e_305::NetPlay_WiimoteUpdate(int) { - //CritLocker crit(::crit_netplay_ptr); + //CritLocker crit(crit_netplay_ptr); - //if (::netplay_ptr) - // ::netplay_ptr->WiimoteUpdate(_number); + //if (netplay_ptr) + // netplay_ptr->WiimoteUpdate(_number); } // called from ---CPU--- thread // int CWII_IPC_HLE_WiiMote::NetPlay_GetWiimoteNum(int _number) { - //CritLocker crit(::crit_netplay_ptr); + //CritLocker crit(crit_netplay_ptr); - //if (::netplay_ptr) - // return ::netplay_ptr->GetPadNum(_number); // just using gcpad mapping for now + //if (netplay_ptr) + // return netplay_ptr->GetPadNum(_number); // just using gcpad mapping for now //else return _number; } @@ -348,9 +348,9 @@ int CWII_IPC_HLE_WiiMote::NetPlay_GetWiimoteNum(int _number) //bool CWII_IPC_HLE_WiiMote::NetPlay_WiimoteInput(int _number, u16 _channelID, const void* _pData, u32& _Size) bool CWII_IPC_HLE_WiiMote::NetPlay_WiimoteInput(int, u16, const void*, u32&) { - CritLocker crit(::crit_netplay_ptr); + CritLocker crit(crit_netplay_ptr); - if (::netplay_ptr) + if (netplay_ptr) //{ // if (_Size >= RPT_SIZE_HACK) // { @@ -359,7 +359,7 @@ bool CWII_IPC_HLE_WiiMote::NetPlay_WiimoteInput(int, u16, const void*, u32&) // } // else // { - // ::netplay_ptr->WiimoteInput(_number, _channelID, _pData, _Size); + // netplay_ptr->WiimoteInput(_number, _channelID, _pData, _Size); // // don't use this packet return true; // } diff --git a/Source/Core/Core/Src/NetPlay.h b/Source/Core/Core/Src/NetPlay.h index 4a4f83042a..068efb12a5 100644 --- a/Source/Core/Core/Src/NetPlay.h +++ b/Source/Core/Core/Src/NetPlay.h @@ -171,9 +171,6 @@ protected: Player* m_local_player; u32 m_current_game; - -private: - }; void NetPlay_Enable(NetPlay* const np); diff --git a/Source/Core/Core/Src/PowerPC/SignatureDB.cpp b/Source/Core/Core/Src/PowerPC/SignatureDB.cpp index 138a9a50a2..4a15ce895a 100644 --- a/Source/Core/Core/Src/PowerPC/SignatureDB.cpp +++ b/Source/Core/Core/Src/PowerPC/SignatureDB.cpp @@ -129,7 +129,7 @@ void SignatureDB::Apply(PPCSymbolDB *symbol_db) else { function->name = iter->second.name; - ERROR_LOG(OSHLE, "Wrong sizzze! Found %s at %08x (size: %08x instead of %08x)!", iter->second.name.c_str(), function->address, function->size, iter->second.size); + ERROR_LOG(OSHLE, "Wrong size! Found %s at %08x (size: %08x instead of %08x)!", iter->second.name.c_str(), function->address, function->size, iter->second.size); } } } diff --git a/Source/Core/DolphinWX/Src/CheatsWindow.cpp b/Source/Core/DolphinWX/Src/CheatsWindow.cpp index ba57e24a3d..634fe4d926 100644 --- a/Source/Core/DolphinWX/Src/CheatsWindow.cpp +++ b/Source/Core/DolphinWX/Src/CheatsWindow.cpp @@ -23,12 +23,14 @@ #include "VolumeHandler.h" #include "ISOProperties.h" #include "HW/Memmap.h" +#include "Frame.h" #define _connect_macro_(b, f, c, s) (b)->Connect(wxID_ANY, (c), wxCommandEventHandler(f), (wxObject*)0, (wxEvtHandler*)s) #define MAX_CHEAT_SEARCH_RESULTS_DISPLAY 256 extern std::vector arCodes; +extern CFrame* main_frame; // meh static wxCheatsWindow *g_cheat_window; @@ -59,6 +61,11 @@ wxCheatsWindow::wxCheatsWindow(wxWindow* const parent) Show(); } +wxCheatsWindow::~wxCheatsWindow() +{ + main_frame->g_CheatsWindow = NULL; +} + void wxCheatsWindow::Init_ChildControls() { wxPanel* const panel = new wxPanel(this); diff --git a/Source/Core/DolphinWX/Src/CheatsWindow.h b/Source/Core/DolphinWX/Src/CheatsWindow.h index 32894b4adb..f6d8a20c1e 100644 --- a/Source/Core/DolphinWX/Src/CheatsWindow.h +++ b/Source/Core/DolphinWX/Src/CheatsWindow.h @@ -107,6 +107,7 @@ class wxCheatsWindow : public wxFrame public: wxCheatsWindow(wxWindow* const parent); + ~wxCheatsWindow(); protected: diff --git a/Source/Core/DolphinWX/Src/Debugger/BreakpointWindow.cpp b/Source/Core/DolphinWX/Src/Debugger/BreakpointWindow.cpp index 6b052b7d8c..98e12253ec 100644 --- a/Source/Core/DolphinWX/Src/Debugger/BreakpointWindow.cpp +++ b/Source/Core/DolphinWX/Src/Debugger/BreakpointWindow.cpp @@ -70,7 +70,7 @@ public: m_imageListNormal->Add(m_Bitmaps[Toolbar_Delete]); m_imageListNormal->Add(m_Bitmaps[Toolbar_Add_BP]); m_imageListNormal->Add(m_Bitmaps[Toolbar_Add_MC]); - SetImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL); + AssignImageList(m_imageListNormal, wxIMAGE_LIST_NORMAL); toolbar_map.insert(toolbar_p(InsertItem(0, _("Delete"), 0), &CBreakPointWindow::OnDelete)); toolbar_map.insert(toolbar_p(InsertItem(1, _("Clear"), 0), &CBreakPointWindow::OnClear)); @@ -115,9 +115,6 @@ void CBreakPointWindow::OnClose(wxCloseEvent& WXUNUSED(event)) void CBreakPointWindow::CreateGUIControls() { - SetSize(8, 8, 400, 370); - Center(); - m_BreakPointBar = new CBreakPointBar(this, ID_TOOLBAR, wxDefaultPosition, wxSize(0, 55), wxLC_ICON | wxSUNKEN_BORDER | wxLC_SINGLE_SEL); m_BreakPointListView = new CBreakPointView(this, ID_BPS, wxDefaultPosition, wxDefaultSize, diff --git a/Source/Core/DolphinWX/Src/Frame.cpp b/Source/Core/DolphinWX/Src/Frame.cpp index 4a12d72a0a..8d25c7d971 100644 --- a/Source/Core/DolphinWX/Src/Frame.cpp +++ b/Source/Core/DolphinWX/Src/Frame.cpp @@ -341,7 +341,7 @@ CFrame::CFrame(wxFrame* parent, bool ShowLogWindow, long style) : CRenderFrame(parent, id, title, pos, size, style) - , g_pCodeWindow(NULL) + , g_pCodeWindow(NULL), g_NetPlaySetupDiag(NULL), g_CheatsWindow(NULL) , bRenderToMain(false), bNoWiimoteMsg(false) , m_ToolBar(NULL), m_ToolBarDebug(NULL), m_ToolBarAui(NULL) , m_GameListCtrl(NULL), m_Panel(NULL) @@ -667,7 +667,7 @@ void CFrame::OnHostMessage(wxCommandEvent& event) #ifdef __WXGTK__ case IDM_PANIC: bPanicResult = (wxYES == wxMessageBox(event.GetString(), - _("Warning"), event.GetInt() ? wxYES_NO : wxOK, this)); + _("Warning"), event.GetInt() ? wxYES_NO : wxOK, wxGetActiveWindow())); panic_event.Set(); break; case IDM_KEYSTATE: diff --git a/Source/Core/DolphinWX/Src/Frame.h b/Source/Core/DolphinWX/Src/Frame.h index 8df88ee801..4a04aadd87 100644 --- a/Source/Core/DolphinWX/Src/Frame.h +++ b/Source/Core/DolphinWX/Src/Frame.h @@ -48,6 +48,8 @@ static inline wxBitmap _wxGetBitmapFromMemory(const unsigned char* data, int len class CGameListCtrl; class GameListItem; class CLogWindow; +class NetPlaySetupDiag; +class wxCheatsWindow; // The CPanel class to receive MSWWindowProc messages from the video backend. class CPanel : public wxPanel @@ -112,6 +114,8 @@ class CFrame : public CRenderFrame // These have to be public CCodeWindow* g_pCodeWindow; + NetPlaySetupDiag* g_NetPlaySetupDiag; + wxCheatsWindow* g_CheatsWindow; void InitBitmaps(); void DoPause(); void DoStop(); diff --git a/Source/Core/DolphinWX/Src/FrameTools.cpp b/Source/Core/DolphinWX/Src/FrameTools.cpp index fb0c664353..7572c33f70 100644 --- a/Source/Core/DolphinWX/Src/FrameTools.cpp +++ b/Source/Core/DolphinWX/Src/FrameTools.cpp @@ -96,11 +96,6 @@ extern "C" { #include "../resources/KDE.h" }; - -// Other Windows -wxCheatsWindow* CheatsWindow; - - // Create menu items // --------------------- void CFrame::CreateMenu() @@ -1274,7 +1269,15 @@ void CFrame::StatusBarMessage(const char * Text, ...) // NetPlay stuff void CFrame::OnNetPlay(wxCommandEvent& WXUNUSED (event)) { - new NetPlaySetupDiag(this, m_GameListCtrl); + if (!g_NetPlaySetupDiag) + { + if (NetPlayDiag::GetInstance() != NULL) + NetPlayDiag::GetInstance()->Raise(); + else + g_NetPlaySetupDiag = new NetPlaySetupDiag(this, m_GameListCtrl); + } + else + g_NetPlaySetupDiag->Raise(); } void CFrame::OnMemcard(wxCommandEvent& WXUNUSED (event)) @@ -1300,7 +1303,10 @@ void CFrame::OnImportSave(wxCommandEvent& WXUNUSED (event)) void CFrame::OnShow_CheatsWindow(wxCommandEvent& WXUNUSED (event)) { - CheatsWindow = new wxCheatsWindow(this); + if (!g_CheatsWindow) + g_CheatsWindow = new wxCheatsWindow(this); + else + g_CheatsWindow->Raise(); } void CFrame::OnLoadWiiMenu(wxCommandEvent& event) diff --git a/Source/Core/DolphinWX/Src/Main.cpp b/Source/Core/DolphinWX/Src/Main.cpp index bc761bb36f..7b0405718b 100644 --- a/Source/Core/DolphinWX/Src/Main.cpp +++ b/Source/Core/DolphinWX/Src/Main.cpp @@ -468,7 +468,7 @@ bool wxMsgAlert(const char* caption, const char* text, bool yes_no, int /*Style* #endif return wxYES == wxMessageBox(wxString::FromUTF8(text), wxString::FromUTF8(caption), - (yes_no) ? wxYES_NO : wxOK, main_frame); + (yes_no) ? wxYES_NO : wxOK, wxGetActiveWindow()); #ifdef __WXGTK__ else { diff --git a/Source/Core/DolphinWX/Src/NetWindow.cpp b/Source/Core/DolphinWX/Src/NetWindow.cpp index 4a6c294030..e478a0d04b 100644 --- a/Source/Core/DolphinWX/Src/NetWindow.cpp +++ b/Source/Core/DolphinWX/Src/NetWindow.cpp @@ -24,7 +24,8 @@ #include -#define _connect_macro_( b, f, c, s ) (b)->Connect( wxID_ANY, (c), wxCommandEventHandler( f ), (wxObject*)0, (wxEvtHandler*)s ) +#define _connect_macro_(b, f, c, s) \ + (b)->Connect(wxID_ANY, (c), wxCommandEventHandler(f), (wxObject*)0, (wxEvtHandler*)s) #define NETPLAY_TITLEBAR "Dolphin NetPlay" @@ -35,6 +36,7 @@ END_EVENT_TABLE() static NetPlay* netplay_ptr = NULL; extern CFrame* main_frame; +NetPlayDiag *NetPlayDiag::npd = NULL; NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* const game_list) : wxFrame(parent, wxID_ANY, wxT(NETPLAY_TITLEBAR), wxDefaultPosition, wxDefaultSize) @@ -47,7 +49,8 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* wxPanel* const panel = new wxPanel(this); // top row - wxStaticText* const nick_lbl = new wxStaticText(panel, wxID_ANY, _("Nickname :"), wxDefaultPosition, wxDefaultSize); + wxStaticText* const nick_lbl = new wxStaticText(panel, wxID_ANY, _("Nickname :"), + wxDefaultPosition, wxDefaultSize); std::string nickname; netplay_section.Get("Nickname", &nickname, "Player"); @@ -68,13 +71,15 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* // connect tab { - wxStaticText* const ip_lbl = new wxStaticText(connect_tab, wxID_ANY, _("Address :"), wxDefaultPosition, wxDefaultSize); + wxStaticText* const ip_lbl = new wxStaticText(connect_tab, wxID_ANY, _("Address :"), + wxDefaultPosition, wxDefaultSize); std::string address; netplay_section.Get("Address", &address, "localhost"); m_connect_ip_text = new wxTextCtrl(connect_tab, wxID_ANY, wxString::FromAscii(address.c_str())); - wxStaticText* const port_lbl = new wxStaticText(connect_tab, wxID_ANY, _("Port :"), wxDefaultPosition, wxDefaultSize); + wxStaticText* const port_lbl = new wxStaticText(connect_tab, wxID_ANY, _("Port :"), + wxDefaultPosition, wxDefaultSize); // string? w/e std::string port; @@ -84,9 +89,9 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* wxButton* const connect_btn = new wxButton(connect_tab, wxID_ANY, _("Connect")); _connect_macro_(connect_btn, NetPlaySetupDiag::OnJoin, wxEVT_COMMAND_BUTTON_CLICKED, this); - wxStaticText* const alert_lbl = new wxStaticText(connect_tab, wxID_ANY - , _("ALERT:\n\nNetPlay will currently only work properly when using the following settings:\n - Dual Core [OFF]\n - Audio Throttle [OFF]\n - DSP-HLE with \"Null Audio\" or DSP-LLE\n - Manually set the exact number of controllers that will be used to [Standard Controller]\n\nAll players should try to use the same Dolphin version and settings.\nDisable all memory cards or send them to all players before starting.\nWiimote support has not been implemented.\n\nYou must forward TCP port to host!!") - , wxDefaultPosition, wxDefaultSize); + wxStaticText* const alert_lbl = new wxStaticText(connect_tab, wxID_ANY, + _("ALERT:\n\nNetPlay will currently only work properly when using the following settings:\n - Dual Core [OFF]\n - Audio Throttle [OFF]\n - DSP-HLE with \"Null Audio\" or DSP-LLE\n - Manually set the exact number of controllers that will be used to [Standard Controller]\n\nAll players should try to use the same Dolphin version and settings.\nDisable all memory cards or send them to all players before starting.\nWiimote support has not been implemented.\n\nYou must forward TCP port to host!!"), + wxDefaultPosition, wxDefaultSize); wxBoxSizer* const top_szr = new wxBoxSizer(wxHORIZONTAL); top_szr->Add(ip_lbl, 0, wxCENTER | wxRIGHT, 5); @@ -106,7 +111,8 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* // host tab { - wxStaticText* const port_lbl = new wxStaticText(host_tab, wxID_ANY, _("Port :"), wxDefaultPosition, wxDefaultSize); + wxStaticText* const port_lbl = new wxStaticText(host_tab, wxID_ANY, _("Port :"), + wxDefaultPosition, wxDefaultSize); // string? w/e std::string port; @@ -171,11 +177,13 @@ NetPlaySetupDiag::~NetPlaySetupDiag() netplay_section.Set("HostPort", m_host_port_text->GetValue().mb_str()); inifile.Save(dolphin_ini); + main_frame->g_NetPlaySetupDiag = NULL; } void NetPlaySetupDiag::OnHost(wxCommandEvent&) { - if (::netplay_ptr) + NetPlayDiag *&npd = NetPlayDiag::GetInstance(); + if (npd) { PanicAlertT("A NetPlay window is already open!!"); return; @@ -189,14 +197,13 @@ void NetPlaySetupDiag::OnHost(wxCommandEvent&) std::string game(m_game_lbox->GetStringSelection().mb_str()); - NetPlayDiag* const npd = new NetPlayDiag(m_parent, m_game_list, game, true); + npd = new NetPlayDiag(m_parent, m_game_list, game, true); unsigned long port = 0; m_host_port_text->GetValue().ToULong(&port); - ::netplay_ptr = new NetPlayServer(u16(port) + netplay_ptr = new NetPlayServer(u16(port) , std::string(m_nickname_text->GetValue().mb_str()), npd, game); - if (::netplay_ptr->is_connected) + if (netplay_ptr->is_connected) { - //NetPlayServerDiag* const npsd = npd->Show(); Destroy(); } @@ -204,36 +211,31 @@ void NetPlaySetupDiag::OnHost(wxCommandEvent&) { PanicAlertT("Failed to Listen!!"); npd->Destroy(); - // dialog will delete netplay - //delete ::netplay_ptr; } } void NetPlaySetupDiag::OnJoin(wxCommandEvent&) { - if (::netplay_ptr) + NetPlayDiag *&npd = NetPlayDiag::GetInstance(); + if (npd) { PanicAlertT("A NetPlay window is already open!!"); return; } - NetPlayDiag* const npd = new NetPlayDiag(m_parent, m_game_list, ""); + npd = new NetPlayDiag(m_parent, m_game_list, ""); unsigned long port = 0; m_connect_port_text->GetValue().ToULong(&port); - ::netplay_ptr = new NetPlayClient(std::string(m_connect_ip_text->GetValue().mb_str()) + netplay_ptr = new NetPlayClient(std::string(m_connect_ip_text->GetValue().mb_str()) , (u16)port, npd, std::string(m_nickname_text->GetValue().mb_str())); - if (::netplay_ptr->is_connected) + if (netplay_ptr->is_connected) { - //NetPlayServerDiag* const npsd = npd->Show(); Destroy(); } else { - //PanicAlertT("Failed to Connect!!"); npd->Destroy(); - // dialog will delete netplay - //delete ::netplay_ptr; } } @@ -242,8 +244,8 @@ void NetPlaySetupDiag::OnQuit(wxCommandEvent&) Destroy(); } -NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game_list - , const std::string& game, const bool is_hosting) +NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game_list, + const std::string& game, const bool is_hosting) : wxFrame(parent, wxID_ANY, wxT(NETPLAY_TITLEBAR), wxDefaultPosition, wxDefaultSize) , m_selected_game(game) , m_game_list(game_list) @@ -251,8 +253,9 @@ NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game wxPanel* const panel = new wxPanel(this); // top crap - m_game_btn = new wxButton(panel, wxID_ANY - , wxString(m_selected_game.c_str(), *wxConvCurrent).Prepend(_(" Game : ")), wxDefaultPosition, wxDefaultSize, wxBU_LEFT); + m_game_btn = new wxButton(panel, wxID_ANY, + wxString(m_selected_game.c_str(), *wxConvCurrent).Prepend(_(" Game : ")), + wxDefaultPosition, wxDefaultSize, wxBU_LEFT); if (is_hosting) _connect_macro_(m_game_btn, NetPlayDiag::OnChangeGame, wxEVT_COMMAND_BUTTON_CLICKED, this); @@ -338,11 +341,12 @@ NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game NetPlayDiag::~NetPlayDiag() { - if (::netplay_ptr) + if (netplay_ptr) { delete netplay_ptr; - ::netplay_ptr = NULL; + netplay_ptr = NULL; } + npd = NULL; } void NetPlayDiag::OnChat(wxCommandEvent&) @@ -351,7 +355,7 @@ void NetPlayDiag::OnChat(wxCommandEvent&) if (s.Length()) { - ::netplay_ptr->SendChatMessage(std::string(s.mb_str())); + netplay_ptr->SendChatMessage(std::string(s.mb_str())); m_chat_text->AppendText(s.Prepend(wxT(" >> ")).Append(wxT('\n'))); m_chat_msg_text->Clear(); } @@ -374,14 +378,14 @@ void NetPlayDiag::OnStart(wxCommandEvent&) } if (path.length()) - ::netplay_ptr->StartGame(path); + netplay_ptr->StartGame(path); else PanicAlertT("Game not found!!"); } void NetPlayDiag::OnStop(wxCommandEvent&) { - ::netplay_ptr->StopGame(); + netplay_ptr->StopGame(); } void NetPlayDiag::BootGame(const std::string& filename) @@ -430,7 +434,7 @@ void NetPlayDiag::OnMsgStopGame() void NetPlayDiag::OnPadBuffHelp(wxCommandEvent&) { - const u64 time = ((NetPlayServer*)::netplay_ptr)->CalculateMinimumBufferTime(); + const u64 time = ((NetPlayServer*)netplay_ptr)->CalculateMinimumBufferTime(); std::ostringstream ss; ss << "< Calculated from pings: required buffer: " << time * (60.0f/1000) << "(60fps) / " @@ -442,11 +446,11 @@ void NetPlayDiag::OnPadBuffHelp(wxCommandEvent&) void NetPlayDiag::OnAdjustBuffer(wxCommandEvent& event) { const int val = ((wxSpinCtrl*)event.GetEventObject())->GetValue(); - ((NetPlayServer*)::netplay_ptr)->AdjustPadBufferSize(val); + ((NetPlayServer*)netplay_ptr)->AdjustPadBufferSize(val); std::ostringstream ss; ss << "< Pad Buffer: " << val << " >"; - ::netplay_ptr->SendChatMessage(ss.str()); + netplay_ptr->SendChatMessage(ss.str()); m_chat_text->AppendText(wxString(ss.str().c_str(), *wxConvCurrent).Append(wxT('\n'))); } @@ -461,7 +465,7 @@ void NetPlayDiag::OnThread(wxCommandEvent& event) // player list m_playerids.clear(); std::string tmps; - ::netplay_ptr->GetPlayerList(tmps, m_playerids); + netplay_ptr->GetPlayerList(tmps, m_playerids); const int selection = m_player_lbox->GetSelection(); @@ -516,7 +520,7 @@ void NetPlayDiag::OnChangeGame(wxCommandEvent&) if (game_name.length()) { m_selected_game = std::string(game_name.mb_str()); - ::netplay_ptr->ChangeGame(m_selected_game); + netplay_ptr->ChangeGame(m_selected_game); m_game_btn->SetLabel(game_name.Prepend(_(" Game : "))); } } @@ -531,14 +535,14 @@ void NetPlayDiag::OnConfigPads(wxCommandEvent&) return; pid = m_playerids.at(pid); - if (false == ((NetPlayServer*)::netplay_ptr)->GetPadMapping(pid, mapping)) + if (false == ((NetPlayServer*)netplay_ptr)->GetPadMapping(pid, mapping)) return; PadMapDiag* const pmd = new PadMapDiag(this, mapping); pmd->ShowModal(); pmd->Destroy(); - if (false == ((NetPlayServer*)::netplay_ptr)->SetPadMapping(pid, mapping)) + if (false == ((NetPlayServer*)netplay_ptr)->SetPadMapping(pid, mapping)) PanicAlertT("Could not set pads. The player left or the game is currently running!\n" "(setting pads while the game is running is not yet supported)"); } diff --git a/Source/Core/DolphinWX/Src/NetWindow.h b/Source/Core/DolphinWX/Src/NetWindow.h index 88812bb236..0e70d352e8 100644 --- a/Source/Core/DolphinWX/Src/NetWindow.h +++ b/Source/Core/DolphinWX/Src/NetWindow.h @@ -87,6 +87,8 @@ public: void OnMsgStartGame(); void OnMsgStopGame(); + static NetPlayDiag *&GetInstance() { return npd; }; + private: DECLARE_EVENT_TABLE() @@ -108,6 +110,8 @@ private: std::vector m_playerids; const CGameListCtrl* const m_game_list; + + static NetPlayDiag* npd; }; DECLARE_EVENT_TYPE(wxEVT_THREAD, -1)