From c4b3f2302a1b389935427f903d83a9538c6400f2 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Tue, 13 Sep 2022 01:18:53 +0200 Subject: [PATCH 1/3] NetPlayClient: Consolidate Wiimote buffer waiting code to function. --- Source/Core/Core/NetPlayClient.cpp | 40 +++++++++++++++--------------- Source/Core/Core/NetPlayClient.h | 2 ++ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index e756a9b603..8165c5b1ec 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -2048,6 +2048,22 @@ u64 NetPlayClient::GetInitialRTCValue() const 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 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 - 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(); - } + if (!WaitForWiimoteBuffer(_number)) + return false; 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; while (nw.report_id != reporting_mode) { - 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(); - } + if (!WaitForWiimoteBuffer(_number)) + return false; m_wiimote_buffer[_number].Pop(nw); diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index d3d0273325..d09648f173 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -252,6 +252,8 @@ private: void DisplayPlayersPing(); u32 GetPlayersMaxPing() const; + bool WaitForWiimoteBuffer(int _number); + void OnData(sf::Packet& packet); void OnPlayerJoin(sf::Packet& packet); void OnPlayerLeave(sf::Packet& packet); From 35f6d12accd1cf2ba0ce60037e98bbe58bf5e5ae Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Tue, 13 Sep 2022 01:22:51 +0200 Subject: [PATCH 2/3] NetPlayClient: Consolidate stopping code to function. --- Source/Core/Core/NetPlayClient.cpp | 17 ++++++++--------- Source/Core/Core/NetPlayClient.h | 1 + 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 8165c5b1ec..cfe22dc2f2 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -2244,8 +2244,7 @@ void NetPlayClient::SendPadHostPoll(const PadIndex pad_num) SendAsync(std::move(packet)); } -// called from ---GUI--- thread and ---NETPLAY--- thread (client side) -bool NetPlayClient::StopGame() +void NetPlayClient::InvokeStop() { m_is_running.Clear(); @@ -2254,6 +2253,12 @@ bool NetPlayClient::StopGame() m_wii_pad_event.Set(); m_first_pad_status_received_event.Set(); m_wait_on_input_event.Set(); +} + +// called from ---GUI--- thread and ---NETPLAY--- thread (client side) +bool NetPlayClient::StopGame() +{ + InvokeStop(); NetPlay_Disable(); @@ -2269,13 +2274,7 @@ void NetPlayClient::Stop() if (!m_is_running.IsSet()) return; - m_is_running.Clear(); - - // 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(); + InvokeStop(); // Tell the server to stop if we have a pad mapped in game. if (LocalPlayerHasControllerMapped()) diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index d09648f173..36fa2cc31a 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -117,6 +117,7 @@ public: // Called from the GUI thread. bool IsConnected() const { return m_is_connected; } bool StartGame(const std::string& path); + void InvokeStop(); bool StopGame(); void Stop(); bool ChangeGame(const std::string& game); From bf331ffa45f12b305aae74033c8f7dabe073a8c9 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Tue, 13 Sep 2022 01:23:17 +0200 Subject: [PATCH 3/3] NetPlayClient: Treat power button event as a netplay stop. --- Source/Core/Core/NetPlayClient.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index cfe22dc2f2..ddba519b8c 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -910,6 +910,7 @@ void NetPlayClient::OnStopGame(sf::Packet& packet) void NetPlayClient::OnPowerButton() { + InvokeStop(); m_dialog->OnMsgPowerButton(); }