Browse Source

Fixes to the time system to make it work on real hardware, and prevent potential crash from division by zero.

tess_experiment
Nico de Poel 3 years ago
parent
commit
780abe0d84
  1. 16
      main.c
  2. 6
      time.c

16
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();
}

6
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;
}

Loading…
Cancel
Save