diff --git a/src/java/com/threerings/parlor/client/DefaultSwingTableConfigurator.java b/src/java/com/threerings/parlor/client/DefaultSwingTableConfigurator.java index 352a67449..408eff86c 100644 --- a/src/java/com/threerings/parlor/client/DefaultSwingTableConfigurator.java +++ b/src/java/com/threerings/parlor/client/DefaultSwingTableConfigurator.java @@ -66,6 +66,8 @@ public class DefaultSwingTableConfigurator extends TableConfigurator public DefaultSwingTableConfigurator (int minPlayers, int desiredPlayers, int maxPlayers, boolean allowPrivate) { + _config.minimumPlayerCount = minPlayers; + // create a slider for players, if applicable if (minPlayers != maxPlayers) { _playerSlider = new SimpleSlider( diff --git a/src/java/com/threerings/parlor/data/Table.java b/src/java/com/threerings/parlor/data/Table.java index 79f7b9a52..a4f9c7e36 100644 --- a/src/java/com/threerings/parlor/data/Table.java +++ b/src/java/com/threerings/parlor/data/Table.java @@ -63,12 +63,11 @@ public class Table /** * Creates a new table instance, and assigns it the next monotonically - * increasing table id. The supplied config instance must implement - * {@link TableConfig} or a ClassCastException will be - * thrown. + * increasing table id. * * @param lobbyOid the object id of the lobby in which this table is * to live. + * @param tconfig the table configuration for this table. * @param config the configuration of the game being matchmade by this * table. */ @@ -113,6 +112,33 @@ public class Table return tableId.intValue(); } + /** + * Returns true if there is no one sitting at this table. + */ + public boolean isEmpty () + { + for (int i = 0; i < bodyOids.length; i++) { + if (bodyOids[i] != 0) { + return false; + } + } + return true; + } + + /** + * Count the number of players currently occupying this table. + */ + public int getOccupiedCount () + { + int count = 0; + for (int ii = 0; ii < occupants.length; ii++) { + if (occupants[ii] != null) { + count++; + } + } + return count; + } + /** * Once a table is ready to play (see {@link #mayBeStarted} and {@link * #shouldBeStarted}), the players array can be fetched using this @@ -126,20 +152,11 @@ public class Table return null; } - // count up the players - int pcount = 0; - for (int i = 0; i < occupants.length; i++) { - if (occupants[i] != null) { - pcount++; - } - } - // create and populate the players array - Name[] players = new Name[pcount]; - pcount = 0; - for (int i = 0; i < occupants.length; i++) { - if (occupants[i] != null) { - players[pcount++] = occupants[i]; + Name[] players = new Name[getOccupiedCount()]; + for (int ii = 0, dex = 0; ii < occupants.length; ii++) { + if (occupants[ii] != null) { + players[dex++] = occupants[ii]; } } @@ -230,19 +247,7 @@ public class Table */ public boolean mayBeStarted () { - // TODO: this becomes more meaningful if we implement games - // that can optionally be started with less than the desired number - - // make sure at least the minimum number of players are here - int want = tconfig.desiredPlayerCount, have = 0; - for (int i = 0; i < occupants.length; i++) { - if (occupants[i] != null) { - if (++have == want) { - return true; - } - } - } - return false; + return tconfig.minimumPlayerCount <= getOccupiedCount(); } /** @@ -251,26 +256,7 @@ public class Table */ public boolean shouldBeStarted () { - int need = tconfig.desiredPlayerCount; - for (int i = 0; i < occupants.length; i++) { - if (occupants[i] != null && --need == 0) { - return true; - } - } - return false; - } - - /** - * Returns true if there is no one sitting at this table. - */ - public boolean isEmpty () - { - for (int i = 0; i < bodyOids.length; i++) { - if (bodyOids[i] != 0) { - return false; - } - } - return true; + return tconfig.desiredPlayerCount <= getOccupiedCount(); } /** diff --git a/src/java/com/threerings/parlor/data/TableConfig.java b/src/java/com/threerings/parlor/data/TableConfig.java index 34eac56d7..63e1a6d24 100644 --- a/src/java/com/threerings/parlor/data/TableConfig.java +++ b/src/java/com/threerings/parlor/data/TableConfig.java @@ -33,6 +33,10 @@ public class TableConfig extends SimpleStreamableObject * party game. */ public int desiredPlayerCount; + /** The minimum number of players needed for the game to start at + * the creator's discretion. */ + public int minimumPlayerCount; + /** Whether the table is "private". */ public boolean privateTable; }