Merge pull request #2859 from lioncash/netplay

NetPlay: Minor cleanup
This commit is contained in:
Lioncash 2015-08-19 04:51:28 -04:00
commit 291f857b0e
10 changed files with 100 additions and 100 deletions

View File

@ -617,17 +617,15 @@ void NetPlayClient::GetPlayerList(std::string& list, std::vector<int>& pid_list)
} }
// called from ---GUI--- thread // called from ---GUI--- thread
void NetPlayClient::GetPlayers(std::vector<const Player *> &player_list) std::vector<const Player*> NetPlayClient::GetPlayers()
{ {
std::lock_guard<std::recursive_mutex> lkp(m_crit.players); std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
std::map<PlayerId, Player>::const_iterator std::vector<const Player*> players;
i = m_players.begin(),
e = m_players.end(); for (const auto& pair : m_players)
for (; i != e; ++i) players.push_back(&pair.second);
{
const Player *player = &(i->second); return players;
player_list.push_back(player);
}
} }

View File

@ -54,7 +54,7 @@ public:
~NetPlayClient(); ~NetPlayClient();
void GetPlayerList(std::string& list, std::vector<int>& pid_list); void GetPlayerList(std::string& list, std::vector<int>& pid_list);
void GetPlayers(std::vector<const Player *>& player_list); std::vector<const Player*> GetPlayers();
bool is_connected; bool is_connected;
@ -121,8 +121,8 @@ protected:
u32 m_current_game; u32 m_current_game;
PadMapping m_pad_map[4]; PadMappingArray m_pad_map;
PadMapping m_wiimote_map[4]; PadMappingArray m_wiimote_map;
bool m_is_recording; bool m_is_recording;

View File

@ -4,10 +4,13 @@
#pragma once #pragma once
#include <array>
#include <vector> #include <vector>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/EXI_Device.h" #include "Core/HW/EXI_Device.h"
#define NETPLAY_VERSION "Dolphin NetPlay 2015-06-24"
struct NetSettings struct NetSettings
{ {
bool m_CPUthread; bool m_CPUthread;
@ -25,18 +28,13 @@ struct NetSettings
}; };
extern NetSettings g_NetPlaySettings; extern NetSettings g_NetPlaySettings;
extern u64 g_netplay_initial_gctime;
struct Rpt : public std::vector<u8> struct Rpt : public std::vector<u8>
{ {
u16 channel; u16 channel;
}; };
typedef std::vector<u8> NetWiimote;
#define NETPLAY_VERSION "Dolphin NetPlay 2015-06-24"
extern u64 g_netplay_initial_gctime;
// messages // messages
enum enum
{ {
@ -70,11 +68,6 @@ enum
NP_MSG_SYNC_GC_SRAM = 0xF0, NP_MSG_SYNC_GC_SRAM = 0xF0,
}; };
typedef u8 MessageId;
typedef u8 PlayerId;
typedef s8 PadMapping;
typedef u32 FrameNum;
enum enum
{ {
CON_ERR_SERVER_FULL = 1, CON_ERR_SERVER_FULL = 1,
@ -82,6 +75,13 @@ enum
CON_ERR_VERSION_MISMATCH = 3 CON_ERR_VERSION_MISMATCH = 3
}; };
using NetWiimote = std::vector<u8>;
using MessageId = u8;
using PlayerId = u8;
using FrameNum = u32;
using PadMapping = s8;
using PadMappingArray = std::array<PadMapping, 4>;
namespace NetPlay namespace NetPlay
{ {
bool IsNetPlayRunning(); bool IsNetPlayRunning();

View File

@ -74,8 +74,9 @@ NetPlayServer::NetPlayServer(const u16 port, bool traversal, const std::string&
PanicAlertT("Enet Didn't Initialize"); PanicAlertT("Enet Didn't Initialize");
} }
memset(m_pad_map, -1, sizeof(m_pad_map)); m_pad_map.fill(-1);
memset(m_wiimote_map, -1, sizeof(m_wiimote_map)); m_wiimote_map.fill(-1);
if (traversal) if (traversal)
{ {
if (!EnsureTraversalClient(centralServer, centralPort)) if (!EnsureTraversalClient(centralServer, centralPort))
@ -402,31 +403,27 @@ unsigned int NetPlayServer::OnDisconnect(Client& player)
} }
// called from ---GUI--- thread // called from ---GUI--- thread
void NetPlayServer::GetPadMapping(PadMapping map[4]) PadMappingArray NetPlayServer::GetPadMapping() const
{ {
for (int i = 0; i < 4; i++) return m_pad_map;
map[i] = m_pad_map[i];
} }
void NetPlayServer::GetWiimoteMapping(PadMapping map[4]) PadMappingArray NetPlayServer::GetWiimoteMapping() const
{ {
for (int i = 0; i < 4; i++) return m_wiimote_map;
map[i] = m_wiimote_map[i];
} }
// called from ---GUI--- thread // called from ---GUI--- thread
void NetPlayServer::SetPadMapping(const PadMapping map[4]) void NetPlayServer::SetPadMapping(const PadMappingArray& mappings)
{ {
for (int i = 0; i < 4; i++) m_pad_map = mappings;
m_pad_map[i] = map[i];
UpdatePadMapping(); UpdatePadMapping();
} }
// called from ---GUI--- thread // called from ---GUI--- thread
void NetPlayServer::SetWiimoteMapping(const PadMapping map[4]) void NetPlayServer::SetWiimoteMapping(const PadMappingArray& mappings)
{ {
for (int i = 0; i < 4; i++) m_wiimote_map = mappings;
m_wiimote_map[i] = map[i];
UpdateWiimoteMapping(); UpdateWiimoteMapping();
} }

View File

@ -34,11 +34,11 @@ public:
bool StartGame(); bool StartGame();
void GetPadMapping(PadMapping map[]); PadMappingArray GetPadMapping() const;
void SetPadMapping(const PadMapping map[]); void SetPadMapping(const PadMappingArray& mappings);
void GetWiimoteMapping(PadMapping map[]); PadMappingArray GetWiimoteMapping() const;
void SetWiimoteMapping(const PadMapping map[]); void SetWiimoteMapping(const PadMappingArray& mappings);
void AdjustPadBufferSize(unsigned int size); void AdjustPadBufferSize(unsigned int size);
@ -95,8 +95,8 @@ private:
bool m_update_pings; bool m_update_pings;
u32 m_current_game; u32 m_current_game;
unsigned int m_target_buffer_size; unsigned int m_target_buffer_size;
PadMapping m_pad_map[4]; PadMappingArray m_pad_map;
PadMapping m_wiimote_map[4]; PadMappingArray m_wiimote_map;
std::map<PlayerId, Client> m_players; std::map<PlayerId, Client> m_players;

View File

@ -9,9 +9,8 @@
#include "DolphinWX/NetPlay/ChangeGameDialog.h" #include "DolphinWX/NetPlay/ChangeGameDialog.h"
#include "DolphinWX/NetPlay/NetWindow.h" #include "DolphinWX/NetPlay/NetWindow.h"
ChangeGameDialog::ChangeGameDialog(wxWindow* parent, const CGameListCtrl* const game_list, wxString& game_name) ChangeGameDialog::ChangeGameDialog(wxWindow* parent, const CGameListCtrl* const game_list)
: wxDialog(parent, wxID_ANY, _("Change Game")) : wxDialog(parent, wxID_ANY, _("Change Game"))
, m_game_name(game_name)
{ {
m_game_lbox = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxLB_SORT); m_game_lbox = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxLB_SORT);
m_game_lbox->Bind(wxEVT_LISTBOX_DCLICK, &ChangeGameDialog::OnPick, this); m_game_lbox->Bind(wxEVT_LISTBOX_DCLICK, &ChangeGameDialog::OnPick, this);
@ -29,9 +28,13 @@ ChangeGameDialog::ChangeGameDialog(wxWindow* parent, const CGameListCtrl* const
SetFocus(); SetFocus();
} }
wxString ChangeGameDialog::GetChosenGameName() const
{
return m_game_name;
}
void ChangeGameDialog::OnPick(wxCommandEvent& event) void ChangeGameDialog::OnPick(wxCommandEvent& event)
{ {
// return the selected game name
m_game_name = m_game_lbox->GetStringSelection(); m_game_name = m_game_lbox->GetStringSelection();
EndModal(wxID_OK); EndModal(wxID_OK);
} }

View File

@ -12,11 +12,13 @@ class wxListBox;
class ChangeGameDialog final : public wxDialog class ChangeGameDialog final : public wxDialog
{ {
public: public:
ChangeGameDialog(wxWindow* parent, const CGameListCtrl* const game_list, wxString& game_name); ChangeGameDialog(wxWindow* parent, const CGameListCtrl* const game_list);
wxString GetChosenGameName() const;
private: private:
void OnPick(wxCommandEvent& event); void OnPick(wxCommandEvent& event);
wxListBox* m_game_lbox; wxListBox* m_game_lbox;
wxString& m_game_name; wxString m_game_name;
}; };

View File

@ -141,17 +141,17 @@ NetPlayDialog::NetPlayDialog(wxWindow* const parent, const CGameListCtrl* const
{ {
wxBoxSizer* const host_szr = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer* const host_szr = new wxBoxSizer(wxHORIZONTAL);
m_host_type_choice = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxSize(60, -1)); m_host_type_choice = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxSize(60, -1));
m_host_type_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &NetPlayDialog::OnChoice, this); m_host_type_choice->Bind(wxEVT_CHOICE, &NetPlayDialog::OnChoice, this);
m_host_type_choice->Append(_("ID:")); m_host_type_choice->Append(_("ID:"));
host_szr->Add(m_host_type_choice); host_szr->Add(m_host_type_choice);
m_host_label = new wxStaticText(panel, wxID_ANY, "555.555.555.555:55555", wxDefaultPosition, wxDefaultSize, wxST_NO_AUTORESIZE | wxALIGN_LEFT); m_host_label = new wxStaticText(panel, wxID_ANY, "555.555.555.555:55555", wxDefaultPosition, wxDefaultSize, wxST_NO_AUTORESIZE | wxALIGN_LEFT);
// Update() should fix this immediately. // Update() should fix this immediately.
m_host_label->SetLabel(_("")); m_host_label->SetLabel("");
host_szr->Add(m_host_label, 1, wxLEFT | wxCENTER, 5); host_szr->Add(m_host_label, 1, wxLEFT | wxCENTER, 5);
m_host_copy_btn = new wxButton(panel, wxID_ANY, _("Copy")); m_host_copy_btn = new wxButton(panel, wxID_ANY, _("Copy"));
m_host_copy_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &NetPlayDialog::OnCopyIP, this); m_host_copy_btn->Bind(wxEVT_BUTTON, &NetPlayDialog::OnCopyIP, this);
m_host_copy_btn->Disable(); m_host_copy_btn->Disable();
host_szr->Add(m_host_copy_btn, 0, wxLEFT | wxCENTER, 5); host_szr->Add(m_host_copy_btn, 0, wxLEFT | wxCENTER, 5);
player_szr->Add(host_szr, 0, wxEXPAND | wxBOTTOM, 5); player_szr->Add(host_szr, 0, wxEXPAND | wxBOTTOM, 5);
@ -383,13 +383,13 @@ void NetPlayDialog::OnThread(wxThreadEvent& event)
m_player_lbox->Append(StrToWxStr(tmps)); m_player_lbox->Append(StrToWxStr(tmps));
// remove ping from selection string, in case it has changed // remove ping from selection string, in case it has changed
selection.erase(selection.find_last_of("|") + 1); selection.erase(selection.rfind('|') + 1);
if (!selection.empty()) if (!selection.empty())
{ {
for (unsigned int i = 0; i < m_player_lbox->GetCount(); ++i) for (unsigned int i = 0; i < m_player_lbox->GetCount(); ++i)
{ {
if (selection == m_player_lbox->GetString(i).Mid(0, selection.length())) if (selection == m_player_lbox->GetString(i).substr(0, selection.length()))
{ {
m_player_lbox->SetSelection(i); m_player_lbox->SetSelection(i);
break; break;
@ -399,10 +399,7 @@ void NetPlayDialog::OnThread(wxThreadEvent& event)
// flash window in taskbar when someone joins if window isn't active // flash window in taskbar when someone joins if window isn't active
static u8 numPlayers = 1; static u8 numPlayers = 1;
bool focus = (wxWindow::FindFocus() == this || (wxWindow::FindFocus() != nullptr && wxWindow::FindFocus()->GetParent() == this) || if (netplay_server != nullptr && numPlayers < m_playerids.size() && !HasFocus())
(wxWindow::FindFocus() != nullptr && wxWindow::FindFocus()->GetParent() != nullptr
&& wxWindow::FindFocus()->GetParent()->GetParent() == this));
if (netplay_server != nullptr && numPlayers < m_playerids.size() && !focus)
{ {
RequestUserAttention(); RequestUserAttention();
} }
@ -413,7 +410,7 @@ void NetPlayDialog::OnThread(wxThreadEvent& event)
case NP_GUI_EVT_CHANGE_GAME: case NP_GUI_EVT_CHANGE_GAME:
// update selected game :/ // update selected game :/
{ {
m_selected_game.assign(WxStrToStr(event.GetString())); m_selected_game = WxStrToStr(event.GetString());
wxString button_label = event.GetString(); wxString button_label = event.GetString();
m_game_btn->SetLabel(button_label.Prepend(_(" Game : "))); m_game_btn->SetLabel(button_label.Prepend(_(" Game : ")));
@ -445,41 +442,32 @@ void NetPlayDialog::OnThread(wxThreadEvent& event)
void NetPlayDialog::OnChangeGame(wxCommandEvent&) void NetPlayDialog::OnChangeGame(wxCommandEvent&)
{ {
wxString game_name; ChangeGameDialog cgd(this, m_game_list);
ChangeGameDialog cgd(this, m_game_list, game_name);
cgd.ShowModal(); cgd.ShowModal();
if (game_name.length()) wxString game_name = cgd.GetChosenGameName();
{ if (game_name.empty())
m_selected_game = WxStrToStr(game_name); return;
netplay_server->ChangeGame(m_selected_game);
m_game_btn->SetLabel(game_name.Prepend(_(" Game : "))); m_selected_game = WxStrToStr(game_name);
} netplay_server->ChangeGame(m_selected_game);
m_game_btn->SetLabel(game_name.Prepend(_(" Game : ")));
} }
void NetPlayDialog::OnConfigPads(wxCommandEvent&) void NetPlayDialog::OnConfigPads(wxCommandEvent&)
{ {
PadMapping mapping[4]; PadMapDialog pmd(this, netplay_server, netplay_client);
PadMapping wiimotemapping[4];
std::vector<const Player *> player_list;
netplay_server->GetPadMapping(mapping);
netplay_server->GetWiimoteMapping(wiimotemapping);
netplay_client->GetPlayers(player_list);
PadMapDialog pmd(this, mapping, wiimotemapping, player_list);
pmd.ShowModal(); pmd.ShowModal();
netplay_server->SetPadMapping(mapping); netplay_server->SetPadMapping(pmd.GetModifiedPadMappings());
netplay_server->SetWiimoteMapping(wiimotemapping); netplay_server->SetWiimoteMapping(pmd.GetModifiedWiimoteMappings());
} }
void NetPlayDialog::OnKick(wxCommandEvent&) void NetPlayDialog::OnKick(wxCommandEvent&)
{ {
wxString selection = m_player_lbox->GetStringSelection(); wxString selection = m_player_lbox->GetStringSelection();
unsigned long player = 0; unsigned long player = 0;
selection.Mid(selection.find_last_of("[") + 1, selection.find_last_of("]")).ToULong(&player); selection.substr(selection.rfind('[') + 1, selection.rfind(']')).ToULong(&player);
netplay_server->KickPlayer((u8)player); netplay_server->KickPlayer((u8)player);
@ -490,10 +478,7 @@ void NetPlayDialog::OnKick(wxCommandEvent&)
void NetPlayDialog::OnPlayerSelect(wxCommandEvent&) void NetPlayDialog::OnPlayerSelect(wxCommandEvent&)
{ {
if (m_player_lbox->GetSelection() > 0) m_kick_btn->Enable(m_player_lbox->GetSelection() > 0);
m_kick_btn->Enable();
else
m_kick_btn->Disable();
} }
bool NetPlayDialog::IsRecording() bool NetPlayDialog::IsRecording()
@ -501,7 +486,6 @@ bool NetPlayDialog::IsRecording()
return m_record_chkbox->GetValue(); return m_record_chkbox->GetValue();
} }
void NetPlayDialog::OnCopyIP(wxCommandEvent&) void NetPlayDialog::OnCopyIP(wxCommandEvent&)
{ {
if (m_host_copy_btn_is_retry) if (m_host_copy_btn_is_retry)

View File

@ -8,13 +8,14 @@
#include "Core/NetPlayClient.h" #include "Core/NetPlayClient.h"
#include "Core/NetPlayProto.h" #include "Core/NetPlayProto.h"
#include "Core/NetPlayServer.h"
#include "DolphinWX/NetPlay/PadMapDialog.h" #include "DolphinWX/NetPlay/PadMapDialog.h"
PadMapDialog::PadMapDialog(wxWindow* parent, PadMapping map[], PadMapping wiimotemap[], std::vector<const Player*>& player_list) PadMapDialog::PadMapDialog(wxWindow* parent, NetPlayServer* server, NetPlayClient* client)
: wxDialog(parent, wxID_ANY, _("Configure Pads")) : wxDialog(parent, wxID_ANY, _("Configure Pads"))
, m_mapping(map) , m_pad_mapping(server->GetPadMapping())
, m_wiimapping(wiimotemap) , m_wii_mapping(server->GetWiimoteMapping())
, m_player_list(player_list) , m_player_list(client->GetPlayers())
{ {
wxBoxSizer* const h_szr = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer* const h_szr = new wxBoxSizer(wxHORIZONTAL);
h_szr->AddSpacer(10); h_szr->AddSpacer(10);
@ -32,7 +33,7 @@ PadMapDialog::PadMapDialog(wxWindow* parent, PadMapping map[], PadMapping wiimot
m_map_cbox[i] = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, player_names); m_map_cbox[i] = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, player_names);
m_map_cbox[i]->Bind(wxEVT_CHOICE, &PadMapDialog::OnAdjust, this); m_map_cbox[i]->Bind(wxEVT_CHOICE, &PadMapDialog::OnAdjust, this);
if (m_mapping[i] == -1) if (m_pad_mapping[i] == -1)
{ {
m_map_cbox[i]->Select(0); m_map_cbox[i]->Select(0);
} }
@ -40,7 +41,7 @@ PadMapDialog::PadMapDialog(wxWindow* parent, PadMapping map[], PadMapping wiimot
{ {
for (unsigned int j = 0; j < m_player_list.size(); j++) for (unsigned int j = 0; j < m_player_list.size(); j++)
{ {
if (m_mapping[i] == m_player_list[j]->pid) if (m_pad_mapping[i] == m_player_list[j]->pid)
m_map_cbox[i]->Select(j + 1); m_map_cbox[i]->Select(j + 1);
} }
} }
@ -59,7 +60,7 @@ PadMapDialog::PadMapDialog(wxWindow* parent, PadMapping map[], PadMapping wiimot
m_map_cbox[i + 4] = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, player_names); m_map_cbox[i + 4] = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, player_names);
m_map_cbox[i + 4]->Bind(wxEVT_CHOICE, &PadMapDialog::OnAdjust, this); m_map_cbox[i + 4]->Bind(wxEVT_CHOICE, &PadMapDialog::OnAdjust, this);
if (m_wiimapping[i] == -1) if (m_wii_mapping[i] == -1)
{ {
m_map_cbox[i + 4]->Select(0); m_map_cbox[i + 4]->Select(0);
} }
@ -67,7 +68,7 @@ PadMapDialog::PadMapDialog(wxWindow* parent, PadMapping map[], PadMapping wiimot
{ {
for (unsigned int j = 0; j < m_player_list.size(); j++) for (unsigned int j = 0; j < m_player_list.size(); j++)
{ {
if (m_wiimapping[i] == m_player_list[j]->pid) if (m_wii_mapping[i] == m_player_list[j]->pid)
m_map_cbox[i + 4]->Select(j + 1); m_map_cbox[i + 4]->Select(j + 1);
} }
} }
@ -87,20 +88,30 @@ PadMapDialog::PadMapDialog(wxWindow* parent, PadMapping map[], PadMapping wiimot
SetFocus(); SetFocus();
} }
PadMappingArray PadMapDialog::GetModifiedPadMappings() const
{
return m_pad_mapping;
}
PadMappingArray PadMapDialog::GetModifiedWiimoteMappings() const
{
return m_wii_mapping;
}
void PadMapDialog::OnAdjust(wxCommandEvent& WXUNUSED(event)) void PadMapDialog::OnAdjust(wxCommandEvent& WXUNUSED(event))
{ {
for (unsigned int i = 0; i < 4; i++) for (unsigned int i = 0; i < 4; i++)
{ {
int player_idx = m_map_cbox[i]->GetSelection(); int player_idx = m_map_cbox[i]->GetSelection();
if (player_idx > 0) if (player_idx > 0)
m_mapping[i] = m_player_list[player_idx - 1]->pid; m_pad_mapping[i] = m_player_list[player_idx - 1]->pid;
else else
m_mapping[i] = -1; m_pad_mapping[i] = -1;
player_idx = m_map_cbox[i + 4]->GetSelection(); player_idx = m_map_cbox[i + 4]->GetSelection();
if (player_idx > 0) if (player_idx > 0)
m_wiimapping[i] = m_player_list[player_idx - 1]->pid; m_wii_mapping[i] = m_player_list[player_idx - 1]->pid;
else else
m_wiimapping[i] = -1; m_wii_mapping[i] = -1;
} }
} }

View File

@ -9,19 +9,24 @@
#include "Core/NetPlayProto.h" #include "Core/NetPlayProto.h"
class NetPlayClient;
class NetPlayServer;
class Player; class Player;
class wxChoice; class wxChoice;
class PadMapDialog final : public wxDialog class PadMapDialog final : public wxDialog
{ {
public: public:
PadMapDialog(wxWindow* parent, PadMapping map[], PadMapping wiimotemap[], std::vector<const Player*>& player_list); PadMapDialog(wxWindow* parent, NetPlayServer* server, NetPlayClient* client);
PadMappingArray GetModifiedPadMappings() const;
PadMappingArray GetModifiedWiimoteMappings() const;
private: private:
void OnAdjust(wxCommandEvent& event); void OnAdjust(wxCommandEvent& event);
wxChoice* m_map_cbox[8]; wxChoice* m_map_cbox[8];
PadMapping* const m_mapping; PadMappingArray m_pad_mapping;
PadMapping* const m_wiimapping; PadMappingArray m_wii_mapping;
std::vector<const Player*>& m_player_list; std::vector<const Player*> m_player_list;
}; };