Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netplay: Fix 2nd session on Wiimote netplay #3992

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions Source/Core/Core/NetPlayClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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)
{
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/NetPlayClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class NetPlayClient : public TraversalClientClient

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;

Expand Down