1.1 --- a/test/sandbox.c Wed Nov 08 23:17:07 2023 +0100 1.2 +++ b/test/sandbox.c Wed Nov 15 22:51:40 2023 +0100 1.3 @@ -26,6 +26,7 @@ 1.4 */ 1.5 1.6 #include <ascension/ascension.h> 1.7 +#include <cx/printf.h> 1.8 1.9 static bool show_message_box_on_error(SDL_Window* window) { 1.10 if (asc_has_error()) { 1.11 @@ -50,13 +51,34 @@ 1.12 1.13 AscWindow *window = asc_window_initialize(0, &settings); 1.14 asc_shader_initialize_predefined(); 1.15 + 1.16 + AscTextNode fps_counter = {0}; 1.17 + unsigned last_fps = 0; 1.18 + 1.19 while (asc_loop_next()) { 1.20 // quit application on any error 1.21 if (show_message_box_on_error(window->window)) break; 1.22 1.23 1.24 + // fps counter 1.25 + if (asc_context.elapsed_millis > 0) { 1.26 + unsigned fps = 1000u / asc_context.elapsed_millis; 1.27 + if (fps != last_fps) { 1.28 + last_fps = fps; 1.29 + asc_set_font(asc_font(ASC_FONT_REGULAR, 24)); 1.30 + asc_ink_rgb(255, 0, 0); 1.31 + cxmutstr fpstext = cx_asprintf("%u FPS", fps); 1.32 + asc_text_draw(&fps_counter, (asc_vec2i) {50, 50}, fpstext); 1.33 + cx_strfree(&fpstext); 1.34 + } else { 1.35 + asc_text_redraw(&fps_counter); 1.36 + } 1.37 + } 1.38 } 1.39 1.40 + // TODO: maybe nodes should also be "garbage collected" 1.41 + asc_text_destroy(&fps_counter); 1.42 + 1.43 asc_context_destroy(); 1.44 return 0; 1.45 }