HostInterface: Modify settings loading interface to support per-frontend settings

This commit is contained in:
Connor McLaughlin 2020-05-01 01:01:50 +10:00
parent 6e7c58de43
commit d8ab587153
8 changed files with 82 additions and 38 deletions

View file

@ -1003,7 +1003,17 @@ void HostInterface::SetDefaultSettings(SettingsInterface& si)
si.SetBoolValue("Debug", "ShowMDECState", false);
}
void HostInterface::UpdateSettings(const std::function<void()>& apply_callback)
void HostInterface::ApplySettings(SettingsInterface& si)
{
m_settings.Load(si);
}
void HostInterface::ExportSettings(SettingsInterface& si)
{
m_settings.Save(si);
}
void HostInterface::UpdateSettings(SettingsInterface& si)
{
const bool old_increase_timer_resolution = m_settings.increase_timer_resolution;
const float old_emulation_speed = m_settings.emulation_speed;
@ -1038,7 +1048,7 @@ void HostInterface::UpdateSettings(const std::function<void()>& apply_callback)
const bool old_log_to_window = m_settings.log_to_window;
const bool old_log_to_file = m_settings.log_to_file;
apply_callback();
ApplySettings(si);
if (m_system)
{

View file

@ -192,7 +192,7 @@ protected:
/// Sets the user directory to the program directory, i.e. "portable mode".
void SetUserDirectoryToProgramDirectory();
/// Performs the initial load of settings. Should call CheckSettings() and m_settings.Load().
/// Performs the initial load of settings. Should call CheckSettings() and ApplySettings().
virtual void LoadSettings() = 0;
/// Updates logging settings.
@ -232,9 +232,14 @@ protected:
/// Restores all settings to defaults.
virtual void SetDefaultSettings(SettingsInterface& si);
/// Applies new settings, updating internal state as needed. apply_callback should call m_settings.Load() after
/// locking any required mutexes.
void UpdateSettings(const std::function<void()>& apply_callback);
/// Loads settings to m_settings and any frontend-specific parameters.
virtual void ApplySettings(SettingsInterface& si);
/// Saves current settings variables to ini.
virtual void ExportSettings(SettingsInterface& si);
/// Applies new settings, updating internal state as needed.
virtual void UpdateSettings(SettingsInterface& si);
/// Quick switch between software and hardware rendering.
void ToggleSoftwareRendering();

View file

@ -144,9 +144,12 @@ void QtHostInterface::setDefaultSettings()
return;
}
std::lock_guard<std::recursive_mutex> guard(m_qsettings_mutex);
QtSettingsInterface si(m_qsettings.get());
UpdateSettings([this, &si]() { m_settings.Load(si); });
{
std::lock_guard<std::recursive_mutex> guard(m_qsettings_mutex);
SetDefaultSettings(si);
}
UpdateSettings(si);
CommonHostInterface::UpdateInputMap(si);
}
@ -160,7 +163,7 @@ void QtHostInterface::applySettings()
std::lock_guard<std::recursive_mutex> guard(m_qsettings_mutex);
QtSettingsInterface si(m_qsettings.get());
UpdateSettings([this, &si]() { m_settings.Load(si); });
UpdateSettings(si);
CommonHostInterface::UpdateInputMap(si);
// detect when render-to-main flag changes
@ -388,6 +391,14 @@ bool QtHostInterface::SetFullscreen(bool enabled)
return true;
}
void QtHostInterface::PollAndUpdate()
{
CommonHostInterface::PollAndUpdate();
if (m_controller_interface)
m_controller_interface->PollEvents();
}
void QtHostInterface::RequestExit()
{
emit exitRequested();
@ -450,7 +461,7 @@ void QtHostInterface::OnSystemPerformanceCountersUpdated()
void QtHostInterface::OnRunningGameChanged()
{
HostInterface::OnRunningGameChanged();
CommonHostInterface::OnRunningGameChanged();
if (m_system)
{
@ -485,7 +496,7 @@ void QtHostInterface::LoadSettings()
// load in settings
CheckSettings(si);
m_settings.Load(si);
ApplySettings(si);
}
void QtHostInterface::SetDefaultSettings(SettingsInterface& si)
@ -495,6 +506,12 @@ void QtHostInterface::SetDefaultSettings(SettingsInterface& si)
si.SetBoolValue("Main", "RenderToMainWindow", true);
}
void QtHostInterface::ApplySettings(SettingsInterface& si)
{
std::lock_guard<std::recursive_mutex> lock(m_qsettings_mutex);
CommonHostInterface::ApplySettings(si);
}
void QtHostInterface::UpdateInputMap()
{
updateInputMap();
@ -771,7 +788,7 @@ void QtHostInterface::saveScreenshot()
void QtHostInterface::doBackgroundControllerPoll()
{
m_controller_interface->PollEvents();
PollAndUpdate();
}
void QtHostInterface::createBackgroundControllerPollTimer()
@ -855,8 +872,7 @@ void QtHostInterface::threadEntryPoint()
m_system->Throttle();
m_worker_thread_event_loop->processEvents(QEventLoop::AllEvents);
if (m_controller_interface)
m_controller_interface->PollEvents();
PollAndUpdate();
}
shutdownOnThread();

View file

@ -136,6 +136,7 @@ protected:
void ReleaseHostDisplay() override;
bool IsFullscreen() const override;
bool SetFullscreen(bool enabled) override;
void PollAndUpdate() override;
void RequestExit() override;
std::optional<HostKeyCode> GetHostKeyCode(const std::string_view key_code) const override;
@ -149,6 +150,7 @@ protected:
void LoadSettings() override;
void SetDefaultSettings(SettingsInterface& si) override;
void ApplySettings(SettingsInterface& si) override;
void UpdateInputMap() override;
private:

View file

@ -295,17 +295,13 @@ void SDLHostInterface::RunLater(std::function<void()> callback)
SDL_PushEvent(&ev);
}
void SDLHostInterface::SaveSettings()
void SDLHostInterface::SaveAndUpdateSettings()
{
m_settings_copy.Save(*m_settings_interface.get());
UpdateSettings(*m_settings_interface.get());
m_settings_interface->Save();
}
void SDLHostInterface::UpdateSettings()
{
CommonHostInterface::UpdateSettings([this]() { m_settings = m_settings_copy; });
}
bool SDLHostInterface::IsFullscreen() const
{
return m_fullscreen;
@ -383,8 +379,8 @@ void SDLHostInterface::LoadSettings()
{
// Settings need to be loaded prior to creating the window for OpenGL bits.
m_settings_interface = std::make_unique<INISettingsInterface>(GetSettingsFileName());
m_settings_copy.Load(*m_settings_interface.get());
m_settings = m_settings_copy;
ApplySettings(*m_settings_interface.get());
m_settings_copy = m_settings;
}
void SDLHostInterface::ReportError(const char* message)
@ -513,6 +509,12 @@ void SDLHostInterface::HandleSDLEvent(const SDL_Event* event)
}
}
void SDLHostInterface::PollAndUpdate()
{
CommonHostInterface::PollAndUpdate();
ProcessEvents();
}
void SDLHostInterface::ProcessEvents()
{
for (;;)
@ -794,12 +796,7 @@ void SDLHostInterface::DrawQuickSettingsMenu()
RunLater([this]() { SaveScreenshot(); });
if (settings_changed)
{
RunLater([this]() {
SaveSettings();
UpdateSettings();
});
}
RunLater([this]() { SaveAndUpdateSettings(); });
}
void SDLHostInterface::DrawDebugMenu()
@ -831,7 +828,7 @@ void SDLHostInterface::DrawDebugMenu()
debug_settings_copy.show_spu_state = debug_settings.show_spu_state;
debug_settings_copy.show_timers_state = debug_settings.show_timers_state;
debug_settings_copy.show_mdec_state = debug_settings.show_mdec_state;
SaveSettings();
SaveAndUpdateSettings();
}
}
@ -1269,12 +1266,7 @@ void SDLHostInterface::DrawSettingsWindow()
ImGui::End();
if (settings_changed)
{
RunLater([this]() {
SaveSettings();
UpdateSettings();
});
}
RunLater([this]() { SaveAndUpdateSettings(); });
}
void SDLHostInterface::DrawAboutWindow()
@ -1380,7 +1372,7 @@ void SDLHostInterface::Run()
{
while (!m_quit_request)
{
ProcessEvents();
PollAndUpdate();
if (m_system && !m_paused)
{

View file

@ -50,6 +50,7 @@ protected:
void OnRunningGameChanged() override;
void RequestExit() override;
void PollAndUpdate() override;
std::optional<HostKeyCode> GetHostKeyCode(const std::string_view key_code) const override;
void UpdateInputMap() override;
@ -75,8 +76,7 @@ private:
/// Executes a callback later, after the UI has finished rendering. Needed to boot while rendering ImGui.
void RunLater(std::function<void()> callback);
void SaveSettings();
void UpdateSettings();
void SaveAndUpdateSettings();
bool IsFullscreen() const override;
bool SetFullscreen(bool enabled) override;

View file

@ -291,6 +291,10 @@ bool CommonHostInterface::ParseCommandLineParameters(int argc, char* argv[],
return true;
}
void CommonHostInterface::PollAndUpdate()
{
}
bool CommonHostInterface::IsFullscreen() const
{
return false;
@ -356,6 +360,11 @@ void CommonHostInterface::OnSystemDestroyed()
StopControllerRumble();
}
void CommonHostInterface::OnRunningGameChanged()
{
HostInterface::OnRunningGameChanged();
}
void CommonHostInterface::OnControllerTypeChanged(u32 slot)
{
HostInterface::OnControllerTypeChanged(slot);
@ -403,6 +412,11 @@ void CommonHostInterface::SetDefaultSettings(SettingsInterface& si)
si.SetStringValue("Hotkeys", "ToggleSoftwareRendering", "Keyboard/End");
}
void CommonHostInterface::ApplySettings(SettingsInterface& si)
{
HostInterface::ApplySettings(si);
}
std::optional<CommonHostInterface::HostKeyCode>
CommonHostInterface::GetHostKeyCode(const std::string_view key_code) const
{

View file

@ -67,6 +67,9 @@ protected:
/// Request the frontend to exit.
virtual void RequestExit() = 0;
/// Executes per-frame tasks such as controller polling.
virtual void PollAndUpdate();
virtual bool IsFullscreen() const;
virtual bool SetFullscreen(bool enabled);
@ -76,10 +79,12 @@ protected:
virtual void OnSystemCreated() override;
virtual void OnSystemPaused(bool paused) override;
virtual void OnSystemDestroyed() override;
virtual void OnRunningGameChanged() override;
virtual void OnControllerTypeChanged(u32 slot) override;
virtual void DrawImGuiWindows() override;
virtual void SetDefaultSettings(SettingsInterface& si) override;
virtual void ApplySettings(SettingsInterface& si) override;
virtual std::optional<HostKeyCode> GetHostKeyCode(const std::string_view key_code) const;