Rebuilt various bits using the code generator. Annotated some Java sources

along the way.


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@99 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2006-10-05 21:00:38 +00:00
parent 0ecfaac648
commit 1ad2584a17
10 changed files with 285 additions and 218 deletions
@@ -23,6 +23,8 @@ package com.threerings.whirled.spot.data {
import flash.geom.Rectangle;
import com.threerings.util.Hashable;
import com.threerings.io.Streamable;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
@@ -33,38 +35,23 @@ import com.threerings.presents.dobj.DSet_Entry;
* Contains information on clusters.
*/
public class Cluster extends Rectangle
implements DSet_Entry, Streamable
implements DSet_Entry, Streamable /*, Hashable */
{
/** A unique identifier for this cluster (also the distributed object
* id of the cluster chat object). */
public var clusterOid :int;
// documentation inherited from interface DSet_Entry
public function getKey () :Object
public function Cluster ()
{
// nothing needed
}
// documentation inherited
public function hashCode () :int
{
return clusterOid;
}
// documentation inherited from interface Streamable
public function writeObject (out :ObjectOutputStream) :void
{
out.writeInt(x);
out.writeInt(y);
out.writeInt(width);
out.writeInt(height);
out.writeInt(clusterOid);
}
// documentation inherited from interface Streamable
public function readObject (ins :ObjectInputStream) :void
{
x = ins.readInt();
y = ins.readInt();
width = ins.readInt();
height = ins.readInt();
clusterOid = ins.readInt();
}
/**
* Generates a string representation of this instance.
*/
@@ -72,5 +59,26 @@ public class Cluster extends Rectangle
{
return super.toString() + ", clusterOid=" + clusterOid;
}
// documentation inherited from interface DSet_Entry
public function getKey () :Object
{
return clusterOid;
}
// documentation inherited from interface Streamable
public function readObject (ins :ObjectInputStream) :void
{
clusterOid = ins.readInt();
}
// documentation inherited from interface Streamable
public function writeObject (out :ObjectOutputStream) :void
{
out.writeInt(clusterOid);
}
/** Used for {@link #getKey}. */
protected var _key :int;
}
}
@@ -39,17 +39,9 @@ public class ModifyPortalsUpdate extends SceneUpdate
/** The portals to be added to the scene. */
public var portalsAdded :TypedArray;
/**
* Initialize the update with all necessary data.
*/
public function initialize (
targetId :int, targetVersion :int, removed :TypedArray,
added :TypedArray) :void
public function ModifyPortalsUpdate ()
{
init(targetId, targetVersion);
portalsRemoved = removed;
portalsAdded = added;
// nothing needed
}
override public function apply (model :SceneModel) :void
@@ -72,20 +64,33 @@ public class ModifyPortalsUpdate extends SceneUpdate
}
}
override public function writeObject (out :ObjectOutputStream) :void
/**
* Initialize the update with all necessary data.
*/
public function initialize (
targetId :int, targetVersion :int, removed :TypedArray,
added :TypedArray) :void
{
super.writeObject(out);
init(targetId, targetVersion);
out.writeObject(portalsRemoved);
out.writeObject(portalsAdded);
portalsRemoved = removed;
portalsAdded = added;
}
// from interface Streamable
override public function readObject (ins :ObjectInputStream) :void
{
super.readObject(ins);
portalsRemoved = (ins.readObject() as TypedArray);
portalsAdded = (ins.readObject() as TypedArray);
}
// from interface Streamable
override public function writeObject (out :ObjectOutputStream) :void
{
super.writeObject(out);
out.writeObject(portalsRemoved);
out.writeObject(portalsAdded);
}
}
}
@@ -23,10 +23,12 @@ package com.threerings.whirled.spot.data {
import com.threerings.util.ClassUtil;
import com.threerings.util.Cloneable;
import com.threerings.util.Hashable;
import com.threerings.util.StringBuilder;
import com.threerings.io.Streamable;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.SimpleStreamableObject;
import com.threerings.util.Hashable;
@@ -39,15 +41,14 @@ import com.threerings.util.Hashable;
* when using this portal and the location at which the body sprite should
* appear in that target scene.
*/
public class Portal
implements Streamable, Hashable, Cloneable
public class Portal extends SimpleStreamableObject
implements Cloneable, Hashable
{
/** This portal's unique identifier. */
public var portalId :int;
/** The location of the portal. Typically this is a base Location (2d)
* class, but different games could use a different subclass of
* Location. */
/** The location of the portal.
* This field is present on client and server, it is streamed specially. */
public var loc :Location;
/** The scene identifier of the scene to which a body will exit when
@@ -55,16 +56,13 @@ public class Portal
public var targetSceneId :int;
/** The portal identifier of the portal at which a body will enter
* the target scene when they "use" this portal. */
* the target scene when they "use" this portal, or -1 to specify
* that the body enters on the default portal, whatever id it is. */
public var targetPortalId :int;
/**
* Returns a location instance configured with the location and
* orientation of this portal.
*/
public function getLocation () :Location
public function Portal ()
{
return (loc.clone() as Location);
// nothing needed
}
/**
@@ -79,34 +77,10 @@ public class Portal
return loc.getOpposite();
}
/**
* Returns true if the portal has a potentially valid target scene and
* portal id (they are not guaranteed to exist, but they are at least
* potentially valid values rather than 0).
*/
public function isValid () :Boolean
// documentation inherited from interface Hashable
public function hashCode () :int
{
return (targetSceneId > 0) &&
// the target portal must be positive, or -1
((targetPortalId > 0) || (targetPortalId == -1));
}
// documentation inherited from interface Streamable
public function writeObject (out :ObjectOutputStream) :void
{
out.writeShort(portalId);
out.writeObject(loc);
out.writeInt(targetSceneId);
out.writeShort(targetPortalId);
}
// documentation inherited from interface Streamable
public function readObject (ins :ObjectInputStream) :void
{
portalId = ins.readShort();
loc = (ins.readObject() as Location);
targetSceneId = ins.readInt();
targetPortalId = ins.readShort();
return portalId;
}
// documentation inherited from interface Cloneable
@@ -127,16 +101,53 @@ public class Portal
((other as Portal).portalId == portalId);
}
// documentation inherited from interface Hashable
public function hashCode () :int
/**
* Returns a location instance configured with the location and
* orientation of this portal.
*/
public function getLocation () :Location
{
return portalId;
return (loc.clone() as Location);
}
public function toString () :String
/**
* Returns true if the portal has a potentially valid target scene and
* portal id (they are not guaranteed to exist, but they are at least
* potentially valid values rather than 0).
*/
public function isValid () :Boolean
{
return "Portal[id=" + portalId + ", destScene=" + targetSceneId +
", loc=" + loc + "].";
return (targetSceneId > 0) &&
// the target portal must be positive, or -1
((targetPortalId > 0) || (targetPortalId == -1));
}
// from interface Streamable
override public function readObject (ins :ObjectInputStream) :void
{
super.readObject(ins);
portalId = ins.readShort();
loc = (ins.readObject() as Location);
targetSceneId = ins.readInt();
targetPortalId = ins.readShort();
}
// from interface Streamable
override public function writeObject (out :ObjectOutputStream) :void
{
super.writeObject(out);
out.writeShort(portalId);
out.writeObject(loc);
out.writeInt(targetSceneId);
out.writeShort(targetPortalId);
}
// from SimpleStreamableObject
override protected function toStringBuilder (buf :StringBuilder): void
{
buf.append("id=").append(portalId);
buf.append(", destScene=").append(targetSceneId);
buf.append(", loc=").append(loc);
}
}
}
@@ -25,6 +25,7 @@ import com.threerings.util.Hashable;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.SimpleStreamableObject;
import com.threerings.presents.dobj.DSet_Entry;
@@ -32,7 +33,7 @@ import com.threerings.presents.dobj.DSet_Entry;
* Extends {@link Location} with the data and functionality needed to
* represent a particular user's location in a scene.
*/
public class SceneLocation
public class SceneLocation extends SimpleStreamableObject
implements DSet_Entry, Hashable
{
/** The oid of the body that occupies this location. */
@@ -50,10 +51,10 @@ public class SceneLocation
this.bodyOid = bodyOid;
}
// documentation inherited from interface DSet_Entry
public function getKey () :Object
// documentation inherited from interface Hashable
public function hashCode () :int
{
return bodyOid;
return loc.hashCode();
}
// documentation inherited from interface Hashable
@@ -63,24 +64,29 @@ public class SceneLocation
this.loc.equals((other as SceneLocation).loc);
}
// documentation inherited from interface Hashable
public function hashCode () :int
// documentation inherited from interface DSet_Entry
public function getKey () :Object
{
return loc.hashCode();
return bodyOid;
}
// documentation inherited from superinterface Streamable
public function writeObject (out :ObjectOutputStream) :void
override public function readObject (ins :ObjectInputStream) :void
{
super.readObject(ins);
bodyOid = ins.readInt();
loc = (ins.readObject() as Location);
}
// documentation inherited from superinterface Streamable
override public function writeObject (out :ObjectOutputStream) :void
{
super.writeObject(out);
out.writeInt(bodyOid);
out.writeObject(loc);
}
// documentation inherited from superinterface Streamable
public function readObject (ins :ObjectInputStream) :void
{
bodyOid = ins.readInt();
loc = (ins.readObject() as Location);
}
/** Used for {@link #getKey}. */
protected var _key :int;
}
}
@@ -24,9 +24,9 @@ package com.threerings.whirled.spot.data {
import com.threerings.util.ArrayUtil;
import com.threerings.util.ClassUtil;
import com.threerings.io.Streamable;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.SimpleStreamableObject;
import com.threerings.io.TypedArray;
import com.threerings.whirled.data.AuxModel;
@@ -38,8 +38,8 @@ import com.threerings.whirled.data.SceneModel;
* scene and unchanging, so that portals can stably reference the target
* portal in the scene to which they connect.
*/
public class SpotSceneModel
implements Streamable, AuxModel
public class SpotSceneModel extends SimpleStreamableObject
implements AuxModel
{
/** An array containing all portals in this scene. */
public var portals :TypedArray = TypedArray.create(Portal);
@@ -49,48 +49,6 @@ public class SpotSceneModel
* portal at which they would appear. */
public var defaultEntranceId :int = -1;
/**
* Adds a portal to this scene model.
*/
public function addPortal (portal :Portal) :void
{
portals.push(portal);
}
/**
* Removes a portal from this model.
*/
public function removePortal (portal :Portal) :void
{
ArrayUtil.removeFirst(portals, portal);
}
// documentation inherited from superinterface Cloneable
public function clone () :Object
{
var clazz :Class = ClassUtil.getClass(this);
var model :SpotSceneModel = new clazz();
for each (var portal :Portal in portals) {
model.portals.push(portal.clone());
}
return model;
}
// documentation inherited from interface Streamable
public function writeObject (out :ObjectOutputStream) :void
{
out.writeObject(portals);
out.writeInt(defaultEntranceId);
}
// documentation inherited from interface Streamable
public function readObject (ins :ObjectInputStream) :void
{
portals = (ins.readObject() as TypedArray);
defaultEntranceId = ins.readInt();
}
/**
* Locates and returns the {@link SpotSceneModel} among the auxiliary
* scene models associated with the supplied scene
@@ -106,5 +64,54 @@ public class SpotSceneModel
}
return null;
}
public function SpotSceneModel ()
{
// nothing needed
}
/**
* Removes a portal from this model.
*/
public function removePortal (portal :Portal) :void
{
ArrayUtil.removeFirst(portals, portal);
}
/**
* Adds a portal to this scene model.
*/
public function addPortal (portal :Portal) :void
{
portals.push(portal);
}
// documentation inherited from superinterface Cloneable
public function clone () :Object
{
var clazz :Class = ClassUtil.getClass(this);
var model :SpotSceneModel = new clazz();
for each (var portal :Portal in portals) {
model.portals.push(portal.clone());
}
return model;
}
// from interface Streamable
override public function readObject (ins :ObjectInputStream) :void
{
super.readObject(ins);
portals = (ins.readObject() as TypedArray);
defaultEntranceId = ins.readInt();
}
// from interface Streamable
override public function writeObject (out :ObjectOutputStream) :void
{
super.writeObject(out);
out.writeObject(portals);
out.writeInt(defaultEntranceId);
}
}
}