Added support for pausing a media panel which pauses all sprites and

animations currently operating therein. (It doesn't pause scrolling which
I suppose I'll have to fix at some point if we ever need it.)


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1292 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-04-25 16:23:31 +00:00
parent 1ba123de96
commit 23d170c83e
11 changed files with 143 additions and 11 deletions
+39 -1
View File
@@ -1,5 +1,5 @@
//
// $Id: MediaPanel.java,v 1.2 2002/04/23 03:10:39 mdb Exp $
// $Id: MediaPanel.java,v 1.3 2002/04/25 16:23:30 mdb Exp $
package com.threerings.media;
@@ -131,6 +131,41 @@ public class MediaPanel extends JComponent
// ", millis=" + millis + "ms, mspp=" + mspp + "].");
}
/**
* Pauses the sprites and animations that are currently active on this
* media panel. Also stops listening to the frame tick while paused.
*/
public void setPaused (boolean paused)
{
// sanity check
if ((paused && (_pauseTime != 0)) ||
(!paused && (_pauseTime == 0))) {
Log.warning("Requested to pause when paused or vice-versa " +
"[paused=" + paused + "].");
return;
}
if (paused) {
// stop listening to the frame tick
_framemgr.removeFrameParticipant(this);
// make a note of our pause time
_pauseTime = System.currentTimeMillis();
} else {
// start listening to the frame tick once again
_framemgr.registerFrameParticipant(this);
// let the animation and sprite managers know that we just
// warped into the future
long delta = System.currentTimeMillis() - _pauseTime;
_animmgr.fastForward(delta);
_spritemgr.fastForward(delta);
// clear out our pause time
_pauseTime = 0;
}
}
/**
* Returns a reference to the region manager that is used to
* accumulate dirty regions each frame.
@@ -483,4 +518,7 @@ public class MediaPanel extends JComponent
/** Used to correlate tick()s with paint()s. */
protected boolean _tickPaintPending = false;
/** Used to track the clock time at which we were paused. */
protected long _pauseTime;
}
@@ -1,5 +1,5 @@
//
// $Id: Animation.java,v 1.5 2002/04/23 01:16:28 mdb Exp $
// $Id: Animation.java,v 1.6 2002/04/25 16:23:30 mdb Exp $
package com.threerings.media.animation;
@@ -75,6 +75,16 @@ public abstract class Animation
*/
public abstract void paint (Graphics2D gfx);
/**
* This is called if the animation manager is paused for some length
* of time and then unpaused. Animations should adjust any time stamps
* they are maintaining internally by the delta so that time maintains
* the illusion of flowing smoothly forward.
*/
public void fastForward (long timeDelta)
{
}
/**
* Returns true if the animation has finished all of its business,
* false if not.
@@ -1,5 +1,5 @@
//
// $Id: AnimationManager.java,v 1.9 2002/04/23 01:16:28 mdb Exp $
// $Id: AnimationManager.java,v 1.10 2002/04/25 16:23:30 mdb Exp $
package com.threerings.media.animation;
@@ -102,6 +102,22 @@ public class AnimationManager
}
}
/**
* If the animation manager is paused for some length of time, it
* should be fast forwarded by the appropriate number of milliseconds.
* This allows animations to smoothly pick up where they left off
* rather than abruptly jumping into the future, thinking that some
* outrageous amount of time passed since their last tick.
*/
public void fastForward (long timeDelta)
{
// fast forward all of our animations
int size = _anims.size();
for (int ii = 0; ii < size; ii++) {
((Animation)_anims.get(ii)).fastForward(timeDelta);
}
}
/**
* Renders all registered animations in the given layer that intersect
* the supplied clipping rectangle to the given graphics context.
@@ -1,5 +1,5 @@
//
// $Id: BobbleAnimation.java,v 1.3 2002/04/15 18:18:20 mdb Exp $
// $Id: BobbleAnimation.java,v 1.4 2002/04/25 16:23:30 mdb Exp $
package com.threerings.media.animation;
@@ -58,6 +58,12 @@ public class BobbleAnimation extends Animation
_y = (_sy + dy) * ((RandomUtil.getInt(2) == 0) ? -1 : 1);
}
// documentation inherited
public void fastForward (long timeDelta)
{
_end += timeDelta;
}
// documentation inherited
public void paint (Graphics2D gfx)
{
@@ -1,5 +1,5 @@
//
// $Id: ExplodeAnimation.java,v 1.7 2002/04/15 18:18:20 mdb Exp $
// $Id: ExplodeAnimation.java,v 1.8 2002/04/25 16:23:30 mdb Exp $
package com.threerings.media.animation;
@@ -134,6 +134,12 @@ public class ExplodeAnimation extends Animation
_start = timestamp;
}
// documentation inherited
public void fastForward (long timeDelta)
{
_start += timeDelta;
}
// documentation inherited
public void tick (long timestamp)
{
@@ -1,5 +1,5 @@
//
// $Id: FadeAnimation.java,v 1.3 2002/01/31 17:35:41 shaper Exp $
// $Id: FadeAnimation.java,v 1.4 2002/04/25 16:23:30 mdb Exp $
package com.threerings.media.animation;
@@ -76,6 +76,12 @@ public class FadeAnimation extends Animation
invalidate();
}
// documentation inherited
public void fastForward (long timeDelta)
{
_start += timeDelta;
}
// documentation inherited
public void paint (Graphics2D gfx)
{
@@ -1,5 +1,5 @@
//
// $Id: RainAnimation.java,v 1.3 2002/04/23 01:16:28 mdb Exp $
// $Id: RainAnimation.java,v 1.4 2002/04/25 16:23:30 mdb Exp $
package com.threerings.media.animation;
@@ -73,6 +73,12 @@ public class RainAnimation extends Animation
invalidate();
}
// documentation inherited
public void fastForward (long timeDelta)
{
_end += timeDelta;
}
// documentation inherited
public void paint (Graphics2D gfx)
{
@@ -1,5 +1,5 @@
//
// $Id: Sprite.java,v 1.42 2002/04/23 01:16:28 mdb Exp $
// $Id: Sprite.java,v 1.43 2002/04/25 16:23:30 mdb Exp $
package com.threerings.media.sprite;
@@ -336,6 +336,20 @@ public abstract class Sprite
}
}
/**
* This is called if the sprite manager is paused for some length of
* time and then unpaused. Sprites should adjust any time stamps they
* are maintaining internally by the delta so that time maintains the
* illusion of flowing smoothly forward.
*/
public void fastForward (long timeDelta)
{
// fast forward any path we're following
if (_path != null) {
_path.fastForward(timeDelta);
}
}
/**
* Updates the sprite's render offset which is used to determine
* where to place the top-left corner of the render bounds.
@@ -1,5 +1,5 @@
//
// $Id: SpriteManager.java,v 1.29 2002/04/23 01:16:28 mdb Exp $
// $Id: SpriteManager.java,v 1.30 2002/04/25 16:23:31 mdb Exp $
package com.threerings.media.sprite;
@@ -209,6 +209,22 @@ public class SpriteManager
handleSpriteEvents();
}
/**
* If the sprite manager is paused for some length of time, it should
* be fast forwarded by the appropriate number of milliseconds. This
* allows sprites to smoothly pick up where they left off rather than
* abruptly jumping into the future, thinking that some outrageous
* amount of time passed since their last tick.
*/
public void fastForward (long timeDelta)
{
int size = _sprites.size();
for (int ii = 0; ii < size; ii++) {
Sprite sprite = (Sprite)_sprites.get(ii);
sprite.fastForward(timeDelta);
}
}
/**
* Call {@link Sprite#tick} on all sprite objects to give them a
* chance to move themselves about, change their display image,
@@ -1,5 +1,5 @@
//
// $Id: LineSegmentPath.java,v 1.20 2002/04/16 20:38:24 mdb Exp $
// $Id: LineSegmentPath.java,v 1.21 2002/04/25 16:23:30 mdb Exp $
package com.threerings.media.sprite;
@@ -212,6 +212,12 @@ public class LineSegmentPath
return false;
}
// documentation inherited
public void fastForward (long timeDelta)
{
_nodestamp += timeDelta;
}
/**
* Place the sprite moving along the path at the end of the
* previous path node, face it appropriately for the next node,
+9 -1
View File
@@ -1,5 +1,5 @@
//
// $Id: Path.java,v 1.4 2002/04/23 01:16:28 mdb Exp $
// $Id: Path.java,v 1.5 2002/04/25 16:23:30 mdb Exp $
package com.threerings.media.sprite;
@@ -41,6 +41,14 @@ public interface Path
*/
public boolean updatePosition (Sprite sprite, long tickStamp);
/**
* This is called if the sprite manager is paused for some length of
* time and then unpaused. Paths should adjust any time stamps they
* are maintaining internally by the delta so that time maintains the
* illusion of flowing smoothly forward.
*/
public void fastForward (long timeDelta);
/**
* Sets the velocity of this sprite in pixels per millisecond. The
* velocity is measured as pixels traversed along the path that the