From ca8509d205d20d034c548489d729f65656da611d Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 21 Jun 2023 21:41:15 -0400 Subject: [PATCH] configuration: Use enum index --- src/yuzu/configuration/configure_cpu.cpp | 4 ++- src/yuzu/configuration/configure_graphics.cpp | 13 ++++--- src/yuzu/configuration/configure_graphics.h | 2 +- src/yuzu/configuration/shared_translation.cpp | 34 +++++++++---------- src/yuzu/configuration/shared_translation.h | 2 +- src/yuzu/configuration/shared_widget.cpp | 2 +- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/yuzu/configuration/configure_cpu.cpp b/src/yuzu/configuration/configure_cpu.cpp index 57cdc4c63a..7d122906ef 100644 --- a/src/yuzu/configuration/configure_cpu.cpp +++ b/src/yuzu/configuration/configure_cpu.cpp @@ -7,6 +7,7 @@ #include #include "common/common_types.h" #include "common/settings.h" +#include "common/settings_enums.h" #include "configuration/shared_widget.h" #include "core/core.h" #include "ui_configure_cpu.h" @@ -76,7 +77,8 @@ void ConfigureCpu::Setup(const ConfigurationShared::Builder& builder) { void ConfigureCpu::UpdateGroup(int index) { const auto accuracy = static_cast( - combobox_translations.at(typeid(Settings::CpuAccuracy))[index].first); + combobox_translations.at(Settings::EnumMetadata::Index())[index] + .first); ui->unsafe_group->setVisible(accuracy == Settings::CpuAccuracy::Unsafe); } diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index 7263af13fc..31e87ccf5d 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp @@ -85,7 +85,8 @@ ConfigureGraphics::ConfigureGraphics( : ConfigurationShared::Tab(group_, parent), ui{std::make_unique()}, records{records_}, expose_compute_option{expose_compute_option_}, system{system_}, combobox_translations{builder.ComboboxTranslations()}, - shader_mapping{combobox_translations.at(typeid(Settings::ShaderBackend))} { + shader_mapping{ + combobox_translations.at(Settings::EnumMetadata::Index())} { vulkan_device = Settings::values.vulkan_device.GetValue(); RetrieveVulkanDevices(); @@ -356,7 +357,7 @@ const QString ConfigureGraphics::TranslateVSyncMode(VkPresentModeKHR mode, } } -int ConfigureGraphics::FindIndex(std::type_index enumeration, int value) const { +int ConfigureGraphics::FindIndex(u32 enumeration, int value) const { for (u32 i = 0; i < combobox_translations.at(enumeration).size(); i++) { if (combobox_translations.at(enumeration)[i].first == static_cast(value)) { return i; @@ -383,7 +384,8 @@ void ConfigureGraphics::ApplyConfiguration() { (!Settings::IsConfiguringGlobal() && api_restore_global_button->isEnabled())) { auto backend = static_cast( combobox_translations - .at(typeid(Settings::RendererBackend))[api_combobox->currentIndex()] + .at(Settings::EnumMetadata< + Settings::RendererBackend>::Index())[api_combobox->currentIndex()] .first); switch (backend) { case Settings::RendererBackend::OpenGL: @@ -440,7 +442,8 @@ void ConfigureGraphics::UpdateAPILayout() { if (is_opengl) { shader_backend_combobox->setCurrentIndex( - FindIndex(typeid(Settings::ShaderBackend), static_cast(shader_backend))); + FindIndex(Settings::EnumMetadata::Index(), + static_cast(shader_backend))); } else if (is_vulkan && static_cast(vulkan_device) < vulkan_device_combobox->count()) { vulkan_device_combobox->setCurrentIndex(vulkan_device); } @@ -466,7 +469,7 @@ Settings::RendererBackend ConfigureGraphics::GetCurrentGraphicsBackend() const { return Settings::values.renderer_backend.GetValue(true); } return static_cast( - combobox_translations.at(typeid(Settings::RendererBackend)) + combobox_translations.at(Settings::EnumMetadata::Index()) .at(api_combobox->currentIndex()) .first); } diff --git a/src/yuzu/configuration/configure_graphics.h b/src/yuzu/configuration/configure_graphics.h index 1848b1593c..633a28414c 100644 --- a/src/yuzu/configuration/configure_graphics.h +++ b/src/yuzu/configuration/configure_graphics.h @@ -75,7 +75,7 @@ private: Settings::RendererBackend GetCurrentGraphicsBackend() const; - int FindIndex(std::type_index enumeration, int value) const; + int FindIndex(u32 enumeration, int value) const; std::unique_ptr ui; QColor bg_color; diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp index f120a632cc..d51286b0ef 100644 --- a/src/yuzu/configuration/shared_translation.cpp +++ b/src/yuzu/configuration/shared_translation.cpp @@ -182,19 +182,19 @@ std::unique_ptr ComboboxEnumeration(QWidget* parent) { // Intentionally skipping VSyncMode to let the UI fill that one out - translations->insert({typeid(Settings::AstcDecodeMode), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(AstcDecodeMode, Cpu, "CPU"), PAIR(AstcDecodeMode, Gpu, "GPU"), PAIR(AstcDecodeMode, CpuAsynchronous, "CPU Asynchronous"), }}); - translations->insert({typeid(Settings::AstcRecompression), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(AstcRecompression, Uncompressed, "Uncompressed (Best quality)"), PAIR(AstcRecompression, Bc1, "BC1 (Low quality)"), PAIR(AstcRecompression, Bc3, "BC3 (Medium quality)"), }}); - translations->insert({typeid(Settings::RendererBackend), + translations->insert({Settings::EnumMetadata::Index(), { #ifdef HAS_OPENGL PAIR(RendererBackend, OpenGL, "OpenGL"), @@ -202,37 +202,37 @@ std::unique_ptr ComboboxEnumeration(QWidget* parent) { PAIR(RendererBackend, Vulkan, "Vulkan"), PAIR(RendererBackend, Null, "Null"), }}); - translations->insert({typeid(Settings::ShaderBackend), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(ShaderBackend, Glsl, "GLSL"), PAIR(ShaderBackend, Glasm, "GLASM (Assembly Shaders, NVIDIA Only)"), PAIR(ShaderBackend, SpirV, "SPIR-V (Experimental, Mesa Only)"), }}); - translations->insert({typeid(Settings::GpuAccuracy), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(GpuAccuracy, Normal, "Normal"), PAIR(GpuAccuracy, High, "High"), PAIR(GpuAccuracy, Extreme, "Extreme"), }}); - translations->insert({typeid(Settings::CpuAccuracy), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(CpuAccuracy, Auto, "Auto"), PAIR(CpuAccuracy, Accurate, "Accurate"), PAIR(CpuAccuracy, Unsafe, "Unsafe"), PAIR(CpuAccuracy, Paranoid, "Paranoid (disables most optimizations)"), }}); - translations->insert({typeid(Settings::FullscreenMode), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(FullscreenMode, Borderless, "Borderless Windowed"), PAIR(FullscreenMode, Exclusive, "Exclusive Fullscreen"), }}); - translations->insert({typeid(Settings::NvdecEmulation), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(NvdecEmulation, Off, "No Video Output"), PAIR(NvdecEmulation, Cpu, "CPU Video Decoding"), PAIR(NvdecEmulation, Gpu, "GPU Video Decoding (Default)"), }}); - translations->insert({typeid(Settings::ResolutionSetup), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(ResolutionSetup, Res1_2X, "0.5X (360p/540p) [EXPERIMENTAL]"), PAIR(ResolutionSetup, Res3_4X, "0.75X (540p/810p) [EXPERIMENTAL]"), @@ -246,7 +246,7 @@ std::unique_ptr ComboboxEnumeration(QWidget* parent) { PAIR(ResolutionSetup, Res7X, "7X (5040p/7560p)"), PAIR(ResolutionSetup, Res8X, "8X (5760p/8640p)"), }}); - translations->insert({typeid(Settings::ScalingFilter), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(ScalingFilter, NearestNeighbor, "Nearest Neighbor"), PAIR(ScalingFilter, Bilinear, "Bilinear"), @@ -255,13 +255,13 @@ std::unique_ptr ComboboxEnumeration(QWidget* parent) { PAIR(ScalingFilter, ScaleForce, "ScaleForce"), PAIR(ScalingFilter, Fsr, "AMD FidelityFX™️ Super Resolution"), }}); - translations->insert({typeid(Settings::AntiAliasing), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(AntiAliasing, None, "None"), PAIR(AntiAliasing, Fxaa, "FXAA"), PAIR(AntiAliasing, Smaa, "SMAA"), }}); - translations->insert({typeid(Settings::AspectRatio), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(AspectRatio, R16_9, "Default (16:9)"), PAIR(AspectRatio, R4_3, "Force 4:3"), @@ -269,7 +269,7 @@ std::unique_ptr ComboboxEnumeration(QWidget* parent) { PAIR(AspectRatio, R16_10, "Force 16:10"), PAIR(AspectRatio, Stretch, "Stretch to Window"), }}); - translations->insert({typeid(Settings::AnisotropyMode), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(AnisotropyMode, Automatic, "Automatic"), PAIR(AnisotropyMode, Default, "Default"), @@ -279,7 +279,7 @@ std::unique_ptr ComboboxEnumeration(QWidget* parent) { PAIR(AnisotropyMode, X16, "16x"), }}); translations->insert( - {typeid(Settings::Language), + {Settings::EnumMetadata::Index(), { PAIR(Language, Japanese, "Japanese (日本語)"), PAIR(Language, EnglishAmerican, "American English"), @@ -300,7 +300,7 @@ std::unique_ptr ComboboxEnumeration(QWidget* parent) { PAIR(Language, ChineseTraditional, "Traditional Chinese (正體中文)"), PAIR(Language, PortugueseBrazilian, "Brazilian Portuguese (português do Brasil)"), }}); - translations->insert({typeid(Settings::Region), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(Region, Japan, "Japan"), PAIR(Region, Usa, "USA"), @@ -311,7 +311,7 @@ std::unique_ptr ComboboxEnumeration(QWidget* parent) { PAIR(Region, Taiwan, "Taiwan"), }}); translations->insert( - {typeid(Settings::TimeZone), + {Settings::EnumMetadata::Index(), { {static_cast(Settings::TimeZone::Auto), tr("Auto (%1)", "Auto select time zone") @@ -361,7 +361,7 @@ std::unique_ptr ComboboxEnumeration(QWidget* parent) { PAIR(TimeZone, Wet, "WET"), PAIR(TimeZone, Zulu, "Zulu"), }}); - translations->insert({typeid(Settings::AudioMode), + translations->insert({Settings::EnumMetadata::Index(), { PAIR(AudioMode, Mono, "Mono"), PAIR(AudioMode, Stereo, "Stereo"), diff --git a/src/yuzu/configuration/shared_translation.h b/src/yuzu/configuration/shared_translation.h index cc8419e03a..99a0e808ca 100644 --- a/src/yuzu/configuration/shared_translation.h +++ b/src/yuzu/configuration/shared_translation.h @@ -16,7 +16,7 @@ class QWidget; namespace ConfigurationShared { using TranslationMap = std::map>; using ComboboxTranslations = std::vector>; -using ComboboxTranslationMap = std::map; +using ComboboxTranslationMap = std::map; std::unique_ptr InitializeTranslations(QWidget* parent); diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index 978bfa5904..ba7f60c2d8 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp @@ -125,7 +125,7 @@ QWidget* Widget::CreateCheckBox(Settings::BasicSetting* bool_setting, const QStr QWidget* Widget::CreateCombobox(std::function& serializer, std::function& restore_func, const std::function& touch) { - const auto type = setting.TypeId(); + const auto type = setting.EnumIndex(); combobox = new QComboBox(this); combobox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);