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
This commit is contained in:
@@ -48,10 +48,6 @@ public abstract class CalibratingTimer
|
|||||||
reset();
|
reset();
|
||||||
Log.info("Using " + getClass() + " timer [mfreq=" + _milliDivider + ", ufreq="
|
Log.info("Using " + getClass() + " timer [mfreq=" + _milliDivider + ", ufreq="
|
||||||
+ _microDivider + ", start=" + _startStamp + "].");
|
+ _microDivider + ", start=" + _startStamp + "].");
|
||||||
new Interval(RunQueue.AWT) {
|
|
||||||
@Override public void expired () {
|
|
||||||
calibrate();
|
|
||||||
}}.schedule(5000, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface
|
// documentation inherited from interface
|
||||||
@@ -69,9 +65,19 @@ public abstract class CalibratingTimer
|
|||||||
// documentation inherited from interface
|
// documentation inherited from interface
|
||||||
public void reset ()
|
public void reset ()
|
||||||
{
|
{
|
||||||
|
if (_calibrateInterval != null) {
|
||||||
|
_calibrateInterval.cancel();
|
||||||
|
_calibrateInterval = null;
|
||||||
|
}
|
||||||
_startStamp = _priorCurrent = current();
|
_startStamp = _priorCurrent = current();
|
||||||
_driftMilliStamp = System.currentTimeMillis();
|
_driftMilliStamp = System.currentTimeMillis();
|
||||||
_driftTimerStamp = current();
|
_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. */
|
/** The largest drift we've had to adjust for. */
|
||||||
protected double _maxDriftRatio = 1.0;
|
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. */
|
/** A debug hook that toggles dumping of calibration values. */
|
||||||
protected static RuntimeAdjust.BooleanAdjust _debugCalibrate = new RuntimeAdjust.BooleanAdjust(
|
protected static RuntimeAdjust.BooleanAdjust _debugCalibrate = new RuntimeAdjust.BooleanAdjust(
|
||||||
|
|||||||
Reference in New Issue
Block a user