mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-08 06:06:43 +01:00
display frame duration along with the fps counter
This commit is contained in:
parent
b31d093e8c
commit
f097ddc54a
2 changed files with 6 additions and 3 deletions
|
@ -150,6 +150,7 @@ SYMBOL_INTERNAL void ResizeGamestates(struct Game* game) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SYMBOL_INTERNAL void DrawConsole(struct Game* game) {
|
SYMBOL_INTERNAL void DrawConsole(struct Game* game) {
|
||||||
|
double game_time = al_get_time();
|
||||||
if (game->_priv.showconsole) {
|
if (game->_priv.showconsole) {
|
||||||
al_set_target_backbuffer(game->display);
|
al_set_target_backbuffer(game->display);
|
||||||
ALLEGRO_TRANSFORM trans;
|
ALLEGRO_TRANSFORM trans;
|
||||||
|
@ -177,9 +178,11 @@ SYMBOL_INTERNAL void DrawConsole(struct Game* game) {
|
||||||
cur++;
|
cur++;
|
||||||
}
|
}
|
||||||
|
|
||||||
char sfps[6] = {0};
|
char sfps[16] = {0};
|
||||||
snprintf(sfps, 6, "%.0f", game->_priv.fps_count.fps);
|
snprintf(sfps, 6, "%.0f", game->_priv.fps_count.fps);
|
||||||
DrawTextWithShadow(game->_priv.font_console, al_map_rgb(255, 255, 255), clipX + clipWidth, clipY, ALLEGRO_ALIGN_RIGHT, sfps);
|
DrawTextWithShadow(game->_priv.font_console, al_map_rgb(255, 255, 255), clipX + clipWidth, clipY, ALLEGRO_ALIGN_RIGHT, sfps);
|
||||||
|
snprintf(sfps, 16, "%.2f ms", 1000 * (game_time - game->_priv.fps_count.time));
|
||||||
|
DrawTextWithShadow(game->_priv.font_console, al_map_rgb(255, 255, 255), clipX + clipWidth, clipY + al_get_font_line_height(game->_priv.font_console), ALLEGRO_ALIGN_RIGHT, sfps);
|
||||||
|
|
||||||
al_use_transform(&game->projection);
|
al_use_transform(&game->projection);
|
||||||
|
|
||||||
|
@ -187,12 +190,12 @@ SYMBOL_INTERNAL void DrawConsole(struct Game* game) {
|
||||||
}
|
}
|
||||||
al_hold_bitmap_drawing(false);
|
al_hold_bitmap_drawing(false);
|
||||||
|
|
||||||
double game_time = al_get_time();
|
|
||||||
if (game_time - game->_priv.fps_count.old_time >= 1.0) {
|
if (game_time - game->_priv.fps_count.old_time >= 1.0) {
|
||||||
game->_priv.fps_count.fps = game->_priv.fps_count.frames_done / (game_time - game->_priv.fps_count.old_time);
|
game->_priv.fps_count.fps = game->_priv.fps_count.frames_done / (game_time - game->_priv.fps_count.old_time);
|
||||||
game->_priv.fps_count.frames_done = 0;
|
game->_priv.fps_count.frames_done = 0;
|
||||||
game->_priv.fps_count.old_time = game_time;
|
game->_priv.fps_count.old_time = game_time;
|
||||||
}
|
}
|
||||||
|
game->_priv.fps_count.time = game_time;
|
||||||
game->_priv.fps_count.frames_done++;
|
game->_priv.fps_count.frames_done++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ struct Game {
|
||||||
ALLEGRO_BITMAP* fb; /*!< Default framebuffer. */
|
ALLEGRO_BITMAP* fb; /*!< Default framebuffer. */
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
double old_time, fps;
|
double old_time, fps, time;
|
||||||
int frames_done;
|
int frames_done;
|
||||||
} fps_count; /*!< Used for counting the effective FPS. */
|
} fps_count; /*!< Used for counting the effective FPS. */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue