diff -r 18de2af03531 -r d3285aed65b3 test/snake.c --- a/test/snake.c Thu Mar 28 23:30:21 2024 +0100 +++ b/test/snake.c Fri Mar 29 00:03:25 2024 +0100 @@ -29,18 +29,17 @@ #include static void update_fps_counter(AscSceneNode *node) { - // addition and multiplication is more efficient testing for zero - // at an unnoticeable cost of imprecision - static unsigned last_fps = 0u; - static unsigned debounce = 999u; - unsigned fps = 1000u; - debounce += asc_context.elapsed_millis; - if (debounce >= 1000u) { + static uint64_t last_fps = 0; + static uint64_t debounce = ASC_NANOS_SECOND - 1; + debounce += asc_context.frame_nanos; + // only update text every seconds + if (debounce >= ASC_NANOS_SECOND) { debounce = 0; - fps /= asc_context.elapsed_millis; + uint64_t fps = ASC_NANOS_SECOND; + fps /= asc_context.frame_nanos; if (fps != last_fps) { last_fps = fps; - snprintf(asc_text_data(node)->text, 9, "%u FPS", fps); + snprintf(asc_text_data(node)->text, 11, "%"PRIu64" FPS", fps); asc_node_update(node); } } @@ -49,7 +48,7 @@ static void create_fps_counter(void) { asc_set_font(asc_font(ASC_FONT_REGULAR, 24)); asc_ink_rgb(255, 0, 0); - AscSceneNode* node = asc_text(10, 10, "XXXXX FPS"); + AscSceneNode* node = asc_text(10, 10, "XXXXXXX FPS"); asc_scene_add_behavior(node, update_fps_counter); asc_scene_add(&asc_window_active->ui, node); }