com.threerings.media.animation
Class AnimationFrameSequencer.MultiFunction

java.lang.Object
  extended by com.threerings.media.animation.AnimationFrameSequencer.MultiFunction
All Implemented Interfaces:
AnimationFrameSequencer, FrameSequencer
Enclosing interface:
AnimationFrameSequencer

public static class AnimationFrameSequencer.MultiFunction
extends Object
implements AnimationFrameSequencer

A sequencer that can step through a series of frames in any order and speed and notify (via SequencedAnimationObserver) when specific frames are reached.


Nested Class Summary
protected static class AnimationFrameSequencer.MultiFunction.FrameReachedOp
          Used to dispatch SequencedAnimationObserver.frameReached(com.threerings.media.animation.Animation, long, int, int).
 
Nested classes/interfaces inherited from interface com.threerings.media.animation.AnimationFrameSequencer
AnimationFrameSequencer.MultiFunction
 
Nested classes/interfaces inherited from interface com.threerings.media.util.FrameSequencer
FrameSequencer.ConstantRate
 
Field Summary
protected  Animation _animation
          The animation that we're sequencing for.
protected  int _curIdx
          The current sequence index.
protected  long _delay
          Or a single delay for all frames.
protected  long[] _delays
          The corresponding delay for each frame, in ms.
protected  long _lastStamp
          The time at which we were last ticked.
protected  int _length
          The length of our animation sequence.
protected  boolean _loop
          Does the animation loop?
protected  boolean[] _marks
          Whether to send a FrameReachedEvent on a sequence index.
protected  boolean _resets
          Do we reset on init?
protected  int[] _sequence
          The sequence of frames to display.
 
Constructor Summary
AnimationFrameSequencer.MultiFunction(int[] sequence, long[] msPerFrame, boolean[] marks, boolean loop)
          Creates a fully-specified multifunction frame sequencer.
AnimationFrameSequencer.MultiFunction(int[] sequence, long msPerFrame, boolean loop)
          Creates the simplest multifunction frame sequencer.
 
Method Summary
protected  void checkNotify(long tickStamp)
          Check to see if we need to notify that we've reached a marked frame.
 void fastForward(long timeDelta)
          Called if the display is paused for some length of time and then unpaused.
protected  long getDelay(int index)
          Get the delay to use for the specified frame.
 int init(MultiFrameImage source)
          Called prior to the execution of an animation sequence (not necessarily immediately, so time stamps should be obtained in the first call to tick).
 void setAnimation(Animation anim)
          Called after init to set the animation.
 void setDelay(long msPerFrame)
          Set the delay to use.
 void setLength(int len)
          Set the length of the sequence we are to use, or 0 means set it to the length of the sequence array that we were constructed with.
 void setResetOnInit(boolean resets)
          Do we reset the animation on init?
 int tick(long tickStamp)
          Called every display frame, the frame sequencer should return the index of the animation frame that should be displayed during this tick.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_curIdx

protected int _curIdx
The current sequence index.


_length

protected int _length
The length of our animation sequence.


_resets

protected boolean _resets
Do we reset on init?


_sequence

protected int[] _sequence
The sequence of frames to display.


_delays

protected long[] _delays
The corresponding delay for each frame, in ms.


_delay

protected long _delay
Or a single delay for all frames.


_marks

protected boolean[] _marks
Whether to send a FrameReachedEvent on a sequence index.


_loop

protected boolean _loop
Does the animation loop?


_lastStamp

protected long _lastStamp
The time at which we were last ticked.


_animation

protected Animation _animation
The animation that we're sequencing for.

Constructor Detail

AnimationFrameSequencer.MultiFunction

public AnimationFrameSequencer.MultiFunction(int[] sequence,
                                             long msPerFrame,
                                             boolean loop)
Creates the simplest multifunction frame sequencer.

Parameters:
sequence - the ordering to display the frames.
msPerFrame - the number of ms to display each frame.
loop - if false, the sequencer will report the end of the animation after progressing through all of the frames once, otherwise it will loop indefinitely.

AnimationFrameSequencer.MultiFunction

public AnimationFrameSequencer.MultiFunction(int[] sequence,
                                             long[] msPerFrame,
                                             boolean[] marks,
                                             boolean loop)
Creates a fully-specified multifunction frame sequencer.

Parameters:
sequence - the ordering to display the frames.
msPerFrame - the number of ms to display each frame.
marks - if true for a frame, a FrameReachedEvent will be generated when that frame is reached.
loop - if false, the sequencer will report the end of the animation after progressing through all of the frames once, otherwise it will loop indefinitely.
Method Detail

setDelay

public void setDelay(long msPerFrame)
Set the delay to use.


setLength

public void setLength(int len)
Set the length of the sequence we are to use, or 0 means set it to the length of the sequence array that we were constructed with.


setResetOnInit

public void setResetOnInit(boolean resets)
Do we reset the animation on init? Default is true.


init

public int init(MultiFrameImage source)
Description copied from interface: FrameSequencer
Called prior to the execution of an animation sequence (not necessarily immediately, so time stamps should be obtained in the first call to tick).

Specified by:
init in interface FrameSequencer
Parameters:
source - the multi-frame image that is providing the animation frames.
Returns:
initial frame index

setAnimation

public void setAnimation(Animation anim)
Description copied from interface: AnimationFrameSequencer
Called after init to set the animation.

Specified by:
setAnimation in interface AnimationFrameSequencer

tick

public int tick(long tickStamp)
Description copied from interface: FrameSequencer
Called every display frame, the frame sequencer should return the index of the animation frame that should be displayed during this tick. If the sequencer returns -1, it is taken as an indication that the animation is finished and should be stopped.

Specified by:
tick in interface FrameSequencer

fastForward

public void fastForward(long timeDelta)
Description copied from interface: FrameSequencer
Called if the display is paused for some length of time and then unpaused. Sequencers should adjust any time stamps they are maintaining internally by the delta so that time maintains the illusion of flowing smoothly forward.

Specified by:
fastForward in interface FrameSequencer

getDelay

protected final long getDelay(int index)
Get the delay to use for the specified frame.


checkNotify

protected void checkNotify(long tickStamp)
Check to see if we need to notify that we've reached a marked frame.