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
This commit is contained in:
Glenn Rice 2011-02-27 02:27:43 +00:00
parent 449e79aea5
commit 217ee43063
12 changed files with 98 additions and 78 deletions

View File

@ -42,21 +42,21 @@ NetPlay::NetPlay(NetPlayUI* dialog)
void NetPlay_Enable(NetPlay* const np) void NetPlay_Enable(NetPlay* const np)
{ {
CritLocker crit(::crit_netplay_ptr); // probably safe without a lock CritLocker crit(crit_netplay_ptr); // probably safe without a lock
::netplay_ptr = np; netplay_ptr = np;
} }
void NetPlay_Disable() void NetPlay_Disable()
{ {
CritLocker crit(::crit_netplay_ptr); CritLocker crit(crit_netplay_ptr);
::netplay_ptr = NULL; netplay_ptr = NULL;
} }
// called from ---GUI--- thread // called from ---GUI--- thread
NetPlay::~NetPlay() NetPlay::~NetPlay()
{ {
CritLocker crit(crit_netplay_ptr); CritLocker crit(crit_netplay_ptr);
::netplay_ptr = NULL; netplay_ptr = NULL;
// not perfect // not perfect
if (m_is_running) if (m_is_running)
@ -288,9 +288,9 @@ u8 NetPlay::GetPadNum(u8 numPAD)
// Actual Core function which is called on every frame // Actual Core function which is called on every frame
bool CSIDevice_GCController::NetPlay_GetInput(u8 numPAD, SPADStatus PadStatus, u32 *PADStatus) 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); return netplay_ptr->GetNetPads(numPAD, &PadStatus, (NetPad*)PADStatus);
else else
return false; return false;
@ -300,9 +300,9 @@ bool CSIDevice_GCController::NetPlay_GetInput(u8 numPAD, SPADStatus PadStatus, u
// so all players' games get the same time // so all players' games get the same time
u32 CEXIIPL::NetPlay_GetGCTime() u32 CEXIIPL::NetPlay_GetGCTime()
{ {
CritLocker crit(::crit_netplay_ptr); CritLocker crit(crit_netplay_ptr);
if (::netplay_ptr) if (netplay_ptr)
return 1272737767; // watev return 1272737767; // watev
else else
return 0; return 0;
@ -312,10 +312,10 @@ u32 CEXIIPL::NetPlay_GetGCTime()
// return the local pad num that should rumble given a ingame pad num // return the local pad num that should rumble given a ingame pad num
u8 CSIDevice_GCController::NetPlay_GetPadNum(u8 numPAD) u8 CSIDevice_GCController::NetPlay_GetPadNum(u8 numPAD)
{ {
CritLocker crit(::crit_netplay_ptr); CritLocker crit(crit_netplay_ptr);
if (::netplay_ptr) if (netplay_ptr)
return ::netplay_ptr->GetPadNum(numPAD); return netplay_ptr->GetPadNum(numPAD);
else else
return numPAD; 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 _number)
void CWII_IPC_HLE_Device_usb_oh1_57e_305::NetPlay_WiimoteUpdate(int) 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) //if (netplay_ptr)
// ::netplay_ptr->WiimoteUpdate(_number); // netplay_ptr->WiimoteUpdate(_number);
} }
// called from ---CPU--- thread // called from ---CPU--- thread
// //
int CWII_IPC_HLE_WiiMote::NetPlay_GetWiimoteNum(int _number) int CWII_IPC_HLE_WiiMote::NetPlay_GetWiimoteNum(int _number)
{ {
//CritLocker crit(::crit_netplay_ptr); //CritLocker crit(crit_netplay_ptr);
//if (::netplay_ptr) //if (netplay_ptr)
// return ::netplay_ptr->GetPadNum(_number); // just using gcpad mapping for now // return netplay_ptr->GetPadNum(_number); // just using gcpad mapping for now
//else //else
return _number; 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 _number, u16 _channelID, const void* _pData, u32& _Size)
bool CWII_IPC_HLE_WiiMote::NetPlay_WiimoteInput(int, u16, const void*, u32&) 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) // if (_Size >= RPT_SIZE_HACK)
// { // {
@ -359,7 +359,7 @@ bool CWII_IPC_HLE_WiiMote::NetPlay_WiimoteInput(int, u16, const void*, u32&)
// } // }
// else // else
// { // {
// ::netplay_ptr->WiimoteInput(_number, _channelID, _pData, _Size); // netplay_ptr->WiimoteInput(_number, _channelID, _pData, _Size);
// // don't use this packet // // don't use this packet
return true; return true;
// } // }

View File

@ -171,9 +171,6 @@ protected:
Player* m_local_player; Player* m_local_player;
u32 m_current_game; u32 m_current_game;
private:
}; };
void NetPlay_Enable(NetPlay* const np); void NetPlay_Enable(NetPlay* const np);

View File

@ -129,7 +129,7 @@ void SignatureDB::Apply(PPCSymbolDB *symbol_db)
else else
{ {
function->name = iter->second.name; 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);
} }
} }
} }

View File

@ -23,12 +23,14 @@
#include "VolumeHandler.h" #include "VolumeHandler.h"
#include "ISOProperties.h" #include "ISOProperties.h"
#include "HW/Memmap.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 _connect_macro_(b, f, c, s) (b)->Connect(wxID_ANY, (c), wxCommandEventHandler(f), (wxObject*)0, (wxEvtHandler*)s)
#define MAX_CHEAT_SEARCH_RESULTS_DISPLAY 256 #define MAX_CHEAT_SEARCH_RESULTS_DISPLAY 256
extern std::vector<ActionReplay::ARCode> arCodes; extern std::vector<ActionReplay::ARCode> arCodes;
extern CFrame* main_frame;
// meh // meh
static wxCheatsWindow *g_cheat_window; static wxCheatsWindow *g_cheat_window;
@ -59,6 +61,11 @@ wxCheatsWindow::wxCheatsWindow(wxWindow* const parent)
Show(); Show();
} }
wxCheatsWindow::~wxCheatsWindow()
{
main_frame->g_CheatsWindow = NULL;
}
void wxCheatsWindow::Init_ChildControls() void wxCheatsWindow::Init_ChildControls()
{ {
wxPanel* const panel = new wxPanel(this); wxPanel* const panel = new wxPanel(this);

View File

@ -107,6 +107,7 @@ class wxCheatsWindow : public wxFrame
public: public:
wxCheatsWindow(wxWindow* const parent); wxCheatsWindow(wxWindow* const parent);
~wxCheatsWindow();
protected: protected:

View File

@ -70,7 +70,7 @@ public:
m_imageListNormal->Add(m_Bitmaps[Toolbar_Delete]); m_imageListNormal->Add(m_Bitmaps[Toolbar_Delete]);
m_imageListNormal->Add(m_Bitmaps[Toolbar_Add_BP]); m_imageListNormal->Add(m_Bitmaps[Toolbar_Add_BP]);
m_imageListNormal->Add(m_Bitmaps[Toolbar_Add_MC]); 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(0, _("Delete"), 0), &CBreakPointWindow::OnDelete));
toolbar_map.insert(toolbar_p(InsertItem(1, _("Clear"), 0), &CBreakPointWindow::OnClear)); toolbar_map.insert(toolbar_p(InsertItem(1, _("Clear"), 0), &CBreakPointWindow::OnClear));
@ -115,9 +115,6 @@ void CBreakPointWindow::OnClose(wxCloseEvent& WXUNUSED(event))
void CBreakPointWindow::CreateGUIControls() void CBreakPointWindow::CreateGUIControls()
{ {
SetSize(8, 8, 400, 370);
Center();
m_BreakPointBar = new CBreakPointBar(this, ID_TOOLBAR, wxDefaultPosition, wxSize(0, 55), m_BreakPointBar = new CBreakPointBar(this, ID_TOOLBAR, wxDefaultPosition, wxSize(0, 55),
wxLC_ICON | wxSUNKEN_BORDER | wxLC_SINGLE_SEL); wxLC_ICON | wxSUNKEN_BORDER | wxLC_SINGLE_SEL);
m_BreakPointListView = new CBreakPointView(this, ID_BPS, wxDefaultPosition, wxDefaultSize, m_BreakPointListView = new CBreakPointView(this, ID_BPS, wxDefaultPosition, wxDefaultSize,

View File

@ -341,7 +341,7 @@ CFrame::CFrame(wxFrame* parent,
bool ShowLogWindow, bool ShowLogWindow,
long style) long style)
: CRenderFrame(parent, id, title, pos, size, style) : CRenderFrame(parent, id, title, pos, size, style)
, g_pCodeWindow(NULL) , g_pCodeWindow(NULL), g_NetPlaySetupDiag(NULL), g_CheatsWindow(NULL)
, bRenderToMain(false), bNoWiimoteMsg(false) , bRenderToMain(false), bNoWiimoteMsg(false)
, m_ToolBar(NULL), m_ToolBarDebug(NULL), m_ToolBarAui(NULL) , m_ToolBar(NULL), m_ToolBarDebug(NULL), m_ToolBarAui(NULL)
, m_GameListCtrl(NULL), m_Panel(NULL) , m_GameListCtrl(NULL), m_Panel(NULL)
@ -667,7 +667,7 @@ void CFrame::OnHostMessage(wxCommandEvent& event)
#ifdef __WXGTK__ #ifdef __WXGTK__
case IDM_PANIC: case IDM_PANIC:
bPanicResult = (wxYES == wxMessageBox(event.GetString(), bPanicResult = (wxYES == wxMessageBox(event.GetString(),
_("Warning"), event.GetInt() ? wxYES_NO : wxOK, this)); _("Warning"), event.GetInt() ? wxYES_NO : wxOK, wxGetActiveWindow()));
panic_event.Set(); panic_event.Set();
break; break;
case IDM_KEYSTATE: case IDM_KEYSTATE:

View File

@ -48,6 +48,8 @@ static inline wxBitmap _wxGetBitmapFromMemory(const unsigned char* data, int len
class CGameListCtrl; class CGameListCtrl;
class GameListItem; class GameListItem;
class CLogWindow; class CLogWindow;
class NetPlaySetupDiag;
class wxCheatsWindow;
// The CPanel class to receive MSWWindowProc messages from the video backend. // The CPanel class to receive MSWWindowProc messages from the video backend.
class CPanel : public wxPanel class CPanel : public wxPanel
@ -112,6 +114,8 @@ class CFrame : public CRenderFrame
// These have to be public // These have to be public
CCodeWindow* g_pCodeWindow; CCodeWindow* g_pCodeWindow;
NetPlaySetupDiag* g_NetPlaySetupDiag;
wxCheatsWindow* g_CheatsWindow;
void InitBitmaps(); void InitBitmaps();
void DoPause(); void DoPause();
void DoStop(); void DoStop();

View File

@ -96,11 +96,6 @@ extern "C" {
#include "../resources/KDE.h" #include "../resources/KDE.h"
}; };
// Other Windows
wxCheatsWindow* CheatsWindow;
// Create menu items // Create menu items
// --------------------- // ---------------------
void CFrame::CreateMenu() void CFrame::CreateMenu()
@ -1274,7 +1269,15 @@ void CFrame::StatusBarMessage(const char * Text, ...)
// NetPlay stuff // NetPlay stuff
void CFrame::OnNetPlay(wxCommandEvent& WXUNUSED (event)) 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)) void CFrame::OnMemcard(wxCommandEvent& WXUNUSED (event))
@ -1300,7 +1303,10 @@ void CFrame::OnImportSave(wxCommandEvent& WXUNUSED (event))
void CFrame::OnShow_CheatsWindow(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) void CFrame::OnLoadWiiMenu(wxCommandEvent& event)

View File

@ -468,7 +468,7 @@ bool wxMsgAlert(const char* caption, const char* text, bool yes_no, int /*Style*
#endif #endif
return wxYES == wxMessageBox(wxString::FromUTF8(text), return wxYES == wxMessageBox(wxString::FromUTF8(text),
wxString::FromUTF8(caption), wxString::FromUTF8(caption),
(yes_no) ? wxYES_NO : wxOK, main_frame); (yes_no) ? wxYES_NO : wxOK, wxGetActiveWindow());
#ifdef __WXGTK__ #ifdef __WXGTK__
else else
{ {

View File

@ -24,7 +24,8 @@
#include <sstream> #include <sstream>
#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" #define NETPLAY_TITLEBAR "Dolphin NetPlay"
@ -35,6 +36,7 @@ END_EVENT_TABLE()
static NetPlay* netplay_ptr = NULL; static NetPlay* netplay_ptr = NULL;
extern CFrame* main_frame; extern CFrame* main_frame;
NetPlayDiag *NetPlayDiag::npd = NULL;
NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* const game_list) NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl* const game_list)
: wxFrame(parent, wxID_ANY, wxT(NETPLAY_TITLEBAR), wxDefaultPosition, wxDefaultSize) : 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); wxPanel* const panel = new wxPanel(this);
// top row // 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; std::string nickname;
netplay_section.Get("Nickname", &nickname, "Player"); netplay_section.Get("Nickname", &nickname, "Player");
@ -68,13 +71,15 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl*
// connect tab // 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; std::string address;
netplay_section.Get("Address", &address, "localhost"); netplay_section.Get("Address", &address, "localhost");
m_connect_ip_text = new wxTextCtrl(connect_tab, wxID_ANY, wxString::FromAscii(address.c_str())); 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 // string? w/e
std::string port; 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")); wxButton* const connect_btn = new wxButton(connect_tab, wxID_ANY, _("Connect"));
_connect_macro_(connect_btn, NetPlaySetupDiag::OnJoin, wxEVT_COMMAND_BUTTON_CLICKED, this); _connect_macro_(connect_btn, NetPlaySetupDiag::OnJoin, wxEVT_COMMAND_BUTTON_CLICKED, this);
wxStaticText* const alert_lbl = new wxStaticText(connect_tab, wxID_ANY 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!!") _("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); wxDefaultPosition, wxDefaultSize);
wxBoxSizer* const top_szr = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer* const top_szr = new wxBoxSizer(wxHORIZONTAL);
top_szr->Add(ip_lbl, 0, wxCENTER | wxRIGHT, 5); top_szr->Add(ip_lbl, 0, wxCENTER | wxRIGHT, 5);
@ -106,7 +111,8 @@ NetPlaySetupDiag::NetPlaySetupDiag(wxWindow* const parent, const CGameListCtrl*
// host tab // 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 // string? w/e
std::string port; std::string port;
@ -171,11 +177,13 @@ NetPlaySetupDiag::~NetPlaySetupDiag()
netplay_section.Set("HostPort", m_host_port_text->GetValue().mb_str()); netplay_section.Set("HostPort", m_host_port_text->GetValue().mb_str());
inifile.Save(dolphin_ini); inifile.Save(dolphin_ini);
main_frame->g_NetPlaySetupDiag = NULL;
} }
void NetPlaySetupDiag::OnHost(wxCommandEvent&) void NetPlaySetupDiag::OnHost(wxCommandEvent&)
{ {
if (::netplay_ptr) NetPlayDiag *&npd = NetPlayDiag::GetInstance();
if (npd)
{ {
PanicAlertT("A NetPlay window is already open!!"); PanicAlertT("A NetPlay window is already open!!");
return; return;
@ -189,14 +197,13 @@ void NetPlaySetupDiag::OnHost(wxCommandEvent&)
std::string game(m_game_lbox->GetStringSelection().mb_str()); 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; unsigned long port = 0;
m_host_port_text->GetValue().ToULong(&port); 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); , 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(); npd->Show();
Destroy(); Destroy();
} }
@ -204,36 +211,31 @@ void NetPlaySetupDiag::OnHost(wxCommandEvent&)
{ {
PanicAlertT("Failed to Listen!!"); PanicAlertT("Failed to Listen!!");
npd->Destroy(); npd->Destroy();
// dialog will delete netplay
//delete ::netplay_ptr;
} }
} }
void NetPlaySetupDiag::OnJoin(wxCommandEvent&) void NetPlaySetupDiag::OnJoin(wxCommandEvent&)
{ {
if (::netplay_ptr) NetPlayDiag *&npd = NetPlayDiag::GetInstance();
if (npd)
{ {
PanicAlertT("A NetPlay window is already open!!"); PanicAlertT("A NetPlay window is already open!!");
return; return;
} }
NetPlayDiag* const npd = new NetPlayDiag(m_parent, m_game_list, ""); npd = new NetPlayDiag(m_parent, m_game_list, "");
unsigned long port = 0; unsigned long port = 0;
m_connect_port_text->GetValue().ToULong(&port); 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())); , (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(); npd->Show();
Destroy(); Destroy();
} }
else else
{ {
//PanicAlertT("Failed to Connect!!");
npd->Destroy(); npd->Destroy();
// dialog will delete netplay
//delete ::netplay_ptr;
} }
} }
@ -242,8 +244,8 @@ void NetPlaySetupDiag::OnQuit(wxCommandEvent&)
Destroy(); Destroy();
} }
NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game_list NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game_list,
, const std::string& game, const bool is_hosting) const std::string& game, const bool is_hosting)
: wxFrame(parent, wxID_ANY, wxT(NETPLAY_TITLEBAR), wxDefaultPosition, wxDefaultSize) : wxFrame(parent, wxID_ANY, wxT(NETPLAY_TITLEBAR), wxDefaultPosition, wxDefaultSize)
, m_selected_game(game) , m_selected_game(game)
, m_game_list(game_list) , m_game_list(game_list)
@ -251,8 +253,9 @@ NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game
wxPanel* const panel = new wxPanel(this); wxPanel* const panel = new wxPanel(this);
// top crap // top crap
m_game_btn = new wxButton(panel, wxID_ANY m_game_btn = new wxButton(panel, wxID_ANY,
, wxString(m_selected_game.c_str(), *wxConvCurrent).Prepend(_(" Game : ")), wxDefaultPosition, wxDefaultSize, wxBU_LEFT); wxString(m_selected_game.c_str(), *wxConvCurrent).Prepend(_(" Game : ")),
wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
if (is_hosting) if (is_hosting)
_connect_macro_(m_game_btn, NetPlayDiag::OnChangeGame, wxEVT_COMMAND_BUTTON_CLICKED, this); _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() NetPlayDiag::~NetPlayDiag()
{ {
if (::netplay_ptr) if (netplay_ptr)
{ {
delete netplay_ptr; delete netplay_ptr;
::netplay_ptr = NULL; netplay_ptr = NULL;
} }
npd = NULL;
} }
void NetPlayDiag::OnChat(wxCommandEvent&) void NetPlayDiag::OnChat(wxCommandEvent&)
@ -351,7 +355,7 @@ void NetPlayDiag::OnChat(wxCommandEvent&)
if (s.Length()) 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_text->AppendText(s.Prepend(wxT(" >> ")).Append(wxT('\n')));
m_chat_msg_text->Clear(); m_chat_msg_text->Clear();
} }
@ -374,14 +378,14 @@ void NetPlayDiag::OnStart(wxCommandEvent&)
} }
if (path.length()) if (path.length())
::netplay_ptr->StartGame(path); netplay_ptr->StartGame(path);
else else
PanicAlertT("Game not found!!"); PanicAlertT("Game not found!!");
} }
void NetPlayDiag::OnStop(wxCommandEvent&) void NetPlayDiag::OnStop(wxCommandEvent&)
{ {
::netplay_ptr->StopGame(); netplay_ptr->StopGame();
} }
void NetPlayDiag::BootGame(const std::string& filename) void NetPlayDiag::BootGame(const std::string& filename)
@ -430,7 +434,7 @@ void NetPlayDiag::OnMsgStopGame()
void NetPlayDiag::OnPadBuffHelp(wxCommandEvent&) void NetPlayDiag::OnPadBuffHelp(wxCommandEvent&)
{ {
const u64 time = ((NetPlayServer*)::netplay_ptr)->CalculateMinimumBufferTime(); const u64 time = ((NetPlayServer*)netplay_ptr)->CalculateMinimumBufferTime();
std::ostringstream ss; std::ostringstream ss;
ss << "< Calculated from pings: required buffer: " ss << "< Calculated from pings: required buffer: "
<< time * (60.0f/1000) << "(60fps) / " << time * (60.0f/1000) << "(60fps) / "
@ -442,11 +446,11 @@ void NetPlayDiag::OnPadBuffHelp(wxCommandEvent&)
void NetPlayDiag::OnAdjustBuffer(wxCommandEvent& event) void NetPlayDiag::OnAdjustBuffer(wxCommandEvent& event)
{ {
const int val = ((wxSpinCtrl*)event.GetEventObject())->GetValue(); const int val = ((wxSpinCtrl*)event.GetEventObject())->GetValue();
((NetPlayServer*)::netplay_ptr)->AdjustPadBufferSize(val); ((NetPlayServer*)netplay_ptr)->AdjustPadBufferSize(val);
std::ostringstream ss; std::ostringstream ss;
ss << "< Pad Buffer: " << val << " >"; 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'))); m_chat_text->AppendText(wxString(ss.str().c_str(), *wxConvCurrent).Append(wxT('\n')));
} }
@ -461,7 +465,7 @@ void NetPlayDiag::OnThread(wxCommandEvent& event)
// player list // player list
m_playerids.clear(); m_playerids.clear();
std::string tmps; std::string tmps;
::netplay_ptr->GetPlayerList(tmps, m_playerids); netplay_ptr->GetPlayerList(tmps, m_playerids);
const int selection = m_player_lbox->GetSelection(); const int selection = m_player_lbox->GetSelection();
@ -516,7 +520,7 @@ void NetPlayDiag::OnChangeGame(wxCommandEvent&)
if (game_name.length()) if (game_name.length())
{ {
m_selected_game = std::string(game_name.mb_str()); 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 : "))); m_game_btn->SetLabel(game_name.Prepend(_(" Game : ")));
} }
} }
@ -531,14 +535,14 @@ void NetPlayDiag::OnConfigPads(wxCommandEvent&)
return; return;
pid = m_playerids.at(pid); pid = m_playerids.at(pid);
if (false == ((NetPlayServer*)::netplay_ptr)->GetPadMapping(pid, mapping)) if (false == ((NetPlayServer*)netplay_ptr)->GetPadMapping(pid, mapping))
return; return;
PadMapDiag* const pmd = new PadMapDiag(this, mapping); PadMapDiag* const pmd = new PadMapDiag(this, mapping);
pmd->ShowModal(); pmd->ShowModal();
pmd->Destroy(); 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" 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)"); "(setting pads while the game is running is not yet supported)");
} }

View File

@ -87,6 +87,8 @@ public:
void OnMsgStartGame(); void OnMsgStartGame();
void OnMsgStopGame(); void OnMsgStopGame();
static NetPlayDiag *&GetInstance() { return npd; };
private: private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
@ -108,6 +110,8 @@ private:
std::vector<int> m_playerids; std::vector<int> m_playerids;
const CGameListCtrl* const m_game_list; const CGameListCtrl* const m_game_list;
static NetPlayDiag* npd;
}; };
DECLARE_EVENT_TYPE(wxEVT_THREAD, -1) DECLARE_EVENT_TYPE(wxEVT_THREAD, -1)