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
This commit is contained in:
@@ -168,90 +168,90 @@ public class Table
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Requests to seat the specified user at the specified position in
|
// * Requests to seat the specified user at the specified position in
|
||||||
* this table.
|
// * this table.
|
||||||
*
|
// *
|
||||||
* @param position the position in which to seat the user.
|
// * @param position the position in which to seat the user.
|
||||||
* @param occupant the occupant to set.
|
// * @param occupant the occupant to set.
|
||||||
*
|
// *
|
||||||
* @return null if the user was successfully seated, a string error
|
// * @return null if the user was successfully seated, a string error
|
||||||
* code explaining the failure if the user was not able to be seated
|
// * code explaining the failure if the user was not able to be seated
|
||||||
* at that position.
|
// * at that position.
|
||||||
*/
|
// */
|
||||||
public function setOccupant (position :int, occupant :BodyObject) :String
|
// public function setOccupant (position :int, occupant :BodyObject) :String
|
||||||
{
|
// {
|
||||||
// make sure the requested position is a valid one
|
// // make sure the requested position is a valid one
|
||||||
if (position >= tconfig.desiredPlayerCount || position < 0) {
|
// if (position >= tconfig.desiredPlayerCount || position < 0) {
|
||||||
return ParlorCodes.INVALID_TABLE_POSITION;
|
// return ParlorCodes.INVALID_TABLE_POSITION;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// make sure the requested position is not already occupied
|
// // make sure the requested position is not already occupied
|
||||||
if (occupants[position] != null) {
|
// if (occupants[position] != null) {
|
||||||
return ParlorCodes.TABLE_POSITION_OCCUPIED;
|
// return ParlorCodes.TABLE_POSITION_OCCUPIED;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// otherwise all is well, stick 'em in
|
// // otherwise all is well, stick 'em in
|
||||||
setOccupantPos(position, occupant);
|
// setOccupantPos(position, occupant);
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* This method is used for party games, it does no bounds checking
|
// * 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
|
// * or verification of the player's ability to join, if you are unsure
|
||||||
* you should call 'setOccupant'.
|
// * you should call 'setOccupant'.
|
||||||
*/
|
// */
|
||||||
public function setOccupantPos (position :int, occupant :BodyObject) :void
|
// public function setOccupantPos (position :int, occupant :BodyObject) :void
|
||||||
{
|
// {
|
||||||
occupants[position] = occupant.getVisibleName();
|
// occupants[position] = occupant.getVisibleName();
|
||||||
bodyOids[position] = occupant.getOid();
|
// bodyOids[position] = occupant.getOid();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Requests that the specified user be removed from their seat at this
|
// * Requests that the specified user be removed from their seat at this
|
||||||
* table.
|
// * table.
|
||||||
*
|
// *
|
||||||
* @return true if the user was seated at the table and has now been
|
// * @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
|
// * removed, false if the user was never seated at the table in the
|
||||||
* first place.
|
// * first place.
|
||||||
*/
|
// */
|
||||||
public function clearOccupant (username :Name) :Boolean
|
// public function clearOccupant (username :Name) :Boolean
|
||||||
{
|
// {
|
||||||
var dex :int = ArrayUtil.indexOf(occupants, username);
|
// var dex :int = ArrayUtil.indexOf(occupants, username);
|
||||||
if (dex != -1) {
|
// if (dex != -1) {
|
||||||
clearOccupantPos(dex);
|
// clearOccupantPos(dex);
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Requests that the user identified by the specified body object id
|
// * Requests that the user identified by the specified body object id
|
||||||
* be removed from their seat at this table.
|
// * be removed from their seat at this table.
|
||||||
*
|
// *
|
||||||
* @return true if the user was seated at the table and has now been
|
// * @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
|
// * removed, false if the user was never seated at the table in the
|
||||||
* first place.
|
// * first place.
|
||||||
*/
|
// */
|
||||||
public function clearOccupantByOid (bodyOid :int) :Boolean
|
// public function clearOccupantByOid (bodyOid :int) :Boolean
|
||||||
{
|
// {
|
||||||
var dex :int = ArrayUtil.indexOf(bodyOids, bodyOid);
|
// var dex :int = ArrayUtil.indexOf(bodyOids, bodyOid);
|
||||||
if (dex != -1) {
|
// if (dex != -1) {
|
||||||
clearOccupantPos(dex);
|
// clearOccupantPos(dex);
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Called to clear an occupant at the specified position.
|
// * Called to clear an occupant at the specified position.
|
||||||
* Only call this method if you know what you're doing.
|
// * Only call this method if you know what you're doing.
|
||||||
*/
|
// */
|
||||||
public function clearOccupantPos (position :int) :void
|
// public function clearOccupantPos (position :int) :void
|
||||||
{
|
// {
|
||||||
occupants[position] = null;
|
// occupants[position] = null;
|
||||||
bodyOids[position] = 0;
|
// bodyOids[position] = 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this table has a sufficient number of occupants
|
* Returns true if this table has a sufficient number of occupants
|
||||||
@@ -359,12 +359,13 @@ public class Table
|
|||||||
// from Streamable
|
// from Streamable
|
||||||
public function writeObject (out :ObjectOutputStream) :void
|
public function writeObject (out :ObjectOutputStream) :void
|
||||||
{
|
{
|
||||||
out.writeInt(tableId);
|
throw new Error();
|
||||||
out.writeInt(lobbyOid);
|
// out.writeInt(tableId);
|
||||||
out.writeInt(gameOid);
|
// out.writeInt(lobbyOid);
|
||||||
out.writeObject(occupants);
|
// out.writeInt(gameOid);
|
||||||
out.writeObject(config);
|
// out.writeObject(occupants);
|
||||||
out.writeObject(tconfig);
|
// out.writeObject(config);
|
||||||
|
// out.writeObject(tconfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -69,7 +69,14 @@ public class Table
|
|||||||
public TableConfig tconfig;
|
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.
|
* increasing table id.
|
||||||
*
|
*
|
||||||
* @param lobbyOid the object id of the lobby in which this table is
|
* @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
|
* @param config the configuration of the game being matchmade by this
|
||||||
* table.
|
* table.
|
||||||
*/
|
*/
|
||||||
public Table (int lobbyOid, TableConfig tconfig, GameConfig config)
|
public void init (int lobbyOid, TableConfig tconfig, GameConfig config)
|
||||||
{
|
{
|
||||||
// assign a unique table id
|
// assign a unique table id
|
||||||
tableId = ++_tableIdCounter;
|
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.
|
* Returns true if there is no one sitting at this table.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -77,6 +77,14 @@ public class TableManager
|
|||||||
_tlobj = (TableLobbyObject)_plobj;
|
_tlobj = (TableLobbyObject)_plobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the subclass of Table that this instance should generate.
|
||||||
|
*/
|
||||||
|
public void setTableClass (Class<? extends Table> tableClass)
|
||||||
|
{
|
||||||
|
_tableClass = tableClass;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests that a new table be created to matchmake the game
|
* Requests that a new table be created to matchmake the game
|
||||||
* described by the supplied game config instance. The config instance
|
* described by the supplied game config instance. The config instance
|
||||||
@@ -108,7 +116,15 @@ public class TableManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create a brand spanking new table
|
// 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
|
// stick the creator into the first non-AI position
|
||||||
int cpos = (config.ais == null) ? 0 : config.ais.length;
|
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. */
|
/** A reference to the place object in which we're managing tables. */
|
||||||
protected PlaceObject _plobj;
|
protected PlaceObject _plobj;
|
||||||
|
|
||||||
|
/** The class of table we instantiate. */
|
||||||
|
protected Class<? extends Table> _tableClass = Table.class;
|
||||||
|
|
||||||
/** A reference to our place object casted to a table lobby object. */
|
/** A reference to our place object casted to a table lobby object. */
|
||||||
protected TableLobbyObject _tlobj;
|
protected TableLobbyObject _tlobj;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user