Browse Source

Tweaks to time system:

- Init time system first, because it no longer depends on video mode.
- Made real time updates less frequent, so it has less impact on performance. Still more than accurate enough.
tess_experiment
Nico de Poel 3 years ago
parent
commit
edd851f9e3
  1. 4
      main.c
  2. 6
      time.c

4
main.c

@ -24,9 +24,9 @@ world_t world;
// Init function // Init function
void init(void) void init(void)
{ {
time_init();
input_init(); input_init();
display_init(); display_init();
time_init();
//asset_loadTexture(tim_e1m1, NULL); //asset_loadTexture(tim_e1m1, NULL);
@ -49,7 +49,7 @@ int main(int argc, const char *argv[])
// Draw stuff // Draw stuff
world_draw(&world); world_draw(&world);
FntPrint(-1, "Time: %d, ticks = %d, delta time = %d, fps = %d\n", time_getRealTime() >> 12, time_getFrameNumber(), time_getDeltaTime(), time_getFrameRate() >> 8);
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); 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); FntFlush(-1);

6
time.c

@ -13,7 +13,7 @@ static u_long measureStartTime;
static void timer_callback() static void timer_callback()
{ {
realTime += 4;
realTime += 16;
} }
void time_init() void time_init()
@ -26,9 +26,9 @@ void time_init()
avgFrameRate = 0; avgFrameRate = 0;
measureStartTime = 0; measureStartTime = 0;
// Set the timer such that we get exactly 1024 interrupts per second on both PAL and NTSC (roughly once per millisecond)
// Set the timer such that we get exactly 256 interrupts per second on both PAL and NTSC (roughly once per 4 milliseconds)
// This allows the game speed to be completely framerate and video mode independent // This allows the game speed to be completely framerate and video mode independent
const int counter = 4096;
const int counter = 16384;
EnterCriticalSection(); EnterCriticalSection();
SetRCnt(RCntCNT2, counter, RCntMdINTR); SetRCnt(RCntCNT2, counter, RCntMdINTR);

Loading…
Cancel
Save