test/sandbox.c

changeset 16
c5dde81b6fb2
parent 15
362b7659dc76
child 19
d0e88022e209
equal deleted inserted replaced
15:362b7659dc76 16:c5dde81b6fb2
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE. 25 * POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include <ascension/ascension.h> 28 #include <ascension/ascension.h>
29 #include <cx/printf.h>
29 30
30 static bool show_message_box_on_error(SDL_Window* window) { 31 static bool show_message_box_on_error(SDL_Window* window) {
31 if (asc_has_error()) { 32 if (asc_has_error()) {
32 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, 33 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
33 "Fatal Error", 34 "Fatal Error",
48 asc_window_settings_init_defaults(&settings); 49 asc_window_settings_init_defaults(&settings);
49 settings.title = "Sandbox Application"; 50 settings.title = "Sandbox Application";
50 51
51 AscWindow *window = asc_window_initialize(0, &settings); 52 AscWindow *window = asc_window_initialize(0, &settings);
52 asc_shader_initialize_predefined(); 53 asc_shader_initialize_predefined();
54
55 AscTextNode fps_counter = {0};
56 unsigned last_fps = 0;
57
53 while (asc_loop_next()) { 58 while (asc_loop_next()) {
54 // quit application on any error 59 // quit application on any error
55 if (show_message_box_on_error(window->window)) break; 60 if (show_message_box_on_error(window->window)) break;
56 61
57 62
63 // fps counter
64 if (asc_context.elapsed_millis > 0) {
65 unsigned fps = 1000u / asc_context.elapsed_millis;
66 if (fps != last_fps) {
67 last_fps = fps;
68 asc_set_font(asc_font(ASC_FONT_REGULAR, 24));
69 asc_ink_rgb(255, 0, 0);
70 cxmutstr fpstext = cx_asprintf("%u FPS", fps);
71 asc_text_draw(&fps_counter, (asc_vec2i) {50, 50}, fpstext);
72 cx_strfree(&fpstext);
73 } else {
74 asc_text_redraw(&fps_counter);
75 }
76 }
58 } 77 }
78
79 // TODO: maybe nodes should also be "garbage collected"
80 asc_text_destroy(&fps_counter);
59 81
60 asc_context_destroy(); 82 asc_context_destroy();
61 return 0; 83 return 0;
62 } 84 }
63 85

mercurial