Merge pull request #7209 from spycrab/netplay_stop
Qt/NetPlay: Fix not being able to stop NetPlay games properly
This commit is contained in:
commit
7cbb111703
|
@ -237,7 +237,7 @@ static void ResetRumble()
|
|||
// Called from GUI thread
|
||||
void Stop() // - Hammertime!
|
||||
{
|
||||
if (GetState() == State::Stopping)
|
||||
if (GetState() == State::Stopping || GetState() == State::Uninitialized)
|
||||
return;
|
||||
|
||||
const SConfig& _CoreParameter = SConfig::GetInstance();
|
||||
|
|
|
@ -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 @@ public:
|
|||
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;
|
||||
|
||||
|
|
|
@ -1041,7 +1041,7 @@ void MainWindow::NetPlayInit()
|
|||
|
||||
connect(m_netplay_dialog, &NetPlayDialog::Boot, this,
|
||||
[this](const QString& path) { StartGame(path); });
|
||||
connect(m_netplay_dialog, &NetPlayDialog::Stop, this, &MainWindow::RequestStop);
|
||||
connect(m_netplay_dialog, &NetPlayDialog::Stop, this, &MainWindow::ForceStop);
|
||||
connect(m_netplay_dialog, &NetPlayDialog::rejected, this, &MainWindow::NetPlayQuit);
|
||||
connect(m_netplay_setup_dialog, &NetPlaySetupDialog::Join, this, &MainWindow::NetPlayJoin);
|
||||
connect(m_netplay_setup_dialog, &NetPlaySetupDialog::Host, this, &MainWindow::NetPlayHost);
|
||||
|
|
|
@ -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 @@ private:
|
|||
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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue