From 16a32bf696cc3541d709275efd5a97d4f92173cb Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 26 Jan 2021 02:48:40 +1000 Subject: [PATCH] Qt: Simplify runahead settings --- src/core/host_interface.cpp | 12 +- src/core/settings.cpp | 6 +- src/core/settings.h | 4 +- src/core/system.cpp | 2 +- .../emulationsettingswidget.cpp | 29 ++--- src/duckstation-qt/emulationsettingswidget.h | 4 +- src/duckstation-qt/emulationsettingswidget.ui | 106 +++++++++++------- 7 files changed, 92 insertions(+), 71 deletions(-) diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 2cf0c152b..3f3da4135 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -495,8 +495,7 @@ void HostInterface::SetDefaultSettings(SettingsInterface& si) si.SetBoolValue("Main", "RewindEnable", false); si.SetFloatValue("Main", "RewindFrequency", 10.0f); si.SetIntValue("Main", "RewindSaveSlots", 10); - si.SetBoolValue("Main", "RunaheadEnable", false); - si.SetFloatValue("Main", "RunaheadFrames", 1); + si.SetFloatValue("Main", "RunaheadFrameCount", 0); si.SetStringValue("CPU", "ExecutionMode", Settings::GetCPUExecutionModeName(Settings::DEFAULT_CPU_EXECUTION_MODE)); si.SetBoolValue("CPU", "RecompilerMemoryExceptions", false); @@ -666,7 +665,7 @@ void HostInterface::FixIncompatibleSettings(bool display_osd_messages) #endif // rewinding causes issues with mmap fastmem, so just use LUT - if ((g_settings.rewind_enable || g_settings.runahead_enable) && g_settings.IsUsingFastmem() && + if ((g_settings.rewind_enable || g_settings.IsRunaheadEnabled()) && g_settings.IsUsingFastmem() && g_settings.cpu_fastmem_mode == CPUFastmemMode::MMap) { Log_WarningPrintf("Disabling mmap fastmem due to rewind being enabled"); @@ -674,13 +673,13 @@ void HostInterface::FixIncompatibleSettings(bool display_osd_messages) } // code compilation is too slow with runahead, use the recompiler - if (g_settings.runahead_enable && g_settings.IsUsingCodeCache()) + if (g_settings.IsRunaheadEnabled() && g_settings.IsUsingCodeCache()) { Log_WarningPrintf("Code cache/recompiler disabled due to runahead"); g_settings.cpu_execution_mode = CPUExecutionMode::Interpreter; } - if (g_settings.runahead_enable && g_settings.rewind_enable) + if (g_settings.IsRunaheadEnabled() && g_settings.rewind_enable) { Log_WarningPrintf("Rewind disabled due to runahead being enabled"); g_settings.rewind_enable = false; @@ -789,7 +788,7 @@ void HostInterface::CheckForSettingsChanges(const Settings& old_settings) g_settings.display_line_start_offset != old_settings.display_line_start_offset || g_settings.display_line_end_offset != old_settings.display_line_end_offset || g_settings.rewind_enable != old_settings.rewind_enable || - g_settings.runahead_enable != old_settings.runahead_enable) + g_settings.runahead_frames != old_settings.runahead_frames) { if (g_settings.IsUsingCodeCache()) CPU::CodeCache::Reinitialize(); @@ -830,7 +829,6 @@ void HostInterface::CheckForSettingsChanges(const Settings& old_settings) if (g_settings.rewind_enable != old_settings.rewind_enable || g_settings.rewind_save_frequency != old_settings.rewind_save_frequency || g_settings.rewind_save_slots != old_settings.rewind_save_slots || - g_settings.runahead_enable != old_settings.runahead_enable || g_settings.runahead_frames != old_settings.runahead_frames) { System::UpdateMemorySaveStateSettings(); diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 4b448fa39..b53722810 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -126,8 +126,7 @@ void Settings::Load(SettingsInterface& si) rewind_enable = si.GetBoolValue("Main", "RewindEnable", false); rewind_save_frequency = si.GetFloatValue("Main", "RewindFrequency", 10.0f); rewind_save_slots = static_cast(si.GetIntValue("Main", "RewindSaveSlots", 10)); - runahead_enable = si.GetBoolValue("Main", "RunaheadEnable", false); - runahead_frames = static_cast(si.GetIntValue("Main", "RunaheadFrames", 1)); + runahead_frames = static_cast(si.GetIntValue("Main", "RunaheadFrameCount", 0)); cpu_execution_mode = ParseCPUExecutionMode( @@ -303,8 +302,7 @@ void Settings::Save(SettingsInterface& si) const si.SetBoolValue("Main", "RewindEnable", rewind_enable); si.SetFloatValue("Main", "RewindFrequency", rewind_save_frequency); si.SetIntValue("Main", "RewindSaveSlots", rewind_save_slots); - si.SetBoolValue("Main", "RunaheadEnable", runahead_enable); - si.SetIntValue("Main", "RunaheadFrames", runahead_frames); + si.SetIntValue("Main", "RunaheadFrameCount", runahead_frames); si.SetStringValue("CPU", "ExecutionMode", GetCPUExecutionModeName(cpu_execution_mode)); si.SetBoolValue("CPU", "OverclockEnable", cpu_overclock_enable); diff --git a/src/core/settings.h b/src/core/settings.h index 0e6ef5a38..517361a19 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -95,10 +95,9 @@ struct Settings bool disable_all_enhancements = false; bool rewind_enable = false; - bool runahead_enable = false; float rewind_save_frequency = 10.0f; u32 rewind_save_slots = 10; - u32 runahead_frames = 1; + u32 runahead_frames = 0; GPURenderer gpu_renderer = GPURenderer::Software; std::string gpu_adapter; @@ -224,6 +223,7 @@ struct Settings ALWAYS_INLINE bool IsUsingCodeCache() const { return (cpu_execution_mode != CPUExecutionMode::Interpreter); } ALWAYS_INLINE bool IsUsingRecompiler() const { return (cpu_execution_mode == CPUExecutionMode::Recompiler); } ALWAYS_INLINE bool IsUsingSoftwareRenderer() const { return (gpu_renderer == GPURenderer::Software); } + ALWAYS_INLINE bool IsRunaheadEnabled() const { return (runahead_frames > 0); } ALWAYS_INLINE PGXPMode GetPGXPMode() { diff --git a/src/core/system.cpp b/src/core/system.cpp index 686390c0b..2d3a8c12e 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -1977,7 +1977,7 @@ void UpdateMemorySaveStateSettings() s_rewind_load_frequency = -1; s_rewind_load_counter = -1; - s_runahead_frames = g_settings.runahead_enable ? g_settings.runahead_frames : 0; + s_runahead_frames = g_settings.runahead_frames; s_runahead_replay_pending = false; if (s_runahead_frames > 0) { diff --git a/src/duckstation-qt/emulationsettingswidget.cpp b/src/duckstation-qt/emulationsettingswidget.cpp index 78bf894bd..74d167ea8 100644 --- a/src/duckstation-qt/emulationsettingswidget.cpp +++ b/src/duckstation-qt/emulationsettingswidget.cpp @@ -18,8 +18,7 @@ EmulationSettingsWidget::EmulationSettingsWidget(QtHostInterface* host_interface SettingWidgetBinder::BindWidgetToFloatSetting(m_host_interface, m_ui.rewindSaveFrequency, "Main", "RewindFrequency", 10.0f); SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.rewindSaveSlots, "Main", "RewindSaveSlots", 10); - SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.runaheadEnable, "Main", "RunaheadEnable", false); - SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.runaheadFrames, "Main", "RunaheadFrames", 1); + SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.runaheadFrames, "Main", "RunaheadFrameCount", 0); QtUtils::FillComboBoxWithEmulationSpeeds(m_ui.emulationSpeed); const int emulation_speed_index = @@ -43,12 +42,13 @@ EmulationSettingsWidget::EmulationSettingsWidget(QtHostInterface* host_interface connect(m_ui.turboSpeed, QOverload::of(&QComboBox::currentIndexChanged), this, &EmulationSettingsWidget::onTurboSpeedIndexChanged); - connect(m_ui.rewindEnable, &QCheckBox::stateChanged, this, &EmulationSettingsWidget::updateRewindSummaryLabel); + connect(m_ui.rewindEnable, &QCheckBox::stateChanged, this, &EmulationSettingsWidget::updateRewind); connect(m_ui.rewindSaveFrequency, QOverload::of(&QDoubleSpinBox::valueChanged), this, - &EmulationSettingsWidget::updateRewindSummaryLabel); + &EmulationSettingsWidget::updateRewind); connect(m_ui.rewindSaveSlots, QOverload::of(&QSpinBox::valueChanged), this, - &EmulationSettingsWidget::updateRewindSummaryLabel); - connect(m_ui.runaheadEnable, &QCheckBox::stateChanged, this, &EmulationSettingsWidget::updateRunaheadFields); + &EmulationSettingsWidget::updateRewind); + connect(m_ui.runaheadFrames, QOverload::of(&QComboBox::currentIndexChanged), this, + &EmulationSettingsWidget::updateRewind); dialog->registerWidgetHelp( m_ui.emulationSpeed, tr("Emulation Speed"), "100%", @@ -69,8 +69,7 @@ EmulationSettingsWidget::EmulationSettingsWidget(QtHostInterface* host_interface "the console's refresh rate is too far from the host's refresh rate. Users with variable refresh rate displays " "should disable this option.")); - updateRewindSummaryLabel(); - updateRunaheadFields(); + updateRewind(); } EmulationSettingsWidget::~EmulationSettingsWidget() = default; @@ -99,8 +98,10 @@ void EmulationSettingsWidget::onTurboSpeedIndexChanged(int index) m_host_interface->applySettings(); } -void EmulationSettingsWidget::updateRewindSummaryLabel() +void EmulationSettingsWidget::updateRewind() { + m_ui.rewindEnable->setEnabled(!runaheadEnabled()); + if (m_ui.rewindEnable->isEnabled() && m_ui.rewindEnable->isChecked()) { const u32 frames = static_cast(m_ui.rewindSaveSlots->value()); @@ -124,7 +125,8 @@ void EmulationSettingsWidget::updateRewindSummaryLabel() { if (!m_ui.rewindEnable->isEnabled()) { - m_ui.rewindSummary->setText(tr("Rewind is disabled because runahead is enabled.")); + m_ui.rewindSummary->setText(tr( + "Rewind is disabled because runahead is enabled. Runahead will significantly increase system requirements.")); } else { @@ -135,10 +137,3 @@ void EmulationSettingsWidget::updateRewindSummaryLabel() m_ui.rewindSaveSlots->setEnabled(false); } } - -void EmulationSettingsWidget::updateRunaheadFields() -{ - m_ui.runaheadFrames->setEnabled(m_ui.runaheadEnable->isChecked()); - m_ui.rewindEnable->setEnabled(!m_ui.runaheadEnable->isChecked()); - updateRewindSummaryLabel(); -} diff --git a/src/duckstation-qt/emulationsettingswidget.h b/src/duckstation-qt/emulationsettingswidget.h index c89afed74..9f46db3fd 100644 --- a/src/duckstation-qt/emulationsettingswidget.h +++ b/src/duckstation-qt/emulationsettingswidget.h @@ -19,10 +19,10 @@ private Q_SLOTS: void onEmulationSpeedIndexChanged(int index); void onFastForwardSpeedIndexChanged(int index); void onTurboSpeedIndexChanged(int index); - void updateRewindSummaryLabel(); - void updateRunaheadFields(); + void updateRewind(); private: + bool runaheadEnabled() { return m_ui.runaheadFrames->currentIndex() > 0; } Ui::EmulationSettingsWidget m_ui; diff --git a/src/duckstation-qt/emulationsettingswidget.ui b/src/duckstation-qt/emulationsettingswidget.ui index 3a109a4a2..9a20a5758 100644 --- a/src/duckstation-qt/emulationsettingswidget.ui +++ b/src/duckstation-qt/emulationsettingswidget.ui @@ -75,7 +75,7 @@ - Rewind + Rewind/Runahead @@ -125,7 +125,73 @@ - + + + + Runahead: + + + + + + + + Disabled + + + + + 1 Frame + + + + + 2 Frames + + + + + 3 Frames + + + + + 4 Frames + + + + + 5 Frames + + + + + 6 Frames + + + + + 7 Frames + + + + + 8 Frames + + + + + 9 Frames + + + + + 10 Frames + + + + + TextLabel @@ -138,42 +204,6 @@ - - - - Runahead - - - - - - Enable Runahead - - - - - - - Runahead Frames: - - - - - - - Frames - - - 1 - - - 20 - - - - - -