Updated some bits.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4058 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-04-26 00:47:49 +00:00
parent 8d87138d2a
commit ad9a3e54e3
5 changed files with 31 additions and 20 deletions
@@ -1,7 +1,10 @@
package com.threerings.presents.client { package com.threerings.presents.client {
import flash.display.Stage;
import flash.events.EventDispatcher; import flash.events.EventDispatcher;
import flash.events.TimerEvent; import flash.events.TimerEvent;
import flash.util.Timer; import flash.util.Timer;
import com.threerings.util.ObserverList; import com.threerings.util.ObserverList;
@@ -23,9 +26,10 @@ public class Client extends EventDispatcher
/** The default port on which the server listens for client connections. */ /** The default port on which the server listens for client connections. */
public static const DEFAULT_SERVER_PORT :int = 47624; public static const DEFAULT_SERVER_PORT :int = 47624;
public function Client (creds :Credentials) public function Client (creds :Credentials, stage :Stage)
{ {
_creds = creds; _creds = creds;
_stage = stage;
} }
/** /**
@@ -86,6 +90,14 @@ public class Client extends EventDispatcher
_port = port; _port = port;
} }
/**
* @return the Stage object we're living in.
*/
public function getStage () :Stage
{
return _stage;
}
public function getHostname () :String public function getHostname () :String
{ {
return _hostname; return _hostname;
@@ -258,7 +270,7 @@ public class Client extends EventDispatcher
return; return;
} }
var now :Number = new Date().getTime(); var now :uint = flash.util.getTimer();
if (now - _comm.getLastWrite() > PingRequest.PING_INTERVAL) { if (now - _comm.getLastWrite() > PingRequest.PING_INTERVAL) {
_comm.postMessage(new PingRequest()); _comm.postMessage(new PingRequest());
} }
@@ -325,6 +337,9 @@ public class Client extends EventDispatcher
/** The credentials we used to authenticate with the server. */ /** The credentials we used to authenticate with the server. */
protected var _creds :Credentials; protected var _creds :Credentials;
/** The stage we're on, needed for creating the Communicator. */
protected var _stage :Stage;
/** The version string reported to the server at auth time. */ /** The version string reported to the server at auth time. */
protected var _version :String = ""; protected var _version :String = "";
@@ -76,9 +76,8 @@ public class ClientDObjectMgr
_flushInterval.addEventListener(TimerEvent.TIMER, flushObjects); _flushInterval.addEventListener(TimerEvent.TIMER, flushObjects);
_flushInterval.start(); _flushInterval.start();
_actionInterval = new Timer(500); //TODO! client.getStage().addEventListener(
_actionInterval.addEventListener(TimerEvent.TIMER, processNextAction); Event.ENTER_FRAME, processNextAction);
//_actionInterval.start();
} }
// documentation inherited from interface DObjectManager // documentation inherited from interface DObjectManager
@@ -117,7 +116,6 @@ public class ClientDObjectMgr
{ {
// queue up an action // queue up an action
_actions.push(new ObjectAction(oid, target, subscribe)); _actions.push(new ObjectAction(oid, target, subscribe));
_actionInterval.start();
} }
// inherit documentation from the interface // inherit documentation from the interface
@@ -181,22 +179,21 @@ public class ClientDObjectMgr
{ {
// append it to our queue // append it to our queue
_actions.push(msg); _actions.push(msg);
_actionInterval.start();
} }
/** /**
* Invoked on the main client thread to process any newly arrived * Invoked on the main client thread to process any newly arrived
* messages that we have waiting in our queue. * messages that we have waiting in our queue.
*/ */
public function processNextAction (event :TimerEvent) :void public function processNextAction () :void
{ {
// process the next event on our queue // process the next event on our queue
if (_actions.length == 0) { if (_actions.length == 0) {
_actionInterval.stop();
return; return;
} }
var obj :Object = _actions.shift(); var obj :Object = _actions.shift();
Log.debug("processNextAction: " + obj);
// do the proper thing depending on the object // do the proper thing depending on the object
if (obj is BootstrapNotification) { if (obj is BootstrapNotification) {
_client.gotBootstrap(obj.getData(), this); _client.gotBootstrap(obj.getData(), this);
@@ -455,7 +452,6 @@ public class ClientDObjectMgr
/** Flushes objects every now and again. */ /** Flushes objects every now and again. */
protected var _flushInterval :Timer; protected var _flushInterval :Timer;
protected var _actionInterval :Timer;
/** Flush expired objects every 30 seconds. */ /** Flush expired objects every 30 seconds. */
protected static const FLUSH_INTERVAL :Number = 30 * 1000; protected static const FLUSH_INTERVAL :Number = 30 * 1000;
@@ -125,7 +125,7 @@ public class Communicator
/** /**
* Returns the time at which we last sent a packet to the server. * Returns the time at which we last sent a packet to the server.
*/ */
internal function getLastWrite () :Number internal function getLastWrite () :uint
{ {
return _lastWrite; return _lastWrite;
} }
@@ -135,7 +135,7 @@ public class Communicator
*/ */
internal function updateWriteStamp () :void internal function updateWriteStamp () :void
{ {
_lastWrite = new Date().getTime(); _lastWrite = flash.util.getTimer();
} }
/** /**
@@ -216,6 +216,6 @@ public class Communicator
protected var _socket :Socket; protected var _socket :Socket;
protected var _lastWrite :Number; protected var _lastWrite :uint;
} }
} }
@@ -7,14 +7,14 @@ public class PingRequest extends UpstreamMessage
/** The number of milliseconds of idle upstream that are allowed to elapse /** The number of milliseconds of idle upstream that are allowed to elapse
* before the client sends a ping message to the server to let it * before the client sends a ping message to the server to let it
* know that we're still alive. */ * know that we're still alive. */
public static const PING_INTERVAL :int = 60 * 1000; public static const PING_INTERVAL :uint = 60 * 1000;
public function PingRequest () public function PingRequest ()
{ {
super(); super();
} }
public function getPackStamp () :Number public function getPackStamp () :uint
{ {
return _packStamp; return _packStamp;
} }
@@ -22,11 +22,11 @@ public class PingRequest extends UpstreamMessage
// documentation inherited // documentation inherited
public override function writeObject (out :ObjectOutputStream) :void public override function writeObject (out :ObjectOutputStream) :void
{ {
_packStamp = new Date().getTime(); _packStamp = flash.util.getTimer();
super.writeObject(out); super.writeObject(out);
} }
/** A time stamp obtained when we serialize this object. */ /** A time stamp obtained when we serialize this object. */
protected var _packStamp :Number; protected var _packStamp :uint;
} }
} }
@@ -23,14 +23,14 @@ public class PongResponse extends DownstreamMessage
return _processDelay; return _processDelay;
} }
public function getUnpackStamp () :Number public function getUnpackStamp () :uint
{ {
return _unpackStamp; return _unpackStamp;
} }
public override function readObject (ins :ObjectInputStream) :void public override function readObject (ins :ObjectInputStream) :void
{ {
_unpackStamp = new Date().getTime(); _unpackStamp = flash.util.getTimer();
super.readObject(ins); super.readObject(ins);
// TODO: Figure out how we're really going to cope with longs // TODO: Figure out how we're really going to cope with longs
@@ -44,6 +44,6 @@ public class PongResponse extends DownstreamMessage
protected var _processDelay :int; protected var _processDelay :int;
protected var _unpackStamp :Number; protected var _unpackStamp :uint;
} }
} }