From edd851f9e3ba5964223686fc0146153da48555fb Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 14 Jan 2023 15:34:43 +0100 Subject: [PATCH] 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. --- main.c | 4 ++-- time.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 051f846..42703c9 100644 --- a/main.c +++ b/main.c @@ -24,9 +24,9 @@ world_t world; // Init function void init(void) { + time_init(); input_init(); display_init(); - time_init(); //asset_loadTexture(tim_e1m1, NULL); @@ -49,7 +49,7 @@ int main(int argc, const char *argv[]) // Draw stuff 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); FntFlush(-1); diff --git a/time.c b/time.c index a11ab59..6e43d33 100644 --- a/time.c +++ b/time.c @@ -13,7 +13,7 @@ static u_long measureStartTime; static void timer_callback() { - realTime += 4; + realTime += 16; } void time_init() @@ -26,9 +26,9 @@ void time_init() avgFrameRate = 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 - const int counter = 4096; + const int counter = 16384; EnterCriticalSection(); SetRCnt(RCntCNT2, counter, RCntMdINTR);