Permalink
Browse files

Merge pull request #7238 from Techjar/netplay-bundle-pad-states

NetPlay: Bundle multiple local pads into one packet
  • Loading branch information...
spycrab committed Jul 11, 2018
2 parents df5d1cf + f68dbed commit fc967908ea439811006c63e5ac138b7c77392d45
Showing with 47 additions and 31 deletions.
  1. +25 −15 Source/Core/Core/NetPlayClient.cpp
  2. +1 −1 Source/Core/Core/NetPlayClient.h
  3. +21 −15 Source/Core/Core/NetPlayServer.cpp
@@ -344,15 +344,20 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
case NP_MSG_PAD_DATA:
{
PadMapping map = 0;
GCPadStatus pad;
packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >>
pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight >> pad.isConnected;
while (!packet.endOfPacket())
{
PadMapping map;
packet >> map;
// Trusting server for good map value (>=0 && <4)
// add to pad buffer
m_pad_buffer.at(map).Push(pad);
m_gc_pad_event.Set();
GCPadStatus pad;
packet >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >>
pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight >> pad.isConnected;
// Trusting server for good map value (>=0 && <4)
// add to pad buffer
m_pad_buffer.at(map).Push(pad);
m_gc_pad_event.Set();
}
}
break;
@@ -797,15 +802,12 @@ void NetPlayClient::SendChatMessage(const std::string& msg)
}
// called from ---CPU--- thread
void NetPlayClient::SendPadState(const int in_game_pad, const GCPadStatus& pad)
void NetPlayClient::AddPadStateToPacket(const int in_game_pad, const GCPadStatus& pad,
sf::Packet& packet)
{
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_PAD_DATA);
packet << static_cast<PadMapping>(in_game_pad);
packet << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY << pad.substickX
<< pad.substickY << pad.triggerLeft << pad.triggerRight << pad.isConnected;
SendAsync(std::move(packet));
}
// called from ---CPU--- thread
@@ -1019,6 +1021,10 @@ bool NetPlayClient::GetNetPads(const int pad_nb, GCPadStatus* pad_status)
// clients.
if (IsFirstInGamePad(pad_nb))
{
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_PAD_DATA);
bool send_packet = false;
const int num_local_pads = NumLocalPads();
for (int local_pad = 0; local_pad < num_local_pads; local_pad++)
{
@@ -1042,10 +1048,14 @@ bool NetPlayClient::GetNetPads(const int pad_nb, GCPadStatus* pad_status)
// add to buffer
m_pad_buffer[ingame_pad].Push(*pad_status);
// send
SendPadState(ingame_pad, *pad_status);
// add to packet
AddPadStateToPacket(ingame_pad, *pad_status, packet);
send_packet = true;
}
}
if (send_packet)
SendAsync(std::move(packet));
}
// Now, we either use the data pushed earlier, or wait for the
@@ -159,7 +159,7 @@ class NetPlayClient : public TraversalClientClient
void SendStopGamePacket();
void UpdateDevices();
void SendPadState(int in_game_pad, const GCPadStatus& np);
void AddPadStateToPacket(int in_game_pad, const GCPadStatus& np, sf::Packet& packet);
void SendWiimoteState(int in_game_pad, const NetWiimote& nw);
unsigned int OnData(sf::Packet& packet);
void Send(const sf::Packet& packet);
@@ -528,24 +528,30 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
if (player.current_game != m_current_game)
break;
PadMapping map = 0;
GCPadStatus pad;
packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >>
pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight >> pad.isConnected;
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_PAD_DATA);
// If the data is not from the correct player,
// then disconnect them.
if (m_pad_map.at(map) != player.pid)
while (!packet.endOfPacket())
{
return 1;
}
PadMapping map;
packet >> map;
// Relay to clients
sf::Packet spac;
spac << (MessageId)NP_MSG_PAD_DATA;
spac << map << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY
<< pad.substickX << pad.substickY << pad.triggerLeft << pad.triggerRight
<< pad.isConnected;
// If the data is not from the correct player,
// then disconnect them.
if (m_pad_map.at(map) != player.pid)
{
return 1;
}
GCPadStatus pad;
packet >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >>
pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight >> pad.isConnected;
// Add to packet for relay to clients
spac << map << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY
<< pad.substickX << pad.substickY << pad.triggerLeft << pad.triggerRight
<< pad.isConnected;
}
SendToClients(spac, player.pid);
}

0 comments on commit fc96790

Please sign in to comment.