Complete reimplementation of the function

This commit is contained in:
SutandoTsukai181 2020-04-29 14:34:39 +00:00
parent 9de6a0cb3a
commit 05941d1634
10 changed files with 106 additions and 32 deletions

View File

@ -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<u16>(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<u16>(sdl2_config->GetInteger("Renderer", "frame_limit_alternate", 200));
Settings::values.use_vsync_new =
static_cast<u16>(sdl2_config->GetInteger("Renderer", "use_vsync_new", 1));
Settings::values.texture_filter_name =

View File

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

View File

@ -78,10 +78,10 @@ const std::array<UISettings::Shortcut, 24> 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<u16>(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);

View File

@ -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() {

View File

@ -82,6 +82,13 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="toggle_alternate_speed">
<property name="text">
<string>Alternate Speed Limit</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
@ -149,6 +156,22 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="frame_limit_alternate">
<property name="suffix">
<string>%</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
<property name="value">
<number>200</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

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

View File

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

View File

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

View File

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

View File

@ -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",