com.threerings.tudey.client.util
Class TimeSmoother

java.lang.Object
  extended by com.threerings.tudey.client.util.TimeSmoother

public class TimeSmoother
extends Object

Provides a continuous estimate of the current time (with millisecond precision) based on a series of discrete time updates, speeding up or slowing down (but never reversing) the local clock as necessary to stay in synch.


Field Summary
protected  long _delta
          The current estimated difference between the tracked time and the timer time.
protected  long _dstamp
          The timestamp of the current delta value.
protected  long _tdelta
          The target delta.
protected static float CONVERGENCE_RATE
          The exponential rate at which we approach our target delta.
 
Constructor Summary
TimeSmoother(int time)
          Creates a new smoother with the given initial clock value.
 
Method Summary
 int getTime()
          Returns the current smoothed time estimate.
 void update(int time)
          Updates the smoother with the current value of the clock being tracked.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_delta

protected long _delta
The current estimated difference between the tracked time and the timer time.


_tdelta

protected long _tdelta
The target delta.


_dstamp

protected long _dstamp
The timestamp of the current delta value.


CONVERGENCE_RATE

protected static final float CONVERGENCE_RATE
The exponential rate at which we approach our target delta.

Constructor Detail

TimeSmoother

public TimeSmoother(int time)
Creates a new smoother with the given initial clock value.

Method Detail

update

public void update(int time)
Updates the smoother with the current value of the clock being tracked.


getTime

public int getTime()
Returns the current smoothed time estimate.