Get rid of netpad and just send the GCPadStatus in netplay.

This commit is contained in:
Rachel Bryk 2014-10-16 02:36:39 -04:00
parent c1325675c7
commit 0f3194abc3
9 changed files with 40 additions and 96 deletions

View File

@ -112,17 +112,11 @@ bool CSIDevice_DanceMat::GetData(u32& _Hi, u32& _Low)
Pad::GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus);
Movie::CallGCInputManip(&PadStatus, ISIDevice::m_iDeviceNumber);
u32 netValues[2];
if (NetPlay_GetInput(ISIDevice::m_iDeviceNumber, PadStatus, netValues))
{
_Hi = netValues[0]; // first 4 bytes
_Low = netValues[1]; // last 4 bytes
return true;
}
Movie::SetPolledDevice();
if (Movie::IsPlayingInput())
if (NetPlay_GetInput(ISIDevice::m_iDeviceNumber, &PadStatus))
{
}
else if (Movie::IsPlayingInput())
{
Movie::PlayController(&PadStatus, ISIDevice::m_iDeviceNumber);
Movie::InputUpdate();

View File

@ -87,7 +87,7 @@ public:
virtual int RunBuffer(u8* _pBuffer, int _iLength) override;
// Send and Receive pad input from network
static bool NetPlay_GetInput(u8 numPAD, GCPadStatus status, u32 *PADStatus);
static bool NetPlay_GetInput(u8 numPAD, GCPadStatus* status);
static u8 NetPlay_InGamePadToLocalPad(u8 numPAD);
// Return true on new data

View File

@ -112,17 +112,11 @@ bool CSIDevice_GCController::GetData(u32& _Hi, u32& _Low)
Pad::GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus);
Movie::CallGCInputManip(&PadStatus, ISIDevice::m_iDeviceNumber);
u32 netValues[2];
if (NetPlay_GetInput(ISIDevice::m_iDeviceNumber, PadStatus, netValues))
{
_Hi = netValues[0]; // first 4 bytes
_Low = netValues[1]; // last 4 bytes
return true;
}
Movie::SetPolledDevice();
if (Movie::IsPlayingInput())
if (NetPlay_GetInput(ISIDevice::m_iDeviceNumber, &PadStatus))
{
}
else if (Movie::IsPlayingInput())
{
Movie::PlayController(&PadStatus, ISIDevice::m_iDeviceNumber);
Movie::InputUpdate();

View File

@ -88,7 +88,7 @@ public:
virtual int RunBuffer(u8* _pBuffer, int _iLength) override;
// Send and Receive pad input from network
static bool NetPlay_GetInput(u8 numPAD, GCPadStatus status, u32 *PADStatus);
static bool NetPlay_GetInput(u8 numPAD, GCPadStatus* status);
static u8 NetPlay_InGamePadToLocalPad(u8 numPAD);
// Return true on new data

View File

@ -103,17 +103,11 @@ bool CSIDevice_GCSteeringWheel::GetData(u32& _Hi, u32& _Low)
Pad::GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus);
Movie::CallGCInputManip(&PadStatus, ISIDevice::m_iDeviceNumber);
u32 netValues[2];
if (NetPlay_GetInput(ISIDevice::m_iDeviceNumber, PadStatus, netValues))
{
_Hi = netValues[0]; // first 4 bytes
_Low = netValues[1]; // last 4 bytes
return true;
}
Movie::SetPolledDevice();
if (Movie::IsPlayingInput())
if (NetPlay_GetInput(ISIDevice::m_iDeviceNumber, &PadStatus))
{
}
else if (Movie::IsPlayingInput())
{
Movie::PlayController(&PadStatus, ISIDevice::m_iDeviceNumber);
Movie::InputUpdate();

View File

@ -88,7 +88,7 @@ public:
virtual int RunBuffer(u8* _pBuffer, int _iLength) override;
// Send and Receive pad input from network
static bool NetPlay_GetInput(u8 numPAD, GCPadStatus status, u32 *PADStatus);
static bool NetPlay_GetInput(u8 numPAD, GCPadStatus* status);
static u8 NetPlay_InGamePadToLocalPad(u8 numPAD);
// Return true on new data

View File

@ -21,24 +21,6 @@ static std::mutex crit_netplay_client;
static NetPlayClient * netplay_client = nullptr;
NetSettings g_NetPlaySettings;
NetPad::NetPad()
{
nHi = 0x00808080;
nLo = 0x80800000;
}
NetPad::NetPad(const GCPadStatus* const pad_status)
{
nHi = (u32)((u8)pad_status->stickY);
nHi |= (u32)((u8)pad_status->stickX << 8);
nHi |= (u32)((u16)pad_status->button << 16);
nHi |= 0x00800000;
nLo = (u8)pad_status->triggerRight;
nLo |= (u32)((u8)pad_status->triggerLeft << 8);
nLo |= (u32)((u8)pad_status->substickY << 16);
nLo |= (u32)((u8)pad_status->substickX << 24);
}
// called from ---GUI--- thread
NetPlayClient::~NetPlayClient()
{
@ -207,12 +189,12 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
case NP_MSG_PAD_DATA :
{
PadMapping map = 0;
NetPad np;
packet >> map >> np.nHi >> np.nLo;
GCPadStatus pad;
packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >> pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight;
// trusting server for good map value (>=0 && <4)
// add to pad buffer
m_pad_buffer[map].Push(np);
m_pad_buffer[map].Push(pad);
}
break;
@ -425,13 +407,13 @@ void NetPlayClient::SendChatMessage(const std::string& msg)
}
// called from ---CPU--- thread
void NetPlayClient::SendPadState(const PadMapping in_game_pad, const NetPad& np)
void NetPlayClient::SendPadState(const PadMapping in_game_pad, const GCPadStatus& pad)
{
// send to server
sf::Packet spac;
spac << (MessageId)NP_MSG_PAD_DATA;
spac << in_game_pad;
spac << np.nHi << np.nLo;
spac << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY << pad.substickX << pad.substickY << pad.triggerLeft << pad.triggerRight;
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
m_socket.Send(spac);
@ -556,7 +538,7 @@ void NetPlayClient::ClearBuffers()
}
// called from ---CPU--- thread
bool NetPlayClient::GetNetPads(const u8 pad_nb, const GCPadStatus* const pad_status, NetPad* const netvalues)
bool NetPlayClient::GetNetPads(const u8 pad_nb, GCPadStatus* pad_status)
{
// The interface for this is extremely silly.
//
@ -589,17 +571,15 @@ bool NetPlayClient::GetNetPads(const u8 pad_nb, const GCPadStatus* const pad_sta
// information given.
if (in_game_num < 4)
{
NetPad np(pad_status);
// adjust the buffer either up or down
// inserting multiple padstates or dropping states
while (m_pad_buffer[in_game_num].Size() <= m_target_buffer_size)
{
// add to buffer
m_pad_buffer[in_game_num].Push(np);
m_pad_buffer[in_game_num].Push(*pad_status);
// send
SendPadState(in_game_num, np);
SendPadState(in_game_num, *pad_status);
}
}
@ -607,7 +587,7 @@ bool NetPlayClient::GetNetPads(const u8 pad_nb, const GCPadStatus* const pad_sta
// retrieved from NetPlay. This could be the value we pushed
// above if we're configured as P1 and the code is trying
// to retrieve data for slot 1.
while (!m_pad_buffer[pad_nb].Pop(*netvalues))
while (!m_pad_buffer[pad_nb].Pop(*pad_status))
{
if (!m_is_running)
return false;
@ -616,23 +596,14 @@ bool NetPlayClient::GetNetPads(const u8 pad_nb, const GCPadStatus* const pad_sta
Common::SleepCurrentThread(1);
}
GCPadStatus tmp;
tmp.stickY = ((u8*)&netvalues->nHi)[0];
tmp.stickX = ((u8*)&netvalues->nHi)[1];
tmp.button = ((u16*)&netvalues->nHi)[1];
tmp.substickX = ((u8*)&netvalues->nLo)[3];
tmp.substickY = ((u8*)&netvalues->nLo)[2];
tmp.triggerLeft = ((u8*)&netvalues->nLo)[1];
tmp.triggerRight = ((u8*)&netvalues->nLo)[0];
if (Movie::IsRecordingInput())
{
Movie::RecordInput(&tmp, pad_nb);
Movie::RecordInput(pad_status, pad_nb);
Movie::InputUpdate();
}
else
{
Movie::CheckPadStatus(&tmp, pad_nb);
Movie::CheckPadStatus(pad_status, pad_nb);
}
return true;
@ -844,12 +815,12 @@ u8 NetPlayClient::LocalWiimoteToInGameWiimote(u8 local_pad)
// called from ---CPU--- thread
// Actual Core function which is called on every frame
bool CSIDevice_GCController::NetPlay_GetInput(u8 numPAD, GCPadStatus PadStatus, u32 *PADStatus)
bool CSIDevice_GCController::NetPlay_GetInput(u8 numPAD, GCPadStatus* PadStatus)
{
std::lock_guard<std::mutex> lk(crit_netplay_client);
if (netplay_client)
return netplay_client->GetNetPads(numPAD, &PadStatus, (NetPad*)PADStatus);
return netplay_client->GetNetPads(numPAD, PadStatus);
else
return false;
}
@ -864,14 +835,14 @@ bool WiimoteEmu::Wiimote::NetPlay_GetWiimoteData(int wiimote, u8* data, u8 size)
return false;
}
bool CSIDevice_GCSteeringWheel::NetPlay_GetInput(u8 numPAD, GCPadStatus PadStatus, u32 *PADStatus)
bool CSIDevice_GCSteeringWheel::NetPlay_GetInput(u8 numPAD, GCPadStatus* PadStatus)
{
return CSIDevice_GCController::NetPlay_GetInput(numPAD, PadStatus, PADStatus);
return false;
}
bool CSIDevice_DanceMat::NetPlay_GetInput(u8 numPAD, GCPadStatus PadStatus, u32 *PADStatus)
bool CSIDevice_DanceMat::NetPlay_GetInput(u8 numPAD, GCPadStatus* PadStatus)
{
return CSIDevice_GCController::NetPlay_GetInput(numPAD, PadStatus, PADStatus);
return false;
}
// called from ---CPU--- thread

View File

@ -19,16 +19,6 @@
#include "InputCommon/GCPadStatus.h"
class NetPad
{
public:
NetPad();
NetPad(const GCPadStatus* const);
u32 nHi;
u32 nLo;
};
class NetPlayUI
{
public:
@ -76,7 +66,7 @@ public:
// Send and receive pads values
bool WiimoteUpdate(int _number, u8* data, const u8 size);
bool GetNetPads(const u8 pad_nb, const GCPadStatus* const, NetPad* const netvalues);
bool GetNetPads(const u8 pad_nb, GCPadStatus* pad_status);
u8 LocalPadToInGamePad(u8 localPad);
u8 InGamePadToLocalPad(u8 localPad);
@ -93,8 +83,8 @@ protected:
std::recursive_mutex players, send;
} m_crit;
Common::FifoQueue<NetPad> m_pad_buffer[4];
Common::FifoQueue<NetWiimote> m_wiimote_buffer[4];
Common::FifoQueue<GCPadStatus> m_pad_buffer[4];
Common::FifoQueue<NetWiimote> m_wiimote_buffer[4];
NetPlayUI* m_dialog;
sf::SocketTCP m_socket;
@ -118,7 +108,7 @@ protected:
private:
void UpdateDevices();
void SendPadState(const PadMapping in_game_pad, const NetPad& np);
void SendPadState(const PadMapping in_game_pad, const GCPadStatus& np);
void SendWiimoteState(const PadMapping in_game_pad, const NetWiimote& nw);
unsigned int OnData(sf::Packet& packet);

View File

@ -7,6 +7,7 @@
#include "Common/StringUtil.h"
#include "Core/NetPlayServer.h"
#include "InputCommon/GCPadStatus.h"
NetPlayServer::~NetPlayServer()
{
@ -394,8 +395,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket)
break;
PadMapping map = 0;
int hi, lo;
packet >> map >> hi >> lo;
GCPadStatus pad;
packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >> pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight;
// If the data is not from the correct player,
// then disconnect them.
@ -405,7 +406,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket)
// Relay to clients
sf::Packet spac;
spac << (MessageId)NP_MSG_PAD_DATA;
spac << map << hi << lo;
spac << map << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY << pad.substickX << pad.substickY << pad.triggerLeft << pad.triggerRight;
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
SendToClients(spac, player.pid);