mirror of
https://github.com/stenzek/duckstation.git
synced 2025-07-13 21:50:09 +00:00
GameDatabase: Use string_view for disc sets
Avoid the allocations, apparently forgot this one.
This commit is contained in:
parent
0a267ce158
commit
fb7772871c
@ -429,7 +429,7 @@ void Cheats::EnumerateChtFiles(const std::string_view serial, std::optional<Game
|
||||
const GameDatabase::Entry* gentry = GameDatabase::GetEntryForSerial(serial);
|
||||
if (gentry && gentry->disc_set_serials.size() > 1)
|
||||
{
|
||||
for (const std::string& set_serial : gentry->disc_set_serials)
|
||||
for (const std::string_view& set_serial : gentry->disc_set_serials)
|
||||
{
|
||||
if (set_serial == serial)
|
||||
continue;
|
||||
|
@ -974,7 +974,7 @@ std::string GameDatabase::Entry::GenerateCompatibilityReport() const
|
||||
if (!disc_set_name.empty())
|
||||
{
|
||||
ret.append_format("**{}:** {}\n", TRANSLATE_SV("GameDatabase", "Disc Set"), disc_set_name);
|
||||
for (const std::string& ds_serial : disc_set_serials)
|
||||
for (const std::string_view& ds_serial : disc_set_serials)
|
||||
ret.append_format(" - {}\n", ds_serial);
|
||||
}
|
||||
|
||||
@ -1172,7 +1172,7 @@ bool GameDatabase::SaveToCache()
|
||||
|
||||
writer.WriteSizePrefixedString(entry.disc_set_name);
|
||||
writer.WriteU32(static_cast<u32>(entry.disc_set_serials.size()));
|
||||
for (const std::string& serial : entry.disc_set_serials)
|
||||
for (const std::string_view& serial : entry.disc_set_serials)
|
||||
writer.WriteSizePrefixedString(serial);
|
||||
}
|
||||
|
||||
|
@ -133,8 +133,8 @@ struct Entry
|
||||
std::optional<float> gpu_pgxp_depth_threshold;
|
||||
std::optional<bool> gpu_pgxp_preserve_proj_fp;
|
||||
|
||||
std::string disc_set_name;
|
||||
std::vector<std::string> disc_set_serials;
|
||||
std::string_view disc_set_name;
|
||||
std::vector<std::string_view> disc_set_serials;
|
||||
|
||||
ALWAYS_INLINE bool HasTrait(Trait trait) const { return traits[static_cast<int>(trait)]; }
|
||||
ALWAYS_INLINE bool HasLanguage(Language language) const { return languages.test(static_cast<size_t>(language)); }
|
||||
|
@ -1129,7 +1129,7 @@ void GameList::CreateDiscSetEntries(const std::vector<std::string>& excluded_pat
|
||||
|
||||
// figure out play time for all discs, and sum it
|
||||
// we do this via lookups, rather than the other entries, because of duplicates
|
||||
for (const std::string& set_serial : dbentry->disc_set_serials)
|
||||
for (const std::string_view& set_serial : dbentry->disc_set_serials)
|
||||
{
|
||||
const auto it = played_time_map.find(set_serial);
|
||||
if (it == played_time_map.end())
|
||||
@ -1612,13 +1612,13 @@ TinyString GameList::FormatTimespan(std::time_t timespan, bool long_format)
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, const GameList::Entry*>>
|
||||
GameList::GetMatchingEntriesForSerial(const std::span<const std::string> serials)
|
||||
std::vector<std::pair<std::string_view, const GameList::Entry*>>
|
||||
GameList::GetMatchingEntriesForSerial(const std::span<const std::string_view> serials)
|
||||
{
|
||||
std::vector<std::pair<std::string, const GameList::Entry*>> ret;
|
||||
std::vector<std::pair<std::string_view, const GameList::Entry*>> ret;
|
||||
ret.reserve(serials.size());
|
||||
|
||||
for (const std::string& serial : serials)
|
||||
for (const std::string_view& serial : serials)
|
||||
{
|
||||
const Entry* matching_entry = nullptr;
|
||||
bool has_multiple_entries = false;
|
||||
|
@ -136,8 +136,8 @@ std::string GetNewCoverImagePathForEntry(const Entry* entry, const char* new_fil
|
||||
|
||||
/// Returns a list of (title, entry) for entries matching serials. Titles will match the gamedb title,
|
||||
/// except when two files have the same serial, in which case the filename will be used instead.
|
||||
std::vector<std::pair<std::string, const Entry*>>
|
||||
GetMatchingEntriesForSerial(const std::span<const std::string> serials);
|
||||
std::vector<std::pair<std::string_view, const Entry*>>
|
||||
GetMatchingEntriesForSerial(const std::span<const std::string_view> serials);
|
||||
|
||||
/// Downloads covers using the specified URL templates. By default, covers are saved by title, but this can be changed
|
||||
/// with the use_serial parameter. save_callback optionall takes the entry and the path the new cover is saved to.
|
||||
|
@ -2037,7 +2037,7 @@ void System::ClearRunningGame()
|
||||
s_state.running_game_hash = 0;
|
||||
|
||||
Host::OnSystemGameChanged(s_state.running_game_path, s_state.running_game_serial, s_state.running_game_title,
|
||||
s_state.running_game_hash);
|
||||
s_state.running_game_hash);
|
||||
|
||||
UpdateRichPresence(true);
|
||||
}
|
||||
@ -4225,7 +4225,7 @@ void System::UpdateRunningGame(const std::string& path, CDImage* image, bool boo
|
||||
s_state.running_game_hash);
|
||||
|
||||
Host::OnSystemGameChanged(s_state.running_game_path, s_state.running_game_serial, s_state.running_game_title,
|
||||
s_state.running_game_hash);
|
||||
s_state.running_game_hash);
|
||||
}
|
||||
|
||||
bool System::CheckForRequiredSubQ(Error* error)
|
||||
@ -6164,20 +6164,25 @@ void System::UpdateRichPresence(bool update_session_time)
|
||||
rp.largeImageKey = "duckstation_logo";
|
||||
rp.largeImageText = "DuckStation PS1/PSX Emulator";
|
||||
rp.startTimestamp = s_state.discord_presence_time_epoch;
|
||||
rp.details = "No Game Running";
|
||||
|
||||
TinyString game_details = "No Game Running";
|
||||
if (IsValidOrInitializing())
|
||||
{
|
||||
// Use disc set name if it's not a custom title.
|
||||
if (s_state.running_game_entry && !s_state.running_game_entry->disc_set_name.empty() &&
|
||||
s_state.running_game_title == s_state.running_game_entry->title)
|
||||
{
|
||||
rp.details = s_state.running_game_entry->disc_set_name.c_str();
|
||||
game_details = s_state.running_game_entry->disc_set_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
rp.details = s_state.running_game_title.empty() ? "Unknown Game" : s_state.running_game_title.c_str();
|
||||
if (s_state.running_game_title.empty())
|
||||
game_details = "Unknown Game";
|
||||
else
|
||||
game_details = std::string_view(s_state.running_game_title);
|
||||
}
|
||||
}
|
||||
rp.details = game_details.c_str();
|
||||
|
||||
const auto lock = Achievements::GetLock();
|
||||
|
||||
|
@ -1258,7 +1258,7 @@ void MainWindow::onChangeDiscMenuAboutToShow()
|
||||
auto lock = GameList::GetLock();
|
||||
for (const auto& [title, glentry] : GameList::GetMatchingEntriesForSerial(entry->disc_set_serials))
|
||||
{
|
||||
QAction* action = m_ui.menuChangeDisc->addAction(QString::fromStdString(title));
|
||||
QAction* action = m_ui.menuChangeDisc->addAction(QtUtils::StringViewToQString(title));
|
||||
QString path = QString::fromStdString(glentry->path);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(path == s_current_game_path);
|
||||
|
Loading…
x
Reference in New Issue
Block a user