Skip to content

Commit 76242cb

Browse files
committed
More gameinfocache fixes
1 parent d7e5928 commit 76242cb

File tree

3 files changed

+47
-34
lines changed

3 files changed

+47
-34
lines changed

UI/GameInfoCache.cpp

+39-31
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void GameInfoTex::Clear() {
5454
}
5555
}
5656

57-
GameInfo::GameInfo() {
57+
GameInfo::GameInfo(const Path &gamePath) : filePath_(gamePath) {
5858
// here due to a forward decl.
5959
fileType = IdentifiedFileType::UNKNOWN;
6060
}
@@ -231,26 +231,13 @@ u64 GameInfo::GetInstallDataSizeInBytes() {
231231
return totalSize;
232232
}
233233

234-
bool GameInfo::LoadFromPath(const Path &gamePath) {
235-
{
236-
std::lock_guard<std::mutex> guard(lock);
237-
// No need to rebuild if we already have it loaded.
238-
if (filePath_ == gamePath) {
239-
return true;
240-
}
241-
}
242-
243-
{
234+
bool GameInfo::CreateLoader() {
235+
if (!fileLoader) {
244236
std::lock_guard<std::mutex> guard(loaderLock);
245-
fileLoader.reset(ConstructFileLoader(gamePath));
237+
fileLoader.reset(ConstructFileLoader(filePath_));
246238
if (!fileLoader)
247239
return false;
248240
}
249-
250-
std::lock_guard<std::mutex> guard(lock);
251-
filePath_ = gamePath;
252-
// This is a fallback title, while we're loading / if unable to load.
253-
title = filePath_.GetFilename();
254241
return true;
255242
}
256243

@@ -463,7 +450,7 @@ class GameInfoWorkItem : public Task {
463450
void Run() override {
464451
// An early-return will result in the destructor running, where we can set
465452
// flags like working and pending.
466-
if (!info_->LoadFromPath(gamePath_)) {
453+
if (!info_->CreateLoader()) {
467454
return;
468455
}
469456

@@ -515,6 +502,7 @@ class GameInfoWorkItem : public Task {
515502
info_->id_version = info_->id + "_1.00";
516503
info_->region = GAMEREGION_MAX + 1; // Homebrew
517504
}
505+
info_->MarkReadyNoLock(GameInfoFlags::PARAM_SFO);
518506
}
519507
}
520508

@@ -606,6 +594,7 @@ class GameInfoWorkItem : public Task {
606594
std::lock_guard<std::mutex> lock(info_->lock);
607595
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
608596
info_->ParseParamSFO();
597+
info_->MarkReadyNoLock(GameInfoFlags::PARAM_SFO);
609598
}
610599
}
611600
if (flags_ & GameInfoFlags::ICON) {
@@ -623,6 +612,8 @@ class GameInfoWorkItem : public Task {
623612
{
624613
if (flags_ & GameInfoFlags::PARAM_SFO) {
625614
info_->SetTitle(SaveState::GetTitle(gamePath_));
615+
std::lock_guard<std::mutex> lock(info_->lock);
616+
info_->MarkReadyNoLock(GameInfoFlags::PARAM_SFO);
626617
}
627618

628619
// Let's use the screenshot as an icon, too.
@@ -664,8 +655,10 @@ class GameInfoWorkItem : public Task {
664655
}
665656
}
666657

667-
ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->icon.data, &info_->lock);
668-
info_->icon.dataLoaded = true;
658+
if (flags_ & GameInfoFlags::ICON) {
659+
ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->icon.data, &info_->lock);
660+
info_->icon.dataLoaded = true;
661+
}
669662
if (flags_ & GameInfoFlags::BG) {
670663
ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0.data, &info_->lock);
671664
info_->pic0.dataLoaded = true;
@@ -704,6 +697,9 @@ class GameInfoWorkItem : public Task {
704697
std::lock_guard<std::mutex> lock(info_->lock);
705698
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
706699
info_->ParseParamSFO();
700+
701+
// quick-update the info while we have the lock, so we don't need to wait for the image load to display the title.
702+
info_->MarkReadyNoLock(GameInfoFlags::PARAM_SFO);
707703
}
708704
}
709705
}
@@ -781,8 +777,7 @@ class GameInfoWorkItem : public Task {
781777

782778
// Time to update the flags.
783779
std::unique_lock<std::mutex> lock(info_->lock);
784-
info_->hasFlags |= flags_;
785-
info_->pendingFlags &= ~flags_;
780+
info_->MarkReadyNoLock(flags_);
786781
// INFO_LOG(SYSTEM, "Completed writing info for %s", info_->GetTitle().c_str());
787782
}
788783

@@ -846,26 +841,39 @@ void GameInfoCache::FlushBGs() {
846841

847842
void GameInfoCache::PurgeType(IdentifiedFileType fileType) {
848843
bool retry = false;
844+
int retryCount = 10;
849845
// Trickery to avoid sleeping with the lock held.
850846
do {
847+
if (retry) {
848+
retryCount--;
849+
if (retryCount == 0) {
850+
break;
851+
}
852+
}
853+
retry = false;
851854
{
852855
std::lock_guard<std::mutex> lock(mapLock_);
853856
for (auto iter = info_.begin(); iter != info_.end();) {
854857
auto &info = iter->second;
855-
858+
if (!(info->hasFlags & GameInfoFlags::FILE_TYPE)) {
859+
iter++;
860+
continue;
861+
}
862+
if (info->fileType != fileType) {
863+
iter++;
864+
continue;
865+
}
856866
// TODO: Find a better way to wait here.
857-
while (info->pendingFlags != (GameInfoFlags)0) {
867+
if (info->pendingFlags != (GameInfoFlags)0) {
868+
INFO_LOG(LOADER, "%s: pending flags %08x, retrying", info->GetTitle().c_str(), info->pendingFlags);
858869
retry = true;
859870
break;
860871
}
861-
if (info->fileType == fileType) {
862-
iter = info_.erase(iter);
863-
} else {
864-
iter++;
865-
}
872+
iter = info_.erase(iter);
866873
}
867874
}
868-
sleep_ms(1);
875+
876+
sleep_ms(10);
869877
} while (retry);
870878
}
871879

@@ -903,7 +911,7 @@ std::shared_ptr<GameInfo> GameInfoCache::GetInfo(Draw::DrawContext *draw, const
903911
return info;
904912
}
905913

906-
std::shared_ptr<GameInfo> info = std::make_shared<GameInfo>();
914+
std::shared_ptr<GameInfo> info = std::make_shared<GameInfo>(gamePath);
907915
info->pendingFlags = wantFlags;
908916
info->lastAccessedTime = time_now_d();
909917
info_.insert(std::make_pair(pathStr, info));

UI/GameInfoCache.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ struct GameInfoTex {
8282

8383
class GameInfo {
8484
public:
85-
GameInfo();
85+
GameInfo(const Path &gamePath);
8686
~GameInfo();
8787

8888
bool Delete(); // Better be sure what you're doing when calling this.
8989
bool DeleteAllSaveData();
90-
bool LoadFromPath(const Path &gamePath);
90+
bool CreateLoader();
9191

9292
bool HasFileLoader() const {
9393
return fileLoader.get() != nullptr;
@@ -114,6 +114,11 @@ class GameInfo {
114114
return (hasFlags & flags) != 0;
115115
}
116116

117+
void MarkReadyNoLock(GameInfoFlags flags) {
118+
hasFlags |= flags;
119+
pendingFlags &= ~flags;
120+
}
121+
117122
GameInfoTex *GetBGPic() {
118123
if (pic1.texture)
119124
return &pic1;

UI/SavedataScreen.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void SavedataButton::Draw(UIContext &dc) {
300300
u32 color = 0, shadowColor = 0;
301301
using namespace UI;
302302

303-
if (ginfo->icon.texture) {
303+
if (ginfo->Ready(GameInfoFlags::ICON) && ginfo->icon.texture) {
304304
texture = ginfo->icon.texture;
305305
}
306306

0 commit comments

Comments
 (0)