Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GameInfoCache: Keep properly track of what's already loaded, lots of cleanup #18775

Merged
merged 4 commits into from
Jan 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
GameInfoCache: Break out a couple functions
  • Loading branch information
hrydgard committed Jan 28, 2024
commit 9b3c14a93103ce883b7dea991719b7a013e85171
62 changes: 33 additions & 29 deletions UI/GameInfoCache.cpp
Original file line number Diff line number Diff line change
@@ -338,6 +338,38 @@ void GameInfo::SetTitle(const std::string &newTitle) {
title = newTitle;
}

void GameInfo::FinishPendingTextureLoads(Draw::DrawContext *draw) {
if (draw && icon.dataLoaded && !icon.texture) {
SetupTexture(draw, icon);
}
if (draw && pic0.dataLoaded && !pic0.texture) {
SetupTexture(draw, pic0);
}
if (draw && pic1.dataLoaded && !pic1.texture) {
SetupTexture(draw, pic1);
}
}

void GameInfo::SetupTexture(Draw::DrawContext *thin3d, GameInfoTex &tex) {
using namespace Draw;
if (tex.data.size()) {
if (!tex.texture) {
// TODO: Use TempImage to semi-load the image in the worker task, then here we
// could just call CreateTextureFromTempImage.
tex.texture = CreateTextureFromFileData(thin3d, (const uint8_t *)tex.data.data(), (int)tex.data.size(), ImageFileType::DETECT, false, GetTitle().c_str());
if (tex.texture) {
tex.timeLoaded = time_now_d();
} else {
ERROR_LOG(G3D, "Failed creating texture (%s) from %d-byte file", GetTitle().c_str(), (int)tex.data.size());
}
}
if ((wantFlags & GAMEINFO_WANTBGDATA) == 0) {
tex.data.clear();
tex.dataLoaded = false;
}
}
}

static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string *contents, std::mutex *mtx) {
PSPFileInfo info = fs->GetFileInfo(filename);
if (!info.exists) {
@@ -822,15 +854,7 @@ std::shared_ptr<GameInfo> GameInfoCache::GetInfo(Draw::DrawContext *draw, const

// If wantFlags don't match, we need to start over. We'll just queue the work item again.
if (info && (info->wantFlags & wantFlags) == wantFlags) {
if (draw && info->icon.dataLoaded && !info->icon.texture) {
SetupTexture(info, draw, info->icon);
}
if (draw && info->pic0.dataLoaded && !info->pic0.texture) {
SetupTexture(info, draw, info->pic0);
}
if (draw && info->pic1.dataLoaded && !info->pic1.texture) {
SetupTexture(info, draw, info->pic1);
}
info->FinishPendingTextureLoads(draw);
info->lastAccessedTime = time_now_d();
return info;
}
@@ -860,23 +884,3 @@ std::shared_ptr<GameInfo> GameInfoCache::GetInfo(Draw::DrawContext *draw, const
info_[pathStr] = info;
return info;
}

void GameInfoCache::SetupTexture(std::shared_ptr<GameInfo> &info, Draw::DrawContext *thin3d, GameInfoTex &tex) {
using namespace Draw;
if (tex.data.size()) {
if (!tex.texture) {
// TODO: Use TempImage to semi-load the image in the worker task, then here we
// could just call CreateTextureFromTempImage.
tex.texture = CreateTextureFromFileData(thin3d, (const uint8_t *)tex.data.data(), (int)tex.data.size(), ImageFileType::DETECT, false, info->GetTitle().c_str());
if (tex.texture) {
tex.timeLoaded = time_now_d();
} else {
ERROR_LOG(G3D, "Failed creating texture (%s) from %d-byte file", info->GetTitle().c_str(), (int)tex.data.size());
}
}
if ((info->wantFlags & GAMEINFO_WANTBGDATA) == 0) {
tex.data.clear();
tex.dataLoaded = false;
}
}
}
4 changes: 3 additions & 1 deletion UI/GameInfoCache.h
Original file line number Diff line number Diff line change
@@ -95,6 +95,7 @@ class GameInfo {
u64 GetInstallDataSizeInBytes();

void ParseParamSFO();
void FinishPendingTextureLoads(Draw::DrawContext *draw);

std::vector<Path> GetSaveDataDirectories();

@@ -158,6 +159,8 @@ class GameInfo {
std::shared_ptr<FileLoader> fileLoader;
Path filePath_;

void SetupTexture(Draw::DrawContext *draw, GameInfoTex &tex);

private:
DISALLOW_COPY_AND_ASSIGN(GameInfo);
};
@@ -184,7 +187,6 @@ class GameInfoCache {
private:
void Init();
void Shutdown();
void SetupTexture(std::shared_ptr<GameInfo> &info, Draw::DrawContext *draw, GameInfoTex &tex);

// Maps ISO path to info. Need to use shared_ptr as we can return these pointers -
// and if they get destructed while being in use, that's bad.