From 45d3c665798a582a95c5c6cfecbbee9d501ff36e Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 18 Oct 2025 22:04:46 +1000 Subject: [PATCH] FullscreenUI: Simplify game properties state Only allow scanned games to be changed like the Qt UI, makes everything much simpler. --- src/core/fullscreenui.cpp | 13 ++++-- src/core/fullscreenui_private.h | 1 - src/core/fullscreenui_settings.cpp | 74 ++++++++++-------------------- src/core/fullscreenui_widgets.cpp | 6 +-- src/core/imgui_overlays.cpp | 4 +- 5 files changed, 36 insertions(+), 62 deletions(-) diff --git a/src/core/fullscreenui.cpp b/src/core/fullscreenui.cpp index 5ffdf3959..e029251e9 100644 --- a/src/core/fullscreenui.cpp +++ b/src/core/fullscreenui.cpp @@ -2,10 +2,10 @@ // SPDX-License-Identifier: CC-BY-NC-ND-4.0 #include "fullscreenui.h" -#include "fullscreenui_private.h" -#include "fullscreenui_widgets.h" #include "achievements_private.h" #include "controller.h" +#include "fullscreenui_private.h" +#include "fullscreenui_widgets.h" #include "game_list.h" #include "gpu_thread.h" #include "system.h" @@ -127,7 +127,7 @@ static constexpr std::string_view ABOUT_DIALOG_NAME = "##about_duckstation"; namespace { -struct ALIGN_TO_CACHE_LINE Locals +struct Locals { // Main MainWindowType current_main_window = MainWindowType::None; @@ -154,7 +154,7 @@ struct ALIGN_TO_CACHE_LINE Locals } // namespace -static Locals s_locals; +ALIGN_TO_CACHE_LINE static Locals s_locals; } // namespace FullscreenUI @@ -1604,8 +1604,11 @@ void FullscreenUI::DrawPauseMenu() DoToggleAnalogMode(); } - if (MenuButtonWithoutSummary(FSUI_ICONVSTR(ICON_FA_WRENCH, "Game Properties"), has_game)) + if (MenuButtonWithoutSummary(FSUI_ICONVSTR(ICON_FA_WRENCH, "Game Properties"), + has_game && !GPUThread::GetGameSerial().empty())) + { BeginTransition([]() { SwitchToGameSettings(); }); + } if (MenuButtonWithoutSummary(FSUI_ICONVSTR(ICON_FA_TROPHY, "Achievements"), Achievements::HasAchievementsOrLeaderboards())) diff --git a/src/core/fullscreenui_private.h b/src/core/fullscreenui_private.h index fcd74638a..269d6ea8c 100644 --- a/src/core/fullscreenui_private.h +++ b/src/core/fullscreenui_private.h @@ -112,7 +112,6 @@ void SwitchToSettings(); bool SwitchToGameSettings(SettingsPage page = SettingsPage::Summary); void SwitchToGameSettings(const GameList::Entry* entry, SettingsPage page = SettingsPage::Summary); bool SwitchToGameSettingsForPath(const std::string& path, SettingsPage page = SettingsPage::Summary); -void SwitchToGameSettingsForSerial(std::string_view serial, GameHash hash, SettingsPage page = SettingsPage::Summary); void DrawSettingsWindow(); SettingsPage GetCurrentSettingsPage(); bool IsInputBindingDialogOpen(); diff --git a/src/core/fullscreenui_settings.cpp b/src/core/fullscreenui_settings.cpp index 8ff7b464d..e409cfca5 100644 --- a/src/core/fullscreenui_settings.cpp +++ b/src/core/fullscreenui_settings.cpp @@ -33,6 +33,7 @@ #include "IconsFontAwesome6.h" #include "IconsPromptFont.h" +#include #include LOG_CHANNEL(FullscreenUI); @@ -186,14 +187,11 @@ static constexpr std::string_view ACHIEVEMENTS_LOGIN_DIALOG_NAME = "##achievemen static constexpr std::string_view COVER_DOWNLOADER_DIALOG_NAME = "##cover_downloader"; namespace { -struct ALIGN_TO_CACHE_LINE SettingsLocals +struct SettingsLocals { float settings_last_bg_alpha = 1.0f; SettingsPage settings_page = SettingsPage::Interface; std::unique_ptr game_settings_interface; - std::string game_settings_serial; - GameHash game_settings_hash = 0; - const GameDatabase::Entry* game_settings_db_entry; std::unique_ptr game_settings_entry; std::vector> game_list_directories_cache; GPUDevice::AdapterInfoList graphics_adapter_list_cache; @@ -213,7 +211,7 @@ struct ALIGN_TO_CACHE_LINE SettingsLocals } // namespace -static SettingsLocals s_settings_locals; +ALIGN_TO_CACHE_LINE static SettingsLocals s_settings_locals; } // namespace FullscreenUI @@ -1564,10 +1562,7 @@ void FullscreenUI::ClearSettingsState() s_settings_locals.input_binding_dialog.ClearState(); std::memset(s_settings_locals.controller_macro_expanded, 0, sizeof(s_settings_locals.controller_macro_expanded)); s_settings_locals.game_list_directories_cache = {}; - s_settings_locals.game_settings_db_entry = nullptr; s_settings_locals.game_settings_entry.reset(); - s_settings_locals.game_settings_hash = 0; - s_settings_locals.game_settings_serial = {}; s_settings_locals.game_settings_interface.reset(); s_settings_locals.game_settings_changed = false; s_settings_locals.game_patch_list = {}; @@ -1585,9 +1580,6 @@ void FullscreenUI::SwitchToSettings() { s_settings_locals.game_settings_entry.reset(); s_settings_locals.game_settings_interface.reset(); - s_settings_locals.game_settings_serial = {}; - s_settings_locals.game_settings_hash = 0; - s_settings_locals.game_settings_db_entry = nullptr; s_settings_locals.game_patch_list = {}; s_settings_locals.enabled_game_patch_cache = {}; s_settings_locals.game_cheats_list = {}; @@ -1609,45 +1601,20 @@ void FullscreenUI::SwitchToSettings() s_settings_locals.settings_last_bg_alpha = GetBackgroundAlpha(); } -void FullscreenUI::SwitchToGameSettingsForSerial(std::string_view serial, GameHash hash, SettingsPage page) -{ - s_settings_locals.game_settings_serial = serial; - s_settings_locals.game_settings_hash = hash; - s_settings_locals.game_settings_entry.reset(); - s_settings_locals.game_settings_db_entry = GameDatabase::GetEntryForSerial(serial); - s_settings_locals.game_settings_interface = - System::GetGameSettingsInterface(s_settings_locals.game_settings_db_entry, serial, true, false); - PopulatePatchesAndCheatsList(); - s_settings_locals.settings_page = page; - SwitchToMainWindow(MainWindowType::Settings); -} - bool FullscreenUI::SwitchToGameSettings(SettingsPage page) { - const std::string& serial = GPUThread::GetGameSerial(); - if (serial.empty()) - return false; - - auto lock = GameList::GetLock(); - const GameList::Entry* entry = GameList::GetEntryForPath(GPUThread::GetGamePath()); - if (!entry) - { - SwitchToGameSettingsForSerial(serial, GPUThread::GetGameHash(), page); - return true; - } - else - { - SwitchToGameSettings(entry, page); - return true; - } + return SwitchToGameSettingsForPath(GPUThread::GetGamePath()); } bool FullscreenUI::SwitchToGameSettingsForPath(const std::string& path, SettingsPage page) { auto lock = GameList::GetLock(); - const GameList::Entry* entry = GameList::GetEntryForPath(path); - if (!entry) + const GameList::Entry* entry = !path.empty() ? GameList::GetEntryForPath(path) : nullptr; + if (!entry || entry->serial.empty()) + { + ShowToast({}, FSUI_STR("Game properties is only available for scanned games.")); return false; + } SwitchToGameSettings(entry, page); return true; @@ -1655,8 +1622,12 @@ bool FullscreenUI::SwitchToGameSettingsForPath(const std::string& path, Settings void FullscreenUI::SwitchToGameSettings(const GameList::Entry* entry, SettingsPage page) { - SwitchToGameSettingsForSerial(entry->serial, entry->hash, page); s_settings_locals.game_settings_entry = std::make_unique(*entry); + s_settings_locals.game_settings_interface = System::GetGameSettingsInterface( + s_settings_locals.game_settings_entry->dbentry, s_settings_locals.game_settings_entry->serial, true, false); + PopulatePatchesAndCheatsList(); + s_settings_locals.settings_page = page; + SwitchToMainWindow(MainWindowType::Settings); } void FullscreenUI::PopulateGraphicsAdapterList() @@ -1683,10 +1654,10 @@ void FullscreenUI::PopulateGameListDirectoryCache(SettingsInterface* si) void FullscreenUI::PopulatePatchesAndCheatsList() { - s_settings_locals.game_patch_list = Cheats::GetCodeInfoList(s_settings_locals.game_settings_serial, - s_settings_locals.game_settings_hash, false, true, true); + s_settings_locals.game_patch_list = Cheats::GetCodeInfoList( + s_settings_locals.game_settings_entry->serial, s_settings_locals.game_settings_entry->hash, false, true, true); s_settings_locals.game_cheats_list = Cheats::GetCodeInfoList( - s_settings_locals.game_settings_serial, s_settings_locals.game_settings_hash, true, + s_settings_locals.game_settings_entry->serial, s_settings_locals.game_settings_entry->hash, true, s_settings_locals.game_settings_interface->GetBoolValue("Cheats", "LoadCheatsFromDatabase", true), s_settings_locals.game_settings_interface->GetBoolValue("Cheats", "SortList", false)); s_settings_locals.game_cheat_groups = Cheats::GetCodeListUniquePrefixes(s_settings_locals.game_cheats_list, true); @@ -2064,11 +2035,12 @@ void FullscreenUI::DrawSummarySettingsPage(bool show_localized_titles) MenuHeading(FSUI_VSTR("Options")); - if (s_settings_locals.game_settings_db_entry && s_settings_locals.game_settings_db_entry->disc_set) + DebugAssert(s_settings_locals.game_settings_entry); + if (s_settings_locals.game_settings_entry->dbentry && s_settings_locals.game_settings_entry->dbentry->disc_set) { // only enable for first disc - const bool is_first_disc = (s_settings_locals.game_settings_db_entry->serial == - s_settings_locals.game_settings_db_entry->disc_set->serials.front()); + const bool is_first_disc = (s_settings_locals.game_settings_entry->dbentry->serial == + s_settings_locals.game_settings_entry->dbentry->disc_set->serials.front()); DrawToggleSetting( GetEditingSettingsInterface(), FSUI_ICONVSTR(ICON_FA_COMPACT_DISC, "Use Separate Disc Settings"), FSUI_VSTR( @@ -5180,8 +5152,8 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) bsi->SetBoolValue("Cheats", "SortList", true); SetSettingsChanged(bsi); s_settings_locals.game_cheats_list = - Cheats::GetCodeInfoList(s_settings_locals.game_settings_serial, s_settings_locals.game_settings_hash, true, - load_database_cheats, sort_list); + Cheats::GetCodeInfoList(s_settings_locals.game_settings_entry->serial, + s_settings_locals.game_settings_entry->hash, true, load_database_cheats, sort_list); } if (code_list.empty()) diff --git a/src/core/fullscreenui_widgets.cpp b/src/core/fullscreenui_widgets.cpp index 30d4240ab..1ada8e094 100644 --- a/src/core/fullscreenui_widgets.cpp +++ b/src/core/fullscreenui_widgets.cpp @@ -297,7 +297,7 @@ public: void End(); }; -struct ALIGN_TO_CACHE_LINE WidgetsState +struct WidgetsState { std::recursive_mutex shared_state_mutex; @@ -370,8 +370,8 @@ struct ALIGN_TO_CACHE_LINE WidgetsState } // namespace -UIStyles UIStyle = {}; -static WidgetsState s_state; +ALIGN_TO_CACHE_LINE UIStyles UIStyle = {}; +ALIGN_TO_CACHE_LINE static WidgetsState s_state; } // namespace FullscreenUI diff --git a/src/core/imgui_overlays.cpp b/src/core/imgui_overlays.cpp index e51b78e9e..249c40eb6 100644 --- a/src/core/imgui_overlays.cpp +++ b/src/core/imgui_overlays.cpp @@ -945,7 +945,7 @@ static constexpr const char* DATE_TIME_FORMAT = namespace { -struct ALIGN_TO_CACHE_LINE State +struct State { std::shared_ptr placeholder_texture; @@ -969,7 +969,7 @@ struct ALIGN_TO_CACHE_LINE State } // namespace -static State s_state; +ALIGN_TO_CACHE_LINE static State s_state; } // namespace SaveStateSelectorUI