mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-31 03:45:38 +00:00
Qt: Add options for CPU overclocking
This commit is contained in:
parent
27697d0508
commit
61a66ed908
|
@ -1,6 +1,9 @@
|
|||
#include "consolesettingswidget.h"
|
||||
#include "core/system.h"
|
||||
#include "qtutils.h"
|
||||
#include "settingsdialog.h"
|
||||
#include "settingwidgetbinder.h"
|
||||
#include <QtWidgets/QMessageBox>
|
||||
|
||||
ConsoleSettingsWidget::ConsoleSettingsWidget(QtHostInterface* host_interface, QWidget* parent, SettingsDialog* dialog)
|
||||
: QWidget(parent), m_host_interface(host_interface)
|
||||
|
@ -25,6 +28,8 @@ ConsoleSettingsWidget::ConsoleSettingsWidget(QtHostInterface* host_interface, QW
|
|||
SettingWidgetBinder::BindWidgetToEnumSetting(m_host_interface, m_ui.cpuExecutionMode, "CPU", "ExecutionMode",
|
||||
&Settings::ParseCPUExecutionMode, &Settings::GetCPUExecutionModeName,
|
||||
Settings::DEFAULT_CPU_EXECUTION_MODE);
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.enableCPUClockSpeedControl, "CPU",
|
||||
"OverclockEnable", false);
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.cdromReadThread, "CDROM", "ReadThread");
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.cdromRegionCheck, "CDROM", "RegionCheck");
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.cdromLoadImageToRAM, "CDROM", "LoadImageToRAM",
|
||||
|
@ -34,6 +39,67 @@ ConsoleSettingsWidget::ConsoleSettingsWidget(QtHostInterface* host_interface, QW
|
|||
m_ui.cdromLoadImageToRAM, tr("Preload Image to RAM"), tr("Unchecked"),
|
||||
tr("Loads the game image into RAM. Useful for network paths that may become unreliable during gameplay. In some "
|
||||
"cases also eliminates stutter when games initiate audio track playback."));
|
||||
|
||||
m_ui.cpuClockSpeed->setEnabled(m_ui.enableCPUClockSpeedControl->checkState() == Qt::Checked);
|
||||
connect(m_ui.enableCPUClockSpeedControl, &QCheckBox::stateChanged, this,
|
||||
&ConsoleSettingsWidget::onEnableCPUClockSpeedControlChecked);
|
||||
connect(m_ui.cpuClockSpeed, &QSlider::valueChanged, this, &ConsoleSettingsWidget::onCPUClockSpeedValueChanged);
|
||||
|
||||
calculateCPUClockValue();
|
||||
}
|
||||
|
||||
ConsoleSettingsWidget::~ConsoleSettingsWidget() = default;
|
||||
|
||||
void ConsoleSettingsWidget::onEnableCPUClockSpeedControlChecked(int state)
|
||||
{
|
||||
if (state == Qt::Checked && !m_host_interface->GetBoolSettingValue("UI", "CPUOverclockingWarningShown", false))
|
||||
{
|
||||
const QString message =
|
||||
tr("Enabling CPU overclocking will break games, cause bugs, reduce performance and can significantly increase "
|
||||
"system requirements.\n\nBy enabling this option you are agreeing to not create any bug reports unless you "
|
||||
"have confirmed the bug also occurs with overclocking disabled.\n\nThis warning will only be shown once.");
|
||||
const QString yes_button = tr("Yes, I will confirm bugs without overclocking before reporting.");
|
||||
const QString no_button = tr("No, take me back to safety.");
|
||||
|
||||
if (QMessageBox::question(QtUtils::GetRootWidget(this), tr("CPU Overclocking Warning"), message, yes_button,
|
||||
no_button) != 0)
|
||||
{
|
||||
QSignalBlocker sb(m_ui.enableCPUClockSpeedControl);
|
||||
m_ui.enableCPUClockSpeedControl->setChecked(Qt::Unchecked);
|
||||
return;
|
||||
}
|
||||
|
||||
m_host_interface->SetBoolSettingValue("UI", "CPUOverclockingWarningShown", true);
|
||||
}
|
||||
|
||||
m_ui.cpuClockSpeed->setEnabled(state == Qt::Checked);
|
||||
updateCPUClockSpeedLabel();
|
||||
}
|
||||
|
||||
void ConsoleSettingsWidget::onCPUClockSpeedValueChanged(int value)
|
||||
{
|
||||
const u32 percent = static_cast<u32>(m_ui.cpuClockSpeed->value());
|
||||
u32 numerator, denominator;
|
||||
Settings::CPUOverclockPercentToFraction(percent, &numerator, &denominator);
|
||||
m_host_interface->SetIntSettingValue("CPU", "OverclockNumerator", static_cast<int>(numerator));
|
||||
m_host_interface->SetIntSettingValue("CPU", "OverclockDenominator", static_cast<int>(denominator));
|
||||
updateCPUClockSpeedLabel();
|
||||
m_host_interface->applySettings();
|
||||
}
|
||||
|
||||
void ConsoleSettingsWidget::updateCPUClockSpeedLabel()
|
||||
{
|
||||
const int percent = m_ui.enableCPUClockSpeedControl->isChecked() ? m_ui.cpuClockSpeed->value() : 100;
|
||||
const double frequency = (static_cast<double>(System::MASTER_CLOCK) * static_cast<double>(percent)) / 100.0;
|
||||
m_ui.cpuClockSpeedLabel->setText(tr("%1% (%2MHz)").arg(percent).arg(frequency / 1000000.0, 0, 'f', 2));
|
||||
}
|
||||
|
||||
void ConsoleSettingsWidget::calculateCPUClockValue()
|
||||
{
|
||||
const u32 numerator = static_cast<u32>(m_host_interface->GetIntSettingValue("CPU", "OverclockNumerator", 1));
|
||||
const u32 denominator = static_cast<u32>(m_host_interface->GetIntSettingValue("CPU", "OverclockDenominator", 1));
|
||||
const u32 percent = Settings::CPUOverclockFractionToPercent(numerator, denominator);
|
||||
QSignalBlocker sb(m_ui.cpuClockSpeed);
|
||||
m_ui.cpuClockSpeed->setValue(static_cast<int>(percent));
|
||||
updateCPUClockSpeedLabel();
|
||||
}
|
||||
|
|
|
@ -15,7 +15,14 @@ public:
|
|||
explicit ConsoleSettingsWidget(QtHostInterface* host_interface, QWidget* parent, SettingsDialog* dialog);
|
||||
~ConsoleSettingsWidget();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onEnableCPUClockSpeedControlChecked(int state);
|
||||
void onCPUClockSpeedValueChanged(int value);
|
||||
void updateCPUClockSpeedLabel();
|
||||
|
||||
private:
|
||||
void calculateCPUClockValue();
|
||||
|
||||
Ui::ConsoleSettingsWidget m_ui;
|
||||
|
||||
QtHostInterface* m_host_interface;
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>502</width>
|
||||
<height>255</height>
|
||||
<width>541</width>
|
||||
<height>351</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -64,6 +64,71 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>CPU Clock Speed Control</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="enableCPUClockSpeedControl">
|
||||
<property name="text">
|
||||
<string>Enable Clock Speed Control (Overclocking/Underclocking)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="cpuClockSpeedLabel">
|
||||
<property name="text">
|
||||
<string>100% (effective 33.3mhz)</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QSlider" name="cpuClockSpeed">
|
||||
<property name="minimum">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>1000</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::TicksBothSides</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>50</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<property name="title">
|
||||
|
|
Loading…
Reference in a new issue