Merge pull request #11059 from AdmiralCurtiss/netplay-graceful-shutdown

NetPlayClient: Treat power button event as a netplay stop.
This commit is contained in:
Admiral H. Curtiss 2022-09-18 00:00:44 +02:00 committed by GitHub
commit 69ad2cc4d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 29 deletions

View File

@ -910,6 +910,7 @@ void NetPlayClient::OnStopGame(sf::Packet& packet)
void NetPlayClient::OnPowerButton() void NetPlayClient::OnPowerButton()
{ {
InvokeStop();
m_dialog->OnMsgPowerButton(); m_dialog->OnMsgPowerButton();
} }
@ -2048,6 +2049,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 +2090,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))
{ return false;
if (!m_is_running.IsSet())
{
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 +2102,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))
{ return false;
if (!m_is_running.IsSet())
{
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);
@ -2244,8 +2245,7 @@ void NetPlayClient::SendPadHostPoll(const PadIndex pad_num)
SendAsync(std::move(packet)); SendAsync(std::move(packet));
} }
// called from ---GUI--- thread and ---NETPLAY--- thread (client side) void NetPlayClient::InvokeStop()
bool NetPlayClient::StopGame()
{ {
m_is_running.Clear(); m_is_running.Clear();
@ -2254,6 +2254,12 @@ bool NetPlayClient::StopGame()
m_wii_pad_event.Set(); m_wii_pad_event.Set();
m_first_pad_status_received_event.Set(); m_first_pad_status_received_event.Set();
m_wait_on_input_event.Set(); m_wait_on_input_event.Set();
}
// called from ---GUI--- thread and ---NETPLAY--- thread (client side)
bool NetPlayClient::StopGame()
{
InvokeStop();
NetPlay_Disable(); NetPlay_Disable();
@ -2269,13 +2275,7 @@ void NetPlayClient::Stop()
if (!m_is_running.IsSet()) if (!m_is_running.IsSet())
return; return;
m_is_running.Clear(); InvokeStop();
// stop waiting for input
m_gc_pad_event.Set();
m_wii_pad_event.Set();
m_first_pad_status_received_event.Set();
m_wait_on_input_event.Set();
// Tell the server to stop if we have a pad mapped in game. // Tell the server to stop if we have a pad mapped in game.
if (LocalPlayerHasControllerMapped()) if (LocalPlayerHasControllerMapped())

View File

@ -117,6 +117,7 @@ public:
// Called from the GUI thread. // Called from the GUI thread.
bool IsConnected() const { return m_is_connected; } bool IsConnected() const { return m_is_connected; }
bool StartGame(const std::string& path); bool StartGame(const std::string& path);
void InvokeStop();
bool StopGame(); bool StopGame();
void Stop(); void Stop();
bool ChangeGame(const std::string& game); bool ChangeGame(const std::string& game);
@ -252,6 +253,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);