Skip to content
Open
Changes from all commits
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
12 changes: 10 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <algorithm>
#include <csignal>
#include <cstdlib>
#include <iomanip>
#include "utils.hpp"

// Color and formatting macros for terminal output
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<double>(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;
Expand Down
Loading