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:
@@ -1,7 +1,10 @@
|
||||
package com.threerings.presents.client {
|
||||
|
||||
import flash.display.Stage;
|
||||
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.TimerEvent;
|
||||
|
||||
import flash.util.Timer;
|
||||
|
||||
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. */
|
||||
public static const DEFAULT_SERVER_PORT :int = 47624;
|
||||
|
||||
public function Client (creds :Credentials)
|
||||
public function Client (creds :Credentials, stage :Stage)
|
||||
{
|
||||
_creds = creds;
|
||||
_stage = stage;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,6 +90,14 @@ public class Client extends EventDispatcher
|
||||
_port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Stage object we're living in.
|
||||
*/
|
||||
public function getStage () :Stage
|
||||
{
|
||||
return _stage;
|
||||
}
|
||||
|
||||
public function getHostname () :String
|
||||
{
|
||||
return _hostname;
|
||||
@@ -258,7 +270,7 @@ public class Client extends EventDispatcher
|
||||
return;
|
||||
}
|
||||
|
||||
var now :Number = new Date().getTime();
|
||||
var now :uint = flash.util.getTimer();
|
||||
if (now - _comm.getLastWrite() > PingRequest.PING_INTERVAL) {
|
||||
_comm.postMessage(new PingRequest());
|
||||
}
|
||||
@@ -325,6 +337,9 @@ public class Client extends EventDispatcher
|
||||
/** The credentials we used to authenticate with the server. */
|
||||
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. */
|
||||
protected var _version :String = "";
|
||||
|
||||
|
||||
@@ -76,9 +76,8 @@ public class ClientDObjectMgr
|
||||
_flushInterval.addEventListener(TimerEvent.TIMER, flushObjects);
|
||||
_flushInterval.start();
|
||||
|
||||
_actionInterval = new Timer(500); //TODO!
|
||||
_actionInterval.addEventListener(TimerEvent.TIMER, processNextAction);
|
||||
//_actionInterval.start();
|
||||
client.getStage().addEventListener(
|
||||
Event.ENTER_FRAME, processNextAction);
|
||||
}
|
||||
|
||||
// documentation inherited from interface DObjectManager
|
||||
@@ -117,7 +116,6 @@ public class ClientDObjectMgr
|
||||
{
|
||||
// queue up an action
|
||||
_actions.push(new ObjectAction(oid, target, subscribe));
|
||||
_actionInterval.start();
|
||||
}
|
||||
|
||||
// inherit documentation from the interface
|
||||
@@ -181,22 +179,21 @@ public class ClientDObjectMgr
|
||||
{
|
||||
// append it to our queue
|
||||
_actions.push(msg);
|
||||
_actionInterval.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked on the main client thread to process any newly arrived
|
||||
* 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
|
||||
if (_actions.length == 0) {
|
||||
_actionInterval.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
var obj :Object = _actions.shift();
|
||||
Log.debug("processNextAction: " + obj);
|
||||
// do the proper thing depending on the object
|
||||
if (obj is BootstrapNotification) {
|
||||
_client.gotBootstrap(obj.getData(), this);
|
||||
@@ -455,7 +452,6 @@ public class ClientDObjectMgr
|
||||
|
||||
/** Flushes objects every now and again. */
|
||||
protected var _flushInterval :Timer;
|
||||
protected var _actionInterval :Timer;
|
||||
|
||||
/** Flush expired objects every 30 seconds. */
|
||||
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.
|
||||
*/
|
||||
internal function getLastWrite () :Number
|
||||
internal function getLastWrite () :uint
|
||||
{
|
||||
return _lastWrite;
|
||||
}
|
||||
@@ -135,7 +135,7 @@ public class Communicator
|
||||
*/
|
||||
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 _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
|
||||
* before the client sends a ping message to the server to let it
|
||||
* 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 ()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function getPackStamp () :Number
|
||||
public function getPackStamp () :uint
|
||||
{
|
||||
return _packStamp;
|
||||
}
|
||||
@@ -22,11 +22,11 @@ public class PingRequest extends UpstreamMessage
|
||||
// documentation inherited
|
||||
public override function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
_packStamp = new Date().getTime();
|
||||
_packStamp = flash.util.getTimer();
|
||||
super.writeObject(out);
|
||||
}
|
||||
|
||||
/** 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;
|
||||
}
|
||||
|
||||
public function getUnpackStamp () :Number
|
||||
public function getUnpackStamp () :uint
|
||||
{
|
||||
return _unpackStamp;
|
||||
}
|
||||
|
||||
public override function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
_unpackStamp = new Date().getTime();
|
||||
_unpackStamp = flash.util.getTimer();
|
||||
super.readObject(ins);
|
||||
|
||||
// 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 _unpackStamp :Number;
|
||||
protected var _unpackStamp :uint;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user