HostInterface: Add proper turbo speed setting

This commit is contained in:
Connor McLaughlin
2020-11-03 21:21:11 +10:00
parent d5a5969bd4
commit 2b66492ed8
20 changed files with 201 additions and 98 deletions

View File

@ -107,6 +107,8 @@ AdvancedSettingsWidget::AdvancedSettingsWidget(QtHostInterface* host_interface,
"UseDebugDevice", false);
addIntRangeTweakOption(m_host_interface, m_ui.tweakOptionTable, tr("Display FPS Limit"), "Display", "MaxFPS", 0, 1000,
0);
addBooleanTweakOption(m_host_interface, m_ui.tweakOptionTable, tr("Increase Timer Resolution"), "Main",
"IncreaseTimerResolution", true);
}
AdvancedSettingsWidget::~AdvancedSettingsWidget() = default;
@ -125,4 +127,5 @@ void AdvancedSettingsWidget::onResetToDefaultClicked()
setIntRangeTweakOption(m_ui.tweakOptionTable, 9, static_cast<int>(Settings::DEFAULT_GPU_MAX_RUN_AHEAD));
setBooleanTweakOption(m_ui.tweakOptionTable, 10, false);
setIntRangeTweakOption(m_ui.tweakOptionTable, 11, 0);
setBooleanTweakOption(m_ui.tweakOptionTable, 12, true);
}

View File

@ -1,6 +1,7 @@
#include "generalsettingswidget.h"
#include "autoupdaterdialog.h"
#include "frontend-common/controller_interface.h"
#include "qtutils.h"
#include "settingsdialog.h"
#include "settingwidgetbinder.h"
@ -27,22 +28,25 @@ GeneralSettingsWidget::GeneralSettingsWidget(QtHostInterface* host_interface, QW
true);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.autoLoadCheats, "Main", "AutoLoadCheats", false);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.enableSpeedLimiter, "Main", "SpeedLimiterEnabled",
true);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.increaseTimerResolution, "Main",
"IncreaseTimerResolution", true);
SettingWidgetBinder::BindWidgetToNormalizedSetting(m_host_interface, m_ui.emulationSpeed, "Main", "EmulationSpeed",
100.0f, 1.0f);
SettingWidgetBinder::BindWidgetToEnumSetting(
m_host_interface, m_ui.controllerBackend, "Main", "ControllerBackend", &ControllerInterface::ParseBackendName,
&ControllerInterface::GetBackendName, ControllerInterface::GetDefaultBackend());
connect(m_ui.enableSpeedLimiter, &QCheckBox::stateChanged, this,
&GeneralSettingsWidget::onEnableSpeedLimiterStateChanged);
connect(m_ui.emulationSpeed, &QSlider::valueChanged, this, &GeneralSettingsWidget::onEmulationSpeedValueChanged);
QtUtils::FillComboBoxWithEmulationSpeeds(m_ui.emulationSpeed);
const int emulation_speed_index =
m_ui.emulationSpeed->findData(QVariant(m_host_interface->GetFloatSettingValue("Main", "EmulationSpeed")));
if (emulation_speed_index >= 0)
m_ui.emulationSpeed->setCurrentIndex(emulation_speed_index);
connect(m_ui.emulationSpeed, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&GeneralSettingsWidget::onEmulationSpeedIndexChanged);
onEnableSpeedLimiterStateChanged();
onEmulationSpeedValueChanged(m_ui.emulationSpeed->value());
QtUtils::FillComboBoxWithEmulationSpeeds(m_ui.fastForwardSpeed);
const int fast_forward_speed_index =
m_ui.emulationSpeed->findData(QVariant(m_host_interface->GetFloatSettingValue("Main", "FastForwardSpeed")));
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);
dialog->registerWidgetHelp(
m_ui.confirmPowerOff, tr("Confirm Power Off"), tr("Checked"),
@ -68,18 +72,14 @@ GeneralSettingsWidget::GeneralSettingsWidget(QtHostInterface* host_interface, QW
m_ui.applyGameSettings, tr("Apply Per-Game Settings"), tr("Checked"),
tr("When enabled, per-game settings will be applied, and incompatible enhancements will be disabled. You should "
"leave this option enabled except when testing enhancements with incompatible games."));
dialog->registerWidgetHelp(
m_ui.enableSpeedLimiter, tr("Enable Speed Limiter"), tr("Checked"),
tr("Throttles the emulation speed to the chosen speed above. If unchecked, the emulator will "
"run as fast as possible, which may not be playable."));
dialog->registerWidgetHelp(
m_ui.increaseTimerResolution, tr("Increase Timer Resolution"), tr("Checked"),
tr("Increases the system timer resolution when emulation is started to provide more accurate "
"frame pacing. May increase battery usage on laptops."));
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, "
"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."));
dialog->registerWidgetHelp(m_ui.controllerBackend, tr("Controller Backend"),
qApp->translate("ControllerInterface", ControllerInterface::GetBackendName(
ControllerInterface::GetDefaultBackend())),
@ -119,12 +119,18 @@ GeneralSettingsWidget::GeneralSettingsWidget(QtHostInterface* host_interface, QW
GeneralSettingsWidget::~GeneralSettingsWidget() = default;
void GeneralSettingsWidget::onEnableSpeedLimiterStateChanged()
void GeneralSettingsWidget::onEmulationSpeedIndexChanged(int index)
{
m_ui.emulationSpeed->setDisabled(!m_ui.enableSpeedLimiter->isChecked());
bool okay;
const float value = m_ui.emulationSpeed->currentData().toFloat(&okay);
m_host_interface->SetFloatSettingValue("Main", "EmulationSpeed", okay ? value : 1.0f);
m_host_interface->applySettings();
}
void GeneralSettingsWidget::onEmulationSpeedValueChanged(int value)
void GeneralSettingsWidget::onFastForwardSpeedIndexChanged(int index)
{
m_ui.emulationSpeedLabel->setText(tr("%1%").arg(value));
bool okay;
const float value = m_ui.fastForwardSpeed->currentData().toFloat(&okay);
m_host_interface->SetFloatSettingValue("Main", "FastForwardSpeed", okay ? value : 0.0f);
m_host_interface->applySettings();
}

View File

@ -16,8 +16,8 @@ public:
~GeneralSettingsWidget();
private Q_SLOTS:
void onEnableSpeedLimiterStateChanged();
void onEmulationSpeedValueChanged(int value);
void onEmulationSpeedIndexChanged(int index);
void onFastForwardSpeedIndexChanged(int index);
private:
Ui::GeneralSettingsWidget m_ui;

View File

@ -94,61 +94,28 @@
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Emulation Speed</string>
<string>Speed Control</string>
</property>
<layout class="QGridLayout" name="formLayout_3">
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSlider" name="emulationSpeed">
<property name="minimum">
<number>25</number>
</property>
<property name="maximum">
<number>500</number>
</property>
<property name="singleStep">
<number>25</number>
</property>
<property name="pageStep">
<number>25</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<number>25</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="emulationSpeedLabel">
<property name="text">
<string>100%</string>
</property>
</widget>
</item>
</layout>
<layout class="QGridLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Emulation Speed:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="emulationSpeed"/>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="enableSpeedLimiter">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Enable Speed Limiter</string>
<string>Fast Forward Speed:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="increaseTimerResolution">
<property name="text">
<string>Increase Timer Resolution</string>
</property>
</widget>
<widget class="QComboBox" name="fastForwardSpeed"/>
</item>
</layout>
</widget>
@ -192,7 +159,7 @@
</layout>
</widget>
<resources>
<include location="resources/icons.qrc"/>
<include location="resources/resources.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -1,5 +1,6 @@
#include "qtutils.h"
#include "common/byte_stream.h"
#include "common/make_array.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QMetaObject>
#include <QtGui/QDesktopServices>
@ -719,4 +720,20 @@ void FillComboBoxWithMSAAModes(QComboBox* cb)
cb->addItem(qApp->translate("GPUSettingsWidget", "%1x SSAA").arg(i), GetMSAAModeValue(i, true));
}
void FillComboBoxWithEmulationSpeeds(QComboBox* cb)
{
cb->addItem(qApp->translate("GeneralSettingsWidget", "Unlimited"), QVariant(0.0f));
static constexpr auto speeds = make_array(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 125, 150, 175, 200, 250, 300, 350,
400, 450, 500, 600, 700, 800, 900, 1000);
for (const int speed : speeds)
{
cb->addItem(qApp->translate("GeneralSettingsWidget", "%1% [%2 FPS (NTSC) / %3 FPS (PAL)]")
.arg(speed)
.arg((60 * speed) / 100)
.arg((50 * speed) / 100),
QVariant(static_cast<float>(speed) / 100.0f));
}
}
} // namespace QtUtils

View File

@ -68,4 +68,7 @@ QVariant GetMSAAModeValue(uint multisamples, bool ssaa);
void DecodeMSAAModeValue(const QVariant& userdata, uint* multisamples, bool* ssaa);
void FillComboBoxWithMSAAModes(QComboBox* cb);
/// Fills a combo box with emulation speed options.
void FillComboBoxWithEmulationSpeeds(QComboBox* cb);
} // namespace QtUtils