From 11f3ded2966726680908deb4505cad41da2938c1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 16 Aug 2015 00:58:15 -0400 Subject: [PATCH] NetPlay: Return mapping arrays and player list vectors directly Simplifies pad map dialog initialization --- Source/Core/Core/NetPlayClient.cpp | 16 ++++----- Source/Core/Core/NetPlayClient.h | 2 +- Source/Core/Core/NetPlayServer.cpp | 20 +++++------ Source/Core/Core/NetPlayServer.h | 8 ++--- Source/Core/DolphinWX/NetPlay/NetWindow.cpp | 14 ++------ .../Core/DolphinWX/NetPlay/PadMapDialog.cpp | 35 ++++++++++++------- Source/Core/DolphinWX/NetPlay/PadMapDialog.h | 13 ++++--- 7 files changed, 55 insertions(+), 53 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index d499e6b90e..a129507bae 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -617,17 +617,15 @@ void NetPlayClient::GetPlayerList(std::string& list, std::vector& pid_list) } // called from ---GUI--- thread -void NetPlayClient::GetPlayers(std::vector &player_list) +std::vector NetPlayClient::GetPlayers() { std::lock_guard lkp(m_crit.players); - std::map::const_iterator - i = m_players.begin(), - e = m_players.end(); - for (; i != e; ++i) - { - const Player *player = &(i->second); - player_list.push_back(player); - } + std::vector players; + + for (const auto& pair : m_players) + players.push_back(&pair.second); + + return players; } diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index f62e337eb7..56e38ef7b2 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -54,7 +54,7 @@ public: ~NetPlayClient(); void GetPlayerList(std::string& list, std::vector& pid_list); - void GetPlayers(std::vector& player_list); + std::vector GetPlayers(); bool is_connected; diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index d15c8ac338..2a48d37f7e 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -403,31 +403,27 @@ unsigned int NetPlayServer::OnDisconnect(Client& player) } // called from ---GUI--- thread -void NetPlayServer::GetPadMapping(PadMapping map[4]) +PadMappingArray NetPlayServer::GetPadMapping() const { - for (int i = 0; i < 4; i++) - map[i] = m_pad_map[i]; + return m_pad_map; } -void NetPlayServer::GetWiimoteMapping(PadMapping map[4]) +PadMappingArray NetPlayServer::GetWiimoteMapping() const { - for (int i = 0; i < 4; i++) - map[i] = m_wiimote_map[i]; + return m_wiimote_map; } // 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[i] = map[i]; + m_pad_map = mappings; UpdatePadMapping(); } // 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[i] = map[i]; + m_wiimote_map = mappings; UpdateWiimoteMapping(); } diff --git a/Source/Core/Core/NetPlayServer.h b/Source/Core/Core/NetPlayServer.h index 360c4491ad..b2888c8708 100644 --- a/Source/Core/Core/NetPlayServer.h +++ b/Source/Core/Core/NetPlayServer.h @@ -34,11 +34,11 @@ public: bool StartGame(); - void GetPadMapping(PadMapping map[]); - void SetPadMapping(const PadMapping map[]); + PadMappingArray GetPadMapping() const; + void SetPadMapping(const PadMappingArray& mappings); - void GetWiimoteMapping(PadMapping map[]); - void SetWiimoteMapping(const PadMapping map[]); + PadMappingArray GetWiimoteMapping() const; + void SetWiimoteMapping(const PadMappingArray& mappings); void AdjustPadBufferSize(unsigned int size); diff --git a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp index 5db7c7e56f..594918b5ab 100644 --- a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp @@ -460,19 +460,11 @@ void NetPlayDialog::OnChangeGame(wxCommandEvent&) void NetPlayDialog::OnConfigPads(wxCommandEvent&) { - PadMapping mapping[4]; - PadMapping wiimotemapping[4]; - std::vector player_list; - - netplay_server->GetPadMapping(mapping); - netplay_server->GetWiimoteMapping(wiimotemapping); - netplay_client->GetPlayers(player_list); - - PadMapDialog pmd(this, mapping, wiimotemapping, player_list); + PadMapDialog pmd(this, netplay_server, netplay_client); pmd.ShowModal(); - netplay_server->SetPadMapping(mapping); - netplay_server->SetWiimoteMapping(wiimotemapping); + netplay_server->SetPadMapping(pmd.GetModifiedPadMappings()); + netplay_server->SetWiimoteMapping(pmd.GetModifiedWiimoteMappings()); } void NetPlayDialog::OnKick(wxCommandEvent&) diff --git a/Source/Core/DolphinWX/NetPlay/PadMapDialog.cpp b/Source/Core/DolphinWX/NetPlay/PadMapDialog.cpp index 5e6d3798cb..8fdd66903e 100644 --- a/Source/Core/DolphinWX/NetPlay/PadMapDialog.cpp +++ b/Source/Core/DolphinWX/NetPlay/PadMapDialog.cpp @@ -8,13 +8,14 @@ #include "Core/NetPlayClient.h" #include "Core/NetPlayProto.h" +#include "Core/NetPlayServer.h" #include "DolphinWX/NetPlay/PadMapDialog.h" -PadMapDialog::PadMapDialog(wxWindow* parent, PadMapping map[], PadMapping wiimotemap[], std::vector& player_list) +PadMapDialog::PadMapDialog(wxWindow* parent, NetPlayServer* server, NetPlayClient* client) : wxDialog(parent, wxID_ANY, _("Configure Pads")) - , m_mapping(map) - , m_wiimapping(wiimotemap) - , m_player_list(player_list) + , m_pad_mapping(server->GetPadMapping()) + , m_wii_mapping(server->GetWiimoteMapping()) + , m_player_list(client->GetPlayers()) { wxBoxSizer* const h_szr = new wxBoxSizer(wxHORIZONTAL); 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]->Bind(wxEVT_CHOICE, &PadMapDialog::OnAdjust, this); - if (m_mapping[i] == -1) + if (m_pad_mapping[i] == -1) { 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++) { - 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); } } @@ -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]->Bind(wxEVT_CHOICE, &PadMapDialog::OnAdjust, this); - if (m_wiimapping[i] == -1) + if (m_wii_mapping[i] == -1) { 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++) { - 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); } } @@ -87,20 +88,30 @@ PadMapDialog::PadMapDialog(wxWindow* parent, PadMapping map[], PadMapping wiimot SetFocus(); } +PadMappingArray PadMapDialog::GetModifiedPadMappings() const +{ + return m_pad_mapping; +} + +PadMappingArray PadMapDialog::GetModifiedWiimoteMappings() const +{ + return m_wii_mapping; +} + void PadMapDialog::OnAdjust(wxCommandEvent& WXUNUSED(event)) { for (unsigned int i = 0; i < 4; i++) { int player_idx = m_map_cbox[i]->GetSelection(); 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 - m_mapping[i] = -1; + m_pad_mapping[i] = -1; player_idx = m_map_cbox[i + 4]->GetSelection(); 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 - m_wiimapping[i] = -1; + m_wii_mapping[i] = -1; } } diff --git a/Source/Core/DolphinWX/NetPlay/PadMapDialog.h b/Source/Core/DolphinWX/NetPlay/PadMapDialog.h index b00cbd40c0..9d2a7768b3 100644 --- a/Source/Core/DolphinWX/NetPlay/PadMapDialog.h +++ b/Source/Core/DolphinWX/NetPlay/PadMapDialog.h @@ -9,19 +9,24 @@ #include "Core/NetPlayProto.h" +class NetPlayClient; +class NetPlayServer; class Player; class wxChoice; class PadMapDialog final : public wxDialog { public: - PadMapDialog(wxWindow* parent, PadMapping map[], PadMapping wiimotemap[], std::vector& player_list); + PadMapDialog(wxWindow* parent, NetPlayServer* server, NetPlayClient* client); + + PadMappingArray GetModifiedPadMappings() const; + PadMappingArray GetModifiedWiimoteMappings() const; private: void OnAdjust(wxCommandEvent& event); wxChoice* m_map_cbox[8]; - PadMapping* const m_mapping; - PadMapping* const m_wiimapping; - std::vector& m_player_list; + PadMappingArray m_pad_mapping; + PadMappingArray m_wii_mapping; + std::vector m_player_list; };