diff --git a/src/java/com/threerings/media/timer/SystemMediaTimer.java b/src/java/com/threerings/media/timer/SystemMediaTimer.java index a81e931f2..5f05cd068 100644 --- a/src/java/com/threerings/media/timer/SystemMediaTimer.java +++ b/src/java/com/threerings/media/timer/SystemMediaTimer.java @@ -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; }