summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/main.cpp64
-rw-r--r--src/yuzu/main.h7
-rw-r--r--src/yuzu/util/overlay_dialog.cpp6
-rw-r--r--src/yuzu/util/overlay_dialog.h1
4 files changed, 64 insertions, 14 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 820f60e61..66fdbcfed 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -1550,8 +1550,9 @@ void GMainWindow::AllowOSSleep() {
1550 1550
1551bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t program_index) { 1551bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t program_index) {
1552 // Shutdown previous session if the emu thread is still active... 1552 // Shutdown previous session if the emu thread is still active...
1553 if (emu_thread != nullptr) 1553 if (emu_thread != nullptr) {
1554 ShutdownGame(); 1554 ShutdownGame();
1555 }
1555 1556
1556 if (!render_window->InitRenderTarget()) { 1557 if (!render_window->InitRenderTarget()) {
1557 return false; 1558 return false;
@@ -1779,7 +1780,7 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
1779 OnStartGame(); 1780 OnStartGame();
1780} 1781}
1781 1782
1782void GMainWindow::ShutdownGame() { 1783void GMainWindow::OnShutdownBegin() {
1783 if (!emulation_running) { 1784 if (!emulation_running) {
1784 return; 1785 return;
1785 } 1786 }
@@ -1802,13 +1803,41 @@ void GMainWindow::ShutdownGame() {
1802 1803
1803 emit EmulationStopping(); 1804 emit EmulationStopping();
1804 1805
1805 // Wait for emulation thread to complete and delete it 1806 shutdown_timer.setSingleShot(true);
1806 if (system->DebuggerEnabled() || !emu_thread->wait(5000)) { 1807 shutdown_timer.start(system->DebuggerEnabled() ? 0 : 5000);
1808 connect(&shutdown_timer, &QTimer::timeout, this, &GMainWindow::OnEmulationStopTimeExpired);
1809 connect(emu_thread.get(), &QThread::finished, this, &GMainWindow::OnEmulationStopped);
1810
1811 // Disable everything to prevent anything from being triggered here
1812 ui->action_Pause->setEnabled(false);
1813 ui->action_Restart->setEnabled(false);
1814 ui->action_Stop->setEnabled(false);
1815}
1816
1817void GMainWindow::OnShutdownBeginDialog() {
1818 shutdown_dialog =
1819 new OverlayDialog(render_window, *system, QString{}, tr("Closing software..."), QString{},
1820 QString{}, Qt::AlignHCenter | Qt::AlignVCenter);
1821 shutdown_dialog->open();
1822}
1823
1824void GMainWindow::OnEmulationStopTimeExpired() {
1825 if (emu_thread) {
1807 emu_thread->ForceStop(); 1826 emu_thread->ForceStop();
1808 emu_thread->wait();
1809 } 1827 }
1828}
1829
1830void GMainWindow::OnEmulationStopped() {
1831 shutdown_timer.stop();
1832 emu_thread->disconnect();
1833 emu_thread->wait();
1810 emu_thread = nullptr; 1834 emu_thread = nullptr;
1811 1835
1836 if (shutdown_dialog) {
1837 shutdown_dialog->deleteLater();
1838 shutdown_dialog = nullptr;
1839 }
1840
1812 emulation_running = false; 1841 emulation_running = false;
1813 1842
1814 discord_rpc->Update(); 1843 discord_rpc->Update();
@@ -1854,6 +1883,20 @@ void GMainWindow::ShutdownGame() {
1854 1883
1855 // When closing the game, destroy the GLWindow to clear the context after the game is closed 1884 // When closing the game, destroy the GLWindow to clear the context after the game is closed
1856 render_window->ReleaseRenderTarget(); 1885 render_window->ReleaseRenderTarget();
1886
1887 Settings::RestoreGlobalState(system->IsPoweredOn());
1888 system->HIDCore().ReloadInputDevices();
1889 UpdateStatusButtons();
1890}
1891
1892void GMainWindow::ShutdownGame() {
1893 if (!emulation_running) {
1894 return;
1895 }
1896
1897 OnShutdownBegin();
1898 OnEmulationStopTimeExpired();
1899 OnEmulationStopped();
1857} 1900}
1858 1901
1859void GMainWindow::StoreRecentFile(const QString& filename) { 1902void GMainWindow::StoreRecentFile(const QString& filename) {
@@ -2956,11 +2999,8 @@ void GMainWindow::OnStopGame() {
2956 return; 2999 return;
2957 } 3000 }
2958 3001
2959 ShutdownGame(); 3002 OnShutdownBegin();
2960 3003 OnShutdownBeginDialog();
2961 Settings::RestoreGlobalState(system->IsPoweredOn());
2962 system->HIDCore().ReloadInputDevices();
2963 UpdateStatusButtons();
2964} 3004}
2965 3005
2966void GMainWindow::OnLoadComplete() { 3006void GMainWindow::OnLoadComplete() {
@@ -4047,10 +4087,6 @@ void GMainWindow::closeEvent(QCloseEvent* event) {
4047 // Shutdown session if the emu thread is active... 4087 // Shutdown session if the emu thread is active...
4048 if (emu_thread != nullptr) { 4088 if (emu_thread != nullptr) {
4049 ShutdownGame(); 4089 ShutdownGame();
4050
4051 Settings::RestoreGlobalState(system->IsPoweredOn());
4052 system->HIDCore().ReloadInputDevices();
4053 UpdateStatusButtons();
4054 } 4090 }
4055 4091
4056 render_window->close(); 4092 render_window->close();
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index 5b84c7a00..ce1de17ef 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -29,6 +29,7 @@ class GImageInfo;
29class GRenderWindow; 29class GRenderWindow;
30class LoadingScreen; 30class LoadingScreen;
31class MicroProfileDialog; 31class MicroProfileDialog;
32class OverlayDialog;
32class ProfilerWidget; 33class ProfilerWidget;
33class ControllerDialog; 34class ControllerDialog;
34class QLabel; 35class QLabel;
@@ -335,6 +336,10 @@ private slots:
335 void OnReinitializeKeys(ReinitializeKeyBehavior behavior); 336 void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
336 void OnLanguageChanged(const QString& locale); 337 void OnLanguageChanged(const QString& locale);
337 void OnMouseActivity(); 338 void OnMouseActivity();
339 void OnShutdownBegin();
340 void OnShutdownBeginDialog();
341 void OnEmulationStopped();
342 void OnEmulationStopTimeExpired();
338 343
339private: 344private:
340 QString GetGameListErrorRemoving(InstalledEntryType type) const; 345 QString GetGameListErrorRemoving(InstalledEntryType type) const;
@@ -384,6 +389,8 @@ private:
384 GRenderWindow* render_window; 389 GRenderWindow* render_window;
385 GameList* game_list; 390 GameList* game_list;
386 LoadingScreen* loading_screen; 391 LoadingScreen* loading_screen;
392 QTimer shutdown_timer;
393 OverlayDialog* shutdown_dialog;
387 394
388 GameListPlaceholder* game_list_placeholder; 395 GameListPlaceholder* game_list_placeholder;
389 396
diff --git a/src/yuzu/util/overlay_dialog.cpp b/src/yuzu/util/overlay_dialog.cpp
index 3fa3d0afb..25fa789ac 100644
--- a/src/yuzu/util/overlay_dialog.cpp
+++ b/src/yuzu/util/overlay_dialog.cpp
@@ -259,3 +259,9 @@ void OverlayDialog::InputThread() {
259 std::this_thread::sleep_for(std::chrono::milliseconds(50)); 259 std::this_thread::sleep_for(std::chrono::milliseconds(50));
260 } 260 }
261} 261}
262
263void OverlayDialog::keyPressEvent(QKeyEvent* e) {
264 if (!ui->buttonsDialog->isHidden() || e->key() != Qt::Key_Escape) {
265 QDialog::keyPressEvent(e);
266 }
267}
diff --git a/src/yuzu/util/overlay_dialog.h b/src/yuzu/util/overlay_dialog.h
index 39c44393c..872283d61 100644
--- a/src/yuzu/util/overlay_dialog.h
+++ b/src/yuzu/util/overlay_dialog.h
@@ -94,6 +94,7 @@ private:
94 94
95 /// The thread where input is being polled and processed. 95 /// The thread where input is being polled and processed.
96 void InputThread(); 96 void InputThread();
97 void keyPressEvent(QKeyEvent* e) override;
97 98
98 std::unique_ptr<Ui::OverlayDialog> ui; 99 std::unique_ptr<Ui::OverlayDialog> ui;
99 100