Use ObserverList; provide timestamp to animation events.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1905 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-11-05 20:51:50 +00:00
parent 144cf2299a
commit 400b8ca638
2 changed files with 32 additions and 15 deletions
@@ -1,5 +1,5 @@
// //
// $Id: AnimationFrameSequencer.java,v 1.2 2002/09/30 06:18:46 shaper Exp $ // $Id: AnimationFrameSequencer.java,v 1.3 2002/11/05 20:51:50 mdb Exp $
package com.threerings.media.animation; package com.threerings.media.animation;
@@ -100,7 +100,8 @@ public interface AnimationFrameSequencer extends FrameSequencer
// obtain our starting timestamp if we don't already have one // obtain our starting timestamp if we don't already have one
if (_nextStamp == 0L) { if (_nextStamp == 0L) {
_nextStamp = tickStamp + _delays[_curIdx]; _nextStamp = tickStamp + _delays[_curIdx];
checkNotify(); // we might need to notify on the first frame // we might need to notify on the first frame
checkNotify(tickStamp);
} }
// we may have rushed through more than one frame since the last // we may have rushed through more than one frame since the last
@@ -114,7 +115,7 @@ public interface AnimationFrameSequencer extends FrameSequencer
return -1; return -1;
} }
} }
checkNotify(); checkNotify(tickStamp);
_nextStamp += _delays[_curIdx]; _nextStamp += _delays[_curIdx];
} }
@@ -132,12 +133,12 @@ public interface AnimationFrameSequencer extends FrameSequencer
/** /**
* Check to see if we need to notify that we've reached a marked frame. * Check to see if we need to notify that we've reached a marked frame.
*/ */
protected void checkNotify () protected void checkNotify (long tickStamp)
{ {
if (_marks[_curIdx]) { if (_marks[_curIdx]) {
_animation.notifyObservers( _animation.notifyObservers(
new FrameReachedEvent( new FrameReachedEvent(
_animation, _sequence[_curIdx], _curIdx)); _animation, tickStamp, _sequence[_curIdx], _curIdx));
} }
} }
@@ -1,11 +1,9 @@
// //
// $Id: AnimationManager.java,v 1.14 2002/10/08 21:03:37 ray Exp $ // $Id: AnimationManager.java,v 1.15 2002/11/05 20:51:50 mdb Exp $
package com.threerings.media.animation; package com.threerings.media.animation;
import java.util.ArrayList; import com.samskivert.util.ObserverList;
import com.samskivert.util.SortableArrayList;
import com.threerings.media.AbstractMediaManager; import com.threerings.media.AbstractMediaManager;
import com.threerings.media.Log; import com.threerings.media.Log;
@@ -57,7 +55,8 @@ public class AnimationManager extends AbstractMediaManager
Animation anim = (Animation)_media.get(ii); Animation anim = (Animation)_media.get(ii);
if (anim.isFinished()) { if (anim.isFinished()) {
// let any animation observers know that we're done // let any animation observers know that we're done
anim.notifyObservers(new AnimationCompletedEvent(anim)); anim.notifyObservers(
new AnimationCompletedEvent(anim, tickStamp));
// un-register the animation // un-register the animation
unregisterAnimation(anim); unregisterAnimation(anim);
// let the animation clean itself up as necessary // let the animation clean itself up as necessary
@@ -68,11 +67,28 @@ public class AnimationManager extends AbstractMediaManager
} }
// documentation inherited // documentation inherited
protected void dispatchEvent (ArrayList observers, Object event) protected void dispatchEvent (ObserverList observers, Object event)
{ {
AnimationEvent aevt = (AnimationEvent) event; _dispatchOp.init((AnimationEvent)event);
for (int ii=0, nn=observers.size(); ii < nn; ii++) { observers.apply(_dispatchOp);
((AnimationObserver) observers.get(ii)).handleEvent(aevt);
}
} }
/** Used by {@link #dispatchEvent}. */
protected static class DispatchOp implements ObserverList.ObserverOp
{
public void init (AnimationEvent event)
{
_event = event;
}
public boolean apply (Object observer)
{
((AnimationObserver)observer).handleEvent(_event);
return true;
}
protected AnimationEvent _event;
};
protected DispatchOp _dispatchOp = new DispatchOp();
} }