From 41be96ef93b4a94f86686ae91c29f566781e860e Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 30 Jan 2021 15:52:36 +1000 Subject: [PATCH] CommonHostInterface: Make RunLater()/ApplySettings() virtual --- src/duckstation-qt/qthostinterface.cpp | 13 ++++++++++++- src/duckstation-qt/qthostinterface.h | 3 +++ src/duckstation-sdl/sdl_host_interface.cpp | 15 ++++++++++----- src/duckstation-sdl/sdl_host_interface.h | 12 ++++++------ src/frontend-common/common_host_interface.h | 6 ++++++ 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 4387f6ca9..1dda607df 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -306,6 +306,11 @@ void QtHostInterface::applySettings(bool display_osd_messages /* = false */) return; } + ApplySettings(display_osd_messages); +} + +void QtHostInterface::ApplySettings(bool display_osd_messages) +{ Settings old_settings(std::move(g_settings)); { std::lock_guard guard(m_settings_mutex); @@ -1168,7 +1173,7 @@ void QtHostInterface::executeOnEmulationThread(std::function callback, b } QMetaObject::invokeMethod(this, "executeOnEmulationThread", Qt::QueuedConnection, - Q_ARG(std::function, callback), Q_ARG(bool, wait)); + Q_ARG(std::function, std::move(callback)), Q_ARG(bool, wait)); if (wait) { // don't deadlock @@ -1178,6 +1183,12 @@ void QtHostInterface::executeOnEmulationThread(std::function callback, b } } +void QtHostInterface::RunLater(std::function func) +{ + QMetaObject::invokeMethod(this, "executeOnEmulationThread", Qt::QueuedConnection, + Q_ARG(std::function, std::move(func)), Q_ARG(bool, false)); +} + void QtHostInterface::loadState(const QString& filename) { if (!isOnWorkerThread()) diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index 2795eec97..87f101dcd 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -2,6 +2,7 @@ #include "common/event.h" #include "core/host_interface.h" #include "core/system.h" +#include "qtutils.h" #include "frontend-common/common_host_interface.h" #include #include @@ -205,10 +206,12 @@ protected: void OnSystemStateSaved(bool global, s32 slot) override; void LoadSettings() override; + void ApplySettings(bool display_osd_messages) override; void SetDefaultSettings(SettingsInterface& si) override; void UpdateInputMap() override; void SetMouseMode(bool relative, bool hide_cursor) override; + void RunLater(std::function func) override; private: enum : u32 diff --git a/src/duckstation-sdl/sdl_host_interface.cpp b/src/duckstation-sdl/sdl_host_interface.cpp index 2d41a369d..a3f1e239b 100644 --- a/src/duckstation-sdl/sdl_host_interface.cpp +++ b/src/duckstation-sdl/sdl_host_interface.cpp @@ -325,15 +325,20 @@ void SDLHostInterface::SaveAndUpdateSettings() { m_settings_copy.Save(*m_settings_interface.get()); - Settings old_settings(std::move(g_settings)); - CommonHostInterface::LoadSettings(*m_settings_interface.get()); - CommonHostInterface::ApplyGameSettings(false); - CommonHostInterface::FixIncompatibleSettings(false); - CheckForSettingsChanges(old_settings); + ApplySettings(false); m_settings_interface->Save(); } +void SDLHostInterface::ApplySettings(bool display_osd_messages) +{ + Settings old_settings(std::move(g_settings)); + CommonHostInterface::LoadSettings(*m_settings_interface.get()); + CommonHostInterface::ApplyGameSettings(display_osd_messages); + CommonHostInterface::FixIncompatibleSettings(display_osd_messages); + CheckForSettingsChanges(old_settings); +} + bool SDLHostInterface::IsFullscreen() const { return m_fullscreen; diff --git a/src/duckstation-sdl/sdl_host_interface.h b/src/duckstation-sdl/sdl_host_interface.h index d77d36768..c915400e5 100644 --- a/src/duckstation-sdl/sdl_host_interface.h +++ b/src/duckstation-sdl/sdl_host_interface.h @@ -40,6 +40,12 @@ public: bool RequestRenderWindowSize(s32 new_window_width, s32 new_window_height) override; + bool IsFullscreen() const override; + bool SetFullscreen(bool enabled) override; + + void RunLater(std::function callback) override; + void ApplySettings(bool display_osd_messages) override; + void Run(); protected: @@ -67,14 +73,8 @@ private: void CreateImGuiContext(); void UpdateFramebufferScale(); - /// Executes a callback later, after the UI has finished rendering. Needed to boot while rendering ImGui. - void RunLater(std::function callback); - void SaveAndUpdateSettings(); - bool IsFullscreen() const override; - bool SetFullscreen(bool enabled) override; - // We only pass mouse input through if it's grabbed void DrawImGuiWindows() override; void DoStartDisc(); diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index 3a17fc2f5..5d70d3f6b 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -88,6 +88,12 @@ public: /// Request the frontend to exit. virtual void RequestExit() = 0; + /// Runs an event next frame as part of the event loop. + virtual void RunLater(std::function func) = 0; + + /// Loads new settings and applies them. + virtual void ApplySettings(bool display_osd_messages) = 0; + virtual bool IsFullscreen() const; virtual bool SetFullscreen(bool enabled);