diff --git a/src/java/com/threerings/media/timer/MediaTimer.java b/src/java/com/threerings/media/timer/MediaTimer.java new file mode 100644 index 000000000..5ef86c311 --- /dev/null +++ b/src/java/com/threerings/media/timer/MediaTimer.java @@ -0,0 +1,34 @@ +// +// $Id: MediaTimer.java,v 1.1 2002/11/20 02:17:38 mdb Exp $ + +package com.threerings.media.timer; + +/** + * Provides a pluggable mechanism for delivering high resolution timing + * information. The timers are not intended to be used by different + * threads and thus must be protected by synchronization in such + * circumstances. + */ +public interface MediaTimer +{ + /** + * Resets the timer's monotonically increasing value. + */ + public void reset (); + + /** + * Returns the number of milliseconds that have elapsed since the + * timer was created or last {@link #reset}. Note: the + * accuracy of this method is highly dependent on the timer + * implementation used. + */ + public long getElapsedMillis (); + + /** + * Returns the number of microseconds that have elapsed since the + * timer was created or last {@link #reset}. Note: the + * accuracy of this method is highly dependent on the timer + * implementation used. + */ + public long getElapsedMicros (); +} diff --git a/src/java/com/threerings/media/timer/SystemMediaTimer.java b/src/java/com/threerings/media/timer/SystemMediaTimer.java new file mode 100644 index 000000000..a81e931f2 --- /dev/null +++ b/src/java/com/threerings/media/timer/SystemMediaTimer.java @@ -0,0 +1,37 @@ +// +// $Id: SystemMediaTimer.java,v 1.1 2002/11/20 02:17:38 mdb Exp $ + +package com.threerings.media.timer; + +/** + * Implements the {@link MediaTimer} interface using {@link + * System#currentTimeMillis} to obtain timing information. + * + *
Note: {@link System#currentTimeMillis} is notoriously + * inaccurate on different platforms. See + * bug report 4486109 for more information. + */ +public class SystemMediaTimer implements MediaTimer +{ + // documentation inherited from interface + public void reset () + { + _resetStamp = System.currentTimeMillis(); + } + + // documentation inherited from interface + public long getElapsedMillis () + { + return System.currentTimeMillis() - _resetStamp; + } + + // documentation inherited from interface + public long getElapsedMicros () + { + return getElapsedMillis() * 10; + } + + /** The time at which this timer was last reset. */ + protected long _resetStamp = System.currentTimeMillis(); +}