pcsx2/pcsx2-qt/Settings/SystemSettingsWidget.cpp

142 lines
6.3 KiB
C++
Raw Normal View History

2021-12-13 12:12:54 +00:00
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2022 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrecompiledHeader.h"
#include <QtWidgets/QMessageBox>
#include <algorithm>
#include "pcsx2/HostSettings.h"
2021-12-13 12:12:54 +00:00
#include "EmuThread.h"
#include "QtUtils.h"
#include "SettingWidgetBinder.h"
#include "SettingsDialog.h"
#include "SystemSettingsWidget.h"
static constexpr int MINIMUM_EE_CYCLE_RATE = -3;
static constexpr int MAXIMUM_EE_CYCLE_RATE = 3;
static constexpr int DEFAULT_EE_CYCLE_RATE = 0;
static constexpr int DEFAULT_EE_CYCLE_SKIP = 0;
2022-02-15 14:29:18 +00:00
SystemSettingsWidget::SystemSettingsWidget(SettingsDialog* dialog, QWidget* parent)
2021-12-13 12:12:54 +00:00
: QWidget(parent)
2022-02-15 14:29:18 +00:00
, m_dialog(dialog)
2021-12-13 12:12:54 +00:00
{
2022-02-15 14:29:18 +00:00
SettingsInterface* sif = dialog->getSettingsInterface();
2021-12-13 12:12:54 +00:00
m_ui.setupUi(this);
2022-03-04 08:04:05 +00:00
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.eeCycleSkipping, "EmuCore/Speedhacks", "EECycleSkip", DEFAULT_EE_CYCLE_SKIP);
2022-02-15 14:29:18 +00:00
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.MTVU, "EmuCore/Speedhacks", "vuThread", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.instantVU1, "EmuCore/Speedhacks", "vu1Instant", true);
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.eeRoundingMode, "EmuCore/CPU", "FPU.Roundmode", 3);
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.vuRoundingMode, "EmuCore/CPU", "VU.Roundmode", 3);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.fastCDVD, "EmuCore/Speedhacks", "fastCDVD", false);
if (m_dialog->isPerGameSettings())
{
m_ui.eeCycleRate->insertItem(
0, tr("Use Global Setting [%1]")
.arg(m_ui.eeCycleRate->itemText(
std::clamp(Host::GetBaseIntSettingValue("EmuCore/Speedhacks", "EECycleRate", DEFAULT_EE_CYCLE_RATE) - MINIMUM_EE_CYCLE_RATE,
2022-02-15 14:29:18 +00:00
0, MAXIMUM_EE_CYCLE_RATE - MINIMUM_EE_CYCLE_RATE))));
m_ui.eeClampMode->insertItem(0, tr("Use Global Setting [%1]").arg(m_ui.eeClampMode->itemText(getGlobalClampingModeIndex(false))));
m_ui.vuClampMode->insertItem(0, tr("Use Global Setting [%1]").arg(m_ui.vuClampMode->itemText(getGlobalClampingModeIndex(true))));
}
const std::optional<int> cycle_rate =
m_dialog->getIntValue("EmuCore/Speedhacks", "EECycleRate", sif ? std::nullopt : std::optional<int>(DEFAULT_EE_CYCLE_RATE));
m_ui.eeCycleRate->setCurrentIndex(cycle_rate.has_value() ? (std::clamp(cycle_rate.value(), MINIMUM_EE_CYCLE_RATE, MAXIMUM_EE_CYCLE_RATE) +
(0 - MINIMUM_EE_CYCLE_RATE) + static_cast<int>(m_dialog->isPerGameSettings())) :
0);
connect(m_ui.eeCycleRate, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index) {
std::optional<int> value;
if (!m_dialog->isPerGameSettings() || index > 0)
value = MINIMUM_EE_CYCLE_RATE + index - static_cast<int>(m_dialog->isPerGameSettings());
m_dialog->setIntSettingValue("EmuCore/Speedhacks", "EECycleRate", value);
2021-12-13 12:12:54 +00:00
});
2022-02-15 14:29:18 +00:00
m_ui.eeClampMode->setCurrentIndex(getClampingModeIndex(false));
2021-12-13 12:12:54 +00:00
m_ui.vuClampMode->setCurrentIndex(getClampingModeIndex(true));
2022-02-15 14:29:18 +00:00
connect(m_ui.eeClampMode, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) { setClampingMode(false, index); });
connect(m_ui.vuClampMode, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) { setClampingMode(true, index); });
2021-12-13 12:12:54 +00:00
updateVU1InstantState();
connect(m_ui.MTVU, &QCheckBox::stateChanged, this, &SystemSettingsWidget::updateVU1InstantState);
}
SystemSettingsWidget::~SystemSettingsWidget() = default;
void SystemSettingsWidget::updateVU1InstantState()
{
2022-02-15 14:29:18 +00:00
m_ui.instantVU1->setEnabled(!m_dialog->getEffectiveBoolValue("EmuCore/Speedhacks", "vuThread", false));
2021-12-13 12:12:54 +00:00
}
2022-02-15 14:29:18 +00:00
int SystemSettingsWidget::getGlobalClampingModeIndex(bool vu) const
2021-12-13 12:12:54 +00:00
{
if (Host::GetBaseBoolSettingValue("EmuCore/CPU/Recompiler", vu ? "vuSignOverflow" : "fpuFullMode", false))
2021-12-13 12:12:54 +00:00
return 3;
2022-02-15 14:29:18 +00:00
if (Host::GetBaseBoolSettingValue("EmuCore/CPU/Recompiler", vu ? "vuExtraOverflow" : "fpuExtraOverflow", false))
2021-12-13 12:12:54 +00:00
return 2;
2022-02-15 14:29:18 +00:00
if (Host::GetBaseBoolSettingValue("EmuCore/CPU/Recompiler", vu ? "vuOverflow" : "fpuOverflow", true))
2021-12-13 12:12:54 +00:00
return 1;
2022-02-15 14:29:18 +00:00
2021-12-13 12:12:54 +00:00
return 0;
}
2022-02-15 14:29:18 +00:00
int SystemSettingsWidget::getClampingModeIndex(bool vu) const
{
// This is so messy... maybe we should just make the mode an int in the settings too...
const bool base = m_dialog->isPerGameSettings() ? 1 : 0;
std::optional<bool> default_false = m_dialog->isPerGameSettings() ? std::nullopt : std::optional<bool>(false);
std::optional<bool> default_true = m_dialog->isPerGameSettings() ? std::nullopt : std::optional<bool>(true);
std::optional<bool> third = m_dialog->getBoolValue("EmuCore/CPU/Recompiler", vu ? "vuSignOverflow" : "fpuFullMode", default_false);
std::optional<bool> second = m_dialog->getBoolValue("EmuCore/CPU/Recompiler", vu ? "vuExtraOverflow" : "fpuExtraOverflow", default_false);
std::optional<bool> first = m_dialog->getBoolValue("EmuCore/CPU/Recompiler", vu ? "vuOverflow" : "fpuOverflow", default_true);
if (third.has_value() && third.value())
return base + 3;
if (second.has_value() && second.value())
return base + 2;
if (first.has_value() && first.value())
return base + 1;
else if (first.has_value())
return base + 0; // none
else
return 0; // no per game override
}
2021-12-13 12:12:54 +00:00
void SystemSettingsWidget::setClampingMode(bool vu, int index)
{
2022-02-15 14:29:18 +00:00
std::optional<bool> first, second, third;
if (!m_dialog->isPerGameSettings() || index > 0)
{
const bool base = m_dialog->isPerGameSettings() ? 1 : 0;
third = (index >= (base + 3));
second = (index >= (base + 2));
first = (index >= (base + 1));
}
m_dialog->setBoolSettingValue("EmuCore/CPU/Recompiler", vu ? "vuSignOverflow" : "fpuFullMode", third);
m_dialog->setBoolSettingValue("EmuCore/CPU/Recompiler", vu ? "vuExtraOverflow" : "fpuExtraOverflow", second);
m_dialog->setBoolSettingValue("EmuCore/CPU/Recompiler", vu ? "vuOverflow" : "fpuOverflow", first);
2021-12-13 12:12:54 +00:00
}