NetPlay: Return mapping arrays and player list vectors directly
Simplifies pad map dialog initialization
This commit is contained in:
parent
b1af2a6bbc
commit
11f3ded296
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -403,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -460,19 +460,11 @@ void NetPlayDialog::OnChangeGame(wxCommandEvent&)
|
||||||
|
|
||||||
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&)
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue