Qt/NetPlayDialog: Stop games properly
This commit is contained in:
parent
bbbd886184
commit
f7887a442f
|
@ -1152,6 +1152,15 @@ void NetPlayClient::Stop()
|
||||||
m_gc_pad_event.Set();
|
m_gc_pad_event.Set();
|
||||||
m_wii_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.
|
// Tell the server to stop if we have a pad mapped in game.
|
||||||
if (LocalPlayerHasControllerMapped())
|
if (LocalPlayerHasControllerMapped())
|
||||||
SendStopGamePacket();
|
SendStopGamePacket();
|
||||||
|
|
|
@ -80,6 +80,7 @@ public:
|
||||||
void Stop();
|
void Stop();
|
||||||
bool ChangeGame(const std::string& game);
|
bool ChangeGame(const std::string& game);
|
||||||
void SendChatMessage(const std::string& msg);
|
void SendChatMessage(const std::string& msg);
|
||||||
|
void RequestStopGame();
|
||||||
|
|
||||||
// Send and receive pads values
|
// Send and receive pads values
|
||||||
bool WiimoteUpdate(int _number, u8* data, const u8 size, u8 reporting_mode);
|
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:
|
case NP_MSG_STOP_GAME:
|
||||||
{
|
{
|
||||||
|
if (!m_is_running)
|
||||||
|
break;
|
||||||
|
|
||||||
|
m_is_running = false;
|
||||||
|
|
||||||
// tell clients to stop game
|
// tell clients to stop game
|
||||||
sf::Packet spac;
|
sf::Packet spac;
|
||||||
spac << (MessageId)NP_MSG_STOP_GAME;
|
spac << (MessageId)NP_MSG_STOP_GAME;
|
||||||
|
|
||||||
std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
|
std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
|
||||||
SendToClients(spac);
|
SendToClients(spac);
|
||||||
|
|
||||||
m_is_running = false;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -245,8 +245,12 @@ void NetPlayDialog::ConnectWidgets()
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [=](Core::State state) {
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [=](Core::State state) {
|
||||||
if (state == Core::State::Uninitialized && isVisible())
|
if (isVisible())
|
||||||
GameStatusChanged(false);
|
{
|
||||||
|
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)
|
void NetPlayDialog::BootGame(const std::string& filename)
|
||||||
{
|
{
|
||||||
|
m_got_stop_request = false;
|
||||||
emit Boot(QString::fromStdString(filename));
|
emit Boot(QString::fromStdString(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetPlayDialog::StopGame()
|
void NetPlayDialog::StopGame()
|
||||||
{
|
{
|
||||||
|
if (m_got_stop_request)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_got_stop_request = true;
|
||||||
emit Stop();
|
emit Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,6 +517,9 @@ void NetPlayDialog::OnMsgChangeGame(const std::string& title)
|
||||||
|
|
||||||
void NetPlayDialog::GameStatusChanged(bool running)
|
void NetPlayDialog::GameStatusChanged(bool running)
|
||||||
{
|
{
|
||||||
|
if (!running && !m_got_stop_request)
|
||||||
|
Settings::Instance().GetNetPlayClient()->RequestStopGame();
|
||||||
|
|
||||||
QueueOnObject(this, [this, running] {
|
QueueOnObject(this, [this, running] {
|
||||||
if (Settings::Instance().GetNetPlayServer() != nullptr)
|
if (Settings::Instance().GetNetPlayServer() != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -525,7 +537,6 @@ void NetPlayDialog::GameStatusChanged(bool running)
|
||||||
void NetPlayDialog::OnMsgStartGame()
|
void NetPlayDialog::OnMsgStartGame()
|
||||||
{
|
{
|
||||||
DisplayMessage(tr("Started game"), "green");
|
DisplayMessage(tr("Started game"), "green");
|
||||||
GameStatusChanged(true);
|
|
||||||
|
|
||||||
QueueOnObject(this, [this] {
|
QueueOnObject(this, [this] {
|
||||||
Settings::Instance().GetNetPlayClient()->StartGame(FindGame(m_current_game));
|
Settings::Instance().GetNetPlayClient()->StartGame(FindGame(m_current_game));
|
||||||
|
@ -534,8 +545,6 @@ void NetPlayDialog::OnMsgStartGame()
|
||||||
|
|
||||||
void NetPlayDialog::OnMsgStopGame()
|
void NetPlayDialog::OnMsgStopGame()
|
||||||
{
|
{
|
||||||
DisplayMessage(tr("Stopped game"), "red");
|
|
||||||
GameStatusChanged(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetPlayDialog::OnPadBufferChanged(u32 buffer)
|
void NetPlayDialog::OnPadBufferChanged(u32 buffer)
|
||||||
|
|
|
@ -109,5 +109,6 @@ private:
|
||||||
GameListModel* m_game_list_model = nullptr;
|
GameListModel* m_game_list_model = nullptr;
|
||||||
bool m_use_traversal = false;
|
bool m_use_traversal = false;
|
||||||
bool m_is_copy_button_retry = false;
|
bool m_is_copy_button_retry = false;
|
||||||
|
bool m_got_stop_request = true;
|
||||||
int m_buffer_size = 0;
|
int m_buffer_size = 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue