Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Lists stay whole across a language change; progress bar while they refresh

Rafael Abud Ferreiradf57285df5e5
diff --git a/src/app/cli_main.cpp b/src/app/cli_main.cpp
index e78d53a..fc044a0 100644
--- a/src/app/cli_main.cpp
+++ b/src/app/cli_main.cpp
@@ -307,6 +307,8 @@ int cmdUiPreview(auth::AuthManager& am, const std::string& dir) {
app.setRows(library.rows());
app.setOwned(library.owned(), library.purchasable(), library.ownedKnown());
app.setSearchPools(library.gamePassSearchPool(), library.librarySearchPool());
+ auto p = library.progress();
+ app.setLoading(p.active, p.done, p.total);
};
if (!library.load(gssv, ui::catalogLanguage(), onRows, err)) {
XC_LOGE("%s", err.c_str());
diff --git a/src/app/library.cpp b/src/app/library.cpp
index df97564..b4bfb8a 100644
--- a/src/app/library.cpp
+++ b/src/app/library.cpp
@@ -188,10 +188,14 @@ bool Library::loadCache() {
if (cachePath_.empty() || !platform::readFile(cachePath_, text)) return false;
auto j = json::parse(text);
if (!j || (*j)["version"].asInt() != kCacheVersion || (*j)["market"].str() != market_) return false;
- // Names and descriptions are in the cache's language: only reused in it.
- if ((*j)["language"].str() == language_)
- for (const auto& [id, v] : (*j)["products"].members())
- if (!products_.count(id)) products_[id] = productFromJson(id, v);
+ // Names and descriptions in another language (the language changed):
+ // still shown, so the lists stay whole, and fetched again in this one.
+ bool sameLanguage = (*j)["language"].str() == language_;
+ for (const auto& [id, v] : (*j)["products"].members())
+ if (!products_.count(id)) {
+ products_[id] = productFromJson(id, v);
+ if (!sameLanguage) otherLanguage_.insert(id);
+ }
for (const auto& [id, code] : (*j)["platforms"].members()) platform_[id] = code.str();
for (const auto& [pid, xbox] : (*j)["xboxTitles"].members()) xboxTitleOf_[pid] = xbox.str();
for (const auto& id : (*j)["freeInStore"].items()) freeInStore_.insert(id.str());
@@ -263,6 +267,8 @@ bool Library::load(xcloud::GssvClient& gssv, const std::string& language, const
purchasable_.clear();
purchasableSet_.clear();
freeInStore_.clear();
+ otherLanguage_.clear();
+ progress_ = {};
xboxTitleOf_.clear();
platform_.clear();
std::string lastErr;
@@ -360,6 +366,8 @@ bool Library::load(xcloud::GssvClient& gssv, const std::string& language, const
}
void Library::loadOwned(xcloud::GssvClient gssv, const Changed& changed, const std::atomic<bool>* stop) {
+ progress_ = {true, 0, 0}; // the account's list: no measure until the names
+ changed();
std::vector<xcloud::Title> titles;
std::string err;
if (!gssv.listTitles(titles, err, false)) {
@@ -413,24 +421,45 @@ void Library::loadOwned(xcloud::GssvClient gssv, const Changed& changed, const s
}
void Library::loadCatalogNames(const Changed& changed, const std::atomic<bool>* stop) {
- // The Game Pass catalog (for its search), then the games to buy.
+ // Names and art: the account's games and the games to buy first (their
+ // lists are on screen), then the Game Pass catalog for its search. Also
+ // anything still in another language.
std::vector<std::string> missing;
- for (const auto& id : allGames_)
- if (!products_.count(id)) missing.push_back(id);
- for (const auto& [id, tid] : purchasable_)
- if (!products_.count(id)) missing.push_back(id);
+ std::set<std::string> queued;
+ auto want = [&](const std::string& id) {
+ if ((!products_.count(id) || otherLanguage_.count(id)) && queued.insert(id).second) missing.push_back(id);
+ };
+ for (const auto* list : {&owned_, &purchasable_})
+ for (const auto& item : *list) want(item.first);
+ for (const auto& id : allGames_) want(id);
+ progress_ = {true, 0, missing.size()};
+ changed();
constexpr size_t kBatch = 100;
for (size_t i = 0; i < missing.size(); i += kBatch) {
- if (stop && *stop) return;
+ if (stop && *stop) break;
std::vector<std::string> batch(missing.begin() + static_cast<long>(i),
missing.begin() + static_cast<long>(std::min(missing.size(), i + kBatch)));
+ std::map<std::string, xcloud::Product> fetched;
std::string e;
- if (!xcloud::fetchProducts(batch, market_, language_, products_, e, false)) {
+ if (!xcloud::fetchProducts(batch, market_, language_, fetched, e, false)) {
XC_LOGW("%s", e.c_str());
- return;
+ break;
+ }
+ for (auto& [id, p] : fetched) {
+ // Keep the hero art and description already known, until they
+ // come in the new language (hydrate()).
+ auto old = products_.find(id);
+ if (old != products_.end()) {
+ if (p.heroUrl.empty()) p.heroUrl = old->second.heroUrl;
+ if (p.description.empty() && !otherLanguage_.count(id)) p.description = old->second.description;
+ }
+ products_[id] = std::move(p);
+ otherLanguage_.erase(id);
}
- if (i == 0 || i + kBatch >= missing.size()) changed();
+ progress_.done = std::min(missing.size(), i + kBatch);
+ changed(); // each batch: the lists fill in as names arrive
}
+ progress_ = {};
saveCache();
XC_LOGI("library: search covers %zu Game Pass games and %zu of yours or to buy", gamePassSearchPool().size(),
librarySearchPool().size());
diff --git a/src/app/library.h b/src/app/library.h
index 1bc3736..817305f 100644
--- a/src/app/library.h
+++ b/src/app/library.h
@@ -67,6 +67,13 @@ public:
std::vector<ui::GameTile> librarySearchPool() const;
// True once the account's games are known (from the cache or the service).
bool ownedKnown() const { return ownershipKnown_; }
+ // The background refresh of the lists: whether it runs, and (while
+ // names come in) how far it is; total 0 = no measure yet.
+ struct Progress {
+ bool active = false;
+ size_t done = 0, total = 0;
+ };
+ Progress progress() const { return progress_; }
private:
using Item = std::pair<std::string, std::string>; // productId, titleId
@@ -102,6 +109,9 @@ private:
std::vector<Item> purchasable_; // streamable once bought
std::set<std::string> purchasableSet_;
std::set<std::string> freeInStore_; // product ids free in the store
+ // Details from a cache in another language: shown until replaced.
+ std::set<std::string> otherLanguage_;
+ Progress progress_;
std::map<std::string, std::string> xboxTitleOf_; // productId -> Xbox title id
std::map<std::string, std::string> platform_; // Xbox title id -> platform code
// Xbox title ids that have a "... - Xbox Series X|S" product, rebuilt
diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cpp
index 257244a..4ae78b4 100644
--- a/src/app/ps5_main.cpp
+++ b/src/app/ps5_main.cpp
@@ -85,6 +85,7 @@ bool g_autoplayDump = false;
int g_autoplayRuns = 1;
bool g_autoplayIdle = false;
bool g_autoplayDetailTest = false; // open a game to buy far down the list, save its page
+bool g_autoplayLibraryTest = false; // open "Your games", save it at 4 s and 25 s
int g_decodeThreads = 1;
std::atomic<bool> g_syntheticA{false};
@@ -107,6 +108,7 @@ void loadAutoplay() {
if (opt == "idle") g_autoplayIdle = true;
if (opt == "rumbletest") input::setRumble(200, 200, 1500);
if (opt == "detailtest") g_autoplayDetailTest = true;
+ if (opt == "librarytest") g_autoplayLibraryTest = true;
if (opt.rfind("threads=", 0) == 0) g_decodeThreads = std::atoi(opt.c_str() + 8);
}
g_autoplayTitle = title;
@@ -456,6 +458,8 @@ void loadLibrary(xcloud::GssvClient& gssv) {
g_ui->setRows(lib.rows());
g_ui->setOwned(lib.owned(), lib.purchasable(), lib.ownedKnown());
g_ui->setSearchPools(lib.gamePassSearchPool(), lib.librarySearchPool());
+ auto p = lib.progress();
+ g_ui->setLoading(p.active, p.done, p.total);
};
bool ok = library->load(gssv, ui::catalogLanguage(),
[&] {
@@ -488,7 +492,7 @@ void loadLibrary(xcloud::GssvClient& gssv) {
library->loadPlatforms(xblAuth, changed, &g_stopHydration);
library->hydrate(changed, &g_stopHydration);
});
- if (!g_autoplayTitle.empty() && g_autoplayTitle != "BENCH" && !g_autoplayDetailTest) {
+ if (!g_autoplayTitle.empty() && g_autoplayTitle != "BENCH" && !g_autoplayDetailTest && !g_autoplayLibraryTest) {
platform::sleepMs(6000); // leave the home screen up for ui.ppm
ui::GameTile tile;
tile.titleId = g_autoplayTitle;
@@ -768,6 +772,23 @@ int main(int argc, char** argv) {
saveCanvas("launch.ppm");
}
}
+ if (g_autoplayLibraryTest && uiSaved) {
+ static uint64_t openedAt = 0;
+ static int saved = 0;
+ if (!openedAt) {
+ ui::NavInput r1;
+ r1.r1 = true;
+ g_ui->handle(r1);
+ openedAt = now;
+ } else if (saved == 0 && now - openedAt > 4000) {
+ saveCanvas("library.ppm");
+ saved = 1;
+ } else if (saved == 1 && now - openedAt > 25000) {
+ saveCanvas("library2.ppm");
+ g_autoplayLibraryTest = false;
+ XC_LOGI("AUTOPLAY END: library test");
+ }
+ }
if (g_autoplayDetailTest && uiSaved) {
// A game to buy far down the list (no prefetched details): its
// page must fill in on its own.
diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cpp
index 1397d95..304a789 100644
--- a/src/ui/app_ui.cpp
+++ b/src/ui/app_ui.cpp
@@ -328,6 +328,36 @@ void AppUi::rebuild(bool keepPosition) {
dirty_ = true;
}
+void AppUi::setLoading(bool active, size_t done, size_t total) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (active == loading_ && done == loadingDone_ && total == loadingTotal_) return;
+ loading_ = active;
+ loadingDone_ = done;
+ loadingTotal_ = total;
+ dirty_ = true;
+}
+
+void AppUi::drawLoadingBar(Canvas& c, int x, int y, int w, uint64_t nowMs) {
+ // "Updating the game list..." over a thin bar: the share done, or a
+ // sliding segment while there's no measure yet.
+ if (!loading_) return;
+ std::string text = tr(Str::UpdatingList);
+ if (loadingTotal_) text += " " + std::to_string(loadingDone_ * 100 / loadingTotal_) + "%";
+ fonts_.semibold.draw(c, text, x, y, 20, kGray);
+ Rect track{x, y + 32, w, 6};
+ c.fillRect(track, rgba(255, 255, 255, 40), 3);
+ if (loadingTotal_) {
+ int fill = static_cast<int>(static_cast<double>(w) * loadingDone_ / loadingTotal_);
+ if (fill > 0) c.fillRect({x, track.y, fill, track.h}, kGreen, 3);
+ } else {
+ int seg = w / 4;
+ int pos = static_cast<int>((nowMs % 1400) * static_cast<uint64_t>(w + seg) / 1400) - seg;
+ int a = std::max(x, x + pos), b = std::min(x + w, x + pos + seg);
+ if (b > a) c.fillRect({a, track.y, b - a, track.h}, kGreen, 3);
+ }
+ animating_ = true;
+}
+
void AppUi::setPrefs(const std::vector<std::string>& hidden, LibrarySort sort) {
std::lock_guard<std::mutex> lock(mutex_);
hidden_ = std::set<std::string>(hidden.begin(), hidden.end());
@@ -1371,6 +1401,7 @@ void AppUi::drawLibrary(Canvas& c, uint64_t nowMs) {
}
}
{
+ drawLoadingBar(c, left, 112, 420, nowMs);
// The order (the whole tab's), right-aligned under the tabs, with its button.
Str sortName = librarySort_ == LibrarySort::AZ ? Str::SortAZ
: librarySort_ == LibrarySort::Console ? Str::SortConsole
@@ -1413,6 +1444,7 @@ void AppUi::drawSearch(Canvas& c, uint64_t nowMs) {
} else {
fonts_.semibold.draw(c, trf(Str::ResultsCount, std::to_string(results_.size())), kResultsX, 150, 26, kGray);
}
+ drawLoadingBar(c, kResultsX + 420, 150, 420, nowMs);
// The query.
const int kbW = kKeyCols * (kKeyW + kKeyGap) - kKeyGap;
diff --git a/src/ui/app_ui.h b/src/ui/app_ui.h
index bb9d853..6a6bb79 100644
--- a/src/ui/app_ui.h
+++ b/src/ui/app_ui.h
@@ -105,6 +105,9 @@ public:
// "Your games": the account's games, then those to buy; `known` false
// while the account's games load.
void setOwned(std::vector<GameTile> owned, std::vector<GameTile> purchasable, bool known);
+ // The lists' background refresh: shown as a bar in "Your games" and the
+ // search; `total` 0 = running, no measure yet.
+ void setLoading(bool active, size_t done, size_t total);
// What each tab's search looks through.
void setSearchPools(std::vector<GameTile> gamePass, std::vector<GameTile> library);
// Measured round trip to each region, ms (shown in Settings).
@@ -232,6 +235,9 @@ private:
std::vector<GameRow> allRows_;
std::vector<GameTile> allOwned_, allPurchasable_;
std::set<std::string> hidden_;
+ bool loading_ = false;
+ size_t loadingDone_ = 0, loadingTotal_ = 0;
+ void drawLoadingBar(Canvas& c, int x, int y, int w, uint64_t nowMs);
LibrarySort librarySort_ = LibrarySort::Recent;
// Search filters (the row of buttons under the keys).
bool filterFree_ = false, filterCheapest_ = false, filterSale_ = false;
diff --git a/src/ui/strings.cpp b/src/ui/strings.cpp
index 3e7405e..29d7294 100644
--- a/src/ui/strings.cpp
+++ b/src/ui/strings.cpp
@@ -113,6 +113,7 @@ constexpr Column kEnglish = {
"All consoles", // FilterAllConsoles
"1 game", // OneGame
"Sections", // Sections
+ "Updating the game list...", // UpdatingList
};
constexpr Column kPortugueseBR = {
@@ -196,6 +197,7 @@ constexpr Column kPortugueseBR = {
"Todos os consoles",
"1 jogo",
"Seções",
+ "Atualizando a lista de jogos...",
};
constexpr Column kSpanish = {
@@ -279,6 +281,7 @@ constexpr Column kSpanish = {
"Todas las consolas",
"1 juego",
"Secciones",
+ "Actualizando la lista de juegos...",
};
constexpr Column kFrench = {
@@ -362,6 +365,7 @@ constexpr Column kFrench = {
"Toutes les consoles",
"1 jeu",
"Sections",
+ "Mise \xC3\xA0 jour de la liste des jeux...",
};
constexpr Column kGerman = {
@@ -445,6 +449,7 @@ constexpr Column kGerman = {
"Alle Konsolen",
"1 Spiel",
"Abschnitte",
+ "Spieleliste wird aktualisiert...",
};
constexpr Column kItalian = {
@@ -528,6 +533,7 @@ constexpr Column kItalian = {
"Tutte le console",
"1 gioco",
"Sezioni",
+ "Aggiornamento dell'elenco dei giochi...",
};
constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,
diff --git a/src/ui/strings.h b/src/ui/strings.h
index cef509b..b907833 100644
--- a/src/ui/strings.h
+++ b/src/ui/strings.h
@@ -90,6 +90,7 @@ enum class Str {
FilterAllConsoles,
OneGame, // GamesCount for exactly one
Sections, // hint for L2 / R2: jump between sections
+ UpdatingList, // the lists refresh in the background
Count
};
diff --git a/tools/ps5/autotest.sh b/tools/ps5/autotest.sh
index f15cf3f..d36002e 100755
--- a/tools/ps5/autotest.sh
+++ b/tools/ps5/autotest.sh
@@ -37,7 +37,7 @@ import io, sys
from ftplib import FTP, error_perm, error_reply
host, port, d, line = sys.argv[1], int(sys.argv[2]), sys.argv[3], sys.argv[4]
f = FTP(); f.connect(host, port, timeout=15); f.login(); f.cwd(d)
-for name in ("xcloud.log", "frame.ppm", "frame2.ppm", "stream.aus", "ui.ppm", "launch.ppm", "screen.ppm", "detail.ppm"):
+for name in ("xcloud.log", "frame.ppm", "frame2.ppm", "stream.aus", "ui.ppm", "launch.ppm", "screen.ppm", "detail.ppm", "library.ppm", "library2.ppm"):
try: f.sendcmd(f"DELE {name}")
except (error_perm, error_reply): pass
f.storbinary("STOR autoplay.txt", io.BytesIO(line.encode() + b"\n"))
@@ -82,7 +82,7 @@ PY
if [[ $status != *"$title_id"* ]]; then result=crashed; break; fi
fi
done
-fetch xcloud.log frame.ppm frame2.ppm stream.aus ui.ppm launch.ppm screen.ppm detail.ppm || true
+fetch xcloud.log frame.ppm frame2.ppm stream.aus ui.ppm launch.ppm screen.ppm detail.ppm library.ppm library2.ppm || true
ctl kill "$title_id" >/dev/null 2>&1 || true
# Remove the request so a manual launch behaves normally.
python3 - "$PS5_HOST" "${FTP_PORT:-2121}" "/data/homebrew/$title_id" <<'PY'