NetPlay: Remove PadMapping type

Its usage was inconsistent, confusing, and buggy, so I opted to just
remove it entirely. It has been replaced with PadIndex for the
appropriate instances (mainly networking), and inappropriate usages
(where it was really just a player ID) have been replaced with the
PlayerId type. The definition of "no mapping" has been changed from -1
to 0 to match the defintion of "no player", as -1 (255 unsigned) is
actually a valid player ID.

The bugs never manifested because it only occurs with a full lobby of
255 players, at which point the last player's ID collides with the "no
mapping" definition and some undefined behavior occurs. Nevertheless, I
thought it best to fix it anyways as the usage of PadMapping was
confusing.
This commit is contained in:
Techjar
2018-11-19 05:30:39 -05:00
parent e6b2758ab4
commit 529796bd59
6 changed files with 37 additions and 37 deletions

View File

@@ -340,7 +340,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
case NP_MSG_PAD_MAPPING:
{
for (PadMapping& mapping : m_pad_map)
for (PlayerId& mapping : m_pad_map)
{
packet >> mapping;
}
@@ -353,7 +353,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
case NP_MSG_WIIMOTE_MAPPING:
{
for (PadMapping& mapping : m_wiimote_map)
for (PlayerId& mapping : m_wiimote_map)
{
packet >> mapping;
}
@@ -366,7 +366,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
{
while (!packet.endOfPacket())
{
PadMapping map;
PadIndex map;
packet >> map;
GCPadStatus pad;
@@ -383,7 +383,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
case NP_MSG_WIIMOTE_DATA:
{
PadMapping map = 0;
PadIndex map;
NetWiimote nw;
u8 size;
packet >> map >> size;
@@ -412,7 +412,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
case NP_MSG_PAD_FIRST_RECEIVED:
{
PadMapping map;
PadIndex map;
packet >> map;
packet >> m_first_pad_status_received[map];
m_first_pad_status_received_event.Set();
@@ -1250,7 +1250,7 @@ void NetPlayClient::SendChatMessage(const std::string& msg)
void NetPlayClient::AddPadStateToPacket(const int in_game_pad, const GCPadStatus& pad,
sf::Packet& packet)
{
packet << static_cast<PadMapping>(in_game_pad);
packet << static_cast<PadIndex>(in_game_pad);
packet << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY << pad.substickX
<< pad.substickY << pad.triggerLeft << pad.triggerRight << pad.isConnected;
}
@@ -1260,7 +1260,7 @@ void NetPlayClient::SendWiimoteState(const int in_game_pad, const NetWiimote& nw
{
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_WIIMOTE_DATA);
packet << static_cast<PadMapping>(in_game_pad);
packet << static_cast<PadIndex>(in_game_pad);
packet << static_cast<u8>(nw.size());
for (auto it : nw)
{
@@ -1814,7 +1814,7 @@ bool NetPlayClient::PollLocalPad(const int local_pad, sf::Packet& packet)
return data_added;
}
void NetPlayClient::SendPadHostPoll(const PadMapping pad_num)
void NetPlayClient::SendPadHostPoll(const PadIndex pad_num)
{
if (!m_local_player->IsHost())
return;
@@ -1835,7 +1835,7 @@ void NetPlayClient::SendPadHostPoll(const PadMapping pad_num)
}
}
}
else if (m_pad_map[pad_num] > 0)
else if (m_pad_map[pad_num] != 0)
{
while (!m_first_pad_status_received[pad_num])
{
@@ -1909,7 +1909,7 @@ void NetPlayClient::SendPowerButtonEvent()
// called from ---GUI--- thread
bool NetPlayClient::LocalPlayerHasControllerMapped() const
{
const auto mapping_matches_player_id = [this](const PadMapping& mapping) {
const auto mapping_matches_player_id = [this](const PlayerId& mapping) {
return mapping == m_local_player->pid;
};