test/sandbox.c

changeset 19
d0e88022e209
parent 16
c5dde81b6fb2
child 22
30b12e88fd84
equal deleted inserted replaced
18:00c0632f0f40 19:d0e88022e209
50 settings.title = "Sandbox Application"; 50 settings.title = "Sandbox Application";
51 51
52 AscWindow *window = asc_window_initialize(0, &settings); 52 AscWindow *window = asc_window_initialize(0, &settings);
53 asc_shader_initialize_predefined(); 53 asc_shader_initialize_predefined();
54 54
55 AscTextNode fps_counter = {0}; 55 asc_set_font(asc_font(ASC_FONT_REGULAR, 24));
56 asc_ink_rgb(255, 0, 0);
57 AscTextNode *fps_counter = asc_text(50, 50, "60 FPS");
56 unsigned last_fps = 0; 58 unsigned last_fps = 0;
57 59
58 while (asc_loop_next()) { 60 while (asc_loop_next()) {
59 // quit application on any error 61 // quit application on any error
60 if (show_message_box_on_error(window->window)) break; 62 if (show_message_box_on_error(window->window)) break;
63 // fps counter 65 // fps counter
64 if (asc_context.elapsed_millis > 0) { 66 if (asc_context.elapsed_millis > 0) {
65 unsigned fps = 1000u / asc_context.elapsed_millis; 67 unsigned fps = 1000u / asc_context.elapsed_millis;
66 if (fps != last_fps) { 68 if (fps != last_fps) {
67 last_fps = fps; 69 last_fps = fps;
68 asc_set_font(asc_font(ASC_FONT_REGULAR, 24)); 70 cxBufferClear(&fps_counter->text);
69 asc_ink_rgb(255, 0, 0); 71 cx_bprintf(&fps_counter->text, "%u FPS", fps);
70 cxmutstr fpstext = cx_asprintf("%u FPS", fps); 72 asc_text_update(fps_counter);
71 asc_text_draw(&fps_counter, (asc_vec2i) {50, 50}, fpstext);
72 cx_strfree(&fpstext);
73 } else {
74 asc_text_redraw(&fps_counter);
75 } 73 }
76 } 74 }
75 asc_text_draw(fps_counter);
77 } 76 }
78 77
79 // TODO: maybe nodes should also be "garbage collected" 78 // TODO: maybe nodes should also be "garbage collected"
80 asc_text_destroy(&fps_counter); 79 asc_text_free(fps_counter);
81 80
82 asc_context_destroy(); 81 asc_context_destroy();
83 return 0; 82 return 0;
84 } 83 }
85 84

mercurial