From 9d3063914d4fc6414b3b2a590998d11706c78c18 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Mon, 12 Aug 2024 22:17:14 -0400 Subject: [PATCH] More accurate frame timer --- Makefile | 1 + scene.c | 20 +++++++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index fb2cc04..8319a88 100644 --- a/Makefile +++ b/Makefile @@ -27,4 +27,5 @@ $(BUILDD)/%.o: %.c %.h clean: rm -rf $(BUILDD) find . -name "*.exe" -type f -delete + cd haloo3d && $(MAKE) clean diff --git a/scene.c b/scene.c index 43187c0..5654e97 100644 --- a/scene.c +++ b/scene.c @@ -45,7 +45,7 @@ #endif #define CALCTIME(thistime, start, end, sum) \ - float thistime = 1000.0 * (float)(end - start) / CLOCKS_PER_SEC; \ + thistime = 1000.0 * (float)(end - start) / CLOCKS_PER_SEC; \ if (sum == 0) \ sum = thistime; \ sum = AVGWEIGHT * sum + (1 - AVGWEIGHT) * thistime; @@ -55,7 +55,6 @@ uint16_t redflower[64] = H3D_FLOWER(0xFE55, 0xF6C4, 0xFFE0, 0xFD44, 0xF492); int main(int argc, char **argv) { if (argc != 4) { - eprintf("WARN: THIS PROGRAM GENERATES A LOT OF FILES!\n"); dieerr("You must pass in the following:\n- obj file .obj\n- texture file " ".ppm\n- camera file (xofs yofs zofs yawdeg pitchdeg)\n"); } @@ -144,7 +143,7 @@ int main(int argc, char **argv) { struct vec4 *vert_precalc; mallocordie(vert_precalc, sizeof(struct vec4) * H3D_OBJ_MAXVERTICES); clock_t begin, end; - float sumframe = 0; + float sumframe = 0, lastframe = 0; int totaldrawn = 0; eprintf("Scene has %d tris, %d verts\n", totalfaces, totalverts); @@ -161,12 +160,13 @@ int main(int argc, char **argv) { int cami = 0; while (1) { + begin = clock(); + unigi_event_get(&event); if (event.type == unigi_enum_event_input_keyboard) { exit(0); } - begin = clock(); totaldrawn = 0; haloo3d_print_refresh(&t); @@ -218,19 +218,17 @@ int main(int argc, char **argv) { } } - end = clock(); + haloo3d_print(&t, "Last frame: %05.2f (%05.2f)\nTris: %d / %d\nVerts: %d\n", + lastframe, sumframe, totaldrawn, totalfaces, totalverts); - CALCTIME(thisframetime, begin, end, sumframe); - haloo3d_print(&t, "Frame: %.2f (%.2f)\nTris: %d / %d\nVerts: %d\n", - thisframetime, sumframe, totaldrawn, totalfaces, totalverts); - - // sprintf(fname, "scene_%04d.ppm", cami); - // haloo3d_img_writeppmfile(&fb, fname); unigi_graphics_blit(0, (unigi_type_color *)fb.buffer, res.width * res.height); unigi_graphics_flush(); cami = (cami + 1) % numcams; + + end = clock(); + CALCTIME(lastframe, begin, end, sumframe); } for (int i = 0; i < NUMOBJECTS; i++) {