diff --git a/main.c b/main.c index 42703c9..2b6246f 100644 --- a/main.c +++ b/main.c @@ -24,13 +24,13 @@ world_t world; // Init function void init(void) { - time_init(); - input_init(); - display_init(); + input_init(); // Works + display_init(); // Works + time_init(); // Works //asset_loadTexture(tim_e1m1, NULL); - world_load(bsp_test, &world); + world_load(bsp_test, &world); // Works } // Main function, program entrypoint @@ -42,18 +42,18 @@ int main(int argc, const char *argv[]) // Main loop while(1) { - input_process(); + input_process(); // Works - display_start(); + display_start(); // Works // Draw stuff - world_draw(&world); + world_draw(&world); // Doesn't work >:( FntPrint(-1, "Time: %d, ticks = %d, delta time = %d, fps = %d\n", (time_getRealTime() * 1000) >> 12, time_getFrameNumber(), time_getDeltaTime(), time_getFrameRate() >> 8); FntPrint(-1, "Camera pos = (%d, %d, %d) rot = (%d, %d, %d)\n", cam_pos.vx, cam_pos.vy, cam_pos.vz, cam_rot.vx, cam_rot.vy, cam_rot.vz); FntFlush(-1); - display_finish(); + display_finish(); // Works time_tick(); } diff --git a/time.c b/time.c index 6e43d33..6d7d950 100644 --- a/time.c +++ b/time.c @@ -46,7 +46,11 @@ void time_tick() u_long currTime = realTime; if ((frameNumber & 0xF) == 0) { - avgFrameRate = (u_short)((0x10 << 20) / (currTime - measureStartTime)); + u_long timeDelta = currTime - measureStartTime; + if (timeDelta == 0) + timeDelta = 1; // Prevent division by zero + + avgFrameRate = (u_short)((0x10 << 20) / timeDelta); measureStartTime = currTime; }