From b82108eceab173db464709f4d7db209a85944818 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 10 May 2006 00:40:15 +0000 Subject: [PATCH] Streaming fixups on the path towards getting things working in beta3. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4105 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/crowd/data/PlaceObject.as | 12 +++--- src/as/com/threerings/io/ObjectInputStream.as | 4 +- src/as/com/threerings/io/Streamer.as | 17 +++++--- .../threerings/io/streamers/ArrayStreamer.as | 43 ++++++++++++------- .../com/threerings/presents/dobj/OidList.as | 14 ++---- 5 files changed, 50 insertions(+), 40 deletions(-) diff --git a/src/as/com/threerings/crowd/data/PlaceObject.as b/src/as/com/threerings/crowd/data/PlaceObject.as index 894875a31..4638d8aa7 100644 --- a/src/as/com/threerings/crowd/data/PlaceObject.as +++ b/src/as/com/threerings/crowd/data/PlaceObject.as @@ -183,9 +183,9 @@ public class PlaceObject extends DObject public override function writeObject (out :ObjectOutputStream) :void { super.writeObject(out); - out.writeField(occupants); - out.writeField(occupantInfo); - out.writeField(speakService); + out.writeObject(occupants); + out.writeObject(occupantInfo); + out.writeObject(speakService); } // documentation inherited @@ -193,9 +193,9 @@ public class PlaceObject extends DObject { super.readObject(ins); // TODO: this needs fixing! - occupants = (ins.readField(OidList) as OidList); - occupantInfo = (ins.readField(DSet) as DSet); - speakService = (ins.readField(SpeakMarshaller) as SpeakMarshaller); + occupants = (ins.readObject() as OidList); + occupantInfo = (ins.readObject() as DSet); + speakService = (ins.readObject() as SpeakMarshaller); } } } diff --git a/src/as/com/threerings/io/ObjectInputStream.as b/src/as/com/threerings/io/ObjectInputStream.as index 88e5dd136..a1ad22a5e 100644 --- a/src/as/com/threerings/io/ObjectInputStream.as +++ b/src/as/com/threerings/io/ObjectInputStream.as @@ -56,11 +56,11 @@ public class ObjectInputStream Log.warning("OMG, cannot stream " + cname); return null; } - Log.debug("Got streamer (" + streamer + ")"); +// Log.debug("Got streamer (" + streamer + ")"); cmap = new ClassMapping(code, cname, streamer); _classMap[code] = cmap; - Log.debug("Created mapping for (" + code + "): " + cname); +// Log.debug("Created mapping for (" + code + "): " + cname); } else { Log.debug("Read known code: " + code); diff --git a/src/as/com/threerings/io/Streamer.as b/src/as/com/threerings/io/Streamer.as index 5b03ffa89..008c25847 100644 --- a/src/as/com/threerings/io/Streamer.as +++ b/src/as/com/threerings/io/Streamer.as @@ -70,7 +70,7 @@ public class Streamer initStreamers(); // see if we have a streamer for it - Log.debug("getStreamer/existing"); +// Log.debug("getStreamer/existing"); for each (var streamer :Streamer in _streamers) { if (streamer.getJavaClassName() === jname) { return streamer; @@ -78,7 +78,7 @@ public class Streamer } // see if it's an array that we unstream using an ArrayStreamer - Log.debug("getStreamer/array"); +// Log.debug("getStreamer/array"); if (jname.charAt(0) === "[") { var streamer :Streamer = new ArrayStreamer(jname); _streamers.push(streamer); @@ -86,18 +86,21 @@ public class Streamer } // otherwise see if it represents a Streamable - Log.debug("getStreamer/Class:Streamable"); +// Log.debug("getStreamer/Class:Streamable"); var clazz :Class = ClassUtil.getClassByName( Translations.getFromServer(jname)); - Log.debug("getStreamer/Class:Streamable2"); +// Log.debug("getStreamer/Class:Streamable2"); if (ClassUtil.isAssignableAs(Streamable, clazz)) { return null; // it's streamable } - // TEMP: workaround for fucked-up bug!!! FUCK ACTIONSCRIPT! - if (clazz == StreamableArrayList) { - return null; // it's streamable, yes it is + // TEMP: workaround for fucked-up bug!!! + // The isAssignableAs (above) does not work right now, so we assume + // ALL classes are streamable, to get things working. + if (true) { + return null; } + // END: hacky temp return BAD_STREAMER; } diff --git a/src/as/com/threerings/io/streamers/ArrayStreamer.as b/src/as/com/threerings/io/streamers/ArrayStreamer.as index 7f86f8ec9..23f9bc23b 100644 --- a/src/as/com/threerings/io/streamers/ArrayStreamer.as +++ b/src/as/com/threerings/io/streamers/ArrayStreamer.as @@ -18,24 +18,27 @@ public class ArrayStreamer extends Streamer { super(TypedArray, jname); - if (jname.charAt(1) === "[") { + var secondChar :String = jname.charAt(1); + + if (secondChar === "[") { // if we're a multi-dimensional array then we need a delegate _delegate = Streamer.getStreamerByJavaName(jname.substring(1)); _isFinal = true; // it just is - } else { - if (jname.charAt(1) === "L") { - // form is "[L;" - var baseClass :String = jname.substring(2, jname.length - 1); - baseClass = Translations.getFromServer(baseClass); - _elementType = ClassUtil.getClassByName(baseClass); - _isFinal = ClassUtil.isFinal(_elementType); + } else if (secondChar === "L") { + // form is "[L;" + var baseClass :String = jname.substring(2, jname.length - 1); + baseClass = Translations.getFromServer(baseClass); + _elementType = ClassUtil.getClassByName(baseClass); + _isFinal = ClassUtil.isFinal(_elementType); - } else { - com.threerings.presents.Log.warning("Other array types are currently not handled yet " + - "[jname=" + jname + "]."); - throw new Error("Unimplemented bit"); - } + } else if (secondChar === "I") { + _elementType = int; + + } else { + com.threerings.presents.Log.warning("Other array types are " + + "currently not handled yet [jname=" + jname + "]."); + throw new Error("Unimplemented bit"); } } @@ -57,7 +60,12 @@ public class ArrayStreamer extends Streamer { var arr :Array = (obj as Array); out.writeInt(arr.length); - if (_isFinal) { + if (_elementType == int) { + for (var ii :int = 0; ii < arr.length; ii++) { + out.writeInt(arr[ii] as int); + } + + } else if (_isFinal) { var mask :ArrayMask = new ArrayMask(arr.length); for (var ii :int = 0; ii < arr.length; ii++) { if (arr[ii] != null) { @@ -84,7 +92,12 @@ public class ArrayStreamer extends Streamer :void { var arr :Array = (obj as Array); - if (_isFinal) { + if (_elementType == int) { + for (var ii :int = 0; ii < arr.length; ii++) { + arr[ii] = ins.readInt(); + } + + } else if (_isFinal) { var mask :ArrayMask = new ArrayMask(); mask.readFrom(ins); for (var ii :int = 0; ii < length; ii++) { diff --git a/src/as/com/threerings/presents/dobj/OidList.as b/src/as/com/threerings/presents/dobj/OidList.as index e420547c3..38b6eb605 100644 --- a/src/as/com/threerings/presents/dobj/OidList.as +++ b/src/as/com/threerings/presents/dobj/OidList.as @@ -4,6 +4,7 @@ import com.threerings.io.Streamable; import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; +import com.threerings.io.TypedArray; import com.threerings.util.StringBuilder; @@ -23,7 +24,7 @@ public class OidList */ public function OidList () { - _oids = new Array(); + _oids = new TypedArray("[I"); } /** @@ -107,16 +108,9 @@ public class OidList // documentation inherited from interface Streamable public function readObject (ins :ObjectInputStream) :void { - // TODO: this is some custom shit. We need to work out array streaming - _oids = new Array(); - var ecount :int = ins.readInt(); - for (var ii :int = 0; ii < ecount; ii++) { - _oids.push(ins.readInt()); - } - _oids.length = ins.readInt(); // then, limit the length to the size + _oids = (ins.readField("[I") as TypedArray); } - public function toString () :String { var buf :StringBuilder = new StringBuilder(); @@ -126,6 +120,6 @@ public class OidList return buf.toString(); } - private var _oids :Array; + private var _oids :TypedArray; } }