From f3c2097498723e7a55b049c34254d71d659ef99f Mon Sep 17 00:00:00 2001 From: Charlie Groves Date: Wed, 12 Mar 2008 00:06:00 +0000 Subject: [PATCH] Cancel the calibration interval and start a new one in reset to prevent calibrate calls coming immediately after the reset from producing a crazy drift git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@442 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../media/timer/CalibratingTimer.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/java/com/threerings/media/timer/CalibratingTimer.java b/src/java/com/threerings/media/timer/CalibratingTimer.java index 39b7fe87..64f9f139 100644 --- a/src/java/com/threerings/media/timer/CalibratingTimer.java +++ b/src/java/com/threerings/media/timer/CalibratingTimer.java @@ -48,10 +48,6 @@ public abstract class CalibratingTimer reset(); Log.info("Using " + getClass() + " timer [mfreq=" + _milliDivider + ", ufreq=" + _microDivider + ", start=" + _startStamp + "]."); - new Interval(RunQueue.AWT) { - @Override public void expired () { - calibrate(); - }}.schedule(5000, true); } // documentation inherited from interface @@ -69,9 +65,19 @@ public abstract class CalibratingTimer // documentation inherited from interface public void reset () { + if (_calibrateInterval != null) { + _calibrateInterval.cancel(); + _calibrateInterval = null; + } _startStamp = _priorCurrent = current(); _driftMilliStamp = System.currentTimeMillis(); _driftTimerStamp = current(); + _calibrateInterval = new Interval(RunQueue.AWT) { + @Override public void expired () { + calibrate(); + } + }; + _calibrateInterval.schedule(5000, true); } /** @@ -161,6 +167,9 @@ public abstract class CalibratingTimer /** The largest drift we've had to adjust for. */ protected double _maxDriftRatio = 1.0; + + /** Interval that fires every five seconds to run the calibration. */ + protected Interval _calibrateInterval; /** A debug hook that toggles dumping of calibration values. */ protected static RuntimeAdjust.BooleanAdjust _debugCalibrate = new RuntimeAdjust.BooleanAdjust(