From 2c27120a61631dffd4527db8b1349379d53ccc3b Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Mon, 11 May 2026 09:47:22 -0400 Subject: fix fps counting --- dc/dc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dc/dc.c b/dc/dc.c index 69df3f8..b0e7b60 100644 --- a/dc/dc.c +++ b/dc/dc.c @@ -15,10 +15,10 @@ struct ty_image img; struct ty_font font; +double last_frame = 0; + void tick(void) { - double start = ty_get_time(); - ty_draw_clear(TY_COLOR_BLACK); ty_draw_image( @@ -31,7 +31,8 @@ void tick(void) ty_draw_text(&font, ty_vec2i(5, SCREEN_HEIGHT - 5 - 8), "hello, world!"); - double frame_time = ty_get_time() - start; + double frame_time = ty_get_time() - last_frame; + last_frame = ty_get_time(); char ms_fmt[] = "%.2g ms"; int ms_width = ty_font_width(&font, ms_fmt, frame_time * 1000); @@ -50,7 +51,7 @@ void tick(void) frame_time * 1000 ); - char fps_fmt[] = "%4d fps"; + char fps_fmt[] = "%2d fps"; int fps_width = ty_font_width(&font, fps_fmt, (int)(1.0 / frame_time)); ty_draw_rect( @@ -85,6 +86,7 @@ void tick(void) ); ty_draw_end(); + } struct ty_image load_qoi_image(const char *path) @@ -105,7 +107,7 @@ int main(void) .scr_width = SCREEN_WIDTH, .scr_height = SCREEN_HEIGHT, .game_title = "Demonchime", - .ticrate = 30, + .ticrate = 60, }; ty_init(hints); -- cgit v1.3-2-g0d8e