Skip to content

Commit 45d3c66

Browse files
committed
FullscreenUI: Simplify game properties state
Only allow scanned games to be changed like the Qt UI, makes everything much simpler.
1 parent 32aa86a commit 45d3c66

File tree

5 files changed

+36
-62
lines changed

5 files changed

+36
-62
lines changed

src/core/fullscreenui.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
33

44
#include "fullscreenui.h"
5-
#include "fullscreenui_private.h"
6-
#include "fullscreenui_widgets.h"
75
#include "achievements_private.h"
86
#include "controller.h"
7+
#include "fullscreenui_private.h"
8+
#include "fullscreenui_widgets.h"
99
#include "game_list.h"
1010
#include "gpu_thread.h"
1111
#include "system.h"
@@ -127,7 +127,7 @@ static constexpr std::string_view ABOUT_DIALOG_NAME = "##about_duckstation";
127127

128128
namespace {
129129

130-
struct ALIGN_TO_CACHE_LINE Locals
130+
struct Locals
131131
{
132132
// Main
133133
MainWindowType current_main_window = MainWindowType::None;
@@ -154,7 +154,7 @@ struct ALIGN_TO_CACHE_LINE Locals
154154

155155
} // namespace
156156

157-
static Locals s_locals;
157+
ALIGN_TO_CACHE_LINE static Locals s_locals;
158158

159159
} // namespace FullscreenUI
160160

@@ -1604,8 +1604,11 @@ void FullscreenUI::DrawPauseMenu()
16041604
DoToggleAnalogMode();
16051605
}
16061606

1607-
if (MenuButtonWithoutSummary(FSUI_ICONVSTR(ICON_FA_WRENCH, "Game Properties"), has_game))
1607+
if (MenuButtonWithoutSummary(FSUI_ICONVSTR(ICON_FA_WRENCH, "Game Properties"),
1608+
has_game && !GPUThread::GetGameSerial().empty()))
1609+
{
16081610
BeginTransition([]() { SwitchToGameSettings(); });
1611+
}
16091612

16101613
if (MenuButtonWithoutSummary(FSUI_ICONVSTR(ICON_FA_TROPHY, "Achievements"),
16111614
Achievements::HasAchievementsOrLeaderboards()))

src/core/fullscreenui_private.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ void SwitchToSettings();
112112
bool SwitchToGameSettings(SettingsPage page = SettingsPage::Summary);
113113
void SwitchToGameSettings(const GameList::Entry* entry, SettingsPage page = SettingsPage::Summary);
114114
bool SwitchToGameSettingsForPath(const std::string& path, SettingsPage page = SettingsPage::Summary);
115-
void SwitchToGameSettingsForSerial(std::string_view serial, GameHash hash, SettingsPage page = SettingsPage::Summary);
116115
void DrawSettingsWindow();
117116
SettingsPage GetCurrentSettingsPage();
118117
bool IsInputBindingDialogOpen();

src/core/fullscreenui_settings.cpp

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "IconsFontAwesome6.h"
3434
#include "IconsPromptFont.h"
3535

36+
#include <limits>
3637
#include <mutex>
3738

3839
LOG_CHANNEL(FullscreenUI);
@@ -186,14 +187,11 @@ static constexpr std::string_view ACHIEVEMENTS_LOGIN_DIALOG_NAME = "##achievemen
186187
static constexpr std::string_view COVER_DOWNLOADER_DIALOG_NAME = "##cover_downloader";
187188

188189
namespace {
189-
struct ALIGN_TO_CACHE_LINE SettingsLocals
190+
struct SettingsLocals
190191
{
191192
float settings_last_bg_alpha = 1.0f;
192193
SettingsPage settings_page = SettingsPage::Interface;
193194
std::unique_ptr<INISettingsInterface> game_settings_interface;
194-
std::string game_settings_serial;
195-
GameHash game_settings_hash = 0;
196-
const GameDatabase::Entry* game_settings_db_entry;
197195
std::unique_ptr<GameList::Entry> game_settings_entry;
198196
std::vector<std::pair<std::string, bool>> game_list_directories_cache;
199197
GPUDevice::AdapterInfoList graphics_adapter_list_cache;
@@ -213,7 +211,7 @@ struct ALIGN_TO_CACHE_LINE SettingsLocals
213211

214212
} // namespace
215213

216-
static SettingsLocals s_settings_locals;
214+
ALIGN_TO_CACHE_LINE static SettingsLocals s_settings_locals;
217215

218216
} // namespace FullscreenUI
219217

@@ -1564,10 +1562,7 @@ void FullscreenUI::ClearSettingsState()
15641562
s_settings_locals.input_binding_dialog.ClearState();
15651563
std::memset(s_settings_locals.controller_macro_expanded, 0, sizeof(s_settings_locals.controller_macro_expanded));
15661564
s_settings_locals.game_list_directories_cache = {};
1567-
s_settings_locals.game_settings_db_entry = nullptr;
15681565
s_settings_locals.game_settings_entry.reset();
1569-
s_settings_locals.game_settings_hash = 0;
1570-
s_settings_locals.game_settings_serial = {};
15711566
s_settings_locals.game_settings_interface.reset();
15721567
s_settings_locals.game_settings_changed = false;
15731568
s_settings_locals.game_patch_list = {};
@@ -1585,9 +1580,6 @@ void FullscreenUI::SwitchToSettings()
15851580
{
15861581
s_settings_locals.game_settings_entry.reset();
15871582
s_settings_locals.game_settings_interface.reset();
1588-
s_settings_locals.game_settings_serial = {};
1589-
s_settings_locals.game_settings_hash = 0;
1590-
s_settings_locals.game_settings_db_entry = nullptr;
15911583
s_settings_locals.game_patch_list = {};
15921584
s_settings_locals.enabled_game_patch_cache = {};
15931585
s_settings_locals.game_cheats_list = {};
@@ -1609,54 +1601,33 @@ void FullscreenUI::SwitchToSettings()
16091601
s_settings_locals.settings_last_bg_alpha = GetBackgroundAlpha();
16101602
}
16111603

1612-
void FullscreenUI::SwitchToGameSettingsForSerial(std::string_view serial, GameHash hash, SettingsPage page)
1613-
{
1614-
s_settings_locals.game_settings_serial = serial;
1615-
s_settings_locals.game_settings_hash = hash;
1616-
s_settings_locals.game_settings_entry.reset();
1617-
s_settings_locals.game_settings_db_entry = GameDatabase::GetEntryForSerial(serial);
1618-
s_settings_locals.game_settings_interface =
1619-
System::GetGameSettingsInterface(s_settings_locals.game_settings_db_entry, serial, true, false);
1620-
PopulatePatchesAndCheatsList();
1621-
s_settings_locals.settings_page = page;
1622-
SwitchToMainWindow(MainWindowType::Settings);
1623-
}
1624-
16251604
bool FullscreenUI::SwitchToGameSettings(SettingsPage page)
16261605
{
1627-
const std::string& serial = GPUThread::GetGameSerial();
1628-
if (serial.empty())
1629-
return false;
1630-
1631-
auto lock = GameList::GetLock();
1632-
const GameList::Entry* entry = GameList::GetEntryForPath(GPUThread::GetGamePath());
1633-
if (!entry)
1634-
{
1635-
SwitchToGameSettingsForSerial(serial, GPUThread::GetGameHash(), page);
1636-
return true;
1637-
}
1638-
else
1639-
{
1640-
SwitchToGameSettings(entry, page);
1641-
return true;
1642-
}
1606+
return SwitchToGameSettingsForPath(GPUThread::GetGamePath());
16431607
}
16441608

16451609
bool FullscreenUI::SwitchToGameSettingsForPath(const std::string& path, SettingsPage page)
16461610
{
16471611
auto lock = GameList::GetLock();
1648-
const GameList::Entry* entry = GameList::GetEntryForPath(path);
1649-
if (!entry)
1612+
const GameList::Entry* entry = !path.empty() ? GameList::GetEntryForPath(path) : nullptr;
1613+
if (!entry || entry->serial.empty())
1614+
{
1615+
ShowToast({}, FSUI_STR("Game properties is only available for scanned games."));
16501616
return false;
1617+
}
16511618

16521619
SwitchToGameSettings(entry, page);
16531620
return true;
16541621
}
16551622

16561623
void FullscreenUI::SwitchToGameSettings(const GameList::Entry* entry, SettingsPage page)
16571624
{
1658-
SwitchToGameSettingsForSerial(entry->serial, entry->hash, page);
16591625
s_settings_locals.game_settings_entry = std::make_unique<GameList::Entry>(*entry);
1626+
s_settings_locals.game_settings_interface = System::GetGameSettingsInterface(
1627+
s_settings_locals.game_settings_entry->dbentry, s_settings_locals.game_settings_entry->serial, true, false);
1628+
PopulatePatchesAndCheatsList();
1629+
s_settings_locals.settings_page = page;
1630+
SwitchToMainWindow(MainWindowType::Settings);
16601631
}
16611632

16621633
void FullscreenUI::PopulateGraphicsAdapterList()
@@ -1683,10 +1654,10 @@ void FullscreenUI::PopulateGameListDirectoryCache(SettingsInterface* si)
16831654

16841655
void FullscreenUI::PopulatePatchesAndCheatsList()
16851656
{
1686-
s_settings_locals.game_patch_list = Cheats::GetCodeInfoList(s_settings_locals.game_settings_serial,
1687-
s_settings_locals.game_settings_hash, false, true, true);
1657+
s_settings_locals.game_patch_list = Cheats::GetCodeInfoList(
1658+
s_settings_locals.game_settings_entry->serial, s_settings_locals.game_settings_entry->hash, false, true, true);
16881659
s_settings_locals.game_cheats_list = Cheats::GetCodeInfoList(
1689-
s_settings_locals.game_settings_serial, s_settings_locals.game_settings_hash, true,
1660+
s_settings_locals.game_settings_entry->serial, s_settings_locals.game_settings_entry->hash, true,
16901661
s_settings_locals.game_settings_interface->GetBoolValue("Cheats", "LoadCheatsFromDatabase", true),
16911662
s_settings_locals.game_settings_interface->GetBoolValue("Cheats", "SortList", false));
16921663
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)
20642035

20652036
MenuHeading(FSUI_VSTR("Options"));
20662037

2067-
if (s_settings_locals.game_settings_db_entry && s_settings_locals.game_settings_db_entry->disc_set)
2038+
DebugAssert(s_settings_locals.game_settings_entry);
2039+
if (s_settings_locals.game_settings_entry->dbentry && s_settings_locals.game_settings_entry->dbentry->disc_set)
20682040
{
20692041
// only enable for first disc
2070-
const bool is_first_disc = (s_settings_locals.game_settings_db_entry->serial ==
2071-
s_settings_locals.game_settings_db_entry->disc_set->serials.front());
2042+
const bool is_first_disc = (s_settings_locals.game_settings_entry->dbentry->serial ==
2043+
s_settings_locals.game_settings_entry->dbentry->disc_set->serials.front());
20722044
DrawToggleSetting(
20732045
GetEditingSettingsInterface(), FSUI_ICONVSTR(ICON_FA_COMPACT_DISC, "Use Separate Disc Settings"),
20742046
FSUI_VSTR(
@@ -5180,8 +5152,8 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats)
51805152
bsi->SetBoolValue("Cheats", "SortList", true);
51815153
SetSettingsChanged(bsi);
51825154
s_settings_locals.game_cheats_list =
5183-
Cheats::GetCodeInfoList(s_settings_locals.game_settings_serial, s_settings_locals.game_settings_hash, true,
5184-
load_database_cheats, sort_list);
5155+
Cheats::GetCodeInfoList(s_settings_locals.game_settings_entry->serial,
5156+
s_settings_locals.game_settings_entry->hash, true, load_database_cheats, sort_list);
51855157
}
51865158

51875159
if (code_list.empty())

src/core/fullscreenui_widgets.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class FixedPopupDialog : public PopupDialog
297297
void End();
298298
};
299299

300-
struct ALIGN_TO_CACHE_LINE WidgetsState
300+
struct WidgetsState
301301
{
302302
std::recursive_mutex shared_state_mutex;
303303

@@ -370,8 +370,8 @@ struct ALIGN_TO_CACHE_LINE WidgetsState
370370

371371
} // namespace
372372

373-
UIStyles UIStyle = {};
374-
static WidgetsState s_state;
373+
ALIGN_TO_CACHE_LINE UIStyles UIStyle = {};
374+
ALIGN_TO_CACHE_LINE static WidgetsState s_state;
375375

376376
} // namespace FullscreenUI
377377

src/core/imgui_overlays.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ static constexpr const char* DATE_TIME_FORMAT =
945945

946946
namespace {
947947

948-
struct ALIGN_TO_CACHE_LINE State
948+
struct State
949949
{
950950
std::shared_ptr<GPUTexture> placeholder_texture;
951951

@@ -969,7 +969,7 @@ struct ALIGN_TO_CACHE_LINE State
969969

970970
} // namespace
971971

972-
static State s_state;
972+
ALIGN_TO_CACHE_LINE static State s_state;
973973

974974
} // namespace SaveStateSelectorUI
975975

0 commit comments

Comments
 (0)