Misc netplay cleanup.

This commit is contained in:
Rachel Bryk 2013-08-07 10:10:40 -04:00
parent d0f05291e7
commit 011bcfee34
4 changed files with 15 additions and 62 deletions

View File

@ -265,7 +265,7 @@ void CWII_IPC_HLE_WiiMote::ExecuteL2capCmd(u8* _pData, u32 _Size)
_dbg_assert_msg_(WII_IPC_WIIMOTE, DoesChannelExist(pHeader->dcid), "L2CAP: SendACLPacket to unknown channel %i", pHeader->dcid); _dbg_assert_msg_(WII_IPC_WIIMOTE, DoesChannelExist(pHeader->dcid), "L2CAP: SendACLPacket to unknown channel %i", pHeader->dcid);
CChannelMap::iterator itr= m_Channel.find(pHeader->dcid); CChannelMap::iterator itr= m_Channel.find(pHeader->dcid);
const int number = NetPlay_GetWiimoteNum(m_ConnectionHandle & 0xFF); const int number = m_ConnectionHandle & 0xFF;
if (itr != m_Channel.end()) if (itr != m_Channel.end())
{ {

View File

@ -56,7 +56,6 @@ public:
void ReceiveL2capData(u16 scid, const void* _pData, u32 _Size); // From wiimote void ReceiveL2capData(u16 scid, const void* _pData, u32 _Size); // From wiimote
int NetPlay_GetWiimoteNum(int _number); int NetPlay_GetWiimoteNum(int _number);
bool NetPlay_WiimoteInput(int _number, u16 _channelID, const void* _pData, u32& _Size);
void EventConnectionAccepted(); void EventConnectionAccepted();
void EventDisconnect(); void EventDisconnect();

View File

@ -263,7 +263,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
delete[] data; delete[] data;
// trusting server for good map value (>=0 && <4) // trusting server for good map value (>=0 && <4)
// add to pad buffer // add to wiimote buffer
m_wiimote_buffer[(unsigned)map].Push(nw); m_wiimote_buffer[(unsigned)map].Push(nw);
} }
break; break;
@ -455,13 +455,6 @@ bool NetPlayClient::StartGame(const std::string &path)
{ {
std::lock_guard<std::recursive_mutex> lkg(m_crit.game); std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
//wtf?
if (m_target_buffer_size > 100)
{
m_target_buffer_size = 20;
NOTICE_LOG(NETPLAY,"WHYYYYYYYYYYYY");
}
// tell server i started the game // tell server i started the game
sf::Packet spac; sf::Packet spac;
spac << (MessageId)NP_MSG_START_GAME; spac << (MessageId)NP_MSG_START_GAME;
@ -487,12 +480,6 @@ bool NetPlayClient::StartGame(const std::string &path)
// boot game // boot game
m_dialog->BootGame(path); m_dialog->BootGame(path);
// temporary
//NetWiimote nw;
//for (unsigned int i = 0; i<4; ++i)
//for (unsigned int f = 0; f<2; ++f)
//m_wiimote_buffer[i].Push(nw);
return true; return true;
} }
@ -584,7 +571,7 @@ bool NetPlayClient::WiimoteUpdate(int _number, u8* data, u8 size)
// in game mapping for this local wiimote // in game mapping for this local wiimote
unsigned int in_game_num = m_local_player->wiimote_map[_number]; unsigned int in_game_num = m_local_player->wiimote_map[_number];
// does this local pad map in game? // does this local wiimote map in game?
if (in_game_num < 4) if (in_game_num < 4)
{ {
static u8 previousSize = 0; static u8 previousSize = 0;
@ -595,7 +582,6 @@ bool NetPlayClient::WiimoteUpdate(int _number, u8* data, u8 size)
m_wiimote_buffer[_number].Clear(); m_wiimote_buffer[_number].Clear();
} }
//m_wiimote_input[in_game_num].data.resize(m_wiimote_input[_number].size + 1);
m_wiimote_input[in_game_num].data.assign(data, data + size); m_wiimote_input[in_game_num].data.assign(data, data + size);
m_wiimote_input[in_game_num].size = size; m_wiimote_input[in_game_num].size = size;
while (m_wiimote_buffer[in_game_num].Size() <= m_target_buffer_size) while (m_wiimote_buffer[in_game_num].Size() <= m_target_buffer_size)
@ -623,15 +609,19 @@ bool NetPlayClient::WiimoteUpdate(int _number, u8* data, u8 size)
// This is either a desync, or the reporting mode changed. No way to really be sure... // This is either a desync, or the reporting mode changed. No way to really be sure...
if (size != nw.size) if (size != nw.size)
{ {
u8 tries = 0;
// Clear the buffer and wait for new input, in case it was just the reporting mode changing as expected. // Clear the buffer and wait for new input, in case it was just the reporting mode changing as expected.
do do
{ {
m_wiimote_buffer[_number].Pop(nw); while (!m_wiimote_buffer[_number].Pop(nw))
{
Common::SleepCurrentThread(1); Common::SleepCurrentThread(1);
if (false == m_is_running) if (false == m_is_running)
return false; return false;
}
// TODO: break if this runs too long; it probably desynced if it runs for longer than the buffer size ++tries;
if (tries > m_target_buffer_size)
break;
} while (nw.size != size); } while (nw.size != size);
// If it still mismatches, it surely desynced // If it still mismatches, it surely desynced
@ -746,43 +736,6 @@ u8 CSIDevice_DanceMat::NetPlay_GetPadNum(u8 numPAD)
return CSIDevice_GCController::NetPlay_GetPadNum(numPAD); return CSIDevice_GCController::NetPlay_GetPadNum(numPAD);
} }
// called from ---CPU--- thread
//
int CWII_IPC_HLE_WiiMote::NetPlay_GetWiimoteNum(int _number)
{
// std::lock_guard<std::mutex> lk(crit_netplay_client);
// if (netplay_client)
// return netplay_client->GetPadNum(_number+4);
// else
return _number;
}
// called from ---CPU--- thread
// intercept wiimote input callback
//bool CWII_IPC_HLE_WiiMote::NetPlay_WiimoteInput(int _number, u16 _channelID, const void* _pData, u32& _Size)
bool CWII_IPC_HLE_WiiMote::NetPlay_WiimoteInput(int, u16, const void*, u32&)
{
std::lock_guard<std::mutex> lk(crit_netplay_client);
if (netplay_client)
//{
// if (_Size >= RPT_SIZE_HACK)
// {
// _Size -= RPT_SIZE_HACK;
// return false;
// }
// else
// {
// netplay_client->WiimoteInput(_number, _channelID, _pData, _Size);
// // don't use this packet
return true;
// }
//}
else
return false;
}
bool NetPlay::IsNetPlayRunning() bool NetPlay::IsNetPlayRunning()
{ {
return netplay_client != NULL; return netplay_client != NULL;

View File

@ -49,6 +49,7 @@ NetPlayServer::NetPlayServer(const u16 port) : is_connected(false), m_is_running
m_do_loop = true; m_do_loop = true;
m_selector.Add(m_socket); m_selector.Add(m_socket);
m_thread = std::thread(std::mem_fun(&NetPlayServer::ThreadFunc), this); m_thread = std::thread(std::mem_fun(&NetPlayServer::ThreadFunc), this);
m_target_buffer_size = 20;
} }
} }