From 05941d1634ef41f653b18181375ccf8a4a41d48b Mon Sep 17 00:00:00 2001 From: SutandoTsukai181 Date: Wed, 29 Apr 2020 14:34:39 +0000 Subject: [PATCH] Complete reimplementation of the function --- src/citra/config.cpp | 7 ++- src/citra/default_ini.h | 9 ++++ src/citra_qt/configuration/config.cpp | 19 ++++--- .../configuration/configure_general.cpp | 14 ++++- .../configuration/configure_general.ui | 23 ++++++++ src/citra_qt/main.cpp | 53 +++++++++++-------- src/core/perf_stats.cpp | 4 ++ src/core/settings.cpp | 2 + src/core/settings.h | 3 +- src/core/telemetry_session.cpp | 4 ++ 10 files changed, 106 insertions(+), 32 deletions(-) diff --git a/src/citra/config.cpp b/src/citra/config.cpp index a407a53ea..a986c11a9 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -126,9 +126,12 @@ void Config::ReadValues() { Settings::values.use_frame_limit = sdl2_config->GetBoolean("Renderer", "use_frame_limit", true); Settings::values.use_disk_shader_cache = sdl2_config->GetBoolean("Renderer", "use_disk_shader_cache", true); - Settings::values.frame_limit = 100; - Settings::values.frame_limit_custom = + Settings::values.frame_limit = static_cast(sdl2_config->GetInteger("Renderer", "frame_limit", 100)); + Settings::values.use_frame_limit_alternate = + sdl2_config->GetBoolean("Renderer", "use_frame_limit_alternate", false); + Settings::values.frame_limit_alternate = + static_cast(sdl2_config->GetInteger("Renderer", "frame_limit_alternate", 200)); Settings::values.use_vsync_new = static_cast(sdl2_config->GetInteger("Renderer", "use_vsync_new", 1)); Settings::values.texture_filter_name = diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h index a6f7d5585..13d6fc3d4 100644 --- a/src/citra/default_ini.h +++ b/src/citra/default_ini.h @@ -143,6 +143,15 @@ use_frame_limit = # 1 - 9999: Speed limit as a percentage of target game speed. 100 (default) frame_limit = +# Overrides the frame limiter to use frame_limit_alternate instead of frame_limit. Will only have +# an effect if use_frame_limit is enabled +# 0: Off (default), 1: On +use_frame_limit_alternate = + +# Alternate speed limit to be used instead of frame_limit if use_frame_limit_alternate is enabled +# 1 - 9999: Speed limit as a percentage of target game speed. 200 (default) +frame_limit_alternate = + # The clear color for the renderer. What shows up on the sides of the bottom screen. # Must be in range of 0.0-1.0. Defaults to 0.0 for all. bg_red = diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 178269d47..842ec66b7 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -78,10 +78,10 @@ const std::array default_hotkeys{ {QStringLiteral("Toggle Filter Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}}, {QStringLiteral("Toggle Frame Advancing"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+A"), Qt::ApplicationShortcut}}, {QStringLiteral("Toggle Screen Layout"), QStringLiteral("Main Window"), {QStringLiteral("F10"), Qt::WindowShortcut}}, - {QStringLiteral("Toggle Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("Backspace"), Qt::ApplicationShortcut}}, + {QStringLiteral("Toggle Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Z"), Qt::ApplicationShortcut}}, + {QStringLiteral("Toggle Alternate Speed"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+X"), Qt::ApplicationShortcut}}, {QStringLiteral("Toggle Status Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+S"), Qt::WindowShortcut}}, - {QStringLiteral("Toggle Texture Dumping"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+D"), Qt::ApplicationShortcut}}, - {QStringLiteral("Unthrottle"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Z"), Qt::ApplicationShortcut}}}}; + {QStringLiteral("Toggle Texture Dumping"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+D"), Qt::ApplicationShortcut}}}}; // clang-format on void Config::ReadValues() { @@ -448,8 +448,11 @@ void Config::ReadRendererValues() { static_cast(ReadSetting(QStringLiteral("resolution_factor"), 1).toInt()); Settings::values.use_frame_limit = ReadSetting(QStringLiteral("use_frame_limit"), true).toBool(); - Settings::values.frame_limit = 100; - Settings::values.frame_limit_custom = ReadSetting(QStringLiteral("frame_limit"), 100).toInt(); + Settings::values.frame_limit = ReadSetting(QStringLiteral("frame_limit"), 100).toInt(); + Settings::values.use_frame_limit_alternate = + ReadSetting(QStringLiteral("use_frame_limit_alternate"), false).toBool(); + Settings::values.frame_limit_alternate = + ReadSetting(QStringLiteral("frame_limit_alternate"), 200).toInt(); Settings::values.bg_red = ReadSetting(QStringLiteral("bg_red"), 0.0).toFloat(); Settings::values.bg_green = ReadSetting(QStringLiteral("bg_green"), 0.0).toFloat(); @@ -932,7 +935,11 @@ void Config::SaveRendererValues() { WriteSetting(QStringLiteral("use_vsync_new"), Settings::values.use_vsync_new, true); WriteSetting(QStringLiteral("resolution_factor"), Settings::values.resolution_factor, 1); WriteSetting(QStringLiteral("use_frame_limit"), Settings::values.use_frame_limit, true); - WriteSetting(QStringLiteral("frame_limit"), Settings::values.frame_limit_custom, 100); + WriteSetting(QStringLiteral("frame_limit"), Settings::values.frame_limit, 100); + WriteSetting(QStringLiteral("use_frame_limit_alternate"), + Settings::values.use_frame_limit_alternate, false); + WriteSetting(QStringLiteral("frame_limit_alternate"), + Settings::values.frame_limit_alternate, 200); // Cast to double because Qt's written float values are not human-readable WriteSetting(QStringLiteral("bg_red"), (double)Settings::values.bg_red, 0.0); diff --git a/src/citra_qt/configuration/configure_general.cpp b/src/citra_qt/configuration/configure_general.cpp index e6abc34c9..b966ac20a 100644 --- a/src/citra_qt/configuration/configure_general.cpp +++ b/src/citra_qt/configuration/configure_general.cpp @@ -16,6 +16,9 @@ ConfigureGeneral::ConfigureGeneral(QWidget* parent) SetConfiguration(); connect(ui->toggle_frame_limit, &QCheckBox::toggled, ui->frame_limit, &QSpinBox::setEnabled); + + connect(ui->toggle_alternate_speed, &QCheckBox::toggled, ui->frame_limit_alternate, + &QSpinBox::setEnabled); ui->updateBox->setVisible(UISettings::values.updater_found); connect(ui->button_reset_defaults, &QPushButton::clicked, this, @@ -37,7 +40,11 @@ void ConfigureGeneral::SetConfiguration() { ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit); ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked()); - ui->frame_limit->setValue(Settings::values.frame_limit_custom); + ui->frame_limit->setValue(Settings::values.frame_limit); + + ui->toggle_alternate_speed->setChecked(Settings::values.use_frame_limit_alternate); + ui->frame_limit_alternate->setEnabled(ui->toggle_alternate_speed->isChecked()); + ui->frame_limit_alternate->setValue(Settings::values.frame_limit_alternate); } void ConfigureGeneral::ResetDefaults() { @@ -64,7 +71,10 @@ void ConfigureGeneral::ApplyConfiguration() { Settings::values.region_value = ui->region_combobox->currentIndex() - 1; Settings::values.use_frame_limit = ui->toggle_frame_limit->isChecked(); - Settings::values.frame_limit_custom = ui->frame_limit->value(); + Settings::values.frame_limit = ui->frame_limit->value(); + + Settings::values.use_frame_limit_alternate = ui->toggle_alternate_speed->isChecked(); + Settings::values.frame_limit_alternate = ui->frame_limit_alternate->value(); } void ConfigureGeneral::RetranslateUI() { diff --git a/src/citra_qt/configuration/configure_general.ui b/src/citra_qt/configuration/configure_general.ui index 6b2aa4416..0d29cb090 100644 --- a/src/citra_qt/configuration/configure_general.ui +++ b/src/citra_qt/configuration/configure_general.ui @@ -82,6 +82,13 @@ + + + + Alternate Speed Limit + + + @@ -149,6 +156,22 @@ + + + + % + + + 1 + + + 9999 + + + 200 + + + diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 7db362e5d..25931c37e 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -492,20 +492,16 @@ void GMainWindow::InitializeHotkeys() { } }); connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Toggle Speed Limit"), this), - &QShortcut::activated, this, [&] { - if (Settings::values.frame_limit != 100) { - Settings::values.frame_limit = 100; - UpdateStatusBar(); - } else { - Settings::values.frame_limit = Settings::values.frame_limit_custom; - UpdateStatusBar(); - } - }); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Unthrottle"), this), &QShortcut::activated, this, [&] { Settings::values.use_frame_limit = !Settings::values.use_frame_limit; UpdateStatusBar(); }); + connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Toggle Alternate Speed"), this), + &QShortcut::activated, this, [&] { + Settings::values.use_frame_limit_alternate = + !Settings::values.use_frame_limit_alternate; + UpdateStatusBar(); + }); connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Toggle Texture Dumping"), this), &QShortcut::activated, this, [&] { Settings::values.dump_textures = !Settings::values.dump_textures; }); @@ -514,22 +510,30 @@ void GMainWindow::InitializeHotkeys() { static constexpr u16 SPEED_LIMIT_STEP = 5; connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Increase Speed Limit"), this), &QShortcut::activated, this, [&] { - if (Settings::values.frame_limit_custom < 9999 - SPEED_LIMIT_STEP) { - Settings::values.frame_limit_custom += SPEED_LIMIT_STEP; - if (Settings::values.frame_limit != 100) { - Settings::values.frame_limit = Settings::values.frame_limit_custom; - } + if (Settings::values.use_frame_limit_alternate) { + if (Settings::values.frame_limit_alternate < 9999 - SPEED_LIMIT_STEP) { + Settings::values.frame_limit_alternate += SPEED_LIMIT_STEP; UpdateStatusBar(); + } + } else { + if (Settings::values.frame_limit < 9999 - SPEED_LIMIT_STEP) { + Settings::values.frame_limit += SPEED_LIMIT_STEP; + UpdateStatusBar(); + } } }); connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Decrease Speed Limit"), this), &QShortcut::activated, this, [&] { - if (Settings::values.frame_limit_custom > SPEED_LIMIT_STEP) { - Settings::values.frame_limit_custom -= SPEED_LIMIT_STEP; - if (Settings::values.frame_limit != 100) { - Settings::values.frame_limit = Settings::values.frame_limit_custom; - } + if (Settings::values.use_frame_limit_alternate) { + if (Settings::values.frame_limit_alternate > SPEED_LIMIT_STEP) { + Settings::values.frame_limit_alternate -= SPEED_LIMIT_STEP; UpdateStatusBar(); + } + } else { + if (Settings::values.frame_limit > SPEED_LIMIT_STEP) { + Settings::values.frame_limit -= SPEED_LIMIT_STEP; + UpdateStatusBar(); + } } }); connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Toggle Frame Advancing"), this), @@ -2038,9 +2042,16 @@ void GMainWindow::UpdateStatusBar() { auto results = Core::System::GetInstance().GetAndResetPerfStats(); if (Settings::values.use_frame_limit) { - emu_speed_label->setText(tr("Speed: %1% / %2%") + if (Settings::values.use_frame_limit_alternate) + { + emu_speed_label->setText(tr("Speed: %1% / %2%") + .arg(results.emulation_speed * 100.0, 0, 'f', 0) + .arg(Settings::values.frame_limit_alternate)); + } else { + emu_speed_label->setText(tr("Speed: %1% / %2%") .arg(results.emulation_speed * 100.0, 0, 'f', 0) .arg(Settings::values.frame_limit)); + } } else { emu_speed_label->setText(tr("Speed: %1%").arg(results.emulation_speed * 100.0, 0, 'f', 0)); } diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp index 00ab24dbc..db3d781e5 100644 --- a/src/core/perf_stats.cpp +++ b/src/core/perf_stats.cpp @@ -140,6 +140,10 @@ void FrameLimiter::DoFrameLimiting(microseconds current_system_time_us) { auto now = Clock::now(); double sleep_scale = Settings::values.frame_limit / 100.0; + if (Settings::values.use_frame_limit_alternate) { + sleep_scale = Settings::values.frame_limit_alternate / 100.0; + } + // Max lag caused by slow frames. Shouldn't be more than the length of a frame at the current // speed percent or it will clamp too much and prevent this from properly limiting to that // percent. High values means it'll take longer after a slow frame to recover and start limiting diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 6af80205b..55e18d67e 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -83,6 +83,8 @@ void LogSettings() { LogSetting("Renderer_UseResolutionFactor", Settings::values.resolution_factor); LogSetting("Renderer_UseFrameLimit", Settings::values.use_frame_limit); LogSetting("Renderer_FrameLimit", Settings::values.frame_limit); + LogSetting("Renderer_UseFrameLimitAlternate", Settings::values.use_frame_limit_alternate); + LogSetting("Renderer_FrameLimitAlternate", Settings::values.frame_limit_alternate); LogSetting("Renderer_PostProcessingShader", Settings::values.pp_shader_name); LogSetting("Renderer_FilterMode", Settings::values.filter_mode); LogSetting("Renderer_TextureFilterName", Settings::values.texture_filter_name); diff --git a/src/core/settings.h b/src/core/settings.h index bf8805f69..c882c0346 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -147,8 +147,9 @@ struct Values { bool use_shader_jit; u16 resolution_factor; bool use_frame_limit; + bool use_frame_limit_alternate; u16 frame_limit; - u16 frame_limit_custom; + u16 frame_limit_alternate; std::string texture_filter_name; LayoutOption layout_option; diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index d13cb7eed..525518dde 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp @@ -168,6 +168,10 @@ void TelemetrySession::AddInitialInfo(Loader::AppLoader& app_loader) { AddField(Telemetry::FieldType::UserConfig, "Renderer_UseFrameLimit", Settings::values.use_frame_limit); AddField(Telemetry::FieldType::UserConfig, "Renderer_FrameLimit", Settings::values.frame_limit); + AddField(Telemetry::FieldType::UserConfig, "Renderer_UseFrameLimitAlternate", + Settings::values.use_frame_limit_alternate); + AddField(Telemetry::FieldType::UserConfig, "Renderer_FrameLimitAlternate", + Settings::values.frame_limit_alternate); AddField(Telemetry::FieldType::UserConfig, "Renderer_UseHwRenderer", Settings::values.use_hw_renderer); AddField(Telemetry::FieldType::UserConfig, "Renderer_UseHwShader",