NetPlayClient: Consolidate Wiimote buffer waiting code to function.

This commit is contained in:
Admiral H. Curtiss 2022-09-13 01:18:53 +02:00
parent 14f427d4cd
commit c4b3f2302a
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
2 changed files with 22 additions and 20 deletions

View File

@ -2048,6 +2048,22 @@ u64 NetPlayClient::GetInitialRTCValue() const
return m_initial_rtc; return m_initial_rtc;
} }
bool NetPlayClient::WaitForWiimoteBuffer(int _number)
{
while (m_wiimote_buffer[_number].Size() == 0)
{
if (!m_is_running.IsSet())
{
return false;
}
// wait for receiving thread to push some data
m_wii_pad_event.Wait();
}
return true;
}
// called from ---CPU--- thread // called from ---CPU--- thread
bool NetPlayClient::WiimoteUpdate(int _number, u8* data, const std::size_t size, u8 reporting_mode) bool NetPlayClient::WiimoteUpdate(int _number, u8* data, const std::size_t size, u8 reporting_mode)
{ {
@ -2073,16 +2089,8 @@ bool NetPlayClient::WiimoteUpdate(int _number, u8* data, const std::size_t size,
} // unlock players } // unlock players
while (m_wiimote_buffer[_number].Size() == 0) if (!WaitForWiimoteBuffer(_number))
{
if (!m_is_running.IsSet())
{
return false; return false;
}
// wait for receiving thread to push some data
m_wii_pad_event.Wait();
}
m_wiimote_buffer[_number].Pop(nw); m_wiimote_buffer[_number].Pop(nw);
@ -2093,16 +2101,8 @@ bool NetPlayClient::WiimoteUpdate(int _number, u8* data, const std::size_t size,
u32 tries = 0; u32 tries = 0;
while (nw.report_id != reporting_mode) while (nw.report_id != reporting_mode)
{ {
while (m_wiimote_buffer[_number].Size() == 0) if (!WaitForWiimoteBuffer(_number))
{
if (!m_is_running.IsSet())
{
return false; return false;
}
// wait for receiving thread to push some data
m_wii_pad_event.Wait();
}
m_wiimote_buffer[_number].Pop(nw); m_wiimote_buffer[_number].Pop(nw);

View File

@ -252,6 +252,8 @@ private:
void DisplayPlayersPing(); void DisplayPlayersPing();
u32 GetPlayersMaxPing() const; u32 GetPlayersMaxPing() const;
bool WaitForWiimoteBuffer(int _number);
void OnData(sf::Packet& packet); void OnData(sf::Packet& packet);
void OnPlayerJoin(sf::Packet& packet); void OnPlayerJoin(sf::Packet& packet);
void OnPlayerLeave(sf::Packet& packet); void OnPlayerLeave(sf::Packet& packet);