From 99fbdaf75b18dd4cdaad1e93fa2a4ad82b0591aa Mon Sep 17 00:00:00 2001 From: merry Date: Fri, 15 Jul 2022 18:37:48 +0100 Subject: common/setting: Make ranged a property of the type - Avoids new GCC 12 warnings when Type is of form std::optional - Makes more sense this way, because ranged is not a property which would change over time --- src/common/settings.h | 67 +++++++++++++-------------- src/yuzu/configuration/config.cpp | 16 +++---- src/yuzu/configuration/config.h | 16 +++---- src/yuzu/configuration/configuration_shared.h | 10 ++-- src/yuzu_cmd/config.cpp | 4 +- src/yuzu_cmd/config.h | 4 +- 6 files changed, 59 insertions(+), 58 deletions(-) diff --git a/src/common/settings.h b/src/common/settings.h index 3583a2e70..368046e87 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -106,7 +106,7 @@ struct ResolutionScalingInfo { * configurations. Specifying a default value and label is required. A minimum and maximum range can * be specified for sanitization. */ -template +template class Setting { protected: Setting() = default; @@ -126,8 +126,8 @@ public: * @param default_val Intial value of the setting, and default value of the setting * @param name Label for the setting */ - explicit Setting(const Type& default_val, const std::string& name) - : value{default_val}, default_value{default_val}, ranged{false}, label{name} {} + explicit Setting(const Type& default_val, const std::string& name) requires(!ranged) + : value{default_val}, default_value{default_val}, label{name} {} virtual ~Setting() = default; /** @@ -139,9 +139,9 @@ public: * @param name Label for the setting */ explicit Setting(const Type& default_val, const Type& min_val, const Type& max_val, - const std::string& name) - : value{default_val}, default_value{default_val}, maximum{max_val}, minimum{min_val}, - ranged{true}, label{name} {} + const std::string& name) requires(ranged) + : value{default_val}, + default_value{default_val}, maximum{max_val}, minimum{min_val}, label{name} {} /** * Returns a reference to the setting's value. @@ -158,7 +158,7 @@ public: * @param val The desired value */ virtual void SetValue(const Type& val) { - Type temp{(ranged) ? std::clamp(val, minimum, maximum) : val}; + Type temp{ranged ? std::clamp(val, minimum, maximum) : val}; std::swap(value, temp); } @@ -188,7 +188,7 @@ public: * @returns A reference to the setting */ virtual const Type& operator=(const Type& val) { - Type temp{(ranged) ? std::clamp(val, minimum, maximum) : val}; + Type temp{ranged ? std::clamp(val, minimum, maximum) : val}; std::swap(value, temp); return value; } @@ -207,7 +207,6 @@ protected: const Type default_value{}; ///< The default value const Type maximum{}; ///< Maximum allowed value of the setting const Type minimum{}; ///< Minimum allowed value of the setting - const bool ranged; ///< The setting has sanitization ranges const std::string label{}; ///< The setting's label }; @@ -219,8 +218,8 @@ protected: * * By default, the global setting is used. */ -template -class SwitchableSetting : virtual public Setting { +template +class SwitchableSetting : virtual public Setting { public: /** * Sets a default value, label, and setting value. @@ -228,7 +227,7 @@ public: * @param default_val Intial value of the setting, and default value of the setting * @param name Label for the setting */ - explicit SwitchableSetting(const Type& default_val, const std::string& name) + explicit SwitchableSetting(const Type& default_val, const std::string& name) requires(!ranged) : Setting{default_val, name} {} virtual ~SwitchableSetting() = default; @@ -241,8 +240,8 @@ public: * @param name Label for the setting */ explicit SwitchableSetting(const Type& default_val, const Type& min_val, const Type& max_val, - const std::string& name) - : Setting{default_val, min_val, max_val, name} {} + const std::string& name) requires(ranged) + : Setting{default_val, min_val, max_val, name} {} /** * Tells this setting to represent either the global or custom setting when other member @@ -290,7 +289,7 @@ public: * @param val The new value */ void SetValue(const Type& val) override { - Type temp{(this->ranged) ? std::clamp(val, this->minimum, this->maximum) : val}; + Type temp{ranged ? std::clamp(val, this->minimum, this->maximum) : val}; if (use_global) { std::swap(this->value, temp); } else { @@ -306,7 +305,7 @@ public: * @returns A reference to the current setting value */ const Type& operator=(const Type& val) override { - Type temp{(this->ranged) ? std::clamp(val, this->minimum, this->maximum) : val}; + Type temp{ranged ? std::clamp(val, this->minimum, this->maximum) : val}; if (use_global) { std::swap(this->value, temp); return this->value; @@ -374,15 +373,15 @@ struct Values { Setting audio_device_id{"auto", "output_device"}; Setting sink_id{"auto", "output_engine"}; Setting audio_muted{false, "audio_muted"}; - SwitchableSetting volume{100, 0, 100, "volume"}; + SwitchableSetting volume{100, 0, 100, "volume"}; // Core SwitchableSetting use_multi_core{true, "use_multi_core"}; SwitchableSetting use_extended_memory_layout{false, "use_extended_memory_layout"}; // Cpu - SwitchableSetting cpu_accuracy{CPUAccuracy::Auto, CPUAccuracy::Auto, - CPUAccuracy::Paranoid, "cpu_accuracy"}; + SwitchableSetting cpu_accuracy{CPUAccuracy::Auto, CPUAccuracy::Auto, + CPUAccuracy::Paranoid, "cpu_accuracy"}; // TODO: remove cpu_accuracy_first_time, migration setting added 8 July 2021 Setting cpu_accuracy_first_time{true, "cpu_accuracy_first_time"}; Setting cpu_debug_mode{false, "cpu_debug_mode"}; @@ -409,7 +408,7 @@ struct Values { true, "cpuopt_unsafe_ignore_global_monitor"}; // Renderer - SwitchableSetting renderer_backend{ + SwitchableSetting renderer_backend{ RendererBackend::Vulkan, RendererBackend::OpenGL, RendererBackend::Vulkan, "backend"}; Setting renderer_debug{false, "debug"}; Setting renderer_shader_feedback{false, "shader_feedback"}; @@ -423,28 +422,28 @@ struct Values { SwitchableSetting anti_aliasing{AntiAliasing::None, "anti_aliasing"}; // *nix platforms may have issues with the borderless windowed fullscreen mode. // Default to exclusive fullscreen on these platforms for now. - SwitchableSetting fullscreen_mode{ + SwitchableSetting fullscreen_mode{ #ifdef _WIN32 FullscreenMode::Borderless, #else FullscreenMode::Exclusive, #endif FullscreenMode::Borderless, FullscreenMode::Exclusive, "fullscreen_mode"}; - SwitchableSetting aspect_ratio{0, 0, 3, "aspect_ratio"}; - SwitchableSetting max_anisotropy{0, 0, 5, "max_anisotropy"}; + SwitchableSetting aspect_ratio{0, 0, 3, "aspect_ratio"}; + SwitchableSetting max_anisotropy{0, 0, 5, "max_anisotropy"}; SwitchableSetting use_speed_limit{true, "use_speed_limit"}; - SwitchableSetting speed_limit{100, 0, 9999, "speed_limit"}; + SwitchableSetting speed_limit{100, 0, 9999, "speed_limit"}; SwitchableSetting use_disk_shader_cache{true, "use_disk_shader_cache"}; - SwitchableSetting gpu_accuracy{GPUAccuracy::High, GPUAccuracy::Normal, - GPUAccuracy::Extreme, "gpu_accuracy"}; + SwitchableSetting gpu_accuracy{GPUAccuracy::High, GPUAccuracy::Normal, + GPUAccuracy::Extreme, "gpu_accuracy"}; SwitchableSetting use_asynchronous_gpu_emulation{true, "use_asynchronous_gpu_emulation"}; SwitchableSetting nvdec_emulation{NvdecEmulation::GPU, "nvdec_emulation"}; SwitchableSetting accelerate_astc{true, "accelerate_astc"}; SwitchableSetting use_vsync{true, "use_vsync"}; - SwitchableSetting fps_cap{1000, 1, 1000, "fps_cap"}; + SwitchableSetting fps_cap{1000, 1, 1000, "fps_cap"}; Setting disable_fps_limit{false, "disable_fps_limit"}; - SwitchableSetting shader_backend{ShaderBackend::GLASM, ShaderBackend::GLSL, - ShaderBackend::SPIRV, "shader_backend"}; + SwitchableSetting shader_backend{ShaderBackend::GLASM, ShaderBackend::GLSL, + ShaderBackend::SPIRV, "shader_backend"}; SwitchableSetting use_asynchronous_shaders{false, "use_asynchronous_shaders"}; SwitchableSetting use_fast_gpu_time{true, "use_fast_gpu_time"}; @@ -460,10 +459,10 @@ struct Values { s64 custom_rtc_differential; Setting current_user{0, "current_user"}; - SwitchableSetting language_index{1, 0, 17, "language_index"}; - SwitchableSetting region_index{1, 0, 6, "region_index"}; - SwitchableSetting time_zone_index{0, 0, 45, "time_zone_index"}; - SwitchableSetting sound_index{1, 0, 2, "sound_index"}; + SwitchableSetting language_index{1, 0, 17, "language_index"}; + SwitchableSetting region_index{1, 0, 6, "region_index"}; + SwitchableSetting time_zone_index{0, 0, 45, "time_zone_index"}; + SwitchableSetting sound_index{1, 0, 2, "sound_index"}; // Controls InputSetting> players; @@ -485,7 +484,7 @@ struct Values { Setting tas_loop{false, "tas_loop"}; Setting mouse_panning{false, "mouse_panning"}; - Setting mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"}; + Setting mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"}; Setting mouse_enabled{false, "mouse_enabled"}; Setting emulate_analog_keyboard{false, "emulate_analog_keyboard"}; diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 9686412d0..a57b2e019 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -143,8 +143,8 @@ void Config::ReadBasicSetting(Settings::Setting& setting) { } } -template -void Config::ReadBasicSetting(Settings::Setting& setting) { +template +void Config::ReadBasicSetting(Settings::Setting& setting) { const QString name = QString::fromStdString(setting.GetLabel()); const Type default_value = setting.GetDefault(); if (qt_config->value(name + QStringLiteral("/default"), false).toBool()) { @@ -164,16 +164,16 @@ void Config::WriteBasicSetting(const Settings::Setting& setting) { qt_config->setValue(name, QString::fromStdString(value)); } -template -void Config::WriteBasicSetting(const Settings::Setting& setting) { +template +void Config::WriteBasicSetting(const Settings::Setting& setting) { const QString name = QString::fromStdString(setting.GetLabel()); const Type value = setting.GetValue(); qt_config->setValue(name + QStringLiteral("/default"), value == setting.GetDefault()); qt_config->setValue(name, value); } -template -void Config::WriteGlobalSetting(const Settings::SwitchableSetting& setting) { +template +void Config::WriteGlobalSetting(const Settings::SwitchableSetting& setting) { const QString name = QString::fromStdString(setting.GetLabel()); const Type& value = setting.GetValue(global); if (!global) { @@ -1421,8 +1421,8 @@ QVariant Config::ReadSetting(const QString& name, const QVariant& default_value) return result; } -template -void Config::ReadGlobalSetting(Settings::SwitchableSetting& setting) { +template +void Config::ReadGlobalSetting(Settings::SwitchableSetting& setting) { QString name = QString::fromStdString(setting.GetLabel()); const bool use_global = qt_config->value(name + QStringLiteral("/use_global"), true).toBool(); setting.SetGlobal(use_global); diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index 9ca878d23..d511b3dbd 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h @@ -159,8 +159,8 @@ private: * * @param The setting */ - template - void ReadGlobalSetting(Settings::SwitchableSetting& setting); + template + void ReadGlobalSetting(Settings::SwitchableSetting& setting); /** * Sets a value to the qt_config using the setting's label and default value. If the config is a @@ -168,8 +168,8 @@ private: * * @param The setting */ - template - void WriteGlobalSetting(const Settings::SwitchableSetting& setting); + template + void WriteGlobalSetting(const Settings::SwitchableSetting& setting); /** * Reads a value from the qt_config using the setting's label and default value and applies the @@ -177,15 +177,15 @@ private: * * @param The setting */ - template - void ReadBasicSetting(Settings::Setting& setting); + template + void ReadBasicSetting(Settings::Setting& setting); /** Sets a value from the setting in the qt_config using the setting's label and default value. * * @param The setting */ - template - void WriteBasicSetting(const Settings::Setting& setting); + template + void WriteBasicSetting(const Settings::Setting& setting); ConfigType type; std::unique_ptr qt_config; diff --git a/src/yuzu/configuration/configuration_shared.h b/src/yuzu/configuration/configuration_shared.h index 77802a367..56800b6ff 100644 --- a/src/yuzu/configuration/configuration_shared.h +++ b/src/yuzu/configuration/configuration_shared.h @@ -27,8 +27,9 @@ enum class CheckState { // ApplyPerGameSetting, given a Settings::Setting and a Qt UI element, properly applies a Setting void ApplyPerGameSetting(Settings::SwitchableSetting* setting, const QCheckBox* checkbox, const CheckState& tracker); -template -void ApplyPerGameSetting(Settings::SwitchableSetting* setting, const QComboBox* combobox) { +template +void ApplyPerGameSetting(Settings::SwitchableSetting* setting, + const QComboBox* combobox) { if (Settings::IsConfiguringGlobal() && setting->UsingGlobal()) { setting->SetValue(static_cast(combobox->currentIndex())); } else if (!Settings::IsConfiguringGlobal()) { @@ -45,8 +46,9 @@ void ApplyPerGameSetting(Settings::SwitchableSetting* setting, const QComb // Sets a Qt UI element given a Settings::Setting void SetPerGameSetting(QCheckBox* checkbox, const Settings::SwitchableSetting* setting); -template -void SetPerGameSetting(QComboBox* combobox, const Settings::SwitchableSetting* setting) { +template +void SetPerGameSetting(QComboBox* combobox, + const Settings::SwitchableSetting* setting) { combobox->setCurrentIndex(setting->UsingGlobal() ? ConfigurationShared::USE_GLOBAL_INDEX : static_cast(setting->GetValue()) + ConfigurationShared::USE_GLOBAL_OFFSET); diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 903e02297..9db7115a2 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -99,8 +99,8 @@ void Config::ReadSetting(const std::string& group, Settings::Setting& sett setting = sdl2_config->GetBoolean(group, setting.GetLabel(), setting.GetDefault()); } -template -void Config::ReadSetting(const std::string& group, Settings::Setting& setting) { +template +void Config::ReadSetting(const std::string& group, Settings::Setting& setting) { setting = static_cast(sdl2_config->GetInteger(group, setting.GetLabel(), static_cast(setting.GetDefault()))); } diff --git a/src/yuzu_cmd/config.h b/src/yuzu_cmd/config.h index ccf77d668..32c03075f 100644 --- a/src/yuzu_cmd/config.h +++ b/src/yuzu_cmd/config.h @@ -33,6 +33,6 @@ private: * @param group The name of the INI group * @param setting The yuzu setting to modify */ - template - void ReadSetting(const std::string& group, Settings::Setting& setting); + template + void ReadSetting(const std::string& group, Settings::Setting& setting); }; -- cgit v1.2.3