- Changed Table to just have an int as its key and use autoboxing to make
that a Comparable. It's a slight performance hit, as when a DSet is binary searched, it will be boxing up an int for every entry examined. Oh well. - Use some generics. - Some other cleanups I spotted while writing actionscript versions. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@29 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -199,12 +199,12 @@ public class TableItem
|
|||||||
"click came from [event=" + event + "].");
|
"click came from [event=" + event + "].");
|
||||||
} else {
|
} else {
|
||||||
// otherwise, request to join the table at this position
|
// otherwise, request to join the table at this position
|
||||||
_tdtr.joinTable(table.getTableId(), position);
|
_tdtr.joinTable(table.tableId, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (cmd.equals("leave")) {
|
} else if (cmd.equals("leave")) {
|
||||||
// if we're not joining, we're leaving
|
// if we're not joining, we're leaving
|
||||||
_tdtr.leaveTable(table.getTableId());
|
_tdtr.leaveTable(table.tableId);
|
||||||
|
|
||||||
} else if (cmd.equals("go")) {
|
} else if (cmd.equals("go")) {
|
||||||
// they want to see the game... so go there
|
// they want to see the game... so go there
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ public class TableListView extends JPanel
|
|||||||
Log.info("Table updated [table=" + table + "].");
|
Log.info("Table updated [table=" + table + "].");
|
||||||
|
|
||||||
// locate the table item associated with this table
|
// locate the table item associated with this table
|
||||||
TableItem item = getTableItem(table.getTableId());
|
TableItem item = getTableItem(table.tableId);
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
Log.warning("Received table updated notification for " +
|
Log.warning("Received table updated notification for " +
|
||||||
"unknown table [table=" + table + "].");
|
"unknown table [table=" + table + "].");
|
||||||
@@ -257,7 +257,7 @@ public class TableListView extends JPanel
|
|||||||
int ccount = _matchList.getComponentCount();
|
int ccount = _matchList.getComponentCount();
|
||||||
for (int i = 0; i < ccount; i++) {
|
for (int i = 0; i < ccount; i++) {
|
||||||
TableItem child = (TableItem)_matchList.getComponent(i);
|
TableItem child = (TableItem)_matchList.getComponent(i);
|
||||||
if (child.table.getTableId() == tableId) {
|
if (child.table.tableId == tableId) {
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ public class TableListView extends JPanel
|
|||||||
ccount = _playList.getComponentCount();
|
ccount = _playList.getComponentCount();
|
||||||
for (int i = 0; i < ccount; i++) {
|
for (int i = 0; i < ccount; i++) {
|
||||||
TableItem child = (TableItem)_playList.getComponent(i);
|
TableItem child = (TableItem)_playList.getComponent(i);
|
||||||
if (child.table.getTableId() == tableId) {
|
if (child.table.tableId == tableId) {
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public abstract class TableConfigurator
|
|||||||
protected ParlorContext _ctx;
|
protected ParlorContext _ctx;
|
||||||
|
|
||||||
/** The config we're configurating. */
|
/** The config we're configurating. */
|
||||||
protected TableConfig _config;
|
protected TableConfig _config;
|
||||||
|
|
||||||
/** The game configurator, which we may wish to reference. */
|
/** The game configurator, which we may wish to reference. */
|
||||||
protected GameConfigurator _gameConfigurator;
|
protected GameConfigurator _gameConfigurator;
|
||||||
|
|||||||
@@ -260,16 +260,16 @@ public class TableDirector extends BasicDirector
|
|||||||
public void entryRemoved (EntryRemovedEvent event)
|
public void entryRemoved (EntryRemovedEvent event)
|
||||||
{
|
{
|
||||||
if (event.getName().equals(_tableField)) {
|
if (event.getName().equals(_tableField)) {
|
||||||
Integer tableId = (Integer)event.getKey();
|
int tableId = ((Integer) event.getKey()).intValue();
|
||||||
|
|
||||||
// check to see if our table just disappeared
|
// check to see if our table just disappeared
|
||||||
if (_ourTable != null && tableId.equals(_ourTable.tableId)) {
|
if (_ourTable != null && tableId == _ourTable.tableId) {
|
||||||
_ourTable = null;
|
_ourTable = null;
|
||||||
notifySeatedness(false);
|
notifySeatedness(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// now let the observer know what's up
|
// now let the observer know what's up
|
||||||
_observer.tableRemoved(tableId.intValue());
|
_observer.tableRemoved(tableId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class Table
|
|||||||
implements DSet.Entry, ParlorCodes
|
implements DSet.Entry, ParlorCodes
|
||||||
{
|
{
|
||||||
/** The unique identifier for this table. */
|
/** The unique identifier for this table. */
|
||||||
public Integer tableId;
|
public int tableId;
|
||||||
|
|
||||||
/** The object id of the lobby object with which this table is
|
/** The object id of the lobby object with which this table is
|
||||||
* associated. */
|
* associated. */
|
||||||
@@ -80,7 +80,7 @@ public class Table
|
|||||||
public Table (int lobbyOid, TableConfig tconfig, GameConfig config)
|
public Table (int lobbyOid, TableConfig tconfig, GameConfig config)
|
||||||
{
|
{
|
||||||
// assign a unique table id
|
// assign a unique table id
|
||||||
tableId = Integer.valueOf(++_tableIdCounter);
|
tableId = ++_tableIdCounter;
|
||||||
|
|
||||||
// keep track of our lobby oid
|
// keep track of our lobby oid
|
||||||
this.lobbyOid = lobbyOid;
|
this.lobbyOid = lobbyOid;
|
||||||
@@ -109,14 +109,6 @@ public class Table
|
|||||||
public Table ()
|
public Table ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenience function for accessing the table id as an int.
|
|
||||||
*/
|
|
||||||
public int getTableId ()
|
|
||||||
{
|
|
||||||
return tableId.intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if there is no one sitting at this table.
|
* Returns true if there is no one sitting at this table.
|
||||||
@@ -363,13 +355,13 @@ public class Table
|
|||||||
public boolean equals (Object other)
|
public boolean equals (Object other)
|
||||||
{
|
{
|
||||||
return (other instanceof Table) &&
|
return (other instanceof Table) &&
|
||||||
tableId.equals(((Table) other).tableId);
|
(tableId == ((Table) other).tableId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public int hashCode ()
|
public int hashCode ()
|
||||||
{
|
{
|
||||||
return tableId.intValue();
|
return tableId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -134,8 +134,8 @@ public abstract class GameController extends PlaceController
|
|||||||
*/
|
*/
|
||||||
public boolean isGameOver ()
|
public boolean isGameOver ()
|
||||||
{
|
{
|
||||||
boolean gameOver =
|
boolean gameOver = (_gobj == null) ||
|
||||||
((_gobj != null) ? (_gobj.state != GameObject.IN_PLAY) : true);
|
(_gobj.state != GameObject.IN_PLAY);
|
||||||
return (_gameOver || gameOver);
|
return (_gameOver || gameOver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,10 +199,10 @@ public abstract class GameController extends PlaceController
|
|||||||
{
|
{
|
||||||
// deal with game state changes
|
// deal with game state changes
|
||||||
if (event.getName().equals(GameObject.STATE)) {
|
if (event.getName().equals(GameObject.STATE)) {
|
||||||
if (!stateDidChange(event.getIntValue())) {
|
int newState = event.getIntValue();
|
||||||
|
if (!stateDidChange(newState)) {
|
||||||
Log.warning("Game transitioned to unknown state " +
|
Log.warning("Game transitioned to unknown state " +
|
||||||
"[gobj=" + _gobj +
|
"[gobj=" + _gobj + ", state=" + newState + "].");
|
||||||
", state=" + event.getIntValue() + "].");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,6 @@ public class GameObject extends PlaceObject
|
|||||||
(playerStatus == null || isActivePlayerStatus(playerStatus[pidx]));
|
(playerStatus == null || isActivePlayerStatus(playerStatus[pidx]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the player index of the given user in the game, or
|
* Returns the player index of the given user in the game, or
|
||||||
* <code>-1</code> if the player is not involved in the game.
|
* <code>-1</code> if the player is not involved in the game.
|
||||||
@@ -194,7 +193,7 @@ public class GameObject extends PlaceObject
|
|||||||
*/
|
*/
|
||||||
public boolean isWinner (int pidx)
|
public boolean isWinner (int pidx)
|
||||||
{
|
{
|
||||||
return (winners == null) ? false : winners[pidx];
|
return (winners != null) && winners[pidx];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ public class TableManager
|
|||||||
_boidMap.put(creator.getOid(), table);
|
_boidMap.put(creator.getOid(), table);
|
||||||
|
|
||||||
// also stick it into our tables tables
|
// also stick it into our tables tables
|
||||||
_tables.put(table.getTableId(), table);
|
_tables.put(table.tableId, table);
|
||||||
|
|
||||||
// if the table has only one seat, start the game immediately
|
// if the table has only one seat, start the game immediately
|
||||||
if (table.shouldBeStarted()) {
|
if (table.shouldBeStarted()) {
|
||||||
@@ -137,7 +137,7 @@ public class TableManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// finally let the caller know what the new table id is
|
// finally let the caller know what the new table id is
|
||||||
return table.getTableId();
|
return table.tableId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,7 +163,7 @@ public class TableManager
|
|||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
// look the table up
|
// look the table up
|
||||||
Table table = (Table)_tables.get(tableId);
|
Table table = _tables.get(tableId);
|
||||||
if (table == null) {
|
if (table == null) {
|
||||||
throw new InvocationException(NO_SUCH_TABLE);
|
throw new InvocationException(NO_SUCH_TABLE);
|
||||||
}
|
}
|
||||||
@@ -207,7 +207,7 @@ public class TableManager
|
|||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
// look the table up
|
// look the table up
|
||||||
Table table = (Table)_tables.get(tableId);
|
Table table = _tables.get(tableId);
|
||||||
if (table == null) {
|
if (table == null) {
|
||||||
throw new InvocationException(NO_SUCH_TABLE);
|
throw new InvocationException(NO_SUCH_TABLE);
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ public class TableManager
|
|||||||
protected void purgeTable (Table table)
|
protected void purgeTable (Table table)
|
||||||
{
|
{
|
||||||
// remove the table from our tables table
|
// remove the table from our tables table
|
||||||
_tables.remove(table.getTableId());
|
_tables.remove(table.tableId);
|
||||||
|
|
||||||
// clear out all matching entries in the boid map
|
// clear out all matching entries in the boid map
|
||||||
for (int i = 0; i < table.bodyOids.length; i++) {
|
for (int i = 0; i < table.bodyOids.length; i++) {
|
||||||
@@ -308,9 +308,7 @@ public class TableManager
|
|||||||
protected void unmapTable (int gameOid)
|
protected void unmapTable (int gameOid)
|
||||||
{
|
{
|
||||||
// look through our tables table for a table with a matching game
|
// look through our tables table for a table with a matching game
|
||||||
Iterator iter = _tables.values().iterator();
|
for (Table table : _tables.values()) {
|
||||||
while (iter.hasNext()) {
|
|
||||||
Table table = (Table)iter.next();
|
|
||||||
if (table.gameOid == gameOid) {
|
if (table.gameOid == gameOid) {
|
||||||
purgeTable(table);
|
purgeTable(table);
|
||||||
return; // all done
|
return; // all done
|
||||||
@@ -337,7 +335,7 @@ public class TableManager
|
|||||||
|
|
||||||
// look up the table to which this occupant is mapped
|
// look up the table to which this occupant is mapped
|
||||||
int bodyOid = event.getOid();
|
int bodyOid = event.getOid();
|
||||||
Table pender = (Table)_boidMap.remove(bodyOid);
|
Table pender = _boidMap.remove(bodyOid);
|
||||||
if (pender == null) {
|
if (pender == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -365,10 +363,10 @@ public class TableManager
|
|||||||
protected TableLobbyObject _tlobj;
|
protected TableLobbyObject _tlobj;
|
||||||
|
|
||||||
/** The table of pending tables. */
|
/** The table of pending tables. */
|
||||||
protected HashIntMap _tables = new HashIntMap();
|
protected HashIntMap<Table> _tables = new HashIntMap<Table>();
|
||||||
|
|
||||||
/** A mapping from body oid to table. */
|
/** A mapping from body oid to table. */
|
||||||
protected HashIntMap _boidMap = new HashIntMap();
|
protected HashIntMap<Table> _boidMap = new HashIntMap<Table>();
|
||||||
|
|
||||||
/** A listener that prunes tables after the game dies. */
|
/** A listener that prunes tables after the game dies. */
|
||||||
protected ChangeListener _gameDeathListener = new ObjectDeathListener() {
|
protected ChangeListener _gameDeathListener = new ObjectDeathListener() {
|
||||||
|
|||||||
Reference in New Issue
Block a user