Permalink
Browse files

Qt/NetPlayDialog: Stop games properly

  • Loading branch information...
spycrab committed Jul 3, 2018
1 parent bbbd886 commit f7887a442f675a90d824a3bd4ca0929b9f78200e
@@ -1152,6 +1152,15 @@ void NetPlayClient::Stop()
m_gc_pad_event.Set();
m_wii_pad_event.Set();
// Tell the server to stop if we have a pad mapped in game.
if (LocalPlayerHasControllerMapped())
SendStopGamePacket();
else
StopGame();
}
void NetPlayClient::RequestStopGame()
{
// Tell the server to stop if we have a pad mapped in game.
if (LocalPlayerHasControllerMapped())
SendStopGamePacket();
@@ -80,6 +80,7 @@ class NetPlayClient : public TraversalClientClient
void Stop();
bool ChangeGame(const std::string& game);
void SendChatMessage(const std::string& msg);
void RequestStopGame();
// Send and receive pads values
bool WiimoteUpdate(int _number, u8* data, const u8 size, u8 reporting_mode);
@@ -607,14 +607,17 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
case NP_MSG_STOP_GAME:
{
if (!m_is_running)
break;
m_is_running = false;
// tell clients to stop game
sf::Packet spac;
spac << (MessageId)NP_MSG_STOP_GAME;
std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
SendToClients(spac);
m_is_running = false;
}
break;
@@ -245,8 +245,12 @@ void NetPlayDialog::ConnectWidgets()
});
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [=](Core::State state) {
if (state == Core::State::Uninitialized && isVisible())
GameStatusChanged(false);
if (isVisible())
{
GameStatusChanged(state != Core::State::Uninitialized);
if (state == Core::State::Uninitialized)
DisplayMessage(tr("Stopped game"), "red");
}
});
}
@@ -452,11 +456,16 @@ void NetPlayDialog::UpdateGUI()
void NetPlayDialog::BootGame(const std::string& filename)
{
m_got_stop_request = false;
emit Boot(QString::fromStdString(filename));
}
void NetPlayDialog::StopGame()
{
if (m_got_stop_request)
return;
m_got_stop_request = true;
emit Stop();
}
@@ -508,6 +517,9 @@ void NetPlayDialog::OnMsgChangeGame(const std::string& title)
void NetPlayDialog::GameStatusChanged(bool running)
{
if (!running && !m_got_stop_request)
Settings::Instance().GetNetPlayClient()->RequestStopGame();
QueueOnObject(this, [this, running] {
if (Settings::Instance().GetNetPlayServer() != nullptr)
{
@@ -525,7 +537,6 @@ void NetPlayDialog::GameStatusChanged(bool running)
void NetPlayDialog::OnMsgStartGame()
{
DisplayMessage(tr("Started game"), "green");
GameStatusChanged(true);
QueueOnObject(this, [this] {
Settings::Instance().GetNetPlayClient()->StartGame(FindGame(m_current_game));
@@ -534,8 +545,6 @@ void NetPlayDialog::OnMsgStartGame()
void NetPlayDialog::OnMsgStopGame()
{
DisplayMessage(tr("Stopped game"), "red");
GameStatusChanged(false);
}
void NetPlayDialog::OnPadBufferChanged(u32 buffer)
@@ -109,5 +109,6 @@ class NetPlayDialog : public QDialog, public NetPlayUI
GameListModel* m_game_list_model = nullptr;
bool m_use_traversal = false;
bool m_is_copy_button_retry = false;
bool m_got_stop_request = true;
int m_buffer_size = 0;
};

0 comments on commit f7887a4

Please sign in to comment.