From cfb63c68dbdc2c8add45cddb2cedf371059af6c4 Mon Sep 17 00:00:00 2001
From: lat9nq <22451773+lat9nq@users.noreply.github.com>
Date: Sun, 7 May 2023 13:28:52 -0400
Subject: [PATCH] shared_translation: Finish using int ids

---
 src/common/settings.h                         |   4 +-
 .../configuration/configuration_shared.cpp    |   6 +-
 src/yuzu/configuration/configure_graphics.cpp |  25 +-
 .../configure_graphics_advanced.cpp           |   2 +-
 src/yuzu/configuration/shared_translation.cpp | 236 +++++++-----------
 src/yuzu/configuration/shared_translation.h   |   2 +-
 6 files changed, 117 insertions(+), 158 deletions(-)

diff --git a/src/common/settings.h b/src/common/settings.h
index 69777421e..a90fc87a7 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -191,7 +191,7 @@ public:
     virtual bool IsEnum() const = 0;
     virtual bool RuntimeModfiable() const = 0;
     virtual void SetGlobal(bool global) {}
-    virtual u32 Id() const = 0;
+    virtual constexpr u32 Id() const = 0;
     virtual bool UsingGlobal() const {
         return false;
     }
@@ -423,7 +423,7 @@ public:
         return std::type_index(typeid(Type));
     }
 
-    virtual u32 Id() const override {
+    virtual constexpr u32 Id() const override {
         return id;
     }
 
diff --git a/src/yuzu/configuration/configuration_shared.cpp b/src/yuzu/configuration/configuration_shared.cpp
index 575d239eb..54fbce53a 100644
--- a/src/yuzu/configuration/configuration_shared.cpp
+++ b/src/yuzu/configuration/configuration_shared.cpp
@@ -136,6 +136,7 @@ std::pair<QWidget*, void*> CreateWidget(Settings::BasicSetting* setting,
                                         std::forward_list<std::function<void(bool)>>& apply_funcs,
                                         std::list<CheckState>& trackers, RequestType request) {
     const auto type = setting->TypeId();
+    const int id = setting->Id();
     QWidget* widget{nullptr};
     void* extra{nullptr};
 
@@ -143,9 +144,8 @@ std::pair<QWidget*, void*> CreateWidget(Settings::BasicSetting* setting,
 
     const auto [label, tooltip] = [&]() {
         const auto& setting_label = setting->GetLabel();
-        if (translations.contains(setting_label)) {
-            return std::pair{translations.at(setting_label).first,
-                             translations.at(setting_label).second};
+        if (translations.contains(id)) {
+            return std::pair{translations.at(id).first, translations.at(id).second};
         }
         LOG_ERROR(Frontend, "Translation table lacks entry for \"{}\"", setting_label);
         return std::pair{QString::fromStdString(setting_label), QStringLiteral("")};
diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp
index 8128a4047..d8e95b9b1 100644
--- a/src/yuzu/configuration/configure_graphics.cpp
+++ b/src/yuzu/configuration/configure_graphics.cpp
@@ -214,13 +214,13 @@ void ConfigureGraphics::SetConfiguration() {
     QLayout& api_layout = *ui->api_widget->layout();
     QLayout& graphics_layout = *ui->graphics_widget->layout();
 
-    std::map<std::string, QWidget*> hold_graphics;
+    std::map<bool, std::map<std::string, QWidget*>> hold_graphics;
 
     for (const auto setting : Settings::values.linkage.by_category[Settings::Category::Renderer]) {
         const auto& setting_label = setting->GetLabel();
 
         auto [widget, extra] = [&]() {
-            if (setting_label == "vulkan_device") {
+            if (setting->Id() == Settings::values.vulkan_device.Id()) {
                 return ConfigurationShared::CreateWidget(
                     setting, translations, this, runtime_lock, apply_funcs, trackers,
                     ConfigurationShared::RequestType::ComboBox);
@@ -233,28 +233,29 @@ void ConfigureGraphics::SetConfiguration() {
             continue;
         }
 
-        if (setting_label == "backend") {
+        if (setting->Id() == Settings::values.vulkan_device.Id()) {
             api_layout.addWidget(widget);
             api_combobox = reinterpret_cast<QComboBox*>(extra);
-        } else if (setting_label == "vulkan_device") {
+        } else if (setting->Id() == Settings::values.vulkan_device.Id()) {
             api_layout.addWidget(widget);
             vulkan_device_combobox = reinterpret_cast<QComboBox*>(extra);
             vulkan_device_widget = widget;
-        } else if (setting_label == "shader_backend") {
+        } else if (setting->Id() == Settings::values.shader_backend.Id()) {
             api_layout.addWidget(widget);
             shader_backend_combobox = reinterpret_cast<QComboBox*>(extra);
             shader_backend_widget = widget;
-        } else {
-            hold_graphics.insert(std::pair(setting_label, widget));
-        }
-
-        if (setting_label == "use_vsync") {
+        } else if (setting->Id() == Settings::values.vsync_mode.Id()) {
             vsync_mode_combobox = reinterpret_cast<QComboBox*>(extra);
+            hold_graphics[setting->IsEnum()][setting_label] = widget;
+        } else {
+            hold_graphics[setting->IsEnum()][setting_label] = widget;
         }
     }
 
-    for (const auto& [label, widget] : hold_graphics) {
-        graphics_layout.addWidget(widget);
+    for (const auto& [_, settings] : hold_graphics) {
+        for (const auto& [label, widget] : settings) {
+            graphics_layout.addWidget(widget);
+        }
     }
 
     // ui->api_widget->setEnabled(runtime_lock);
diff --git a/src/yuzu/configuration/configure_graphics_advanced.cpp b/src/yuzu/configuration/configure_graphics_advanced.cpp
index 8a9495109..3a207e2cd 100644
--- a/src/yuzu/configuration/configure_graphics_advanced.cpp
+++ b/src/yuzu/configuration/configure_graphics_advanced.cpp
@@ -45,7 +45,7 @@ void ConfigureGraphicsAdvanced::SetConfiguration() {
             layout.addWidget(widget);
         }
 
-        if (setting->GetLabel() == "enable_compute_pipelines") {
+        if (setting->Id() == Settings::values.enable_compute_pipelines.Id()) {
             checkbox_enable_compute_pipelines = widget;
         }
     }
diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp
index 73c3086ae..181dd7cf0 100644
--- a/src/yuzu/configuration/shared_translation.cpp
+++ b/src/yuzu/configuration/shared_translation.cpp
@@ -18,196 +18,111 @@ std::unique_ptr<TranslationMap> InitializeTranslations(QWidget* parent) {
     std::unique_ptr<TranslationMap> translations = std::make_unique<TranslationMap>();
     const auto& tr = [parent](const char* text) -> QString { return parent->tr(text); };
 
-#define INSERT(LABEL, NAME, TOOLTIP)                                                               \
-    translations->insert(std::pair{(LABEL), std::pair{tr((NAME)), tr((TOOLTIP))}})
+#define INSERT(ID, NAME, TOOLTIP)                                                                  \
+    translations->insert(std::pair{Settings::values.ID.Id(), std::pair{tr((NAME)), tr((TOOLTIP))}})
 
     // A setting can be ignored by giving it a blank name
 
     // Audio
-    INSERT("output_engine", "Output Engine:", "");
-    INSERT("output_device", "Output Device:", "");
-    INSERT("input_device", "Input Device:", "");
-    INSERT("audio_muted", "Mute audio when in background", "");
-    INSERT("volume", "Volume:", "");
+    INSERT(sink_id, "Output Engine:", "");
+    INSERT(audio_output_device_id, "Output Device:", "");
+    INSERT(audio_input_device_id, "Input Device:", "");
+    INSERT(audio_muted, "Mute audio when in background", "");
+    INSERT(volume, "Volume:", "");
 
     // Core
-    INSERT("use_multi_core", "Multicore CPU Emulation", "");
-    INSERT("use_unsafe_extended_memory_layout", "Unsafe extended memory layout (8GB DRAM)", "");
+    INSERT(use_multi_core, "Multicore CPU Emulation", "");
+    INSERT(use_unsafe_extended_memory_layout, "Unsafe extended memory layout (8GB DRAM)", "");
 
     // Cpu
-    INSERT("cpu_accuracy", "Accuracy:", "");
-    INSERT("cpu_accuracy_first_time", "", "");
+    INSERT(cpu_accuracy, "Accuracy:", "");
+    INSERT(cpu_accuracy_first_time, "", "");
 
     // Cpu Debug
-    INSERT("cpu_debug_mode", "Enable CPU Debugging", "");
-    INSERT("cpuopt_page_tables", "Enable inline page tables", "");
-    INSERT("cpuopt_block_linking", "Enable block linking", "");
-    INSERT("cpuopt_return_stack_buffer", "Enable return stack buffer", "");
-    INSERT("cpuopt_fast_dispatcher", "Enable fast dispatcher", "");
-    INSERT("cpuopt_context_elimination", "Enable context elimination", "");
-    INSERT("cpuopt_const_prop", "Enable constant propagation", "");
-    INSERT("cpuopt_misc_ir", "Enable miscellaneous optimizations", "");
-    INSERT("cpuopt_reduce_misalign_checks", "Enable misalignment check reduction", "");
-    INSERT("cpuopt_fastmem", "Enable Host MMU Emulation (general memory instructions)", "");
-    INSERT("cpuopt_fastmem_exclusives", "Enable Host MMU Emulation (exclusive memory instructions)",
-           "");
-    INSERT("cpuopt_recompile_exclusives", "Enable recompilation of exlucsive memory instructions",
-           "");
-    INSERT("cpuopt_ignore_memory_aborts", "Enable fallbacks for invalid memory accesses", "");
 
     // Cpu Unsafe
-    INSERT("cpuopt_unsafe_unfuse_fma", "Unfuse FMA (improve performance on CPUs without FMA)", "");
-    INSERT("cpuopt_unsafe_reduce_fp_error", "Faster FRSQRTE and FRECPE", "");
-    INSERT("cpuopt_unsafe_ignore_standard_fpcr", "Faster ASIMD instructions (32 bits only)", "");
-    INSERT("cpuopt_unsafe_inaccurate_nan", "Inaccurate NaN handling", "");
-    INSERT("cpuopt_unsafe_fastmem_check", "Disable address space checks", "");
-    INSERT("cpuopt_unsafe_ignore_global_monitor", "Ignore global monitor", "");
+    INSERT(cpuopt_unsafe_unfuse_fma, "Unfuse FMA (improve performance on CPUs without FMA)", "");
+    INSERT(cpuopt_unsafe_reduce_fp_error, "Faster FRSQRTE and FRECPE", "");
+    INSERT(cpuopt_unsafe_ignore_standard_fpcr, "Faster ASIMD instructions (32 bits only)", "");
+    INSERT(cpuopt_unsafe_inaccurate_nan, "Inaccurate NaN handling", "");
+    INSERT(cpuopt_unsafe_fastmem_check, "Disable address space checks", "");
+    INSERT(cpuopt_unsafe_ignore_global_monitor, "Ignore global monitor", "");
 
     // Renderer
-    INSERT("backend", "API:", "");
-    INSERT("vulkan_device", "Device:", "");
-    INSERT("shader_backend", "Shader Backend:", "");
-    INSERT("resolution_setup", "Resolution:", "");
-    INSERT("scaling_filter", "Window Adapting Filter:", "");
-    INSERT("fsr_sharpening_slider", "AMD FidelityFX™ Super Resolution Sharpness:", "");
-    INSERT("anti_aliasing", "Anti-Aliasing Method:", "");
-    INSERT("fullscreen_mode", "Fullscreen Mode:", "");
-    INSERT("aspect_ratio", "Aspect Ratio:", "");
-    INSERT("use_disk_shader_cache", "Use disk pipeline cache", "");
-    INSERT("use_asynchronous_gpu_emulation", "Use asynchronous GPU emulation", "");
-    INSERT("nvdec_emulation", "NVDEC emulation:", "");
-    INSERT("accelerate_astc", "ASTC Decoding Method:", "");
+    INSERT(renderer_backend, "API:", "");
+    INSERT(vulkan_device, "Device:", "");
+    INSERT(shader_backend, "Shader Backend:", "");
+    INSERT(resolution_setup, "Resolution:", "");
+    INSERT(scaling_filter, "Window Adapting Filter:", "");
+    INSERT(fsr_sharpening_slider, "AMD FidelityFX™ Super Resolution Sharpness:", "");
+    INSERT(anti_aliasing, "Anti-Aliasing Method:", "");
+    INSERT(fullscreen_mode, "Fullscreen Mode:", "");
+    INSERT(aspect_ratio, "Aspect Ratio:", "");
+    INSERT(use_disk_shader_cache, "Use disk pipeline cache", "");
+    INSERT(use_asynchronous_gpu_emulation, "Use asynchronous GPU emulation", "");
+    INSERT(nvdec_emulation, "NVDEC emulation:", "");
+    INSERT(accelerate_astc, "ASTC Decoding Method:", "");
     INSERT(
-        "use_vsync", "VSync Mode:",
+        vsync_mode, "VSync Mode:",
         "FIFO (VSync) does not drop frames or exhibit tearing but is limited by the screen refresh "
         "rate. FIFO Relaxed is similar to FIFO but allows tearing as it recovers from a slow down. "
         "Mailbox can have lower latency than FIFO and does not tear but may drop frames. Immediate "
         "(no synchronization) just presents whatever is available and can exhibit tearing.");
-    INSERT("bg_red", "", "");
-    INSERT("bg_green", "", "");
-    INSERT("bg_blue", "", "");
+    INSERT(bg_red, "", "");
+    INSERT(bg_green, "", "");
+    INSERT(bg_blue, "", "");
 
     // Renderer (Advanced Graphics)
-    INSERT("async_presentation", "Enable asynchronous presentation (Vulkan only)", "");
-    INSERT("force_max_clock", "Force maximum clocks (Vulkan only)",
+    INSERT(async_presentation, "Enable asynchronous presentation (Vulkan only)", "");
+    INSERT(renderer_force_max_clock, "Force maximum clocks (Vulkan only)",
            "Runs work in the background while waiting for graphics commands to keep the GPU from "
            "lowering its clock speed.");
-    INSERT("max_anisotropy", "Anisotropic Filtering:", "");
-    INSERT("gpu_accuracy", "Accuracy Level:", "");
-    INSERT("use_asynchronous_shaders", "Use asynchronous shader building (Hack)",
+    INSERT(max_anisotropy, "Anisotropic Filtering:", "");
+    INSERT(gpu_accuracy, "Accuracy Level:", "");
+    INSERT(use_asynchronous_shaders, "Use asynchronous shader building (Hack)",
            "Enables asynchronous shader compilation, which may reduce shader stutter. This feature "
            "is experimental.");
-    INSERT("use_fast_gpu_time", "Use Fast GPU Time (Hack)",
+    INSERT(use_fast_gpu_time, "Use Fast GPU Time (Hack)",
            "Enables Fast GPU Time. This option will force most games to run at their highest "
            "native resolution.");
-    INSERT("use_vulkan_driver_pipeline_cache", "Use Vulkan pipeline cache",
+    INSERT(use_vulkan_driver_pipeline_cache, "Use Vulkan pipeline cache",
            "Enables GPU vendor-specific pipeline cache. This option can improve shader loading "
            "time significantly in cases where the Vulkan driver does not store pipeline cache "
            "files internally.");
-    INSERT("enable_compute_pipelines", "Enable Compute Pipelines (Intel Vulkan Only)",
+    INSERT(enable_compute_pipelines, "Enable Compute Pipelines (Intel Vulkan Only)",
            "Enable compute pipelines, required by some games.\nThis setting only exists for Intel "
            "proprietary drivers, and may crash if enabled.\nCompute pipelines are always enabled "
            "on all other drivers.");
 
     // Renderer (Debug)
-    INSERT("debug", "Enable Graphics Debugging",
-           "When checked, the graphics API enters a slower debugging mode");
-    INSERT("shader_feedback", "Enable Shader Feedback",
-           "When checked, yuzu will log statistics about the compiled pipeline cache");
-    INSERT("nsight_aftermath", "Enable Nsight Aftermath",
-           "When checked, it enables Nsight Aftermath crash dumps");
-    INSERT("disable_shader_loop_safety_checks", "Disable Loop safety checks",
-           "When checked, it executes shaders without loop logic changes");
 
     // Renderer (General)
-    INSERT("use_speed_limit", "Limit Speed Percent", "");
-    INSERT("speed_limit", "Limit Speed Percent", "");
+    INSERT(use_speed_limit, "Limit Speed Percent", "");
+    INSERT(speed_limit, "Limit Speed Percent", "");
 
     // System
-    INSERT("rng_seed_enabled", "RNG Seed", "");
-    INSERT("rng_seed", "RNG Seed", "");
-    INSERT("device_name", "Device Name", "");
-    INSERT("custom_rtc_enabled", "Custom RTC", "");
-    INSERT("custom_rtc", "Custom RTC", "");
-    INSERT("language_index", "Language:", "");
-    INSERT("region_index", "Region:", "");
-    INSERT("time_zone_index", "Time Zone:", "");
-    INSERT("sound_index", "Sound Output Mode:", "");
-    INSERT("use_docked_mode", "", "");
+    INSERT(rng_seed_enabled, "RNG Seed", "");
+    INSERT(rng_seed, "RNG Seed", "");
+    INSERT(device_name, "Device Name", "");
+    INSERT(custom_rtc_enabled, "Custom RTC", "");
+    INSERT(custom_rtc, "Custom RTC", "");
+    INSERT(language_index, "Language:", "");
+    INSERT(region_index, "Region:", "");
+    INSERT(time_zone_index, "Time Zone:", "");
+    INSERT(sound_index, "Sound Output Mode:", "");
+    INSERT(use_docked_mode, "", "");
 
     // Controls
-    INSERT("enable_raw_input", "", "");
-    INSERT("controller_navigation", "", "");
-    INSERT("enable_joycon_driver", "", "");
-    INSERT("enable_procon_driver", "", "");
-    INSERT("vibration_enabled", "", "");
-    INSERT("enable_accurate_vibrations", "", "");
-    INSERT("motion_enabled", "", "");
-    INSERT("udp_input_servers", "", "");
-    INSERT("enable_udp_controller", "", "");
-    INSERT("pause_tas_on_load", "", "");
-    INSERT("tas_enable", "", "");
-    INSERT("tas_loop", "", "");
-    INSERT("mouse_panning", "", "");
-    INSERT("mouse_panning_sensitivity", "", "");
-    INSERT("mouse_enabled", "", "");
-    INSERT("emulate_analog_keyboard", "", "");
-    INSERT("keyboard_enabled", "", "");
-    INSERT("debug_pad_enabled", "", "");
-    INSERT("touch_device", "", "");
-    INSERT("touch_from_button_map", "", "");
-    INSERT("enable_ring_controller", "", "");
-    INSERT("enable_ir_sensor", "", "");
-    INSERT("ir_sensor_device", "", "");
 
     // Data Storage
-    INSERT("use_virtual_sd", "", "");
-    INSERT("gamecard_inserted", "Inserted", "");
-    INSERT("gamecard_current_game", "Current Game", "");
-    INSERT("gamecard_path", "Path", "");
 
     // Debugging
-    INSERT("use_gdbstub", "Enable GDB Stub", "");
-    INSERT("gdbstub_port", "Port:", "");
-    INSERT("program_args", "Arguments String", "");
-    INSERT("dump_exefs", "Dump ExeFS", "");
-    INSERT("dump_nso", "Dump Decompressed NSOs", "");
-    INSERT("enable_fs_access_log", "Enable FS Access Log", "");
-    INSERT("reporting_services", "Enable Verbose Repoting Services**", "");
-    INSERT("quest_flag", "Kiosk (Quest) Mode", "");
-    INSERT("extended_logging", "Enable Extended Logging**",
-           "When checked, the max size of the log increases from 100 MB to 1 GB");
-    INSERT("use_debug_asserts", "Enable Debug Asserts", "");
-    INSERT("use_auto_stub", "Enable Auto-Stub**", "");
-    INSERT("enable_all_controllers", "Enable All Controller Types", "");
-    INSERT("create_crash_dumps", "Create Minidump After Crash", "");
-    INSERT("perform_vulkan_check", "Perform Startup Vulkan Check",
-           "Enables yuzu to check for a working Vulkan environment when the program starts up. "
-           "Disable this if this is causing issues with external programs seeing yuzu.");
-    INSERT("log_filter", "Global Log Filter", "");
-    INSERT("use_dev_keys", "", "");
 
     // Debugging Graphics
-    INSERT("dump_shaders", "Dump Game Shaders",
-           "When checked, it will dump all the original assembler shaders from the disk shader "
-           "cache or game as found");
-    INSERT("disable_macro_jit", "Disable Macro JIT",
-           "When checked, it disables the macro Just In Time compiler. Enabling this makes games "
-           "run slower");
-    INSERT(
-        "disable_macro_hle", "Disable Macro HLE",
-        "When checked, it disables the macro HLE functions. Enabling this makes games run slower");
-    INSERT("dump_macros", "Dump Maxwell Macros",
-           "When checked, it will dump all the macro programs of the GPU");
 
     // Network
-    INSERT("network_interface", "Network Interface", "");
 
     // Web Service
-    INSERT("enable_telemetry", "Share anonymous usage data with the yuzu team", "");
-    INSERT("web_api_url", "", "");
-    INSERT("yuzu_username", "", "");
-    INSERT("yuzu_token", "Token:", "");
 
 #undef INSERT
 
@@ -241,6 +156,49 @@ std::forward_list<QString> ComboboxEnumeration(std::type_index type, QWidget* pa
             tr("High"),
             tr("Extreme"),
         };
+    } else if (type == typeid(Settings::CPUAccuracy)) {
+        return {
+            tr("Auto"),
+            tr("Accurate"),
+            tr("Unsafe"),
+            tr("Paranoid (disables most optimizations)"),
+        };
+    } else if (type == typeid(Settings::FullscreenMode)) {
+        return {
+            tr("Borderless Windowed"),
+            tr("Exclusive Fullscreen"),
+        };
+    } else if (type == typeid(Settings::NvdecEmulation)) {
+        return {
+            tr("No Video Output"),
+            tr("CPU Video Decoding"),
+            tr("GPU Video Decoding (Default)"),
+        };
+    } else if (type == typeid(Settings::ResolutionSetup)) {
+        return {
+            tr("0.5X (360p/540p) [EXPERIMENTAL]"),
+            tr("0.75X (540p/810p) [EXPERIMENTAL]"),
+            tr("1X (720p/1080p)"),
+            tr("1.5X (1080p/1620p) [EXPERIMENTAL]"),
+            tr("2X (1440p/2160p)"),
+            tr("3X (2160p/3240p)"),
+            tr("4X (2880p/4320p)"),
+            tr("5X (3600p/5400p)"),
+            tr("6X (4320p/6480p)"),
+            tr("7X (5040p/7560p)"),
+            tr("8X (5760p/8640p)"),
+        };
+    } else if (type == typeid(Settings::ScalingFilter)) {
+        return {
+            tr("Nearest Neighbor"), tr("Bilinear"),   tr("Bicubic"),
+            tr("Gaussian"),         tr("ScaleForce"), tr("AMD FidelityFX™️ Super Resolution"),
+        };
+    } else if (type == typeid(Settings::AntiAliasing)) {
+        return {
+            tr("None"),
+            tr("FXAA"),
+            tr("SMAA"),
+        };
     } else if (type == typeid(Settings::AnisotropyMode)) {
         return {
             tr("Automatic"), tr("Default"), tr("2x"), tr("4x"), tr("8x"), tr("16x"),
diff --git a/src/yuzu/configuration/shared_translation.h b/src/yuzu/configuration/shared_translation.h
index 79cd08a6a..fcf638ea5 100644
--- a/src/yuzu/configuration/shared_translation.h
+++ b/src/yuzu/configuration/shared_translation.h
@@ -12,7 +12,7 @@
 class QWidget;
 
 namespace ConfigurationShared {
-using TranslationMap = std::map<std::string, std::pair<QString, QString>>;
+using TranslationMap = std::map<u32, std::pair<QString, QString>>;
 
 std::unique_ptr<TranslationMap> InitializeTranslations(QWidget* parent);