More accurate frame timer
This commit is contained in:
parent
d4886f2ff2
commit
9d3063914d
1
Makefile
1
Makefile
@ -27,4 +27,5 @@ $(BUILDD)/%.o: %.c %.h
|
||||
clean:
|
||||
rm -rf $(BUILDD)
|
||||
find . -name "*.exe" -type f -delete
|
||||
cd haloo3d && $(MAKE) clean
|
||||
|
||||
|
20
scene.c
20
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++) {
|
||||
|
Loading…
Reference in New Issue
Block a user