com.threerings.presents.client
Class DeltaCalculator

java.lang.Object
  extended by com.threerings.presents.client.DeltaCalculator

public class DeltaCalculator
extends Object

Used to compute the client/server time delta, attempting to account for the network delay experienced when the server sends its current time to the client.


Field Summary
protected  long[] _deltas
          Client/server time delta estimates.
protected  int _iter
          The number of ping/pong iterations we've made.
protected  PingRequest _ping
          A reference to the most recently sent ping which we use to obtain the appropriate send stamp when we get the corresponding receive stamp.
protected static int CLOCK_SYNC_PING_COUNT
          The number of times we PING during clock sync to try to smooth out network jiggling.
 
Constructor Summary
DeltaCalculator()
          Constructs a delta calculator which is used to calculate the time delta between the client and server, accounting reasonably well for the delay introduced by sending a timestamp over the network from the server to the client.
 
Method Summary
 long getTimeDelta()
          Returns the best estimate client/server time-delta.
 boolean gotPong(PongResponse pong)
          Must be called when the pong response arrives back from the server.
 boolean isDone()
          Returns true if this calculator has enough data to compute a time delta estimate.
 void sentPing(PingRequest ping)
          Must be called when a ping message is sent to the server.
 boolean shouldSendPing()
          Should we send another ping?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_iter

protected int _iter
The number of ping/pong iterations we've made.


_deltas

protected long[] _deltas
Client/server time delta estimates.


_ping

protected PingRequest _ping
A reference to the most recently sent ping which we use to obtain the appropriate send stamp when we get the corresponding receive stamp.


CLOCK_SYNC_PING_COUNT

protected static final int CLOCK_SYNC_PING_COUNT
The number of times we PING during clock sync to try to smooth out network jiggling.

See Also:
Constant Field Values
Constructor Detail

DeltaCalculator

public DeltaCalculator()
Constructs a delta calculator which is used to calculate the time delta between the client and server, accounting reasonably well for the delay introduced by sending a timestamp over the network from the server to the client.

Method Detail

shouldSendPing

public boolean shouldSendPing()
Should we send another ping?


sentPing

public void sentPing(PingRequest ping)
Must be called when a ping message is sent to the server.


gotPong

public boolean gotPong(PongResponse pong)
Must be called when the pong response arrives back from the server.

Returns:
true if we've iterated sufficiently many times to establish a stable time delta estimate.

getTimeDelta

public long getTimeDelta()
Returns the best estimate client/server time-delta.


isDone

public boolean isDone()
Returns true if this calculator has enough data to compute a time delta estimate. Stick a fork in it!