From 17be4c69b9a924573d8b7cbe9df7d1af7a003f7c Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 26 May 2018 15:06:57 +0200 Subject: [PATCH] DolphinQt2: Provide proper CPU core options for non-x64 systems --- .../Core/DolphinQt2/Settings/GeneralPane.cpp | 69 +++++++++---------- Source/Core/DolphinQt2/Settings/GeneralPane.h | 6 +- 2 files changed, 34 insertions(+), 41 deletions(-) diff --git a/Source/Core/DolphinQt2/Settings/GeneralPane.cpp b/Source/Core/DolphinQt2/Settings/GeneralPane.cpp index a50640f944..ecc091db23 100644 --- a/Source/Core/DolphinQt2/Settings/GeneralPane.cpp +++ b/Source/Core/DolphinQt2/Settings/GeneralPane.cpp @@ -4,6 +4,8 @@ #include "DolphinQt2/Settings/GeneralPane.h" +#include + #include #include #include @@ -33,6 +35,13 @@ 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 CPU_CORE_NAMES = { + {PowerPC::CORE_INTERPRETER, QT_TR_NOOP("Interpreter (slowest)")}, + {PowerPC::CORE_CACHEDINTERPRETER, QT_TR_NOOP("Cached Interpreter (slower)")}, + {PowerPC::CORE_JIT64, QT_TR_NOOP("JIT Recompiler (recommended)")}, + {PowerPC::CORE_JITARM64, QT_TR_NOOP("JIT Arm64 (experimental)")}, +}; + GeneralPane::GeneralPane(QWidget* parent) : QWidget(parent) { CreateLayout(); @@ -68,9 +77,8 @@ void GeneralPane::OnEmulationStateChanged(Core::State state) m_checkbox_dualcore->setEnabled(!running); m_checkbox_cheats->setEnabled(!running); - m_radio_interpreter->setEnabled(!running); - m_radio_cached_interpreter->setEnabled(!running); - m_radio_jit->setEnabled(!running); + for (QRadioButton* radio_button : m_cpu_cores) + radio_button->setEnabled(!running); } void GeneralPane::ConnectLayout() @@ -91,9 +99,8 @@ void GeneralPane::ConnectLayout() connect(m_combobox_speedlimit, static_cast(&QComboBox::currentIndexChanged), [this]() { OnSaveConfig(); }); - connect(m_radio_interpreter, &QRadioButton::toggled, this, &GeneralPane::OnSaveConfig); - connect(m_radio_cached_interpreter, &QRadioButton::toggled, this, &GeneralPane::OnSaveConfig); - connect(m_radio_jit, &QRadioButton::toggled, this, &GeneralPane::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); @@ -180,13 +187,11 @@ void GeneralPane::CreateAdvanced() engine_group->setLayout(engine_group_layout); advanced_group_layout->addWidget(engine_group); - m_radio_interpreter = new QRadioButton(tr("Interpreter (slowest)")); - m_radio_cached_interpreter = new QRadioButton(tr("Cached Interpreter (slower)")); - m_radio_jit = new QRadioButton(tr("JIT Recompiler (recommended)")); - - engine_group_layout->addWidget(m_radio_interpreter); - engine_group_layout->addWidget(m_radio_cached_interpreter); - engine_group_layout->addWidget(m_radio_jit); + 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() @@ -215,22 +220,11 @@ void GeneralPane::LoadConfig() m_combobox_speedlimit->setCurrentIndex(selection); m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread); - switch (SConfig::GetInstance().iCPUCore) + const std::vector& available_cpu_cores = PowerPC::AvailableCPUCores(); + for (size_t i = 0; i < available_cpu_cores.size(); ++i) { - case PowerPC::CPUCore::CORE_INTERPRETER: - m_radio_interpreter->setChecked(true); - break; - case PowerPC::CPUCore::CORE_CACHEDINTERPRETER: - m_radio_cached_interpreter->setChecked(true); - break; - case PowerPC::CPUCore::CORE_JIT64: - m_radio_jit->setChecked(true); - break; - case PowerPC::CPUCore::CORE_JITARM64: - // TODO: Implement JITARM - break; - default: - break; + if (available_cpu_cores[i] == SConfig::GetInstance().iCPUCore) + m_cpu_cores[i]->setChecked(true); } } @@ -272,17 +266,16 @@ void GeneralPane::OnSaveConfig() settings.bCPUThread = m_checkbox_dualcore->isChecked(); Settings::Instance().SetCheatsEnabled(m_checkbox_cheats->isChecked()); settings.m_EmulationSpeed = m_combobox_speedlimit->currentIndex() * 0.1f; - int engine_value = 0; - if (m_radio_interpreter->isChecked()) - engine_value = PowerPC::CPUCore::CORE_INTERPRETER; - else if (m_radio_cached_interpreter->isChecked()) - engine_value = PowerPC::CPUCore::CORE_CACHEDINTERPRETER; - else if (m_radio_jit->isChecked()) - engine_value = PowerPC::CPUCore::CORE_JIT64; - else - engine_value = PowerPC::CPUCore::CORE_JIT64; - settings.iCPUCore = engine_value; + for (size_t i = 0; i < m_cpu_cores.size(); ++i) + { + if (m_cpu_cores[i]->isChecked()) + { + settings.iCPUCore = PowerPC::AvailableCPUCores()[i]; + break; + } + } + settings.SaveSettings(); } diff --git a/Source/Core/DolphinQt2/Settings/GeneralPane.h b/Source/Core/DolphinQt2/Settings/GeneralPane.h index f1bbc0ff82..d98cb76c16 100644 --- a/Source/Core/DolphinQt2/Settings/GeneralPane.h +++ b/Source/Core/DolphinQt2/Settings/GeneralPane.h @@ -4,6 +4,8 @@ #pragma once +#include + #include class QCheckBox; @@ -44,9 +46,7 @@ private: QCheckBox* m_checkbox_cheats; QLabel* m_label_speedlimit; - QRadioButton* m_radio_interpreter; - QRadioButton* m_radio_cached_interpreter; - QRadioButton* m_radio_jit; + std::vector m_cpu_cores; // Analytics related #if defined(USE_ANALYTICS) && USE_ANALYTICS