From 60352fe5e06a811cb83521e8a0d4ea67fa553ea4 Mon Sep 17 00:00:00 2001 From: Caspian Rychlik-Prince Date: Wed, 7 Jul 2004 22:24:33 +0000 Subject: [PATCH] Now copes with processors that adjust their clockspeed --- src/java/org/lwjgl/util/Timer.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/java/org/lwjgl/util/Timer.java b/src/java/org/lwjgl/util/Timer.java index fce6bf8c..554e0cf6 100644 --- a/src/java/org/lwjgl/util/Timer.java +++ b/src/java/org/lwjgl/util/Timer.java @@ -47,7 +47,11 @@ import org.lwjgl.Sys; public class Timer { // Record the timer resolution on classload - private static final long resolution = Sys.getTimerResolution(); + private static long resolution = Sys.getTimerResolution(); + + // Every so often we will re-query the timer resolution + private static final int QUERY_INTERVAL = 1000; // in calls to tick() + private static int queryCount = 0; // Globally keeps track of time for all instances of Timer private static long currentTime; @@ -129,6 +133,13 @@ public class Timer { */ public static void tick() { currentTime = Sys.getTime(); + + // Periodically refresh the timer resolution: + queryCount ++; + if (queryCount > QUERY_INTERVAL) { + queryCount = 0; + resolution = Sys.getTimerResolution(); + } } /**