From a4756eaeb00dce0c36d696993b173b71f470f26b Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Fri, 4 May 2012 00:26:24 +0200 Subject: [PATCH] implement fps counter --- TODO | 3 +-- src/main.c | 17 ++++++++++++++++- src/pause.c | 2 -- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index 783e5f8..02fdb0e 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ -- obstracles/bonuses handling +- obstracles/bonuses - HUD - some love for about screen -- spritesheet manager - voice manager - night map diff --git a/src/main.c b/src/main.c index 1bcb1d4..89da5be 100644 --- a/src/main.c +++ b/src/main.c @@ -56,6 +56,9 @@ #define DRAW_STATE(state, name) case state:\ name ## _Draw(game); break; +double old_time = 0, fps; +int frames_done = 0; + void al_draw_text_with_shadow(ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, float y, int flags, char const *text) { al_draw_text(font, al_map_rgba(0,0,0,128), x+1, y+1, flags, text); al_draw_text(font, color, x, y, flags, text); @@ -81,7 +84,19 @@ void PrintConsole(struct Game *game, char* format, ...) { } void DrawConsole(struct Game *game) { - if (game->showconsole) al_draw_bitmap(game->console, 0, 0, 0); + if (game->showconsole) { + al_draw_bitmap(game->console, 0, 0, 0); + double game_time = al_get_time(); + if(game_time - old_time >= 1.0) { + fps = frames_done / (game_time - old_time); + frames_done = 0; + old_time = game_time; + } + char sfps[6] = { }; + sprintf(sfps, "%.0f", fps); + al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.99, 0, ALLEGRO_ALIGN_RIGHT, sfps); + } + frames_done++; } void PreloadGameState(struct Game *game) { diff --git a/src/pause.c b/src/pause.c index e040a99..502f36d 100644 --- a/src/pause.c +++ b/src/pause.c @@ -96,8 +96,6 @@ void Pause_Draw(struct Game* game) { al_draw_text_with_shadow(game->menu.font_subtitle, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.275, ALLEGRO_ALIGN_CENTRE, "Game paused."); DrawMenuState(game); - - DrawConsole(game); } void Pause_Unload_Real(struct Game* game) {