Do things in a slightly more thread-safe manner (whatever that means).
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3148 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Client.java,v 1.49 2004/08/27 02:20:17 mdb Exp $
|
||||
// $Id: Client.java,v 1.50 2004/10/18 21:40:24 mdb Exp $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -418,10 +418,16 @@ public class Client
|
||||
|
||||
long now = RunAnywhere.currentTimeMillis();
|
||||
if (_dcalc != null) {
|
||||
// if we're syncing the clock, send another ping
|
||||
PingRequest req = new PingRequest();
|
||||
_comm.postMessage(req);
|
||||
_dcalc.sentPing(req);
|
||||
// if our current calculator is done, clear it out
|
||||
if (_dcalc.isDone()) {
|
||||
Log.debug("Time offset from server: " + _serverDelta + "ms.");
|
||||
_dcalc = null;
|
||||
} else {
|
||||
// otherwise, send another ping
|
||||
PingRequest req = new PingRequest();
|
||||
_comm.postMessage(req);
|
||||
_dcalc.sentPing(req);
|
||||
}
|
||||
|
||||
} else if (now - _comm.getLastWrite() > PingRequest.PING_INTERVAL) {
|
||||
// if we haven't sent anything over the network in a while, we
|
||||
@@ -575,13 +581,8 @@ public class Client
|
||||
// we update the delta after every receipt so as to immediately
|
||||
// obtain an estimate of the clock delta and then refine it as
|
||||
// more packets come in
|
||||
boolean done = _dcalc.gotPong(pong);
|
||||
_dcalc.gotPong(pong);
|
||||
_serverDelta = _dcalc.getTimeDelta();
|
||||
|
||||
if (done) {
|
||||
Log.debug("Time offset from server: " + _serverDelta + "ms.");
|
||||
_dcalc = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DeltaCalculator.java,v 1.6 2004/08/27 02:20:18 mdb Exp $
|
||||
// $Id: DeltaCalculator.java,v 1.7 2004/10/18 21:40:24 mdb Exp $
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -93,6 +93,15 @@ public class DeltaCalculator
|
||||
return _deltas[_deltas.length/2];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this calculator has enough data to compute a time
|
||||
* delta estimate. Stick a fork in it!
|
||||
*/
|
||||
public boolean isDone ()
|
||||
{
|
||||
return (_iter >= CLOCK_SYNC_PING_COUNT);
|
||||
}
|
||||
|
||||
/** The number of ping/pong iterations we've made. */
|
||||
protected int _iter;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user