From cec3ffe59deb8389186343524ec8c9f0029ae50e Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 2 Mar 2006 03:44:37 +0000 Subject: [PATCH] Fixed up some things and added streaming translations. I'm to the point where I need to go back to array streaming and straighten that out. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3905 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/io/ObjectInputStream.as | 20 +++++++++++++++++++ .../com/threerings/io/ObjectOutputStream.as | 20 ++++++++++++++++++- .../com/threerings/presents/client/Client.as | 8 +++++--- .../presents/client/ClientDObjectMgr.as | 5 ++--- .../presents/client/Communicator.as | 10 ++++++++++ 5 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/as/com/threerings/io/ObjectInputStream.as b/src/as/com/threerings/io/ObjectInputStream.as index 699257746..cd9170415 100644 --- a/src/as/com/threerings/io/ObjectInputStream.as +++ b/src/as/com/threerings/io/ObjectInputStream.as @@ -8,6 +8,8 @@ import flash.util.IDataInput; import com.threerings.util.ClassUtil; import com.threerings.util.SimpleMap; +import com.threerings.presents.Log; + public class ObjectInputStream { public function ObjectInputStream (source :IDataInput = null) @@ -26,6 +28,14 @@ public class ObjectInputStream _source = source; } + /** + * Add a translation that should be used when writing objects. + */ + public function addTranslation (oldName :String, newName :String) :void + { + _translations[oldName] = newName; + } + public function readObject () :Object //throws IOError { @@ -48,6 +58,12 @@ public class ObjectInputStream // read in the class metadata var cname :String = readUTF(); + Log.debug("read cname: " + cname); + // if we have a translation, use it + var tname :String = _translations[cname]; + if (tname != null) { + cname = tname; + } var streamer :Streamer = Streamer.getStreamerByJavaName(cname); cmap = new ClassMapping(code, cname, streamer); @@ -199,5 +215,9 @@ public class ObjectInputStream /** A map of short class code to ClassMapping info. */ protected var _classMap :Array = new Array(); + + /** An collection of class name translations to use when unserializing + * objects. */ + protected var _translations :SimpleMap = new SimpleMap(); } } diff --git a/src/as/com/threerings/io/ObjectOutputStream.as b/src/as/com/threerings/io/ObjectOutputStream.as index e1949b683..5b96b6ac9 100644 --- a/src/as/com/threerings/io/ObjectOutputStream.as +++ b/src/as/com/threerings/io/ObjectOutputStream.as @@ -15,6 +15,15 @@ public class ObjectOutputStream _targ = targ; } + /** + * Add a classname translation for rewriting the names of objects + * that we send to the server. + */ + public function addTranslation (oldName :String, newName :String) :void + { + _translations[oldName] = newName; + } + public function writeObject (obj :Object) :void //throws IOError { @@ -43,6 +52,12 @@ public class ObjectOutputStream // TODO: if _nextCode blows short, log an error + // see if there's a translation we should use + var tname :String = _translations[cname]; + if (tname != null) { + cname = tname; + } + writeShort(-cmap.code); writeUTF((streamer == null) ? cname : streamer.getJavaClassName()); @@ -183,7 +198,10 @@ public class ObjectOutputStream /** The streamer being used currently. */ protected var _streamer :Streamer; - /** A map of classname to ClassMapping inffaro. */ + /** A map of classname to ClassMapping info. */ protected var _classMap :SimpleMap = new SimpleMap(); + + /** A map of classname translations. */ + protected var _translations :SimpleMap = new SimpleMap(); } } diff --git a/src/as/com/threerings/presents/client/Client.as b/src/as/com/threerings/presents/client/Client.as index dfb985a73..91745f2a6 100644 --- a/src/as/com/threerings/presents/client/Client.as +++ b/src/as/com/threerings/presents/client/Client.as @@ -95,9 +95,9 @@ public class Client extends EventDispatcher public function getService (clazz :Class) :InvocationService { if (_bstrap != null) { - for each (var service :InvocationService in _bstrap.services) { - if (service is clazz) { - return service; + for each (var isvc :InvocationService in _bstrap.services.source) { + if (isvc is clazz) { + return isvc; } } } @@ -190,6 +190,8 @@ public class Client extends EventDispatcher _cloid = data.clientOid; _invdir.init(omgr, _cloid, this); + + Log.debug("TimeBaseService: " + requireService(TimeBaseService)); } /** diff --git a/src/as/com/threerings/presents/client/ClientDObjectMgr.as b/src/as/com/threerings/presents/client/ClientDObjectMgr.as index 5e52f529d..5e7eff757 100644 --- a/src/as/com/threerings/presents/client/ClientDObjectMgr.as +++ b/src/as/com/threerings/presents/client/ClientDObjectMgr.as @@ -298,8 +298,7 @@ public class ClientDObjectMgr _ocache[oid] = obj; // let the penders know that the object is available - var req :PendingRequest = _penders[oid]; - _penders[oid] = undefined; + var req :PendingRequest = (_penders.remove(oid) as PendingRequest); if (req == null) { Log.warning("Got object, but no one cares?! " + "[oid=" + oid + ", obj=" + obj + "]."); @@ -368,7 +367,7 @@ public class ClientDObjectMgr // otherwise we need to create a new request req = new PendingRequest(oid); req.addTarget(target); - _penders.put(oid, req); + _penders[oid] = req; // Log.info("Registering pending request [oid=" + oid + "]."); // and issue a request to get things rolling diff --git a/src/as/com/threerings/presents/client/Communicator.as b/src/as/com/threerings/presents/client/Communicator.as index 8b292afce..8eebf1dd8 100644 --- a/src/as/com/threerings/presents/client/Communicator.as +++ b/src/as/com/threerings/presents/client/Communicator.as @@ -50,9 +50,19 @@ public class Communicator inputFrameReceived); _inStream = new ObjectInputStream(); + addClassTranslations(); + _socket.connect(_client.getHostname(), _client.getPort()); } + private function addClassTranslations () :void + { + _inStream.addTranslation("com.threerings.presents.dobj.DSet$Entry", + "com.threerings.presents.dobj.DSetEntry"); + _outStream.addTranslation("com.threerings.presents.dobj.DSetEntry", + "com.threerings.presents.dobj.DSet$Entry"); + } + public function logoff () :void { if (_socket == null) {