diff --git a/src/as/com/threerings/parlor/data/Table.as b/src/as/com/threerings/parlor/data/Table.as index b67c6979..a6d0dc6a 100644 --- a/src/as/com/threerings/parlor/data/Table.as +++ b/src/as/com/threerings/parlor/data/Table.as @@ -46,7 +46,7 @@ import com.threerings.parlor.game.data.PartyGameConfig; * the Parlor services. */ public class Table - implements Hashable, DSet_Entry + implements DSet_Entry, Hashable { /** The unique identifier for this table. */ public var tableId :int; @@ -61,11 +61,11 @@ public class Table /** An array of the usernames of the occupants of this table (some * slots may not be filled), or null if a party game. */ - public var occupants :TypedArray /* of Name */; + public var occupants :TypedArray; /** The body oids of the occupants of this table, or null if a party game. * (This is not propagated to remote instances.) */ - public var bodyOids :TypedArray /* of int */; + public var bodyOids :TypedArray; /** The game config for the game that is being matchmade. */ public var config :GameConfig; @@ -78,19 +78,6 @@ public class Table { } - /** - * Returns true if there is no one sitting at this table. - */ - public function isEmpty () :Boolean - { - for (var ii :int = 0; ii < bodyOids.length; ii++) { - if ((bodyOids[ii] as int) !== 0) { - return false; - } - } - return true; - } - /** * Count the number of players currently occupying this table. */ @@ -313,8 +300,8 @@ public class Table return gameOid != -1; } - // documentation inherited - public function getKey () :Object + // from Hashable + public function hashCode () :int { return tableId; } @@ -326,21 +313,36 @@ public class Table (tableId == (other as Table).tableId); } - // from Hashable - public function hashCode () :int + /** + * Generates a string representation of this table instance. + */ + public function toString () :String + { + var buf :StringBuilder = new StringBuilder(); + buf.append(ClassUtil.shortClassName(this)); + buf.append(" ["); + toStringBuilder(buf); + buf.append("]"); + return buf.toString(); + } + + // documentation inherited + public function getKey () :Object { return tableId; } - // from Streamable - public function writeObject (out :ObjectOutputStream) :void + /** + * Returns true if there is no one sitting at this table. + */ + public function isEmpty () :Boolean { - out.writeInt(tableId); - out.writeInt(lobbyOid); - out.writeInt(gameOid); - out.writeObject(occupants); - out.writeObject(config); - out.writeObject(tconfig); + for (var ii :int = 0; ii < bodyOids.length; ii++) { + if ((bodyOids[ii] as int) !== 0) { + return false; + } + } + return true; } // from Streamable @@ -354,23 +356,21 @@ public class Table tconfig = (ins.readObject() as TableConfig); } - /** - * Generates a string representation of this table instance. - */ - public function toString () :String + // from Streamable + public function writeObject (out :ObjectOutputStream) :void { - var buf :StringBuilder = new StringBuilder(); - buf.append(ClassUtil.shortClassName(this)); - buf.append(" ["); - toStringBuf(buf); - buf.append("]"); - return buf.toString(); + out.writeInt(tableId); + out.writeInt(lobbyOid); + out.writeInt(gameOid); + out.writeObject(occupants); + out.writeObject(config); + out.writeObject(tconfig); } /** * Helper method for toString, ripe for overrideability. */ - protected function toStringBuf (buf :StringBuilder) :void + protected function toStringBuilder (buf :StringBuilder) :void { buf.append("tableId=").append(tableId); buf.append(", lobbyOid=").append(lobbyOid); @@ -378,5 +378,8 @@ public class Table buf.append(", occupants=").append(occupants.join()); buf.append(", config=").append(config); } + + /** A counter for assigning table ids. */ + protected static var _tableIdCounter :int = 0; } } diff --git a/src/as/com/threerings/parlor/data/TableConfig.as b/src/as/com/threerings/parlor/data/TableConfig.as index cd20b11e..b2f35883 100644 --- a/src/as/com/threerings/parlor/data/TableConfig.as +++ b/src/as/com/threerings/parlor/data/TableConfig.as @@ -2,8 +2,8 @@ // $Id: TableConfig.java 3604 2005-06-17 20:25:28Z ray $ // // Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ +// Copyright (C) 2002-2006 Three Rings Design, Inc., All Rights Reserved +// http://www.threerings.net/code/vilya/ // // This library is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License as published @@ -23,15 +23,14 @@ package com.threerings.parlor.data { import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; -import com.threerings.io.Streamable; +import com.threerings.io.SimpleStreamableObject; import com.threerings.io.TypedArray; /** * Table configuration parameters for a game that is to be matchmade * using the table services. */ -public class TableConfig - implements Streamable +public class TableConfig extends SimpleStreamableObject { /** The total number of players that are desired for the table, * or -1 for a party game. For team games, this should be set to the @@ -51,22 +50,27 @@ public class TableConfig /** Whether the table is "private". */ public var privateTable :Boolean; - // from Streamable - public function writeObject (out :ObjectOutputStream) :void + public function TableConfig () { - out.writeInt(desiredPlayerCount); - out.writeInt(minimumPlayerCount); - out.writeObject(teamMemberIndices); - out.writeBoolean(privateTable); + // nothing needed } // from Streamable - public function readObject (ins :ObjectInputStream) :void + override public function readObject (ins :ObjectInputStream) :void { desiredPlayerCount = ins.readInt(); minimumPlayerCount = ins.readInt(); teamMemberIndices = (ins.readObject() as TypedArray); privateTable = ins.readBoolean(); } + + // from Streamable + override public function writeObject (out :ObjectOutputStream) :void + { + out.writeInt(desiredPlayerCount); + out.writeInt(minimumPlayerCount); + out.writeObject(teamMemberIndices); + out.writeBoolean(privateTable); + } } }