NetPlay: Return mapping arrays and player list vectors directly

Simplifies pad map dialog initialization
This commit is contained in:
Lioncash 2015-08-16 00:58:15 -04:00
parent b1af2a6bbc
commit 11f3ded296
7 changed files with 55 additions and 53 deletions

View File

@ -617,17 +617,15 @@ void NetPlayClient::GetPlayerList(std::string& list, std::vector<int>& pid_list)
}
// 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::map<PlayerId, Player>::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<const Player*> players;
for (const auto& pair : m_players)
players.push_back(&pair.second);
return players;
}

View File

@ -54,7 +54,7 @@ public:
~NetPlayClient();
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;

View File

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

View File

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

View File

@ -460,19 +460,11 @@ void NetPlayDialog::OnChangeGame(wxCommandEvent&)
void NetPlayDialog::OnConfigPads(wxCommandEvent&)
{
PadMapping mapping[4];
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);
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&)

View File

@ -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<const Player*>& 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;
}
}

View File

@ -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<const Player*>& 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<const Player*>& m_player_list;
PadMappingArray m_pad_mapping;
PadMappingArray m_wii_mapping;
std::vector<const Player*> m_player_list;
};