Further clean up. We love helper classes.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1911 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-11-05 21:17:32 +00:00
parent da1119b61a
commit f3fd0744ec
@@ -1,5 +1,5 @@
// //
// $Id: AnimationSequencer.java,v 1.3 2002/11/05 21:12:55 mdb Exp $ // $Id: AnimationSequencer.java,v 1.4 2002/11/05 21:17:32 mdb Exp $
package com.threerings.media.animation; package com.threerings.media.animation;
@@ -93,33 +93,21 @@ public abstract class AnimationSequencer extends Animation
// add all animations whose time has come // add all animations whose time has come
while (_queued.size() > 0) { while (_queued.size() > 0) {
AnimRecord arec = (AnimRecord)_queued.get(0); AnimRecord arec = (AnimRecord)_queued.get(0);
if (!arec.readyToFire(tickStamp, _lastStamp)) {
if (arec.readyToFire(tickStamp, _lastStamp)) { // if it's not time to add this animation, all subsequent
// remove it from the queued list and put it on the // animations must surely wait as well
// running list
_queued.remove(0);
_running.add(arec);
// note that we've advanced to the next animation
_lastStamp = tickStamp;
// Log.info("Adding animation [anim=" + arec.anim +
// ", tickStamp=" + tickStamp + "].");
if (arec.anim != null) {
addAnimation(arec.anim, tickStamp);
arec.anim.addAnimationObserver(arec);
} else {
// since there's no animation, we need to fire this
// record's animation completion routine immediately
arec.fireCompletion(tickStamp);
}
} else {
// it's not time to add this animation, and so all
// subsequent animations must surely wait as well
break; break;
} }
// remove it from queued and put it on the running list
_queued.remove(0);
_running.add(arec);
// note that we've advanced to the next animation
_lastStamp = tickStamp;
// fire in the hole!
arec.fire(tickStamp);
} }
// we're done when both lists are empty // we're done when both lists are empty
@@ -154,14 +142,13 @@ public abstract class AnimationSequencer extends Animation
protected class AnimRecord protected class AnimRecord
implements AnimationObserver implements AnimationObserver
{ {
public Animation anim;
public long delta; public long delta;
public AnimRecord dependent; public AnimRecord dependent;
public AnimRecord ( public AnimRecord (
Animation anim, long delta, Runnable completionAction) Animation anim, long delta, Runnable completionAction)
{ {
this.anim = anim; _anim = anim;
this.delta = delta; this.delta = delta;
_completionAction = completionAction; _completionAction = completionAction;
} }
@@ -171,6 +158,24 @@ public abstract class AnimationSequencer extends Animation
return (delta != -1) && (lastStamp + delta >= now); return (delta != -1) && (lastStamp + delta >= now);
} }
public void fire (long when)
{
// Log.info("Firing animation [anim=" + anim +
// ", tickStamp=" + tickStamp + "].");
// if we have an animation, start it up and await its
// completion
if (_anim != null) {
addAnimation(_anim, when);
_anim.addAnimationObserver(this);
} else {
// since there's no animation, we need to fire our
// completion routine immediately
fireCompletion(when);
}
}
public void fireCompletion (long when) public void fireCompletion (long when)
{ {
// call the completion action, if there is one // call the completion action, if there is one
@@ -208,6 +213,7 @@ public abstract class AnimationSequencer extends Animation
} }
} }
protected Animation _anim;
protected Runnable _completionAction; protected Runnable _completionAction;
} }