Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

feat(hud): in-game performance HUD overlay with 60-frame frametime sparkline

Rafael Abud Ferreiraa8db0e0d2ba0
diff --git a/src/app/stream_screen.cpp b/src/app/stream_screen.cpp
index c41d378..b1e3ce5 100644
--- a/src/app/stream_screen.cpp
+++ b/src/app/stream_screen.cpp
@@ -137,6 +137,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
// Apply controller profile settings
triggerStrength_ = prof.triggerStrength;
+ triggerProfile_ = prof.triggerProfile;
deadzone_ = prof.deadzoneLeft;
circleConfirms_ = prof.circleConfirms;
keyMap_ = prof.keyMap;
@@ -145,7 +146,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
gyroLevel_ = prof.gyroLevel;
input::setGyro(gyroMode_, gyroLevel_);
input::setDeadzone(prof.deadzoneLeft / 100.0f, prof.deadzoneRight / 100.0f);
- input::setTriggerFeel(prof.triggerStrength, prof.triggerHz, prof.triggerResistance, prof.triggerPulses);
+ input::setTriggerFeel(prof.triggerStrength, prof.triggerHz, prof.triggerResistance, prof.triggerPulses, triggerProfile_);
input::setCircleConfirms(prof.circleConfirms);
if (g_ui) g_ui->setCircleConfirms(prof.circleConfirms);
// 120 Hz (VRR) for this game's stream: active when enabled in profile,
@@ -162,6 +163,21 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
}
if (g_player) {
updateTextInput(g_player);
+ // L3 + R3 simultaneous press toggles HUD statistics overlay
+ bool l3r3 = pad.btnL3 && pad.btnR3;
+ if (l3r3 && !prevL3R3_ && !menu_.isOpen()) {
+ showStats_ = !showStats_;
+ {
+ std::lock_guard<std::mutex> settingsLock(g_settingsMutex);
+ g_settings.streamStats = showStats_;
+ g_settings.save(settingsPath());
+ }
+ overlaySeq_ = 0;
+ platform::notify(showStats_ ? "Telemetria ativada" : "Telemetria desativada",
+ showStats_ ? "stats on" : "stats off");
+ }
+ prevL3R3_ = l3r3;
+
// OPTIONS + TOUCHPAD opens the menu (and closes it again).
bool wasOpen = menu_.isOpen();
if (!wasOpen && (menuCombo || swipeMenu_) && g_keyboardFor.empty()) {
@@ -225,6 +241,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
p.triggerHz = g_settings.triggerHz;
p.triggerResistance = g_settings.triggerResistance;
p.triggerPulses = g_settings.triggerPulses;
+ p.triggerProfile = triggerProfile_;
p.circleConfirms = circleConfirms_;
auto had = g_settings.perGame.find(gameKey_); // not set from this menu: kept
p.highRefresh = had != g_settings.perGame.end() ? had->second.highRefresh : g_settings.highRefresh;
@@ -242,6 +259,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
streamResolution_ = def.resolution;
deadzone_ = def.deadzoneLeft;
triggerStrength_ = def.triggerStrength;
+ triggerProfile_ = def.triggerProfile;
keyMap_ = def.keyMap;
padMap_ = def.padMap;
circleConfirms_ = def.circleConfirms;
@@ -253,7 +271,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
applyDeband_();
applyUpscaler(upscaler_);
input::setDeadzone(deadzone_ / 100.0f, deadzone_ / 100.0f);
- input::setTriggerFeel(triggerStrength_, g_settings.triggerHz, g_settings.triggerResistance, g_settings.triggerPulses);
+ input::setTriggerFeel(triggerStrength_, g_settings.triggerHz, g_settings.triggerResistance, g_settings.triggerPulses, triggerProfile_);
input::setCircleConfirms(circleConfirms_);
menu_.setProfileValues(streamResolution_, sharpness_, deband_, upscaler_,
triggerStrength_, deadzone_, circleConfirms_, false);
@@ -531,6 +549,8 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
ui::Canvas c = ui::renderToastPanel(fonts_, shown);
display::setOverlay(c.data(), (static_cast<int>(display::kWidth) - c.width()) / 2, 28, c.width(), c.height(), 235);
} else if (showStats_ && seq) {
+ if (info.onScreenMs > 0) menu_.recordFrametime(static_cast<float>(info.onScreenMs));
+ else if (info.fps > 0) menu_.recordFrametime(static_cast<float>(1000.0 / info.fps));
ui::Canvas c = menu_.renderStats(info);
display::setOverlay(c.data(), ui::StreamMenu::kStatsX, ui::StreamMenu::kStatsY, c.width(), c.height(), 200);
} else if (info.degraded) {
@@ -573,7 +593,7 @@ void StreamScreen::idle() {
overlayPlayer_ = nullptr;
std::lock_guard<std::mutex> lock(g_settingsMutex);
input::setDeadzone(g_settings.deadzoneLeft / 100.0f, g_settings.deadzoneRight / 100.0f);
- input::setTriggerFeel(g_settings.triggerStrength, g_settings.triggerHz, g_settings.triggerResistance, g_settings.triggerPulses);
+ input::setTriggerFeel(g_settings.triggerStrength, g_settings.triggerHz, g_settings.triggerResistance, g_settings.triggerPulses, g_settings.triggerProfile);
input::setCircleConfirms(g_settings.circleConfirms);
if (g_ui) g_ui->setCircleConfirms(g_settings.circleConfirms);
if (highRefresh_) display::setHighRefresh(false);
diff --git a/src/app/stream_screen.h b/src/app/stream_screen.h
index 7d24454..ff35fae 100644
--- a/src/app/stream_screen.h
+++ b/src/app/stream_screen.h
@@ -75,6 +75,7 @@ private:
bool hasCustomProfile_ = false;
std::string gameKey_;
int triggerStrength_ = 2;
+ int triggerProfile_ = 0;
int deadzone_ = 15;
bool circleConfirms_ = false;
input::KeyMap keyMap_ = input::defaultKeyMap(); // this game's keys (the keyboard as a controller)
@@ -93,6 +94,7 @@ private:
uint64_t lastMenuRedrawMs_ = 0;
uint64_t toastsShown_ = 0; // platform::toasts()'s version in the overlay
bool mouseCaptured_ = false; // as last asked of input::kbmSetCaptured
+ bool prevL3R3_ = false; // L3 + R3 HUD telemetry shortcut
};
} // namespace xc::app
diff --git a/src/ui/stream_menu.cpp b/src/ui/stream_menu.cpp
index b420aab..d1c6e3f 100644
--- a/src/ui/stream_menu.cpp
+++ b/src/ui/stream_menu.cpp
@@ -387,22 +387,59 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {
return c;
}
+void StreamMenu::recordFrametime(float ms) const {
+ if (ms <= 0.0f || ms > 250.0f) return;
+ frametimes_.push_back(ms);
+ if (frametimes_.size() > 60) frametimes_.erase(frametimes_.begin());
+}
+
Canvas StreamMenu::renderStats(const StreamInfo& info) const {
std::string text;
if (info.height > 0) text += std::to_string(info.height) + "p ";
text += fmt("%.0f fps", info.fps) + " " + fmt("%.1f Mbps", info.mbps);
if (info.rttMs > 0) text += " " + std::to_string(info.rttMs) + " ms";
text += " " + fmt("%.1f%%", info.lossPct);
- if (info.qp >= 0) text += " QP " + fmt("%.0f", info.qp); // the encoder's quantiser: lower is finer
+ if (info.qp >= 0) text += " QP " + fmt("%.0f", info.qp); // encoder quantiser
+ if (info.onScreenMs > 0) text += " Screen " + fmt("%.1f ms", info.onScreenMs);
+ if (info.decodeMs > 0) text += " Dec " + fmt("%.1f ms", info.decodeMs);
if (!micMuted_) text += " MIC";
- constexpr int kPx = 20, kH = 36;
+ constexpr int kPx = 18;
std::string warn = info.degraded ? std::string(" ") + tr(Str::ConnectionUnstable) : std::string();
int tw = fonts_.semibold.measure(text, kPx);
int w = tw + fonts_.semibold.measure(warn, kPx) + 28;
+ w = std::max(w, 440);
+
+ constexpr int kH = 62;
Canvas c(w, kH);
c.clear(kPanel);
- fonts_.semibold.draw(c, text, 14, fonts_.semibold.centeredY(0, kH, kPx), kPx, kWhite);
- if (!warn.empty()) fonts_.semibold.draw(c, warn, 14 + tw, fonts_.semibold.centeredY(0, kH, kPx), kPx, kWarnColor);
+ fonts_.semibold.draw(c, text, 14, 8, kPx, kWhite);
+ if (!warn.empty()) fonts_.semibold.draw(c, warn, 14 + tw, 8, kPx, kWarnColor);
+
+ // Row 2: Frametime sparkline bars (last 60 frames)
+ int graphX = 14;
+ int graphY = 32;
+ int graphH = 22;
+ int graphW = w - 28;
+ // Draw subtle baseline
+ c.line(graphX, graphY + graphH, graphX + graphW, graphY + graphH, 1.0f, rgba(80, 80, 80, 160));
+ // Target 60fps line (16.7ms out of 40ms scale = ~9px above baseline)
+ float targetLineY = (graphY + graphH) - (16.7f / 40.0f) * graphH;
+ c.line(graphX, targetLineY, graphX + graphW, targetLineY, 1.0f, rgba(60, 160, 90, 120));
+
+ if (!frametimes_.empty()) {
+ size_t count = frametimes_.size();
+ float barW = std::max(2.0f, static_cast<float>(graphW) / 60.0f - 1.0f);
+ float step = barW + 1.0f;
+ for (size_t i = 0; i < count; ++i) {
+ float ms = frametimes_[i];
+ float norm = std::clamp(ms / 40.0f, 0.08f, 1.0f);
+ float bh = norm * graphH;
+ float bx = graphX + i * step;
+ if (bx + barW > graphX + graphW) break;
+ Color barColor = ms <= 17.5f ? rgba(40, 200, 60) : ms <= 33.3f ? rgba(255, 190, 40) : rgba(255, 60, 60);
+ c.fillRect({static_cast<int>(bx), static_cast<int>(graphY + graphH - bh), static_cast<int>(barW), static_cast<int>(bh)}, barColor);
+ }
+ }
return c;
}
diff --git a/src/ui/stream_menu.h b/src/ui/stream_menu.h
index 0e66b45..f5431ac 100644
--- a/src/ui/stream_menu.h
+++ b/src/ui/stream_menu.h
@@ -93,6 +93,7 @@ public:
Canvas renderMenu(const StreamInfo& info) const;
Canvas renderStats(const StreamInfo& info) const;
+ void recordFrametime(float ms) const;
// "Unstable connection", on its own (when the statistics line is off).
Canvas renderWarning() const;
@@ -133,6 +134,7 @@ private:
bool micMuted_ = false;
float micLevel_ = 0.0f;
PadSlots pads_{};
+ mutable std::vector<float> frametimes_;
};
} // namespace xc::ui