Skip to content

Commit

Permalink
Merge pull request #8408 from ethteck/move-cpu-emulation-engine-options
Browse files Browse the repository at this point in the history
Qt: Move CPU Emulation Engine options to the Advanced tab
  • Loading branch information
Helios747 committed Oct 17, 2019
2 parents 6a15de5 + 2647e41 commit acf9bd5
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Config/SettingsWindow.cpp
Expand Up @@ -47,7 +47,7 @@ SettingsWindow::SettingsWindow(QWidget* parent) : QDialog(parent)
wii_pane->OnEmulationStateChanged(state != Core::State::Uninitialized);
});

m_tab_widget->addTab(new AdvancedPane(), tr("Advanced"));
m_tab_widget->addTab(GetWrappedWidget(new AdvancedPane, this, 125, 200), tr("Advanced"));

// Dialog box buttons
QDialogButtonBox* close_box = new QDialogButtonBox(QDialogButtonBox::Close);
Expand Down
56 changes: 53 additions & 3 deletions Source/Core/DolphinQt/Settings/AdvancedPane.cpp
Expand Up @@ -5,10 +5,13 @@
#include "DolphinQt/Settings/AdvancedPane.h"

#include <QCheckBox>
#include <QComboBox>
#include <QDateTimeEdit>
#include <QFormLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QRadioButton>
#include <QSignalBlocker>
#include <QSlider>
#include <QVBoxLayout>
Expand All @@ -18,9 +21,17 @@
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/SystemTimers.h"
#include "Core/PowerPC/PowerPC.h"

#include "DolphinQt/Settings.h"

static const std::map<PowerPC::CPUCore, const char*> CPU_CORE_NAMES = {
{PowerPC::CPUCore::Interpreter, QT_TR_NOOP("Interpreter (slowest)")},
{PowerPC::CPUCore::CachedInterpreter, QT_TR_NOOP("Cached Interpreter (slower)")},
{PowerPC::CPUCore::JIT64, QT_TR_NOOP("JIT Recompiler (recommended)")},
{PowerPC::CPUCore::JITARM64, QT_TR_NOOP("JIT Arm64 (experimental)")},
};

AdvancedPane::AdvancedPane(QWidget* parent) : QWidget(parent)
{
CreateLayout();
Expand All @@ -29,6 +40,8 @@ AdvancedPane::AdvancedPane(QWidget* parent) : QWidget(parent)
ConnectLayout();

connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, &AdvancedPane::Update);
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
&AdvancedPane::OnEmulationStateChanged);
}

void AdvancedPane::CreateLayout()
Expand All @@ -41,12 +54,28 @@ void AdvancedPane::CreateLayout()
cpu_options->setLayout(cpu_options_layout);
main_layout->addWidget(cpu_options);

QGridLayout* cpu_emulation_layout = new QGridLayout();
QLabel* cpu_emulation_engine_label = new QLabel(tr("CPU Emulation Engine:"));
m_cpu_emulation_engine_combobox = new QComboBox(this);
for (PowerPC::CPUCore cpu_core : PowerPC::AvailableCPUCores())
{
m_cpu_emulation_engine_combobox->addItem(tr(CPU_CORE_NAMES.at(cpu_core)));
}
cpu_emulation_layout->addWidget(cpu_emulation_engine_label, 0, 0);
cpu_emulation_layout->addWidget(m_cpu_emulation_engine_combobox, 0, 1, Qt::AlignLeft);
cpu_options_layout->addLayout(cpu_emulation_layout);

auto* clock_override = new QGroupBox(tr("Clock Override"));
auto* clock_override_layout = new QVBoxLayout();
clock_override->setLayout(clock_override_layout);
main_layout->addWidget(clock_override);

m_cpu_clock_override_checkbox = new QCheckBox(tr("Enable Emulated CPU Clock Override"));
cpu_options_layout->addWidget(m_cpu_clock_override_checkbox);
clock_override_layout->addWidget(m_cpu_clock_override_checkbox);

auto* cpu_clock_override_slider_layout = new QHBoxLayout();
cpu_clock_override_slider_layout->setContentsMargins(0, 0, 0, 0);
cpu_options_layout->addLayout(cpu_clock_override_slider_layout);
clock_override_layout->addLayout(cpu_clock_override_slider_layout);

m_cpu_clock_override_slider = new QSlider(Qt::Horizontal);
m_cpu_clock_override_slider->setRange(0, 150);
Expand All @@ -64,7 +93,7 @@ void AdvancedPane::CreateLayout()
"break games and cause glitches. Do so at your own risk. "
"Please do not report bugs that occur with a non-default clock."));
cpu_clock_override_description->setWordWrap(true);
cpu_options_layout->addWidget(cpu_clock_override_description);
clock_override_layout->addWidget(cpu_clock_override_description);

auto* rtc_options = new QGroupBox(tr("Custom RTC Options"));
rtc_options->setLayout(new QVBoxLayout());
Expand Down Expand Up @@ -100,6 +129,14 @@ void AdvancedPane::CreateLayout()

void AdvancedPane::ConnectLayout()
{
connect(m_cpu_emulation_engine_combobox,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
[this](int index) {
SConfig::GetInstance().cpu_core = PowerPC::AvailableCPUCores()[index];
Config::SetBaseOrCurrent(Config::MAIN_CPU_CORE, PowerPC::AvailableCPUCores()[index]);
Update();
});

m_cpu_clock_override_checkbox->setChecked(SConfig::GetInstance().m_OCEnable);
connect(m_cpu_clock_override_checkbox, &QCheckBox::toggled, [this](bool enable_clock_override) {
SConfig::GetInstance().m_OCEnable = enable_clock_override;
Expand Down Expand Up @@ -136,6 +173,13 @@ void AdvancedPane::Update()
const bool enable_cpu_clock_override_widgets = SConfig::GetInstance().m_OCEnable;
const bool enable_custom_rtc_widgets = SConfig::GetInstance().bEnableCustomRTC && !running;

const std::vector<PowerPC::CPUCore>& available_cpu_cores = PowerPC::AvailableCPUCores();
for (int i = 0; i < available_cpu_cores.size(); ++i)
{
if (available_cpu_cores[i] == SConfig::GetInstance().cpu_core)
m_cpu_emulation_engine_combobox->setCurrentIndex(i);
}

QFont bf = font();
bf.setBold(Config::GetActiveLayerForConfig(Config::MAIN_OVERCLOCK_ENABLE) !=
Config::LayerType::Base);
Expand All @@ -161,3 +205,9 @@ void AdvancedPane::Update()
m_custom_rtc_checkbox->setEnabled(!running);
m_custom_rtc_datetime->setEnabled(enable_custom_rtc_widgets);
}

void AdvancedPane::OnEmulationStateChanged(Core::State state)
{
const bool running = state != Core::State::Uninitialized;
m_cpu_emulation_engine_combobox->setEnabled(!running);
}
11 changes: 11 additions & 0 deletions Source/Core/DolphinQt/Settings/AdvancedPane.h
Expand Up @@ -4,13 +4,22 @@

#pragma once

#include <vector>

#include <QWidget>

class QCheckBox;
class QComboBox;
class QLabel;
class QRadioButton;
class QSlider;
class QDateTimeEdit;

namespace Core
{
enum class State;
}

class AdvancedPane final : public QWidget
{
Q_OBJECT
Expand All @@ -21,7 +30,9 @@ class AdvancedPane final : public QWidget
void CreateLayout();
void ConnectLayout();
void Update();
void OnEmulationStateChanged(Core::State state);

QComboBox* m_cpu_emulation_engine_combobox;
QCheckBox* m_cpu_clock_override_checkbox;
QSlider* m_cpu_clock_override_slider;
QLabel* m_cpu_clock_override_slider_label;
Expand Down
51 changes: 0 additions & 51 deletions Source/Core/DolphinQt/Settings/GeneralPane.cpp
Expand Up @@ -12,7 +12,6 @@
#include <QGroupBox>
#include <QLabel>
#include <QPushButton>
#include <QRadioButton>
#include <QSlider>
#include <QVBoxLayout>
#include <QWidget>
Expand Down Expand Up @@ -42,13 +41,6 @@ constexpr const char* AUTO_UPDATE_STABLE_STRING = "stable";
constexpr const char* AUTO_UPDATE_BETA_STRING = "beta";
constexpr const char* AUTO_UPDATE_DEV_STRING = "dev";

static const std::map<PowerPC::CPUCore, const char*> CPU_CORE_NAMES = {
{PowerPC::CPUCore::Interpreter, QT_TR_NOOP("Interpreter (slowest)")},
{PowerPC::CPUCore::CachedInterpreter, QT_TR_NOOP("Cached Interpreter (slower)")},
{PowerPC::CPUCore::JIT64, QT_TR_NOOP("JIT Recompiler (recommended)")},
{PowerPC::CPUCore::JITARM64, QT_TR_NOOP("JIT Arm64 (experimental)")},
};

GeneralPane::GeneralPane(QWidget* parent) : QWidget(parent)
{
CreateLayout();
Expand All @@ -72,7 +64,6 @@ void GeneralPane::CreateLayout()
#if defined(USE_ANALYTICS) && USE_ANALYTICS
CreateAnalytics();
#endif
CreateAdvanced();

m_main_layout->addStretch(1);
setLayout(m_main_layout);
Expand All @@ -88,9 +79,6 @@ void GeneralPane::OnEmulationStateChanged(Core::State state)
#ifdef USE_DISCORD_PRESENCE
m_checkbox_discord_presence->setEnabled(!running);
#endif

for (QRadioButton* radio_button : m_cpu_cores)
radio_button->setEnabled(!running);
}

void GeneralPane::ConnectLayout()
Expand All @@ -117,8 +105,6 @@ void GeneralPane::ConnectLayout()
connect(m_combobox_speedlimit,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
[this]() { OnSaveConfig(); });
for (QRadioButton* radio_button : m_cpu_cores)
connect(radio_button, &QRadioButton::toggled, this, &GeneralPane::OnSaveConfig);

#if defined(USE_ANALYTICS) && USE_ANALYTICS
connect(&Settings::Instance(), &Settings::AnalyticsToggled, this, &GeneralPane::LoadConfig);
Expand Down Expand Up @@ -208,26 +194,6 @@ void GeneralPane::CreateAnalytics()
}
#endif

void GeneralPane::CreateAdvanced()
{
auto* advanced_group = new QGroupBox(tr("Advanced Settings"));
auto* advanced_group_layout = new QVBoxLayout;
advanced_group->setLayout(advanced_group_layout);
m_main_layout->addWidget(advanced_group);

// Speed Limit
auto* engine_group = new QGroupBox(tr("CPU Emulation Engine"));
auto* engine_group_layout = new QVBoxLayout;
engine_group->setLayout(engine_group_layout);
advanced_group_layout->addWidget(engine_group);

for (PowerPC::CPUCore cpu_core : PowerPC::AvailableCPUCores())
{
m_cpu_cores.emplace_back(new QRadioButton(tr(CPU_CORE_NAMES.at(cpu_core))));
engine_group_layout->addWidget(m_cpu_cores.back());
}
}

void GeneralPane::LoadConfig()
{
if (AutoUpdateChecker::SystemSupportsAutoUpdates())
Expand Down Expand Up @@ -258,13 +224,6 @@ void GeneralPane::LoadConfig()
if (selection < m_combobox_speedlimit->count())
m_combobox_speedlimit->setCurrentIndex(selection);
m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread);

const std::vector<PowerPC::CPUCore>& available_cpu_cores = PowerPC::AvailableCPUCores();
for (size_t i = 0; i < available_cpu_cores.size(); ++i)
{
if (available_cpu_cores[i] == SConfig::GetInstance().cpu_core)
m_cpu_cores[i]->setChecked(true);
}
}

static QString UpdateTrackFromIndex(int index)
Expand Down Expand Up @@ -319,16 +278,6 @@ void GeneralPane::OnSaveConfig()
Config::SetBaseOrCurrent(Config::MAIN_ENABLE_CHEATS, m_checkbox_cheats->isChecked());
settings.m_EmulationSpeed = m_combobox_speedlimit->currentIndex() * 0.1f;

for (size_t i = 0; i < m_cpu_cores.size(); ++i)
{
if (m_cpu_cores[i]->isChecked())
{
settings.cpu_core = PowerPC::AvailableCPUCores()[i];
Config::SetBaseOrCurrent(Config::MAIN_CPU_CORE, PowerPC::AvailableCPUCores()[i]);
break;
}
}

settings.SaveSettings();
}

Expand Down
5 changes: 0 additions & 5 deletions Source/Core/DolphinQt/Settings/GeneralPane.h
Expand Up @@ -4,8 +4,6 @@

#pragma once

#include <vector>

#include <QWidget>

class QCheckBox;
Expand All @@ -32,7 +30,6 @@ class GeneralPane final : public QWidget
void ConnectLayout();
void CreateBasic();
void CreateAutoUpdate();
void CreateAdvanced();

void LoadConfig();
void OnSaveConfig();
Expand All @@ -51,8 +48,6 @@ class GeneralPane final : public QWidget
#endif
QLabel* m_label_speedlimit;

std::vector<QRadioButton*> m_cpu_cores;

// Analytics related
#if defined(USE_ANALYTICS) && USE_ANALYTICS
void CreateAnalytics();
Expand Down

0 comments on commit acf9bd5

Please sign in to comment.