System.currentTimeMillis() begone! We use our own pluggable timer system
now (which uses System.currentTimeMillis() at the moment but eventually won't). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1968 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: FrameManager.java,v 1.20 2002/11/16 00:15:57 mdb Exp $
|
// $Id: FrameManager.java,v 1.21 2002/11/20 02:18:49 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media;
|
package com.threerings.media;
|
||||||
|
|
||||||
@@ -34,6 +34,7 @@ import com.samskivert.util.IntervalManager;
|
|||||||
import com.samskivert.util.ObserverList;
|
import com.samskivert.util.ObserverList;
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
|
import com.threerings.media.timer.MediaTimer;
|
||||||
import com.threerings.media.util.PerformanceMonitor;
|
import com.threerings.media.util.PerformanceMonitor;
|
||||||
import com.threerings.media.util.PerformanceObserver;
|
import com.threerings.media.util.PerformanceObserver;
|
||||||
|
|
||||||
@@ -101,10 +102,11 @@ public class FrameManager
|
|||||||
*
|
*
|
||||||
* @see GraphicsDevice#setFullScreenWindow
|
* @see GraphicsDevice#setFullScreenWindow
|
||||||
*/
|
*/
|
||||||
public FrameManager (Frame frame)
|
public FrameManager (Frame frame, MediaTimer timer)
|
||||||
{
|
{
|
||||||
_frame = frame;
|
_frame = frame;
|
||||||
_frame.setIgnoreRepaint(true);
|
_frame.setIgnoreRepaint(true);
|
||||||
|
_timer = timer;
|
||||||
|
|
||||||
// set up our custom repaint manager
|
// set up our custom repaint manager
|
||||||
_remgr = new FrameRepaintManager(_frame);
|
_remgr = new FrameRepaintManager(_frame);
|
||||||
@@ -149,14 +151,24 @@ public class FrameManager
|
|||||||
_participants.remove(participant);
|
_participants.remove(participant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a millisecond granularity time stamp using the {@link
|
||||||
|
* MediaTimer} with which this frame manager was configured.
|
||||||
|
* <em>Note:</em> this should only be called from the AWT thread.
|
||||||
|
*/
|
||||||
|
public long getTimeStamp ()
|
||||||
|
{
|
||||||
|
return _timer.getElapsedMillis();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts up the per-frame tick
|
* Starts up the per-frame tick
|
||||||
*/
|
*/
|
||||||
public void start ()
|
public void start ()
|
||||||
{
|
{
|
||||||
if (_timer == null) {
|
if (_ticker == null) {
|
||||||
_timer = new Timer(true);
|
_ticker = new Timer(true);
|
||||||
_timer.scheduleAtFixedRate(_callTick, new Date(), _millisPerFrame);
|
_ticker.scheduleAtFixedRate(_callTick, new Date(), _millisPerFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,9 +177,9 @@ public class FrameManager
|
|||||||
*/
|
*/
|
||||||
public synchronized void stop ()
|
public synchronized void stop ()
|
||||||
{
|
{
|
||||||
if (_timer != null) {
|
if (_ticker != null) {
|
||||||
_timer.cancel();
|
_ticker.cancel();
|
||||||
_timer = null;
|
_ticker = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +189,7 @@ public class FrameManager
|
|||||||
*/
|
*/
|
||||||
public synchronized boolean isRunning ()
|
public synchronized boolean isRunning ()
|
||||||
{
|
{
|
||||||
return (_timer != null);
|
return (_ticker != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -527,6 +539,9 @@ public class FrameManager
|
|||||||
/** The frame into which we do our rendering. */
|
/** The frame into which we do our rendering. */
|
||||||
protected Frame _frame;
|
protected Frame _frame;
|
||||||
|
|
||||||
|
/** Used to obtain timing measurements. */
|
||||||
|
protected MediaTimer _timer;
|
||||||
|
|
||||||
/** Our custom repaint manager. */
|
/** Our custom repaint manager. */
|
||||||
protected FrameRepaintManager _remgr;
|
protected FrameRepaintManager _remgr;
|
||||||
|
|
||||||
@@ -541,7 +556,7 @@ public class FrameManager
|
|||||||
protected long _millisPerFrame = 14;
|
protected long _millisPerFrame = 14;
|
||||||
|
|
||||||
/** The timer that dispatches our frame ticks. */
|
/** The timer that dispatches our frame ticks. */
|
||||||
protected Timer _timer;
|
protected Timer _ticker;
|
||||||
|
|
||||||
/** Used to detect when we need to drop frames. */
|
/** Used to detect when we need to drop frames. */
|
||||||
protected boolean _ticking;
|
protected boolean _ticking;
|
||||||
@@ -564,7 +579,7 @@ public class FrameManager
|
|||||||
protected TimerTask _callTick = new TimerTask () {
|
protected TimerTask _callTick = new TimerTask () {
|
||||||
public void run () {
|
public void run () {
|
||||||
if (EventQueue.isDispatchThread()) {
|
if (EventQueue.isDispatchThread()) {
|
||||||
tick(System.currentTimeMillis());
|
tick(_timer.getElapsedMillis());
|
||||||
} else if (!isTicking()) {
|
} else if (!isTicking()) {
|
||||||
EventQueue.invokeLater(this);
|
EventQueue.invokeLater(this);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: MediaPanel.java,v 1.21 2002/10/29 20:33:51 shaper Exp $
|
// $Id: MediaPanel.java,v 1.22 2002/11/20 02:18:49 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media;
|
package com.threerings.media;
|
||||||
|
|
||||||
@@ -93,12 +93,12 @@ public class MediaPanel extends JComponent
|
|||||||
|
|
||||||
if (_paused = paused) {
|
if (_paused = paused) {
|
||||||
// make a note of our pause time
|
// make a note of our pause time
|
||||||
_pauseTime = System.currentTimeMillis();
|
_pauseTime = _framemgr.getTimeStamp();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// let the animation and sprite managers know that we just
|
// let the animation and sprite managers know that we just
|
||||||
// warped into the future
|
// warped into the future
|
||||||
long delta = System.currentTimeMillis() - _pauseTime;
|
long delta = _framemgr.getTimeStamp() - _pauseTime;
|
||||||
_animmgr.fastForward(delta);
|
_animmgr.fastForward(delta);
|
||||||
_spritemgr.fastForward(delta);
|
_spritemgr.fastForward(delta);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: BobbleAnimation.java,v 1.4 2002/04/25 16:23:30 mdb Exp $
|
// $Id: BobbleAnimation.java,v 1.5 2002/11/20 02:18:49 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.animation;
|
package com.threerings.media.animation;
|
||||||
|
|
||||||
@@ -26,10 +26,10 @@ public class BobbleAnimation extends Animation
|
|||||||
* @param sy the starting y-position.
|
* @param sy the starting y-position.
|
||||||
* @param rx the horizontal bobble range.
|
* @param rx the horizontal bobble range.
|
||||||
* @param ry the vertical bobble range.
|
* @param ry the vertical bobble range.
|
||||||
* @param length the time to animate in milliseconds.
|
* @param duration the time to animate in milliseconds.
|
||||||
*/
|
*/
|
||||||
public BobbleAnimation (
|
public BobbleAnimation (
|
||||||
Image image, int sx, int sy, int rx, int ry, int length)
|
Image image, int sx, int sy, int rx, int ry, int duration)
|
||||||
{
|
{
|
||||||
super(new Rectangle(sx - rx, sy - ry, sx + image.getWidth(null) + rx,
|
super(new Rectangle(sx - rx, sy - ry, sx + image.getWidth(null) + rx,
|
||||||
sy + image.getHeight(null) + ry));
|
sy + image.getHeight(null) + ry));
|
||||||
@@ -42,13 +42,18 @@ public class BobbleAnimation extends Animation
|
|||||||
_ry = ry;
|
_ry = ry;
|
||||||
|
|
||||||
// calculate animation ending time
|
// calculate animation ending time
|
||||||
_end = System.currentTimeMillis() + length;
|
_duration = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public void tick (long timestamp)
|
public void tick (long tickStamp)
|
||||||
{
|
{
|
||||||
_finished = (timestamp >= _end);
|
// grab our ending time on our first tick
|
||||||
|
if (_end == 0L) {
|
||||||
|
_end = tickStamp + _duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
_finished = (tickStamp >= _end);
|
||||||
invalidate();
|
invalidate();
|
||||||
|
|
||||||
// calculate the latest position
|
// calculate the latest position
|
||||||
@@ -95,6 +100,6 @@ public class BobbleAnimation extends Animation
|
|||||||
/** The image to animate. */
|
/** The image to animate. */
|
||||||
protected Image _image;
|
protected Image _image;
|
||||||
|
|
||||||
/** The ending animation time. */
|
/** Animation ending timing information. */
|
||||||
protected long _end;
|
protected long _duration, _end;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: RainAnimation.java,v 1.4 2002/04/25 16:23:30 mdb Exp $
|
// $Id: RainAnimation.java,v 1.5 2002/11/20 02:18:49 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.animation;
|
package com.threerings.media.animation;
|
||||||
|
|
||||||
@@ -19,32 +19,32 @@ public class RainAnimation extends Animation
|
|||||||
* of raindrops and their dimensions.
|
* of raindrops and their dimensions.
|
||||||
*
|
*
|
||||||
* @param bounds the bounding rectangle for the animation.
|
* @param bounds the bounding rectangle for the animation.
|
||||||
* @param delay the number of seconds the animation should last.
|
* @param duration the number of seconds the animation should last.
|
||||||
*/
|
*/
|
||||||
public RainAnimation (Rectangle bounds, long delay)
|
public RainAnimation (Rectangle bounds, long duration)
|
||||||
{
|
{
|
||||||
super(bounds);
|
super(bounds);
|
||||||
|
|
||||||
init(delay, DEFAULT_COUNT, DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
init(duration, DEFAULT_COUNT, DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a rain animation.
|
* Constructs a rain animation.
|
||||||
*
|
*
|
||||||
* @param bounds the bounding rectangle for the animation.
|
* @param bounds the bounding rectangle for the animation.
|
||||||
* @param delay the number of seconds the animation should last.
|
* @param duration the number of seconds the animation should last.
|
||||||
* @param count the number of raindrops to render in each frame.
|
* @param count the number of raindrops to render in each frame.
|
||||||
* @param wid the width of a raindrop's bounding rectangle.
|
* @param wid the width of a raindrop's bounding rectangle.
|
||||||
* @param hei the height of a raindrop's bounding rectangle.
|
* @param hei the height of a raindrop's bounding rectangle.
|
||||||
*/
|
*/
|
||||||
public RainAnimation (
|
public RainAnimation (
|
||||||
Rectangle bounds, long delay, int count, int wid, int hei)
|
Rectangle bounds, long duration, int count, int wid, int hei)
|
||||||
{
|
{
|
||||||
super(bounds);
|
super(bounds);
|
||||||
init(delay, count, wid, hei);
|
init(duration, count, wid, hei);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void init (long delay, int count, int wid, int hei)
|
protected void init (long duration, int count, int wid, int hei)
|
||||||
{
|
{
|
||||||
// save things off
|
// save things off
|
||||||
_count = count;
|
_count = count;
|
||||||
@@ -55,13 +55,18 @@ public class RainAnimation extends Animation
|
|||||||
_drops = new int[count];
|
_drops = new int[count];
|
||||||
|
|
||||||
// calculate ending time
|
// calculate ending time
|
||||||
_end = System.currentTimeMillis() + delay;
|
_duration = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public void tick (long timestamp)
|
public void tick (long tickStamp)
|
||||||
{
|
{
|
||||||
_finished = (timestamp >= _end);
|
// grab our ending time on our first tick
|
||||||
|
if (_end == 0L) {
|
||||||
|
_end = tickStamp + _duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
_finished = (tickStamp >= _end);
|
||||||
|
|
||||||
// calculate the latest raindrop locations
|
// calculate the latest raindrop locations
|
||||||
for (int ii = 0; ii < _count; ii++) {
|
for (int ii = 0; ii < _count; ii++) {
|
||||||
@@ -106,6 +111,6 @@ public class RainAnimation extends Animation
|
|||||||
/** The raindrop locations. */
|
/** The raindrop locations. */
|
||||||
protected int[] _drops;
|
protected int[] _drops;
|
||||||
|
|
||||||
/** The ending animation time. */
|
/** Animation ending timing information. */
|
||||||
protected long _end;
|
protected long _duration, _end;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
//
|
//
|
||||||
// $Id: PerformanceMonitor.java,v 1.4 2002/04/23 01:16:28 mdb Exp $
|
// $Id: PerformanceMonitor.java,v 1.5 2002/11/20 02:18:49 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media.util;
|
package com.threerings.media.util;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import com.threerings.media.Log;
|
import com.threerings.media.Log;
|
||||||
|
import com.threerings.media.timer.MediaTimer;
|
||||||
|
import com.threerings.media.timer.SystemMediaTimer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a simple mechanism for monitoring the number of times an
|
* Provides a simple mechanism for monitoring the number of times an
|
||||||
@@ -112,8 +114,27 @@ public class PerformanceMonitor
|
|||||||
action.tick();
|
action.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to configure the performance monitor with a particular {@link
|
||||||
|
* MediaTimer} implementation. By default it uses a pure-Java
|
||||||
|
* implementation which isn't extremely accurate across platforms.
|
||||||
|
*/
|
||||||
|
public static void setMediaTimer (MediaTimer timer)
|
||||||
|
{
|
||||||
|
_timer = timer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Used by the performance actions. */
|
||||||
|
protected synchronized static long getTimeStamp ()
|
||||||
|
{
|
||||||
|
return _timer.getElapsedMillis();
|
||||||
|
}
|
||||||
|
|
||||||
/** The observers monitoring some set of actions. */
|
/** The observers monitoring some set of actions. */
|
||||||
protected static HashMap _observers = new HashMap();
|
protected static HashMap _observers = new HashMap();
|
||||||
|
|
||||||
|
/** Used to obtain high resolution time stamps. */
|
||||||
|
protected static MediaTimer _timer = new SystemMediaTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,14 +148,14 @@ class PerformanceAction
|
|||||||
_obs = obs;
|
_obs = obs;
|
||||||
_name = name;
|
_name = name;
|
||||||
_delta = delta;
|
_delta = delta;
|
||||||
_lastDelta = System.currentTimeMillis();
|
_lastDelta = PerformanceMonitor.getTimeStamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick ()
|
public void tick ()
|
||||||
{
|
{
|
||||||
_numTicks++;
|
_numTicks++;
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
long now = PerformanceMonitor.getTimeStamp();
|
||||||
long passed = now - _lastDelta;
|
long passed = now - _lastDelta;
|
||||||
if (passed >= _delta) {
|
if (passed >= _delta) {
|
||||||
// update the last checkpoint time
|
// update the last checkpoint time
|
||||||
|
|||||||
Reference in New Issue
Block a user