From 689b62e065bde2e9a101b1daaf9987a93ddcd894 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 23 Jan 2021 19:48:17 +1000 Subject: [PATCH] Qt: Add settings for rewind --- .../emulationsettingswidget.cpp | 43 ++++++++++++ src/duckstation-qt/emulationsettingswidget.h | 1 + src/duckstation-qt/emulationsettingswidget.ui | 70 ++++++++++++++++++- 3 files changed, 112 insertions(+), 2 deletions(-) diff --git a/src/duckstation-qt/emulationsettingswidget.cpp b/src/duckstation-qt/emulationsettingswidget.cpp index 77b607b99..ea2d94caa 100644 --- a/src/duckstation-qt/emulationsettingswidget.cpp +++ b/src/duckstation-qt/emulationsettingswidget.cpp @@ -4,6 +4,7 @@ #include "settingsdialog.h" #include "settingwidgetbinder.h" #include +#include EmulationSettingsWidget::EmulationSettingsWidget(QtHostInterface* host_interface, QWidget* parent, SettingsDialog* dialog) @@ -13,6 +14,10 @@ EmulationSettingsWidget::EmulationSettingsWidget(QtHostInterface* host_interface SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.syncToHostRefreshRate, "Main", "SyncToHostRefreshRate", false); + SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.rewindEnable, "Main", "RewindEnable", false); + SettingWidgetBinder::BindWidgetToFloatSetting(m_host_interface, m_ui.rewindSaveFrequency, "Main", "RewindFrequency", + 10.0f); + SettingWidgetBinder::BindWidgetToIntSetting(m_host_interface, m_ui.rewindSaveSlots, "Main", "RewindSaveSlots", 10); QtUtils::FillComboBoxWithEmulationSpeeds(m_ui.emulationSpeed); const int emulation_speed_index = @@ -36,6 +41,12 @@ 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.rewindSaveFrequency, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &EmulationSettingsWidget::updateRewindSummaryLabel); + connect(m_ui.rewindSaveSlots, QOverload::of(&QSpinBox::valueChanged), this, + &EmulationSettingsWidget::updateRewindSummaryLabel); + dialog->registerWidgetHelp( m_ui.emulationSpeed, tr("Emulation Speed"), "100%", tr("Sets the target emulation speed. It is not guaranteed that this speed will be reached, " @@ -54,6 +65,8 @@ EmulationSettingsWidget::EmulationSettingsWidget(QtHostInterface* host_interface "potentially increasing the emulation speed by less than 1%. Sync To Host Refresh Rate will not take effect if " "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(); } EmulationSettingsWidget::~EmulationSettingsWidget() = default; @@ -81,3 +94,33 @@ void EmulationSettingsWidget::onTurboSpeedIndexChanged(int index) m_host_interface->SetFloatSettingValue("Main", "TurboSpeed", okay ? value : 0.0f); m_host_interface->applySettings(); } + +void EmulationSettingsWidget::updateRewindSummaryLabel() +{ + if (m_ui.rewindEnable->isChecked()) + { + const u32 frames = static_cast(m_ui.rewindSaveSlots->value()); + const float frequency = static_cast(m_ui.rewindSaveFrequency->value()); + const float duration = + ((frequency <= std::numeric_limits::epsilon()) ? (1.0f / 60.0f) : frequency) * static_cast(frames); + + u64 ram_usage, vram_usage; + System::CalculateRewindMemoryUsage(frames, &ram_usage, &vram_usage); + + m_ui.rewindSummary->setText( + tr("Rewind for %1 frames, lasting %2 seconds will require up to %3MB of RAM and %4MB of VRAM.") + .arg(frames) + .arg(duration) + .arg(ram_usage / 1048576) + .arg(vram_usage / 1048576)); + m_ui.rewindSaveFrequency->setEnabled(true); + m_ui.rewindSaveSlots->setEnabled(true); + } + else + { + m_ui.rewindSummary->setText( + tr("Rewind is not enabled. Please note that enabling rewind may significantly increase system requirements.")); + m_ui.rewindSaveFrequency->setEnabled(false); + m_ui.rewindSaveSlots->setEnabled(false); + } +} diff --git a/src/duckstation-qt/emulationsettingswidget.h b/src/duckstation-qt/emulationsettingswidget.h index ab10831ed..799b9e0a3 100644 --- a/src/duckstation-qt/emulationsettingswidget.h +++ b/src/duckstation-qt/emulationsettingswidget.h @@ -19,6 +19,7 @@ private Q_SLOTS: void onEmulationSpeedIndexChanged(int index); void onFastForwardSpeedIndexChanged(int index); void onTurboSpeedIndexChanged(int index); + void updateRewindSummaryLabel(); private: diff --git a/src/duckstation-qt/emulationsettingswidget.ui b/src/duckstation-qt/emulationsettingswidget.ui index 9db54fa67..345e04817 100644 --- a/src/duckstation-qt/emulationsettingswidget.ui +++ b/src/duckstation-qt/emulationsettingswidget.ui @@ -6,8 +6,8 @@ 0 0 - 648 - 456 + 672 + 518 @@ -72,6 +72,72 @@ + + + + Rewind + + + + + + Enable Rewinding + + + + + + + Rewind Save Frequency: + + + + + + + Seconds + + + 3600.000000000000000 + + + 0.100000000000000 + + + + + + + Rewind Buffer Size: + + + + + + + Frames + + + 1 + + + 10000 + + + + + + + TextLabel + + + true + + + + + +