Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Search: On sale ordered by the discounted price, lowest first

Rafael Abud Ferreira897c7f95f5c4
diff --git a/ROADMAP.md b/ROADMAP.md
index 3a44eb3..c02aed0 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -124,6 +124,7 @@ is rolled back at the next start), then the app restarts itself
| Item | Why | Size |
| --- | --- | --- |
+| Per-game settings (next release) | A profile per game (picture, triggers, dead zones, controls) that overrides the general settings for that game only; games without one use the general ones | medium |
| Voice chat (microphone) | xCloud has a chat channel; needs PS5 audio capture | large |
| USB keyboard and mouse | Some xCloud games accept them | medium |
diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cpp
index c3e8133..35ee711 100644
--- a/src/app/autoplay.cpp
+++ b/src/app/autoplay.cpp
@@ -82,6 +82,7 @@ void loadAutoplay() {
if (opt == "menushot") g_autoplay.menuShot = true;
if (opt == "confirmtest") g_autoplay.confirmTest = true;
if (opt == "tunetest") g_autoplay.tuneTest = true;
+ if (opt == "searchtest") g_autoplay.searchTest = true;
if (opt == "norestart") g_autoplay.noRestart = true;
if (opt.rfind("threads=", 0) == 0) g_autoplay.decodeThreads = std::atoi(opt.c_str() + 8);
}
@@ -435,6 +436,27 @@ void autoplayScreens(const ui::Canvas& canvas, uint64_t now) {
saveCanvas("home.ppm");
XC_LOGI("AUTOPLAY END: confirm test, on the %s screen", g_ui->screen() == ui::Screen::Home ? "home" : "WRONG");
}
+ if (g_autoplay.searchTest && uiSaved) {
+ // "Your games" by lowest price, then on sale, once the prices are in
+ // (the background fetch): each saved, its first results logged.
+ static uint64_t since = 0;
+ static int step = 0;
+ if (!since) since = now;
+ auto logResults = [](const char* what) {
+ int i = 0;
+ for (const auto& [name, p] : g_ui->searchResults(12))
+ XC_LOGI("search %s %2d: %.2f (was %.2f) %s", what, ++i, p.list, p.msrp, name.c_str());
+ };
+ if (step == 0 && now - since > 20000) g_ui->showFilteredSearch(1), ++step;
+ else if (step == 1 && now - since > 24000) saveCanvas("cheapest.ppm"), logResults("lowest"), ++step;
+ else if (step == 2) g_ui->showFilteredSearch(2), ++step;
+ else if (step == 3 && now - since > 28000) {
+ saveCanvas("sale.ppm");
+ logResults("sale");
+ g_autoplay.searchTest = false;
+ XC_LOGI("AUTOPLAY END: search test");
+ }
+ }
if (pickerShot) {
saveCanvas(pickerShot);
if (std::string(pickerShot) == "settings.ppm") XC_LOGI("AUTOPLAY END: picker test");
diff --git a/src/app/autoplay.h b/src/app/autoplay.h
index 53ad25d..6042049 100644
--- a/src/app/autoplay.h
+++ b/src/app/autoplay.h
@@ -60,6 +60,7 @@ struct Autoplay {
bool updateTest = false; // updatetest: accept the update pop-up, save update.ppm / updating.ppm
bool updateSkip = false; // updateskip: "Not now" on the update pop-up
bool settingsUpdate = false; // settingsupdate: Settings > Updates, Cross
+ bool searchTest = false; // searchtest: "Your games" by lowest price, then on sale (cheapest.ppm, sale.ppm)
bool tuneTest = false; // tunetest: the dead zone's stick tester and the trigger tester (sticks.ppm, triggers.ppm)
bool confirmTest = false; // confirmtest: physical Cross / Circle presses through Settings > Confirm button
bool menuShot = false; // menushot: the game menu open over the 10 s snapshot (screen.ppm)
diff --git a/src/app/worker.cpp b/src/app/worker.cpp
index 9d40ed2..9b8013e 100644
--- a/src/app/worker.cpp
+++ b/src/app/worker.cpp
@@ -535,7 +535,7 @@ void loadLibrary(xcloud::GssvClient& gssv) {
});
if (!g_autoplay.title.empty() && g_autoplay.title != "BENCH" && g_autoplay.title != "UPDATE" && !g_autoplay.detailTest && !g_autoplay.libraryTest &&
!g_autoplay.consolesTab && !g_autoplay.settingsTest &&
- !g_autoplay.imeTest && !g_autoplay.vibeTest) {
+ !g_autoplay.imeTest && !g_autoplay.vibeTest && !g_autoplay.searchTest) {
platform::sleepMs(6000); // leave the home screen up for ui.ppm
ui::GameTile tile;
tile.titleId = g_autoplay.title;
diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cpp
index 20677e2..bb855cc 100644
--- a/src/ui/app_ui.cpp
+++ b/src/ui/app_ui.cpp
@@ -513,6 +513,28 @@ const GameTile* AppUi::libraryTile(int index) const {
return i < hiddenTiles_.size() ? &hiddenTiles_[i] : nullptr;
}
+void AppUi::showFilteredSearch(int filterIndex) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ screen_ = Screen::Home;
+ tab_ = Tab::Library;
+ searching_ = true;
+ query_.clear();
+ filterFree_ = filterCheapest_ = filterSale_ = false;
+ filterConsole_ = 0;
+ pressFilter(filterIndex);
+ dirty_ = true;
+}
+
+std::vector<std::pair<std::string, PriceInfo>> AppUi::searchResults(size_t max) const {
+ std::lock_guard<std::mutex> lock(mutex_);
+ std::vector<std::pair<std::string, PriceInfo>> out;
+ for (size_t i = 0; i < results_.size() && i < max; ++i) {
+ auto p = prices_.find(results_[i].productId);
+ out.push_back({results_[i].name, p == prices_.end() ? PriceInfo{} : p->second});
+ }
+ return out;
+}
+
void AppUi::showTab(Tab t) {
std::lock_guard<std::mutex> lock(mutex_);
tab_ = t;
@@ -573,7 +595,8 @@ void AppUi::runSearch() {
static const char* kConsoleCodes[] = {"", "XS", "ONE", "360"};
struct Hit {
int score;
- double order; // price or discount, by the active order filter
+ double order; // the price now (with any discount), by the active order filter
+ double discount; // On sale: the bigger first among equal prices
const GameTile* tile;
};
std::vector<Hit> hits;
@@ -607,14 +630,17 @@ void AppUi::runSearch() {
score = name.rfind(words[0], 0) == 0 ? 0 : name.find(" " + words[0]) != std::string::npos ? 1 : 2;
}
if (!t.playable) score += 3; // in "Your games": owned before games to buy
- double order = 0;
- if (filterCheapest_) order = priced ? price->second.list : 1e12; // unknown prices last
- if (filterSale_ && priced) order = -(1.0 - price->second.list / price->second.msrp); // biggest discount first
- hits.push_back({score, order, &t});
+ // Both price orders go by the price now, lowest first (on sale: the
+ // discounted price, not the regular one); unknown prices last.
+ double order = 0, discount = 0;
+ if (filterCheapest_ || filterSale_) order = priced ? price->second.list : 1e12;
+ if (filterSale_ && priced) discount = 1.0 - price->second.list / price->second.msrp;
+ hits.push_back({score, order, discount, &t});
}
bool byOrder = tab_ == Tab::Library && (filterCheapest_ || filterSale_);
std::stable_sort(hits.begin(), hits.end(), [&](const Hit& a, const Hit& b) {
if (byOrder && a.order != b.order) return a.order < b.order;
+ if (byOrder && a.discount != b.discount) return a.discount > b.discount;
if (a.score != b.score) return a.score < b.score;
return fold(a.tile->name) < fold(b.tile->name);
});
diff --git a/src/ui/app_ui.h b/src/ui/app_ui.h
index 47d6bb7..58547de 100644
--- a/src/ui/app_ui.h
+++ b/src/ui/app_ui.h
@@ -214,6 +214,10 @@ public:
Tab tab() const;
// Switches the home screen's tab (autoplay tests).
void showTab(Tab t);
+ // Autoplay tests: "Your games" searched with one filter button pressed
+ // (0 free, 1 lowest price, 2 on sale), and the first results with prices.
+ void showFilteredSearch(int filterIndex);
+ std::vector<std::pair<std::string, PriceInfo>> searchResults(size_t max) const;
void invalidate();
// --- UI thread -----------------------------------------------------------