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

@ -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;