com.threerings.media.util
Class TimeFunction

java.lang.Object
  extended by com.threerings.media.util.TimeFunction
Direct Known Subclasses:
LinearTimeFunction

public abstract class TimeFunction
extends Object

Used to vary a value over time where time is provided at discrete increments (on the frame tick) and the value is computed appropriately.


Field Summary
protected  int _duration
          The number of milliseconds over which we vary our value.
protected  int _end
          Our starting and ending values.
protected  int _start
          Our starting and ending values.
protected  long _startStamp
          The timestamp at which we began varying our value.
 
Constructor Summary
TimeFunction(int start, int end, int duration)
          Every time function varies a value from some starting value to some ending value over some duration.
 
Method Summary
protected abstract  int computeValue(int dt)
          This must be implemented by our derived class to compute our value given the specified elapsed time (in millis).
 void fastForward(long timeDelta)
          Called to fast forward our time stamps if we are ever paused and need to resume where we left off.
 int getValue(long tickStamp)
          Returns the current value given the supplied time stamp.
 void init(long tickStamp)
          Configures this function with a starting time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_start

protected int _start
Our starting and ending values.


_end

protected int _end
Our starting and ending values.


_duration

protected int _duration
The number of milliseconds over which we vary our value.


_startStamp

protected long _startStamp
The timestamp at which we began varying our value.

Constructor Detail

TimeFunction

public TimeFunction(int start,
                    int end,
                    int duration)
Every time function varies a value from some starting value to some ending value over some duration. The way in which it varies (linearly, for example) is up to the derived class.

Note: it is assumed that we will operate with relatively short durations such that integer arithmetic may be used rather than long arithmetic.

Method Detail

init

public void init(long tickStamp)
Configures this function with a starting time. This method need not be called, and instead the first vall to getValue(long) will be used to obtain a starting time stamp.


fastForward

public void fastForward(long timeDelta)
Called to fast forward our time stamps if we are ever paused and need to resume where we left off.


getValue

public int getValue(long tickStamp)
Returns the current value given the supplied time stamp. The value will be bounded to the originally supplied starting and ending values at times 0 (and below) and _duration (and above) respectively.


computeValue

protected abstract int computeValue(int dt)
This must be implemented by our derived class to compute our value given the specified elapsed time (in millis).