mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 19:16:44 +01:00
implement fps counter
This commit is contained in:
parent
827f096838
commit
a4756eaeb0
3 changed files with 17 additions and 5 deletions
3
TODO
3
TODO
|
@ -1,7 +1,6 @@
|
||||||
- obstracles/bonuses handling
|
- obstracles/bonuses
|
||||||
- HUD
|
- HUD
|
||||||
- some love for about screen
|
- some love for about screen
|
||||||
- spritesheet manager
|
|
||||||
- voice manager
|
- voice manager
|
||||||
- night map
|
- night map
|
||||||
|
|
||||||
|
|
17
src/main.c
17
src/main.c
|
@ -56,6 +56,9 @@
|
||||||
#define DRAW_STATE(state, name) case state:\
|
#define DRAW_STATE(state, name) case state:\
|
||||||
name ## _Draw(game); break;
|
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) {
|
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, al_map_rgba(0,0,0,128), x+1, y+1, flags, text);
|
||||||
al_draw_text(font, color, x, y, 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) {
|
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) {
|
void PreloadGameState(struct Game *game) {
|
||||||
|
|
|
@ -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.");
|
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);
|
DrawMenuState(game);
|
||||||
|
|
||||||
DrawConsole(game);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pause_Unload_Real(struct Game* game) {
|
void Pause_Unload_Real(struct Game* game) {
|
||||||
|
|
Loading…
Reference in a new issue