Qt: Add turbo speed setting

This commit is contained in:
Connor McLaughlin 2021-01-11 01:57:10 +10:00
parent d73fedcef1
commit 54f5563321
8 changed files with 64 additions and 5 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -131,6 +131,16 @@
<item row="1" column="1">
<widget class="QComboBox" name="fastForwardSpeed"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Turbo Speed:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="turboSpeed"/>
</item>
</layout>
</widget>
</item>

View file

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

View file

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