diff options
| author | 2021-10-02 01:06:48 -0700 | |
|---|---|---|
| committer | 2021-10-02 01:06:48 -0700 | |
| commit | ae3e51c795ea72dd1eaea64d44b94afab7d74007 (patch) | |
| tree | 89860f4f5df991336bab7332a77e76bb58e1047f | |
| parent | Merge pull request #7102 from Morph1984/remove-boxcat (diff) | |
| parent | service: am: Make use of Exit to exit the currently running application (diff) | |
| download | yuzu-ae3e51c795ea72dd1eaea64d44b94afab7d74007.tar.gz yuzu-ae3e51c795ea72dd1eaea64d44b94afab7d74007.tar.xz yuzu-ae3e51c795ea72dd1eaea64d44b94afab7d74007.zip | |
Merge pull request #7093 from Morph1984/exit
core: Properly shutdown and exit the running application when ISelfController::Exit is called
| -rw-r--r-- | src/core/core.cpp | 13 | ||||
| -rw-r--r-- | src/core/core.h | 12 | ||||
| -rw-r--r-- | src/core/hle/service/am/am.cpp | 4 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.cpp | 5 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.h | 4 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 7 | ||||
| -rw-r--r-- | src/yuzu/main.h | 1 |
7 files changed, 44 insertions, 2 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index 50d5dab4b..bb268a319 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -421,6 +421,7 @@ struct System::Impl { | |||
| 421 | bool is_async_gpu{}; | 421 | bool is_async_gpu{}; |
| 422 | 422 | ||
| 423 | ExecuteProgramCallback execute_program_callback; | 423 | ExecuteProgramCallback execute_program_callback; |
| 424 | ExitCallback exit_callback; | ||
| 424 | 425 | ||
| 425 | std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{}; | 426 | std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{}; |
| 426 | std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_dynarmic{}; | 427 | std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_dynarmic{}; |
| @@ -798,6 +799,18 @@ void System::ExecuteProgram(std::size_t program_index) { | |||
| 798 | } | 799 | } |
| 799 | } | 800 | } |
| 800 | 801 | ||
| 802 | void System::RegisterExitCallback(ExitCallback&& callback) { | ||
| 803 | impl->exit_callback = std::move(callback); | ||
| 804 | } | ||
| 805 | |||
| 806 | void System::Exit() { | ||
| 807 | if (impl->exit_callback) { | ||
| 808 | impl->exit_callback(); | ||
| 809 | } else { | ||
| 810 | LOG_CRITICAL(Core, "exit_callback must be initialized by the frontend"); | ||
| 811 | } | ||
| 812 | } | ||
| 813 | |||
| 801 | void System::ApplySettings() { | 814 | void System::ApplySettings() { |
| 802 | if (IsPoweredOn()) { | 815 | if (IsPoweredOn()) { |
| 803 | Renderer().RefreshBaseSettings(); | 816 | Renderer().RefreshBaseSettings(); |
diff --git a/src/core/core.h b/src/core/core.h index 715ab88e7..a796472b2 100644 --- a/src/core/core.h +++ b/src/core/core.h | |||
| @@ -387,6 +387,18 @@ public: | |||
| 387 | */ | 387 | */ |
| 388 | void ExecuteProgram(std::size_t program_index); | 388 | void ExecuteProgram(std::size_t program_index); |
| 389 | 389 | ||
| 390 | /// Type used for the frontend to designate a callback for System to exit the application. | ||
| 391 | using ExitCallback = std::function<void()>; | ||
| 392 | |||
| 393 | /** | ||
| 394 | * Registers a callback from the frontend for System to exit the application. | ||
| 395 | * @param callback Callback from the frontend to exit the application. | ||
| 396 | */ | ||
| 397 | void RegisterExitCallback(ExitCallback&& callback); | ||
| 398 | |||
| 399 | /// Instructs the frontend to exit the application. | ||
| 400 | void Exit(); | ||
| 401 | |||
| 390 | /// Applies any changes to settings to this core instance. | 402 | /// Applies any changes to settings to this core instance. |
| 391 | void ApplySettings(); | 403 | void ApplySettings(); |
| 392 | 404 | ||
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 8c2e2f920..49e9787a4 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp | |||
| @@ -332,10 +332,10 @@ ISelfController::~ISelfController() = default; | |||
| 332 | void ISelfController::Exit(Kernel::HLERequestContext& ctx) { | 332 | void ISelfController::Exit(Kernel::HLERequestContext& ctx) { |
| 333 | LOG_DEBUG(Service_AM, "called"); | 333 | LOG_DEBUG(Service_AM, "called"); |
| 334 | 334 | ||
| 335 | system.Shutdown(); | ||
| 336 | |||
| 337 | IPC::ResponseBuilder rb{ctx, 2}; | 335 | IPC::ResponseBuilder rb{ctx, 2}; |
| 338 | rb.Push(ResultSuccess); | 336 | rb.Push(ResultSuccess); |
| 337 | |||
| 338 | system.Exit(); | ||
| 339 | } | 339 | } |
| 340 | 340 | ||
| 341 | void ISelfController::LockExit(Kernel::HLERequestContext& ctx) { | 341 | void ISelfController::LockExit(Kernel::HLERequestContext& ctx) { |
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 1519a46ed..8b9e186b0 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp | |||
| @@ -302,12 +302,17 @@ GRenderWindow::GRenderWindow(GMainWindow* parent, EmuThread* emu_thread_, | |||
| 302 | connect(this, &GRenderWindow::FirstFrameDisplayed, parent, &GMainWindow::OnLoadComplete); | 302 | connect(this, &GRenderWindow::FirstFrameDisplayed, parent, &GMainWindow::OnLoadComplete); |
| 303 | connect(this, &GRenderWindow::ExecuteProgramSignal, parent, &GMainWindow::OnExecuteProgram, | 303 | connect(this, &GRenderWindow::ExecuteProgramSignal, parent, &GMainWindow::OnExecuteProgram, |
| 304 | Qt::QueuedConnection); | 304 | Qt::QueuedConnection); |
| 305 | connect(this, &GRenderWindow::ExitSignal, parent, &GMainWindow::OnExit, Qt::QueuedConnection); | ||
| 305 | } | 306 | } |
| 306 | 307 | ||
| 307 | void GRenderWindow::ExecuteProgram(std::size_t program_index) { | 308 | void GRenderWindow::ExecuteProgram(std::size_t program_index) { |
| 308 | emit ExecuteProgramSignal(program_index); | 309 | emit ExecuteProgramSignal(program_index); |
| 309 | } | 310 | } |
| 310 | 311 | ||
| 312 | void GRenderWindow::Exit() { | ||
| 313 | emit ExitSignal(); | ||
| 314 | } | ||
| 315 | |||
| 311 | GRenderWindow::~GRenderWindow() { | 316 | GRenderWindow::~GRenderWindow() { |
| 312 | input_subsystem->Shutdown(); | 317 | input_subsystem->Shutdown(); |
| 313 | } | 318 | } |
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index 402dd2ee1..54c4e2142 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h | |||
| @@ -181,6 +181,9 @@ public: | |||
| 181 | */ | 181 | */ |
| 182 | void ExecuteProgram(std::size_t program_index); | 182 | void ExecuteProgram(std::size_t program_index); |
| 183 | 183 | ||
| 184 | /// Instructs the window to exit the application. | ||
| 185 | void Exit(); | ||
| 186 | |||
| 184 | public slots: | 187 | public slots: |
| 185 | void OnEmulationStarting(EmuThread* emu_thread); | 188 | void OnEmulationStarting(EmuThread* emu_thread); |
| 186 | void OnEmulationStopping(); | 189 | void OnEmulationStopping(); |
| @@ -191,6 +194,7 @@ signals: | |||
| 191 | void Closed(); | 194 | void Closed(); |
| 192 | void FirstFrameDisplayed(); | 195 | void FirstFrameDisplayed(); |
| 193 | void ExecuteProgramSignal(std::size_t program_index); | 196 | void ExecuteProgramSignal(std::size_t program_index); |
| 197 | void ExitSignal(); | ||
| 194 | void MouseActivity(); | 198 | void MouseActivity(); |
| 195 | 199 | ||
| 196 | private: | 200 | private: |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 3c2824362..0bd0c5b04 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -1384,6 +1384,9 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t | |||
| 1384 | system.RegisterExecuteProgramCallback( | 1384 | system.RegisterExecuteProgramCallback( |
| 1385 | [this](std::size_t program_index) { render_window->ExecuteProgram(program_index); }); | 1385 | [this](std::size_t program_index) { render_window->ExecuteProgram(program_index); }); |
| 1386 | 1386 | ||
| 1387 | // Register an Exit callback such that Core can exit the currently running application. | ||
| 1388 | system.RegisterExitCallback([this]() { render_window->Exit(); }); | ||
| 1389 | |||
| 1387 | connect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); | 1390 | connect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); |
| 1388 | connect(render_window, &GRenderWindow::MouseActivity, this, &GMainWindow::OnMouseActivity); | 1391 | connect(render_window, &GRenderWindow::MouseActivity, this, &GMainWindow::OnMouseActivity); |
| 1389 | // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views | 1392 | // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views |
| @@ -2469,6 +2472,10 @@ void GMainWindow::OnExecuteProgram(std::size_t program_index) { | |||
| 2469 | BootGame(last_filename_booted, 0, program_index); | 2472 | BootGame(last_filename_booted, 0, program_index); |
| 2470 | } | 2473 | } |
| 2471 | 2474 | ||
| 2475 | void GMainWindow::OnExit() { | ||
| 2476 | OnStopGame(); | ||
| 2477 | } | ||
| 2478 | |||
| 2472 | void GMainWindow::ErrorDisplayDisplayError(QString error_code, QString error_text) { | 2479 | void GMainWindow::ErrorDisplayDisplayError(QString error_code, QString error_text) { |
| 2473 | OverlayDialog dialog(render_window, Core::System::GetInstance(), error_code, error_text, | 2480 | OverlayDialog dialog(render_window, Core::System::GetInstance(), error_code, error_text, |
| 2474 | QString{}, tr("OK"), Qt::AlignLeft | Qt::AlignVCenter); | 2481 | QString{}, tr("OK"), Qt::AlignLeft | Qt::AlignVCenter); |
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 36eed6103..60ce01471 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -153,6 +153,7 @@ signals: | |||
| 153 | public slots: | 153 | public slots: |
| 154 | void OnLoadComplete(); | 154 | void OnLoadComplete(); |
| 155 | void OnExecuteProgram(std::size_t program_index); | 155 | void OnExecuteProgram(std::size_t program_index); |
| 156 | void OnExit(); | ||
| 156 | void ControllerSelectorReconfigureControllers( | 157 | void ControllerSelectorReconfigureControllers( |
| 157 | const Core::Frontend::ControllerParameters& parameters); | 158 | const Core::Frontend::ControllerParameters& parameters); |
| 158 | void SoftwareKeyboardInitialize( | 159 | void SoftwareKeyboardInitialize( |