From 5e07ab5bf8d301f5b5c0715e779fb015de1939e5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 19 Aug 2026 17:30:10 +0000 Subject: [PATCH] Display real-time CPS in terminal game HUD Added real-time Clicks Per Second (CPS) tracking and display to the live game HUD in `src/main.cpp`. The CPS metric is updated continuously during gameplay and formatted to one decimal place, providing immediate tactile feedback to the player. Co-authored-by: aidasofialily-cmd <247843425+aidasofialily-cmd@users.noreply.github.com> --- src/main.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b9144b7..6e626a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "utils.hpp" // Color and formatting macros for terminal output @@ -114,7 +115,8 @@ int main() { std::this_thread::sleep_for(std::chrono::milliseconds(200)); tcflush(STDIN_FILENO, TCIFLUSH); - auto last_tick = std::chrono::steady_clock::now(); + auto game_start = std::chrono::steady_clock::now(); + auto last_tick = game_start; bool updateUI = true; struct pollfd fds[1] = {{STDIN_FILENO, POLLIN, 0}}; while (true) { @@ -143,7 +145,13 @@ int main() { } if (updateUI) { - std::cout << "\r" ERASE_LINE << CLR_SCORE << "Score: " << formatWithCommas(score) << CLR_RESET << " | High: " << formatWithCommas(highscore) << " " + auto current_now = std::chrono::steady_clock::now(); + double duration_sec = std::chrono::duration(current_now - game_start).count(); + double cps = (duration_sec > 0.0) ? (score / duration_sec) : 0.0; + + std::cout << "\r" ERASE_LINE << CLR_SCORE << "Score: " << formatWithCommas(score) << CLR_RESET + << " | High: " << formatWithCommas(highscore) + << " | CPS: " << std::fixed << std::setprecision(1) << cps << " " << (hardMode ? CLR_HARD "[HARD MODE]" : CLR_NORM "[NORMAL MODE]") << (score > initialHighscore ? " NEW BEST! 🥳 (was " + formatWithCommas(initialHighscore) + ")" : "") << std::flush;