From 54f55633214b8e32366b1d8bcdccd7cfc041c70e Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 11 Jan 2021 01:57:10 +1000 Subject: [PATCH] Qt: Add turbo speed setting --- src/core/host_interface.cpp | 1 + src/core/settings.cpp | 2 ++ src/core/settings.h | 1 + src/duckstation-qt/generalsettingswidget.cpp | 25 ++++++++++++++--- src/duckstation-qt/generalsettingswidget.h | 1 + src/duckstation-qt/generalsettingswidget.ui | 10 +++++++ src/frontend-common/common_host_interface.cpp | 28 ++++++++++++++++++- src/frontend-common/common_host_interface.h | 1 + 8 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 5464ff9c9..e184773f4 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -472,6 +472,7 @@ void HostInterface::SetDefaultSettings(SettingsInterface& si) si.SetFloatValue("Main", "EmulationSpeed", 1.0f); si.SetFloatValue("Main", "FastForwardSpeed", 0.0f); + si.SetFloatValue("Main", "TurboSpeed", 0.0f); si.SetBoolValue("Main", "IncreaseTimerResolution", true); si.SetBoolValue("Main", "StartPaused", false); si.SetBoolValue("Main", "StartFullscreen", false); diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 8d3a288fe..a0d7ddf81 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -111,6 +111,7 @@ void Settings::Load(SettingsInterface& si) emulation_speed = si.GetFloatValue("Main", "EmulationSpeed", 1.0f); fast_forward_speed = si.GetFloatValue("Main", "FastForwardSpeed", 0.0f); + turbo_speed = si.GetFloatValue("Main", "TurboSpeed", 0.0f); increase_timer_resolution = si.GetBoolValue("Main", "IncreaseTimerResolution", true); start_paused = si.GetBoolValue("Main", "StartPaused", false); start_fullscreen = si.GetBoolValue("Main", "StartFullscreen", false); @@ -281,6 +282,7 @@ void Settings::Save(SettingsInterface& si) const si.SetFloatValue("Main", "EmulationSpeed", emulation_speed); si.SetFloatValue("Main", "FastForwardSpeed", fast_forward_speed); + si.SetFloatValue("Main", "TurboSpeed", turbo_speed); si.SetBoolValue("Main", "IncreaseTimerResolution", increase_timer_resolution); si.SetBoolValue("Main", "StartPaused", start_paused); si.SetBoolValue("Main", "StartFullscreen", start_fullscreen); diff --git a/src/core/settings.h b/src/core/settings.h index 196bed78a..c58f30995 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -81,6 +81,7 @@ struct Settings float emulation_speed = 1.0f; float fast_forward_speed = 0.0f; + float turbo_speed = 0.0f; bool increase_timer_resolution = true; bool start_paused = false; bool start_fullscreen = false; diff --git a/src/duckstation-qt/generalsettingswidget.cpp b/src/duckstation-qt/generalsettingswidget.cpp index 8cfb2b7ac..eac6130ed 100644 --- a/src/duckstation-qt/generalsettingswidget.cpp +++ b/src/duckstation-qt/generalsettingswidget.cpp @@ -40,7 +40,7 @@ GeneralSettingsWidget::GeneralSettingsWidget(QtHostInterface* host_interface, QW QtUtils::FillComboBoxWithEmulationSpeeds(m_ui.emulationSpeed); const int emulation_speed_index = - m_ui.emulationSpeed->findData(QVariant(m_host_interface->GetFloatSettingValue("Main", "EmulationSpeed"))); + m_ui.emulationSpeed->findData(QVariant(m_host_interface->GetFloatSettingValue("Main", "EmulationSpeed", 1.0f))); if (emulation_speed_index >= 0) m_ui.emulationSpeed->setCurrentIndex(emulation_speed_index); connect(m_ui.emulationSpeed, QOverload::of(&QComboBox::currentIndexChanged), this, @@ -48,11 +48,18 @@ GeneralSettingsWidget::GeneralSettingsWidget(QtHostInterface* host_interface, QW QtUtils::FillComboBoxWithEmulationSpeeds(m_ui.fastForwardSpeed); const int fast_forward_speed_index = - m_ui.emulationSpeed->findData(QVariant(m_host_interface->GetFloatSettingValue("Main", "FastForwardSpeed"))); + m_ui.fastForwardSpeed->findData(QVariant(m_host_interface->GetFloatSettingValue("Main", "FastForwardSpeed", 0.0f))); if (fast_forward_speed_index >= 0) m_ui.fastForwardSpeed->setCurrentIndex(fast_forward_speed_index); connect(m_ui.fastForwardSpeed, QOverload::of(&QComboBox::currentIndexChanged), this, &GeneralSettingsWidget::onFastForwardSpeedIndexChanged); + QtUtils::FillComboBoxWithEmulationSpeeds(m_ui.turboSpeed); + const int turbo_speed_index = + m_ui.turboSpeed->findData(QVariant(m_host_interface->GetFloatSettingValue("Main", "TurboSpeed", 0.0f))); + if (turbo_speed_index >= 0) + m_ui.turboSpeed->setCurrentIndex(turbo_speed_index); + connect(m_ui.turboSpeed, QOverload::of(&QComboBox::currentIndexChanged), this, + &GeneralSettingsWidget::onTurboSpeedIndexChanged); dialog->registerWidgetHelp( m_ui.confirmPowerOff, tr("Confirm Power Off"), tr("Checked"), @@ -89,8 +96,10 @@ GeneralSettingsWidget::GeneralSettingsWidget(QtHostInterface* host_interface, QW "and if not, the emulator will run as fast as it can manage.")); dialog->registerWidgetHelp( m_ui.fastForwardSpeed, tr("Fast Forward Speed"), "100%", - tr( - "Sets the fast forward (turbo) speed. This speed will be used when the fast forward hotkey is pressed/toggled.")); + tr("Sets the fast forward speed. This speed will be used when the fast forward hotkey is pressed/toggled.")); + dialog->registerWidgetHelp( + m_ui.turboSpeed, tr("Turbo Speed"), "100%", + tr("Sets the turbo speed. This speed will be used when the turbo hotkey is pressed/toggled.")); dialog->registerWidgetHelp(m_ui.controllerBackend, tr("Controller Backend"), qApp->translate("ControllerInterface", ControllerInterface::GetBackendName( ControllerInterface::GetDefaultBackend())), @@ -156,3 +165,11 @@ void GeneralSettingsWidget::onFastForwardSpeedIndexChanged(int index) m_host_interface->SetFloatSettingValue("Main", "FastForwardSpeed", okay ? value : 0.0f); m_host_interface->applySettings(); } + +void GeneralSettingsWidget::onTurboSpeedIndexChanged(int index) +{ + bool okay; + const float value = m_ui.turboSpeed->currentData().toFloat(&okay); + m_host_interface->SetFloatSettingValue("Main", "TurboSpeed", okay ? value : 0.0f); + m_host_interface->applySettings(); +} diff --git a/src/duckstation-qt/generalsettingswidget.h b/src/duckstation-qt/generalsettingswidget.h index c7b3eb886..e168251af 100644 --- a/src/duckstation-qt/generalsettingswidget.h +++ b/src/duckstation-qt/generalsettingswidget.h @@ -18,6 +18,7 @@ public: private Q_SLOTS: void onEmulationSpeedIndexChanged(int index); void onFastForwardSpeedIndexChanged(int index); + void onTurboSpeedIndexChanged(int index); private: Ui::GeneralSettingsWidget m_ui; diff --git a/src/duckstation-qt/generalsettingswidget.ui b/src/duckstation-qt/generalsettingswidget.ui index 597e06b17..49d5d0785 100644 --- a/src/duckstation-qt/generalsettingswidget.ui +++ b/src/duckstation-qt/generalsettingswidget.ui @@ -131,6 +131,16 @@ + + + + Turbo Speed: + + + + + + diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 0cee32314..e612f694c 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -604,7 +604,9 @@ bool CommonHostInterface::ResumeSystemFromMostRecentState() void CommonHostInterface::UpdateSpeedLimiterState() { - const float target_speed = m_fast_forward_enabled ? g_settings.fast_forward_speed : g_settings.emulation_speed; + const float target_speed = m_turbo_enabled ? + g_settings.turbo_speed : + (m_fast_forward_enabled ? g_settings.fast_forward_speed : g_settings.emulation_speed); m_speed_limiter_enabled = (target_speed != 0.0f); const bool is_non_standard_speed = (std::abs(target_speed - 1.0f) > 0.05f); @@ -1435,6 +1437,9 @@ void CommonHostInterface::RegisterGeneralHotkeys() TRANSLATABLE("Hotkeys", "Fast Forward"), [this](bool pressed) { m_fast_forward_enabled = pressed; UpdateSpeedLimiterState(); + AddOSDMessage(m_fast_forward_enabled ? TranslateStdString("OSDMessage", "Fast forwarding...") : + TranslateStdString("OSDMessage", "Stopped fast forwarding."), + 2.0f); }); RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleFastForward"), @@ -1449,6 +1454,27 @@ void CommonHostInterface::RegisterGeneralHotkeys() 2.0f); } }); + + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("Turbo"), + TRANSLATABLE("Hotkeys", "Turbo"), [this](bool pressed) { + m_turbo_enabled = pressed; + UpdateSpeedLimiterState(); + AddOSDMessage(m_turbo_enabled ? TranslateStdString("OSDMessage", "Turboing...") : + TranslateStdString("OSDMessage", "Stopped turboing."), + 2.0f); + }); + + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleTurbo"), + StaticString(TRANSLATABLE("Hotkeys", "Toggle Turbo")), [this](bool pressed) { + if (pressed) + { + m_turbo_enabled = !m_turbo_enabled; + UpdateSpeedLimiterState(); + AddOSDMessage(m_turbo_enabled ? TranslateStdString("OSDMessage", "Turboing...") : + TranslateStdString("OSDMessage", "Stopped turboing."), + 2.0f); + } + }); #ifndef ANDROID RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleFullscreen"), StaticString(TRANSLATABLE("Hotkeys", "Toggle Fullscreen")), [this](bool pressed) { diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index adc3bdd90..40b57ebb3 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -349,6 +349,7 @@ protected: bool m_frame_step_request = false; bool m_fast_forward_enabled = false; + bool m_turbo_enabled = false; bool m_timer_resolution_increased = false; bool m_speed_limiter_enabled = true;