From 6d791167b23750604e904347cc53404cd5cd7a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Sun, 27 Aug 2017 11:05:52 +0200 Subject: [PATCH] game: show the state on the terminal --- src/game.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/game.c b/src/game.c index a62f50a..b94331a 100644 --- a/src/game.c +++ b/src/game.c @@ -302,6 +302,23 @@ static void end(struct oshu_game *game) ); } +/** + * Show the state of the game (paused/playing) and the current song position. + * + * Only do that for terminal outputs in order not to spam something if the + * output is redirected. + */ +static void dump_state(struct oshu_game *game, double now) +{ + if (!isatty(fileno(stdout))) + return; + int minutes = (int) now / 60.; + double seconds = now - (minutes * 60.); + const char *state = game->paused ? "Paused": "Playing"; + printf("%s: %d:%06.3f\r", state, minutes, seconds); + fflush(stdout); +} + int oshu_game_run(struct oshu_game *game) { SDL_Event event; @@ -314,6 +331,7 @@ int oshu_game_run(struct oshu_game *game) check_audio(game); double now = game->audio->current_timestamp; oshu_draw_beatmap(game->display, game->beatmap, now); + dump_state(game, now); game->previous_time = now; SDL_Delay(20); }