Merge pull request #3992 from mimimi085181/wiimote-netplay-fix-second-session

Netplay: Fix 2nd session on Wiimote netplay
This commit is contained in:
Pierre Bourdon 2016-07-08 23:33:21 +02:00 committed by GitHub
commit 1be5f23d9f
2 changed files with 8 additions and 7 deletions

View File

@ -722,6 +722,7 @@ bool NetPlayClient::StartGame(const std::string& path)
// Needed to prevent locking up at boot if (when) the wiimotes connect out of order.
NetWiimote nw;
nw.resize(4, 0);
m_wiimote_current_data_size = {4, 4, 4, 4};
for (unsigned int w = 0; w < 4; ++w)
{
@ -923,7 +924,6 @@ bool NetPlayClient::GetNetPads(const u8 pad_nb, GCPadStatus* pad_status)
bool NetPlayClient::WiimoteUpdate(int _number, u8* data, const u8 size)
{
NetWiimote nw;
static u8 previousSize[4] = {4, 4, 4, 4};
{
std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
@ -932,7 +932,7 @@ bool NetPlayClient::WiimoteUpdate(int _number, u8* data, const u8 size)
// does this local Wiimote map in game?
if (in_game_num < 4)
{
if (previousSize[in_game_num] == size)
if (m_wiimote_current_data_size[in_game_num] == size)
{
nw.assign(data, data + size);
do
@ -960,13 +960,13 @@ bool NetPlayClient::WiimoteUpdate(int _number, u8* data, const u8 size)
m_wiimote_buffer[in_game_num].Push(nw);
m_wiimote_buffer[in_game_num].Push(nw);
m_wiimote_buffer[in_game_num].Push(nw);
previousSize[in_game_num] = size;
m_wiimote_current_data_size[in_game_num] = size;
}
}
} // unlock players
while (previousSize[_number] == size && !m_wiimote_buffer[_number].Pop(nw))
while (m_wiimote_current_data_size[_number] == size && !m_wiimote_buffer[_number].Pop(nw))
{
// wait for receiving thread to push some data
Common::SleepCurrentThread(1);
@ -975,7 +975,7 @@ bool NetPlayClient::WiimoteUpdate(int _number, u8* data, const u8 size)
}
// Use a blank input, since we may not have any valid input.
if (previousSize[_number] != size)
if (m_wiimote_current_data_size[_number] != size)
{
nw.resize(size, 0);
m_wiimote_buffer[_number].Push(nw);
@ -989,7 +989,7 @@ bool NetPlayClient::WiimoteUpdate(int _number, u8* data, const u8 size)
// until we reach a good input
if (nw.size() != size)
{
u8 tries = 0;
u32 tries = 0;
// Clear the buffer and wait for new input, since we probably just changed reporting mode.
while (nw.size() != size)
{
@ -1012,7 +1012,7 @@ bool NetPlayClient::WiimoteUpdate(int _number, u8* data, const u8 size)
}
}
previousSize[_number] = size;
m_wiimote_current_data_size[_number] = size;
memcpy(data, nw.data(), size);
return true;
}

View File

@ -99,6 +99,7 @@ protected:
std::array<Common::FifoQueue<GCPadStatus>, 4> m_pad_buffer;
std::array<Common::FifoQueue<NetWiimote>, 4> m_wiimote_buffer;
std::array<u32, 4> m_wiimote_current_data_size;
NetPlayUI* m_dialog = nullptr;