Permalink
Browse files

NetPlay: Sync power button event

This fixes the deadlock on shutdown when Wii Remotes are in use.
  • Loading branch information...
Techjar committed Nov 11, 2018
1 parent 97e3200 commit ef89e4e70c256989ede03d33145ee05be141dc06
@@ -568,6 +568,12 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
}
break;
case NP_MSG_POWER_BUTTON:
{
m_dialog->OnMsgPowerButton();
}
break;
case NP_MSG_PING:
{
u32 ping_key = 0;
@@ -1701,6 +1707,13 @@ void NetPlayClient::RequestStopGame()
SendStopGamePacket();
}
void NetPlayClient::SendPowerButtonEvent()
{
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_POWER_BUTTON);
SendAsync(std::move(packet));
}
// called from ---GUI--- thread
bool NetPlayClient::LocalPlayerHasControllerMapped() const
{
@@ -1883,6 +1896,12 @@ void SetSIPollBatching(bool state)
s_si_poll_batching = state;
}
void SendPowerButtonEvent()
{
ASSERT(IsNetPlayRunning());
netplay_client->SendPowerButtonEvent();
}
void NetPlay_Enable(NetPlayClient* const np)
{
std::lock_guard<std::mutex> lk(crit_netplay_client);
@@ -43,6 +43,7 @@ class NetPlayUI
virtual void OnMsgChangeGame(const std::string& filename) = 0;
virtual void OnMsgStartGame() = 0;
virtual void OnMsgStopGame() = 0;
virtual void OnMsgPowerButton() = 0;
virtual void OnPadBufferChanged(u32 buffer) = 0;
virtual void OnHostInputAuthorityChanged(bool enabled) = 0;
virtual void OnDesync(u32 frame, const std::string& player) = 0;
@@ -102,6 +103,7 @@ class NetPlayClient : public TraversalClientClient
bool ChangeGame(const std::string& game);
void SendChatMessage(const std::string& msg);
void RequestStopGame();
void SendPowerButtonEvent();
// Send and receive pads values
bool WiimoteUpdate(int _number, u8* data, const u8 size, u8 reporting_mode);
@@ -124,6 +124,7 @@ enum
NP_MSG_GAME_STATUS = 0xA4,
NP_MSG_IPL_STATUS = 0xA5,
NP_MSG_HOST_INPUT_AUTHORITY = 0xA6,
NP_MSG_POWER_BUTTON = 0xA7,
NP_MSG_TIMEBASE = 0xB0,
NP_MSG_DESYNC_DETECTED = 0xB1,
@@ -180,4 +181,5 @@ IOS::HLE::FS::FileSystem* GetWiiSyncFS();
void SetWiiSyncFS(std::unique_ptr<IOS::HLE::FS::FileSystem> fs);
void ClearWiiSyncFS();
void SetSIPollBatching(bool state);
void SendPowerButtonEvent();
} // namespace NetPlay
@@ -743,6 +743,14 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_POWER_BUTTON:
{
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_POWER_BUTTON);
SendToClients(spac, player.pid);
}
break;
case NP_MSG_TIMEBASE:
{
u64 timebase = Common::PacketReadU64(packet);
@@ -744,6 +744,10 @@ bool MainWindow::RequestStop()
if (Core::GetState() == Core::State::Paused)
Core::SetState(Core::State::Running);
// Tell NetPlay about the power event
if (NetPlay::IsNetPlayRunning())
NetPlay::SendPowerButtonEvent();
return true;
}
@@ -54,6 +54,7 @@
#include "UICommon/DiscordPresence.h"
#include "UICommon/GameFile.h"
#include "UICommon/UICommon.h"
#include "VideoCommon/VideoConfig.h"
@@ -796,6 +797,13 @@ void NetPlayDialog::OnMsgStopGame()
QueueOnObject(this, [this] { UpdateDiscordPresence(); });
}
void NetPlayDialog::OnMsgPowerButton()
{
if (!Core::IsRunning())
return;
QueueOnObject(this, [] { UICommon::TriggerSTMPowerEvent(); });
}
void NetPlayDialog::OnPadBufferChanged(u32 buffer)
{
QueueOnObject(this, [this, buffer] {
@@ -46,6 +46,7 @@ class NetPlayDialog : public QDialog, public NetPlay::NetPlayUI
void OnMsgChangeGame(const std::string& filename) override;
void OnMsgStartGame() override;
void OnMsgStopGame() override;
void OnMsgPowerButton() override;
void OnPadBufferChanged(u32 buffer) override;
void OnHostInputAuthorityChanged(bool enabled) override;
void OnDesync(u32 frame, const std::string& player) override;

0 comments on commit ef89e4e

Please sign in to comment.