Skip to content

Commit

Permalink
game: show the state on the terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
fmang committed Aug 27, 2017
1 parent dbd40bd commit 6d79116
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit 6d79116

Please sign in to comment.