com.threerings.media.util
Class BobblePath

java.lang.Object
  extended by com.threerings.media.util.BobblePath
All Implemented Interfaces:
Path
Direct Known Subclasses:
SmoothBobblePath

public class BobblePath
extends Object
implements Path

Bobble a Pathable.


Field Summary
protected  long _duration
          How long we'll bobble.
protected  int _dx
          The variance we will bobble around that initial position.
protected  int _dy
          The variance we will bobble around that initial position.
protected  long _nextMove
          The time at which we'll next update the position of the pathable.
protected  long _stopTime
          The time at which we'll stop pathin'.
protected  int _sx
          The initial position of the pathable.
protected  int _sy
          The initial position of the pathable.
protected  long _updateFreq
          How often we update the locations.
 
Constructor Summary
BobblePath(int dx, int dy, long duration)
          Construct a bobble path that updates as often as possible.
BobblePath(int dx, int dy, long duration, long updateFreq)
          Construct a bobble path.
 
Method Summary
 void fastForward(long timeDelta)
          This is called if the pathable is paused for some length of time and then unpaused.
 void init(Pathable pable, long tickstamp)
          Called once to let the path prepare itself for the process of animating the supplied pathable.
 void paint(Graphics2D gfx)
          Paint this path on the screen (used for debugging purposes only).
 void setUpdateFrequency(long freq)
          Set a new update frequency.
 void setVariance(int dx, int dy)
          Set the variance of bobblin' in each direction.
 void stop()
          Have the Pathable stop bobbling asap.
 boolean tick(Pathable pable, long tickStamp)
          Called to request that this path update the position of the specified pathable based on the supplied timestamp information.
protected  boolean updatePositionTo(Pathable pable, int x, int y)
          Update the position of the pathable or return false if it's already there.
 void wasRemoved(Pathable pable)
          When a path is removed from a pathable, whether that is because the path was completed or because it was replaced by another path, this method will be called to let the path know that it is no longer associated with this pathable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_sx

protected int _sx
The initial position of the pathable.


_sy

protected int _sy
The initial position of the pathable.


_dx

protected int _dx
The variance we will bobble around that initial position.


_dy

protected int _dy
The variance we will bobble around that initial position.


_duration

protected long _duration
How long we'll bobble.


_updateFreq

protected long _updateFreq
How often we update the locations.


_stopTime

protected long _stopTime
The time at which we'll stop pathin'.


_nextMove

protected long _nextMove
The time at which we'll next update the position of the pathable.

Constructor Detail

BobblePath

public BobblePath(int dx,
                  int dy,
                  long duration)
Construct a bobble path that updates as often as possible.

Parameters:
dx - the variance in the x direction.
dy - the variance in the y direction.
duration - the duration to bobble, or -1 to bobble until stop() is called.

BobblePath

public BobblePath(int dx,
                  int dy,
                  long duration,
                  long updateFreq)
Construct a bobble path.

Parameters:
dx - the variance in the x direction.
dy - the variance in the y direction.
duration - the duration to bobble, or -1 to bobble until stop() is called.
updateFreq - how often to update the Pathable's location.
Method Detail

setVariance

public void setVariance(int dx,
                        int dy)
Set the variance of bobblin' in each direction.


setUpdateFrequency

public void setUpdateFrequency(long freq)
Set a new update frequency.


stop

public void stop()
Have the Pathable stop bobbling asap.


init

public void init(Pathable pable,
                 long tickstamp)
Description copied from interface: Path
Called once to let the path prepare itself for the process of animating the supplied pathable. Path users should also call Path.tick(com.threerings.media.util.Pathable, long) after Path.init(com.threerings.media.util.Pathable, long) with the same initialization timestamp.

Specified by:
init in interface Path

tick

public boolean tick(Pathable pable,
                    long tickStamp)
Description copied from interface: Path
Called to request that this path update the position of the specified pathable based on the supplied timestamp information. A path should record its initial timestamp and determine the progress of the pathable along the path based on the time elapsed since the pathable began down the path.

Specified by:
tick in interface Path
Parameters:
pable - the pathable whose position should be updated.
tickStamp - the timestamp associated with this frame.
Returns:
true if the pathable's position was updated, false if the path determined that the pathable should not move at this time.

fastForward

public void fastForward(long timeDelta)
Description copied from interface: Path
This is called if the pathable 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.

Specified by:
fastForward in interface Path

paint

public void paint(Graphics2D gfx)
Description copied from interface: Path
Paint this path on the screen (used for debugging purposes only).

Specified by:
paint in interface Path

wasRemoved

public void wasRemoved(Pathable pable)
Description copied from interface: Path
When a path is removed from a pathable, whether that is because the path was completed or because it was replaced by another path, this method will be called to let the path know that it is no longer associated with this pathable.

Specified by:
wasRemoved in interface Path

updatePositionTo

protected boolean updatePositionTo(Pathable pable,
                                   int x,
                                   int y)
Update the position of the pathable or return false if it's already there.