configuration: add comments, assume less, and clang format

No longer assumes that a disabled UI element means the global state is turned
off, instead opting to directly answer that question. Still however assumes a
game is running if it is in that state.
This commit is contained in:
lat9nq
2020-06-24 23:59:29 -04:00
parent 4ac4554e9a
commit 081f91fcf8
10 changed files with 62 additions and 37 deletions

View File

@@ -547,6 +547,7 @@ std::string GetTimeZoneString();
void Apply();
void LogSettings();
// Restore the global state of all applicable settings in the Values struct
void RestoreGlobalState();
} // namespace Settings

View File

@@ -1156,7 +1156,8 @@ void Config::SaveSystemValues() {
WriteSettingGlobal(QStringLiteral("rng_seed_enabled"),
Settings::values.rng_seed.GetValue(global).has_value(),
Settings::values.rng_seed.UsingGlobal(), false);
WriteSettingGlobal(QStringLiteral("rng_seed"), Settings::values.rng_seed.GetValue(global).value_or(0),
WriteSettingGlobal(QStringLiteral("rng_seed"),
Settings::values.rng_seed.GetValue(global).value_or(0),
Settings::values.rng_seed.UsingGlobal(), 0);
WriteSettingGlobal(QStringLiteral("custom_rtc_enabled"),

View File

@@ -83,6 +83,8 @@ private:
QVariant ReadSetting(const QString& name) const;
QVariant ReadSetting(const QString& name, const QVariant& default_value) const;
// Templated ReadSettingGlobal functions will also look for the use_global setting and set
// both the value and the global state properly
template <typename Type>
void ReadSettingGlobal(Settings::Setting<Type>& setting, const QString& name);
template <typename Type>
@@ -90,6 +92,8 @@ private:
const QVariant& default_value);
template <typename Type>
void ReadSettingGlobal(Type& setting, const QString& name, const QVariant& default_value) const;
// Templated WriteSettingGlobal functions will also write the global state if needed and will
// skip writing the actual setting if it defers to the global value
void WriteSetting(const QString& name, const QVariant& value);
void WriteSetting(const QString& name, const QVariant& value, const QVariant& default_value);
template <typename Type>

View File

@@ -16,6 +16,8 @@ constexpr int USE_GLOBAL_SEPARATOR_INDEX = 1;
constexpr int USE_GLOBAL_OFFSET = 2;
const QString use_global_text = QString::fromUtf8("Use global configuration");
// Global-aware apply and set functions
void ApplyPerGameSetting(Settings::Setting<bool>* setting, const QCheckBox* checkbox);
void ApplyPerGameSetting(Settings::Setting<int>* setting, const QComboBox* combobox);
void ApplyPerGameSetting(Settings::Setting<Settings::RendererBackend>* setting,

View File

@@ -103,12 +103,18 @@ void ConfigureAudio::ApplyConfiguration() {
Settings::values.sink_id =
ui->output_sink_combo_box->itemText(ui->output_sink_combo_box->currentIndex())
.toStdString();
Settings::values.enable_audio_stretching = ui->toggle_audio_stretching->isChecked();
Settings::values.audio_device_id =
ui->audio_device_combo_box->itemText(ui->audio_device_combo_box->currentIndex())
.toStdString();
Settings::values.volume =
static_cast<float>(ui->volume_slider->sliderPosition()) / ui->volume_slider->maximum();
// Guard if during game and set to game-specific value
if (!Settings::values.enable_audio_stretching.UsingGlobal()) {
Settings::values.enable_audio_stretching = ui->toggle_audio_stretching->isChecked();
}
if (!Settings::values.volume.UsingGlobal()) {
Settings::values.volume = static_cast<float>(ui->volume_slider->sliderPosition()) /
ui->volume_slider->maximum();
}
} else {
ConfigurationShared::ApplyPerGameSetting(&Settings::values.enable_audio_stretching,
ui->toggle_audio_stretching);
@@ -157,7 +163,8 @@ void ConfigureAudio::RetranslateUI() {
void ConfigureAudio::SetupPerGameUI() {
if (Settings::configuring_global) {
ui->volume_slider->setEnabled(Settings::values.volume.UsingGlobal());
ui->toggle_audio_stretching->setEnabled(Settings::values.enable_audio_stretching.UsingGlobal());
ui->toggle_audio_stretching->setEnabled(
Settings::values.enable_audio_stretching.UsingGlobal());
return;
}

View File

@@ -43,7 +43,8 @@ void ConfigureGeneral::SetConfiguration() {
ui->toggle_frame_limit->setCheckState(Qt::PartiallyChecked);
}
ui->frame_limit->setEnabled(ui->toggle_frame_limit->checkState() == Qt::Checked && ui->toggle_frame_limit->isEnabled());
ui->frame_limit->setEnabled(ui->toggle_frame_limit->checkState() == Qt::Checked &&
ui->toggle_frame_limit->isEnabled());
}
void ConfigureGeneral::ApplyConfiguration() {
@@ -60,14 +61,16 @@ void ConfigureGeneral::ApplyConfiguration() {
Settings::values.use_frame_limit.SetGlobal(false);
Settings::values.frame_limit.SetGlobal(false);
}
if (ui->toggle_frame_limit->isEnabled()) {
// Guard if during game and set to game-specific value
if (!Settings::values.use_frame_limit.UsingGlobal()) {
Settings::values.use_frame_limit = ui->toggle_frame_limit->checkState() == Qt::Checked;
Settings::values.frame_limit = ui->frame_limit->value();
}
}
else {
Settings::values.use_frame_limit.SetGlobal(ui->toggle_frame_limit->checkState() == Qt::PartiallyChecked);
Settings::values.frame_limit.SetGlobal(ui->toggle_frame_limit->checkState() == Qt::PartiallyChecked);
} else {
Settings::values.use_frame_limit.SetGlobal(ui->toggle_frame_limit->checkState() ==
Qt::PartiallyChecked);
Settings::values.frame_limit.SetGlobal(ui->toggle_frame_limit->checkState() ==
Qt::PartiallyChecked);
Settings::values.use_frame_limit = ui->toggle_frame_limit->checkState() == Qt::Checked;
Settings::values.frame_limit = ui->frame_limit->value();
}

View File

@@ -85,23 +85,24 @@ void ConfigureGraphics::SetConfiguration() {
void ConfigureGraphics::ApplyConfiguration() {
if (Settings::configuring_global) {
if (ui->api->isEnabled()) {
// Guard if during game and set to game-specific value
if (!Settings::values.renderer_backend.UsingGlobal()) {
Settings::values.renderer_backend = GetCurrentGraphicsBackend();
}
if (ui->device->isEnabled()) {
if (!Settings::values.vulkan_device.UsingGlobal()) {
Settings::values.vulkan_device = vulkan_device;
}
if (ui->aspect_ratio_combobox->isEnabled()) {
if (!Settings::values.aspect_ratio.UsingGlobal()) {
Settings::values.aspect_ratio = ui->aspect_ratio_combobox->currentIndex();
}
if (ui->use_disk_shader_cache->isEnabled()) {
if (!Settings::values.use_disk_shader_cache.UsingGlobal()) {
Settings::values.use_disk_shader_cache = ui->use_disk_shader_cache->isChecked();
}
if (ui->use_asynchronous_gpu_emulation->isEnabled()) {
if (!Settings::values.use_asynchronous_gpu_emulation.UsingGlobal()) {
Settings::values.use_asynchronous_gpu_emulation =
ui->use_asynchronous_gpu_emulation->isChecked();
}
if (ui->bg_button->isEnabled()) {
if (!Settings::values.bg_red.UsingGlobal()) {
Settings::values.bg_red = static_cast<float>(bg_color.redF());
Settings::values.bg_green = static_cast<float>(bg_color.greenF());
Settings::values.bg_blue = static_cast<float>(bg_color.blueF());
@@ -212,7 +213,8 @@ void ConfigureGraphics::SetupPerGameUI() {
ui->api->setEnabled(Settings::values.renderer_backend.UsingGlobal());
ui->device->setEnabled(Settings::values.renderer_backend.UsingGlobal());
ui->aspect_ratio_combobox->setEnabled(Settings::values.aspect_ratio.UsingGlobal());
ui->use_asynchronous_gpu_emulation->setEnabled(Settings::values.use_asynchronous_gpu_emulation.UsingGlobal());
ui->use_asynchronous_gpu_emulation->setEnabled(
Settings::values.use_asynchronous_gpu_emulation.UsingGlobal());
ui->use_disk_shader_cache->setEnabled(Settings::values.use_disk_shader_cache.UsingGlobal());
ui->bg_button->setEnabled(Settings::values.bg_red.UsingGlobal());

View File

@@ -52,27 +52,27 @@ void ConfigureGraphicsAdvanced::SetConfiguration() {
void ConfigureGraphicsAdvanced::ApplyConfiguration() {
// Subtract 2 if configuring per-game (separator and "use global configuration" take 2 slots)
auto gpu_accuracy = static_cast<Settings::GPUAccuracy>(
ui->gpu_accuracy->currentIndex() - ((Settings::configuring_global) ? 0 : 2));
ui->gpu_accuracy->currentIndex() -
((Settings::configuring_global) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET));
if (Settings::configuring_global) {
// Must guard if they aren't enabled in case of a in-game configuration of settings while
// already set to be game-specific.
if (ui->gpu_accuracy->isEnabled()) {
// Must guard in case of a during-game configuration when set to be game-specific.
if (!Settings::values.gpu_accuracy.UsingGlobal()) {
Settings::values.gpu_accuracy = gpu_accuracy;
}
if (ui->use_vsync->isEnabled()) {
if (!Settings::values.use_vsync.UsingGlobal()) {
Settings::values.use_vsync = ui->use_vsync->isChecked();
}
if (ui->use_assembly_shaders->isEnabled()) {
if (!Settings::values.use_assembly_shaders.UsingGlobal()) {
Settings::values.use_assembly_shaders = ui->use_assembly_shaders->isChecked();
}
if (ui->use_fast_gpu_time->isEnabled()) {
if (!Settings::values.use_fast_gpu_time.UsingGlobal()) {
Settings::values.use_fast_gpu_time = ui->use_fast_gpu_time->isChecked();
}
if (ui->force_30fps_mode->isEnabled()) {
if (!Settings::values.force_30fps_mode.UsingGlobal()) {
Settings::values.force_30fps_mode = ui->force_30fps_mode->isChecked();
}
if (ui->anisotropic_filtering_combobox->isEnabled()) {
if (!Settings::values.max_anisotropy.UsingGlobal()) {
Settings::values.max_anisotropy = ui->anisotropic_filtering_combobox->currentIndex();
}
} else {
@@ -88,7 +88,7 @@ void ConfigureGraphicsAdvanced::ApplyConfiguration() {
ConfigurationShared::ApplyPerGameSetting(&Settings::values.max_anisotropy,
ui->anisotropic_filtering_combobox);
if (ui->gpu_accuracy->currentIndex() == 0) {
if (ui->gpu_accuracy->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
Settings::values.gpu_accuracy.SetGlobal(true);
} else {
Settings::values.gpu_accuracy.SetGlobal(false);
@@ -117,7 +117,8 @@ void ConfigureGraphicsAdvanced::SetupPerGameUI() {
ui->use_assembly_shaders->setEnabled(Settings::values.use_assembly_shaders.UsingGlobal());
ui->use_fast_gpu_time->setEnabled(Settings::values.use_fast_gpu_time.UsingGlobal());
ui->force_30fps_mode->setEnabled(Settings::values.force_30fps_mode.UsingGlobal());
ui->anisotropic_filtering_combobox->setEnabled(Settings::values.max_anisotropy.UsingGlobal());
ui->anisotropic_filtering_combobox->setEnabled(
Settings::values.max_anisotropy.UsingGlobal());
return;
}

View File

@@ -61,6 +61,7 @@ void ConfigurePerGame::ApplyConfiguration() {
Settings::Apply();
Settings::LogSettings();
// If a game is running, DO NOT restore the global settings state
if (!Core::System::GetInstance().IsPoweredOn()) {
Settings::RestoreGlobalState();
}

View File

@@ -74,11 +74,13 @@ void ConfigureSystem::SetConfiguration() {
ui->combo_sound->setCurrentIndex(Settings::values.sound_index);
ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.GetValue().has_value());
ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.GetValue().has_value() && Settings::values.rng_seed.UsingGlobal());
ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.GetValue().has_value() &&
Settings::values.rng_seed.UsingGlobal());
ui->rng_seed_edit->setText(rng_seed);
ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc.GetValue().has_value());
ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.GetValue().has_value() && Settings::values.rng_seed.UsingGlobal());
ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.GetValue().has_value() &&
Settings::values.rng_seed.UsingGlobal());
ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time.count()));
} else {
ConfigurationShared::SetPerGameSetting(ui->combo_language,
@@ -120,20 +122,21 @@ void ConfigureSystem::ApplyConfiguration() {
}
if (Settings::configuring_global) {
if (ui->combo_language->isEnabled()) {
// Guard if during game and set to game-specific value
if (!Settings::values.language_index.UsingGlobal()) {
Settings::values.language_index = ui->combo_language->currentIndex();
}
if (ui->combo_region->isEnabled()) {
if (!Settings::values.region_index.UsingGlobal()) {
Settings::values.region_index = ui->combo_region->currentIndex();
}
if (ui->combo_time_zone->isEnabled()) {
if (!Settings::values.time_zone_index.UsingGlobal()) {
Settings::values.time_zone_index = ui->combo_time_zone->currentIndex();
}
if (ui->combo_sound->isEnabled()) {
if (!Settings::values.sound_index.UsingGlobal()) {
Settings::values.sound_index = ui->combo_sound->currentIndex();
}
if (ui->rng_seed_checkbox->isEnabled()) {
if (!Settings::values.rng_seed.UsingGlobal()) {
if (ui->rng_seed_checkbox->isChecked()) {
Settings::values.rng_seed = ui->rng_seed_edit->text().toULongLong(nullptr, 16);
} else {
@@ -141,7 +144,7 @@ void ConfigureSystem::ApplyConfiguration() {
}
}
if (ui->custom_rtc_checkbox->isEnabled()) {
if (!Settings::values.custom_rtc.UsingGlobal()) {
if (ui->custom_rtc_checkbox->isChecked()) {
Settings::values.custom_rtc =
std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch());