Added a workaround to the time fluctuation WinXP bug.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2735 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2003-07-29 00:27:32 +00:00
parent 1b9c9dac62
commit 28bdcd942d
@@ -1,8 +1,10 @@
//
// $Id: SystemMediaTimer.java,v 1.1 2002/11/20 02:17:38 mdb Exp $
// $Id: SystemMediaTimer.java,v 1.2 2003/07/29 00:27:32 mdb Exp $
package com.threerings.media.timer;
import com.threerings.media.Log;
/**
* Implements the {@link MediaTimer} interface using {@link
* System#currentTimeMillis} to obtain timing information.
@@ -23,7 +25,23 @@ public class SystemMediaTimer implements MediaTimer
// documentation inherited from interface
public long getElapsedMillis ()
{
return System.currentTimeMillis() - _resetStamp;
long stamp = System.currentTimeMillis() - _resetStamp;
// on WinXP the time sometimes seems to leap into the
// past; here we do our best to work around this insanity
if (stamp < _lastStamp) {
// only warn once per time anomaly
if (stamp > _lastWarning) {
Log.warning("Someone call Einstein! The clock is " +
"running backwards [dt=" +
(stamp - _lastStamp) + "].");
_lastWarning = _lastStamp;
}
stamp = _lastStamp;
}
_lastStamp = stamp;
return stamp;
}
// documentation inherited from interface
@@ -34,4 +52,7 @@ public class SystemMediaTimer implements MediaTimer
/** The time at which this timer was last reset. */
protected long _resetStamp = System.currentTimeMillis();
/** Used to ensure that the timer is sane. */
protected long _lastStamp, _lastWarning;
}