More accurate frame timer

This commit is contained in:
Carlos Sanchez 2024-08-12 22:17:14 -04:00
parent d4886f2ff2
commit 9d3063914d
2 changed files with 10 additions and 11 deletions

View File

@ -27,4 +27,5 @@ $(BUILDD)/%.o: %.c %.h
clean: clean:
rm -rf $(BUILDD) rm -rf $(BUILDD)
find . -name "*.exe" -type f -delete find . -name "*.exe" -type f -delete
cd haloo3d && $(MAKE) clean

20
scene.c
View File

@ -45,7 +45,7 @@
#endif #endif
#define CALCTIME(thistime, start, end, sum) \ #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) \ if (sum == 0) \
sum = thistime; \ sum = thistime; \
sum = AVGWEIGHT * sum + (1 - AVGWEIGHT) * 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) { int main(int argc, char **argv) {
if (argc != 4) { 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 " dieerr("You must pass in the following:\n- obj file .obj\n- texture file "
".ppm\n- camera file (xofs yofs zofs yawdeg pitchdeg)\n"); ".ppm\n- camera file (xofs yofs zofs yawdeg pitchdeg)\n");
} }
@ -144,7 +143,7 @@ int main(int argc, char **argv) {
struct vec4 *vert_precalc; struct vec4 *vert_precalc;
mallocordie(vert_precalc, sizeof(struct vec4) * H3D_OBJ_MAXVERTICES); mallocordie(vert_precalc, sizeof(struct vec4) * H3D_OBJ_MAXVERTICES);
clock_t begin, end; clock_t begin, end;
float sumframe = 0; float sumframe = 0, lastframe = 0;
int totaldrawn = 0; int totaldrawn = 0;
eprintf("Scene has %d tris, %d verts\n", totalfaces, totalverts); eprintf("Scene has %d tris, %d verts\n", totalfaces, totalverts);
@ -161,12 +160,13 @@ int main(int argc, char **argv) {
int cami = 0; int cami = 0;
while (1) { while (1) {
begin = clock();
unigi_event_get(&event); unigi_event_get(&event);
if (event.type == unigi_enum_event_input_keyboard) { if (event.type == unigi_enum_event_input_keyboard) {
exit(0); exit(0);
} }
begin = clock();
totaldrawn = 0; totaldrawn = 0;
haloo3d_print_refresh(&t); 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, unigi_graphics_blit(0, (unigi_type_color *)fb.buffer,
res.width * res.height); res.width * res.height);
unigi_graphics_flush(); unigi_graphics_flush();
cami = (cami + 1) % numcams; cami = (cami + 1) % numcams;
end = clock();
CALCTIME(lastframe, begin, end, sumframe);
} }
for (int i = 0; i < NUMOBJECTS; i++) { for (int i = 0; i < NUMOBJECTS; i++) {