From 52febf265b7b04a05eb60cc475d06dcb9eb4cfd7 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Fri, 17 Nov 2006 23:24:14 +0000 Subject: [PATCH] Allow the TableManager to be configured to create subclasses of Table. Commented out unneeded flash client code in Table. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@131 c613c5cb-e716-0410-b11b-feb51c14d237 --- src/as/com/threerings/parlor/data/Table.as | 181 +++++++++--------- .../com/threerings/parlor/data/Table.java | 18 +- .../parlor/server/TableManager.java | 21 +- 3 files changed, 120 insertions(+), 100 deletions(-) diff --git a/src/as/com/threerings/parlor/data/Table.as b/src/as/com/threerings/parlor/data/Table.as index a6d0dc6a..abdba0d9 100644 --- a/src/as/com/threerings/parlor/data/Table.as +++ b/src/as/com/threerings/parlor/data/Table.as @@ -168,90 +168,90 @@ public class Table } } - /** - * Requests to seat the specified user at the specified position in - * this table. - * - * @param position the position in which to seat the user. - * @param occupant the occupant to set. - * - * @return null if the user was successfully seated, a string error - * code explaining the failure if the user was not able to be seated - * at that position. - */ - public function setOccupant (position :int, occupant :BodyObject) :String - { - // make sure the requested position is a valid one - if (position >= tconfig.desiredPlayerCount || position < 0) { - return ParlorCodes.INVALID_TABLE_POSITION; - } - - // make sure the requested position is not already occupied - if (occupants[position] != null) { - return ParlorCodes.TABLE_POSITION_OCCUPIED; - } - - // otherwise all is well, stick 'em in - setOccupantPos(position, occupant); - return null; - } - - /** - * This method is used for party games, it does no bounds checking - * or verification of the player's ability to join, if you are unsure - * you should call 'setOccupant'. - */ - public function setOccupantPos (position :int, occupant :BodyObject) :void - { - occupants[position] = occupant.getVisibleName(); - bodyOids[position] = occupant.getOid(); - } - - /** - * Requests that the specified user be removed from their seat at this - * table. - * - * @return true if the user was seated at the table and has now been - * removed, false if the user was never seated at the table in the - * first place. - */ - public function clearOccupant (username :Name) :Boolean - { - var dex :int = ArrayUtil.indexOf(occupants, username); - if (dex != -1) { - clearOccupantPos(dex); - return true; - } - return false; - } - - /** - * Requests that the user identified by the specified body object id - * be removed from their seat at this table. - * - * @return true if the user was seated at the table and has now been - * removed, false if the user was never seated at the table in the - * first place. - */ - public function clearOccupantByOid (bodyOid :int) :Boolean - { - var dex :int = ArrayUtil.indexOf(bodyOids, bodyOid); - if (dex != -1) { - clearOccupantPos(dex); - return true; - } - return false; - } - - /** - * Called to clear an occupant at the specified position. - * Only call this method if you know what you're doing. - */ - public function clearOccupantPos (position :int) :void - { - occupants[position] = null; - bodyOids[position] = 0; - } +// /** +// * Requests to seat the specified user at the specified position in +// * this table. +// * +// * @param position the position in which to seat the user. +// * @param occupant the occupant to set. +// * +// * @return null if the user was successfully seated, a string error +// * code explaining the failure if the user was not able to be seated +// * at that position. +// */ +// public function setOccupant (position :int, occupant :BodyObject) :String +// { +// // make sure the requested position is a valid one +// if (position >= tconfig.desiredPlayerCount || position < 0) { +// return ParlorCodes.INVALID_TABLE_POSITION; +// } +// +// // make sure the requested position is not already occupied +// if (occupants[position] != null) { +// return ParlorCodes.TABLE_POSITION_OCCUPIED; +// } +// +// // otherwise all is well, stick 'em in +// setOccupantPos(position, occupant); +// return null; +// } +// +// /** +// * This method is used for party games, it does no bounds checking +// * or verification of the player's ability to join, if you are unsure +// * you should call 'setOccupant'. +// */ +// public function setOccupantPos (position :int, occupant :BodyObject) :void +// { +// occupants[position] = occupant.getVisibleName(); +// bodyOids[position] = occupant.getOid(); +// } +// +// /** +// * Requests that the specified user be removed from their seat at this +// * table. +// * +// * @return true if the user was seated at the table and has now been +// * removed, false if the user was never seated at the table in the +// * first place. +// */ +// public function clearOccupant (username :Name) :Boolean +// { +// var dex :int = ArrayUtil.indexOf(occupants, username); +// if (dex != -1) { +// clearOccupantPos(dex); +// return true; +// } +// return false; +// } +// +// /** +// * Requests that the user identified by the specified body object id +// * be removed from their seat at this table. +// * +// * @return true if the user was seated at the table and has now been +// * removed, false if the user was never seated at the table in the +// * first place. +// */ +// public function clearOccupantByOid (bodyOid :int) :Boolean +// { +// var dex :int = ArrayUtil.indexOf(bodyOids, bodyOid); +// if (dex != -1) { +// clearOccupantPos(dex); +// return true; +// } +// return false; +// } +// +// /** +// * Called to clear an occupant at the specified position. +// * Only call this method if you know what you're doing. +// */ +// public function clearOccupantPos (position :int) :void +// { +// occupants[position] = null; +// bodyOids[position] = 0; +// } /** * Returns true if this table has a sufficient number of occupants @@ -359,12 +359,13 @@ public class Table // from Streamable public function writeObject (out :ObjectOutputStream) :void { - out.writeInt(tableId); - out.writeInt(lobbyOid); - out.writeInt(gameOid); - out.writeObject(occupants); - out.writeObject(config); - out.writeObject(tconfig); + throw new Error(); +// out.writeInt(tableId); +// out.writeInt(lobbyOid); +// out.writeInt(gameOid); +// out.writeObject(occupants); +// out.writeObject(config); +// out.writeObject(tconfig); } /** diff --git a/src/java/com/threerings/parlor/data/Table.java b/src/java/com/threerings/parlor/data/Table.java index ec863fee..52d7974f 100644 --- a/src/java/com/threerings/parlor/data/Table.java +++ b/src/java/com/threerings/parlor/data/Table.java @@ -69,7 +69,14 @@ public class Table public TableConfig tconfig; /** - * Creates a new table instance, and assigns it the next monotonically + * Constructs a blank table instance, suitable for unserialization. + */ + public Table () + { + } + + /** + * Initializes a new table instance, and assigns it the next monotonically * increasing table id. * * @param lobbyOid the object id of the lobby in which this table is @@ -78,7 +85,7 @@ public class Table * @param config the configuration of the game being matchmade by this * table. */ - public Table (int lobbyOid, TableConfig tconfig, GameConfig config) + public void init (int lobbyOid, TableConfig tconfig, GameConfig config) { // assign a unique table id tableId = ++_tableIdCounter; @@ -104,13 +111,6 @@ public class Table } } - /** - * Constructs a blank table instance, suitable for unserialization. - */ - public Table () - { - } - /** * Returns true if there is no one sitting at this table. */ diff --git a/src/java/com/threerings/parlor/server/TableManager.java b/src/java/com/threerings/parlor/server/TableManager.java index 2c08a589..a93839ae 100644 --- a/src/java/com/threerings/parlor/server/TableManager.java +++ b/src/java/com/threerings/parlor/server/TableManager.java @@ -77,6 +77,14 @@ public class TableManager _tlobj = (TableLobbyObject)_plobj; } + /** + * Set the subclass of Table that this instance should generate. + */ + public void setTableClass (Class tableClass) + { + _tableClass = tableClass; + } + /** * Requests that a new table be created to matchmake the game * described by the supplied game config instance. The config instance @@ -108,7 +116,15 @@ public class TableManager } // create a brand spanking new table - Table table = new Table(_plobj.getOid(), tableConfig, config); + Table table; + try { + table = _tableClass.newInstance(); + } catch (Exception e) { + Log.warning("Unable to create a new table instance! " + + "[tableClass=" + _tableClass + ", error=" + e + "]."); + throw new InvocationException(INTERNAL_ERROR); + } + table.init(_plobj.getOid(), tableConfig, config); // stick the creator into the first non-AI position int cpos = (config.ais == null) ? 0 : config.ais.length; @@ -387,6 +403,9 @@ public class TableManager /** A reference to the place object in which we're managing tables. */ protected PlaceObject _plobj; + /** The class of table we instantiate. */ + protected Class _tableClass = Table.class; + /** A reference to our place object casted to a table lobby object. */ protected TableLobbyObject _tlobj;