summaryrefslogtreecommitdiff
path: root/src/core/settings.h
diff options
context:
space:
mode:
authorGravatar lat9nq2020-07-09 22:42:09 -0400
committerGravatar GitHub2020-07-09 22:42:09 -0400
commit63d23835ef4445b3a010cc0e8b1e73ebe012ac08 (patch)
treeb243c1167280dbf2e3f5af4597b6638fb707f091 /src/core/settings.h
parentMerge pull request #4281 from RealJohnGalt/linkfix2 (diff)
downloadyuzu-63d23835ef4445b3a010cc0e8b1e73ebe012ac08.tar.gz
yuzu-63d23835ef4445b3a010cc0e8b1e73ebe012ac08.tar.xz
yuzu-63d23835ef4445b3a010cc0e8b1e73ebe012ac08.zip
configuration: implement per-game configurations (#4098)
* Switch game settings to use a pointer In order to add full per-game settings, we need to be able to tell yuzu to switch to using either the global or game configuration. Using a pointer makes it easier to switch. * configuration: add new UI without changing existing funcitonality The new UI also adds General, System, Graphics, Advanced Graphics, and Audio tabs, but as yet they do nothing. This commit keeps yuzu to the same functionality as originally branched. * configuration: Rename files These weren't included in the last commit. Now they are. * configuration: setup global configuration checkbox Global config checkbox now enables/disables the appropriate tabs in the game properties dialog. The use global configuration setting is now saved to the config, defaulting to true. This also addresses some changes requested in the PR. * configuration: swap to per-game config memory for properties dialog Does not set memory going in-game. Swaps to game values when opening the properties dialog, then swaps back when closing it. Uses a `memcpy` to swap. Also implements saving config files, limited to certain groups of configurations so as to not risk setting unsafe configurations. * configuration: change config interfaces to use config-specific pointers When a game is booted, we need to be able to open the configuration dialogs without changing the settings pointer in the game's emualtion. A new pointer specific to just the configuration dialogs can be used to separate changes to just those config dialogs without affecting the emulation. * configuration: boot a game using per-game settings Swaps values where needed to boot a game. * configuration: user correct config during emulation Creates a new pointer specifically for modifying the configuration while emulation is in progress. Both the regular configuration dialog and the game properties dialog now use the pointer Settings::config_values to focus edits to the correct struct. * settings: split Settings::values into two different structs By splitting the settings into two mutually exclusive structs, it becomes easier, as a developer, to determine how to use the Settings structs after per-game configurations is merged. Other benefits include only duplicating the required settings in memory. * settings: move use_docked_mode to Controls group `use_docked_mode` is set in the input settings and cannot be accessed from the system settings. Grouping it with system settings causes it to be saved with per-game settings, which may make transferring configs more difficult later on, especially since docked mode cannot be set from within the game properties dialog. * configuration: Fix the other yuzu executables and a regression In main.cpp, we have to get the title ID before the ROM is loaded, else the renderer will reflect only the global settings and now the user's game specific settings. * settings: use a template to duplicate memory for each setting Replaces the type of each variable in the Settings::Values struct with a new class that allows basic data reading and writing. The new struct Settings::Setting duplicates the data in memory and can manage global overrides per each setting. * configuration: correct add-ons config and swap settings when apropriate Any add-ons interaction happens directly through the global values struct. Swapping bewteen structs now also includes copying the necessary global configs that cannot be changed nor saved in per-game settings. General and System config menus now update based on whether it is viewing the global or per-game settings. * settings: restore old values struct No longer needed with the Settings::Setting class template. * configuration: implement hierarchical game properties dialog This sets the apropriate global or local data in each setting. * clang format * clang format take 2 can the docker container save this? * address comments and style issues * config: read and write settings with global awareness Adds new functions to read and write settings while keeping the global state in focus. Files now generated per-game are much smaller since often they only need address the global state. * settings: restore global state when necessary Upon closing a game or the game properties dialog, we need to restore all global settings to the original global state so that we can properly open the configuration dialog or boot a different game. * configuration: guard setting values incorrectly This disables setting values while a game is running if the setting is overwritten by a per game setting. * config: don't write local settings in the global config Simple guards to prevent writing the wrong settings in the wrong files. * 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. * configuration: fix a logic error Should not be negated * restore settings' global state regardless of accept/cancel Fixes loading a properties dialog and causing the global config dialog to show local settings. * fix more logic errors Fixed the frame limit would set the global setting from the game properties dialog. Also strengthened the Settings::Setting member variables and simplified the logic in config reading (ReadSettingGlobal). * fix another logic error In my efforts to guard RestoreGlobalState, I accidentally negated the IsPowered condition. * configure_audio: set toggle_stretched_audio to tristate * fixed custom rtc and rng seed overwriting the global value * clang format * rebased * clang format take 4 * address my own review Basically revert unintended changes * settings: literal instead of casting "No need to cast, use 1U instead" Thanks, Morph! Co-authored-by: Morph <39850852+Morph1984@users.noreply.github.com> * Revert "settings: literal instead of casting " This reverts commit 95e992a87c898f3e882ffdb415bb0ef9f80f613f. * main: fix status buttons reporting wrong settings after stop emulation * settings: Log UseDockedMode in the Controls group This should have happened when use_docked_mode was moved over to the controls group internally. This just reflects this in the log. * main: load settings if the file has a title id In other words, don't exit if the loader has trouble getting a title id. * use a zero * settings: initalize resolution factor with constructor instead of casting * Revert "settings: initalize resolution factor with constructor instead of casting" This reverts commit 54c35ecb46a29953842614620f9b7de1aa9d5dc8. * configure_graphics: guard device selector when Vulkan is global Prevents the user from editing the device selector if Vulkan is the global renderer backend. Also resets the vulkan_device variable when the users switches back-and-forth between global and Vulkan. * address reviewer concerns Changes function variables to const wherever they don't need to be changed. Sets Settings::Setting to final as it should not be inherited from. Sets ConfigurationShared::use_global_text to static. Co-Authored-By: VolcaEM <volcaem@users.noreply.github.com> * main: load per-game settings after LoadROM This prevents `Restart Emulation` from restoring the global settings *after* the per-game settings were applied. Thanks to BSoDGamingYT for finding this bug. * Revert "main: load per-game settings after LoadROM" This reverts commit 9d0d48c52d2dcf3bfb1806cc8fa7d5a271a8a804. * main: only restore global settings when necessary Loading the per-game settings cannot happen after the ROM is loaded, so we have to specify when to restore the global state. Again thanks to BSoD for finding the bug. * configuration_shared: address reviewer concerns except operator overrides Dropping operator override usage in next commit. Co-Authored-By: LC <lioncash@users.noreply.github.com> * settings: Drop operator overrides from Setting template Requires using GetValue and SetValue explicitly. Also reverts a change that broke title ID formatting in the game properties dialog. * complete rebase * configuration_shared: translate "Use global configuration" Uses ConfigurePerGame to do so, since its usage, at least as of now, corresponds with ConfigurationShared. * configure_per_game: address reviewer concern As far as I understand, it prevents the program from unnecessarily copying strings. Co-Authored-By: LC <lioncash@users.noreply.github.com> Co-authored-by: Morph <39850852+Morph1984@users.noreply.github.com> Co-authored-by: VolcaEM <volcaem@users.noreply.github.com> Co-authored-by: LC <lioncash@users.noreply.github.com>
Diffstat (limited to 'src/core/settings.h')
-rw-r--r--src/core/settings.h124
1 files changed, 81 insertions, 43 deletions
diff --git a/src/core/settings.h b/src/core/settings.h
index a598ccbc1..850ca4072 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -382,20 +382,85 @@ enum class GPUAccuracy : u32 {
382 Extreme = 2, 382 Extreme = 2,
383}; 383};
384 384
385extern bool configuring_global;
386
387template <typename Type>
388class Setting final {
389public:
390 Setting() = default;
391 explicit Setting(Type val) : global{val} {}
392 ~Setting() = default;
393 void SetGlobal(bool to_global) {
394 use_global = to_global;
395 }
396 bool UsingGlobal() const {
397 return use_global;
398 }
399 Type GetValue(bool need_global = false) const {
400 if (use_global || need_global) {
401 return global;
402 }
403 return local;
404 }
405 void SetValue(const Type& value) {
406 if (use_global) {
407 global = value;
408 } else {
409 local = value;
410 }
411 }
412
413private:
414 bool use_global = true;
415 Type global{};
416 Type local{};
417};
418
385struct Values { 419struct Values {
420 // Audio
421 std::string audio_device_id;
422 std::string sink_id;
423 bool audio_muted;
424 Setting<bool> enable_audio_stretching;
425 Setting<float> volume;
426
427 // Core
428 Setting<bool> use_multi_core;
429
430 // Renderer
431 Setting<RendererBackend> renderer_backend;
432 bool renderer_debug;
433 Setting<int> vulkan_device;
434
435 Setting<u16> resolution_factor = Setting(static_cast<u16>(1));
436 Setting<int> aspect_ratio;
437 Setting<int> max_anisotropy;
438 Setting<bool> use_frame_limit;
439 Setting<u16> frame_limit;
440 Setting<bool> use_disk_shader_cache;
441 Setting<GPUAccuracy> gpu_accuracy;
442 Setting<bool> use_asynchronous_gpu_emulation;
443 Setting<bool> use_vsync;
444 Setting<bool> use_assembly_shaders;
445 Setting<bool> force_30fps_mode;
446 Setting<bool> use_fast_gpu_time;
447
448 Setting<float> bg_red;
449 Setting<float> bg_green;
450 Setting<float> bg_blue;
451
386 // System 452 // System
387 bool use_docked_mode; 453 Setting<std::optional<u32>> rng_seed;
388 std::optional<u32> rng_seed;
389 // Measured in seconds since epoch 454 // Measured in seconds since epoch
390 std::optional<std::chrono::seconds> custom_rtc; 455 Setting<std::optional<std::chrono::seconds>> custom_rtc;
391 // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc` 456 // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc`
392 std::chrono::seconds custom_rtc_differential; 457 std::chrono::seconds custom_rtc_differential;
393 458
394 s32 current_user; 459 s32 current_user;
395 s32 language_index; 460 Setting<s32> language_index;
396 s32 region_index; 461 Setting<s32> region_index;
397 s32 time_zone_index; 462 Setting<s32> time_zone_index;
398 s32 sound_index; 463 Setting<s32> sound_index;
399 464
400 // Controls 465 // Controls
401 std::array<PlayerInput, 10> players; 466 std::array<PlayerInput, 10> players;
@@ -419,8 +484,7 @@ struct Values {
419 u16 udp_input_port; 484 u16 udp_input_port;
420 u8 udp_pad_index; 485 u8 udp_pad_index;
421 486
422 // Core 487 bool use_docked_mode;
423 bool use_multi_core;
424 488
425 // Data Storage 489 // Data Storage
426 bool use_virtual_sd; 490 bool use_virtual_sd;
@@ -432,39 +496,6 @@ struct Values {
432 NANDUserSize nand_user_size; 496 NANDUserSize nand_user_size;
433 SDMCSize sdmc_size; 497 SDMCSize sdmc_size;
434 498
435 // Renderer
436 RendererBackend renderer_backend;
437 bool renderer_debug;
438 int vulkan_device;
439
440 u16 resolution_factor{1};
441 int aspect_ratio;
442 int max_anisotropy;
443 bool use_frame_limit;
444 u16 frame_limit;
445 bool use_disk_shader_cache;
446 GPUAccuracy gpu_accuracy;
447 bool use_asynchronous_gpu_emulation;
448 bool use_vsync;
449 bool use_assembly_shaders;
450 bool force_30fps_mode;
451 bool use_fast_gpu_time;
452
453 float bg_red;
454 float bg_green;
455 float bg_blue;
456
457 std::string log_filter;
458
459 bool use_dev_keys;
460
461 // Audio
462 bool audio_muted;
463 std::string sink_id;
464 bool enable_audio_stretching;
465 std::string audio_device_id;
466 float volume;
467
468 // Debugging 499 // Debugging
469 bool record_frame_times; 500 bool record_frame_times;
470 bool use_gdbstub; 501 bool use_gdbstub;
@@ -477,7 +508,11 @@ struct Values {
477 bool disable_cpu_opt; 508 bool disable_cpu_opt;
478 bool disable_macro_jit; 509 bool disable_macro_jit;
479 510
480 // BCAT 511 // Misceallaneous
512 std::string log_filter;
513 bool use_dev_keys;
514
515 // Services
481 std::string bcat_backend; 516 std::string bcat_backend;
482 bool bcat_boxcat_local; 517 bool bcat_boxcat_local;
483 518
@@ -501,4 +536,7 @@ std::string GetTimeZoneString();
501void Apply(); 536void Apply();
502void LogSettings(); 537void LogSettings();
503 538
539// Restore the global state of all applicable settings in the Values struct
540void RestoreGlobalState();
541
504} // namespace Settings 542} // namespace Settings