From 377d0c93f51b09d7a77c45c9593dc97c72cc03a0 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Sat, 6 Oct 2007 00:35:30 +0000 Subject: [PATCH] Keep track of of players that have arrived and players that are ready separately. The old check would start the game as soon as everyone had arrived and *one* person called playerReady(). Now we do the right thing and only start the game once everyone has arrived and everyone has called playerReady(). As with the old code, this only affects clients that use the playerInRoom() method. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@442 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../parlor/game/server/GameManager.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/java/com/threerings/parlor/game/server/GameManager.java b/src/java/com/threerings/parlor/game/server/GameManager.java index 4e1b0564..8bad5106 100644 --- a/src/java/com/threerings/parlor/game/server/GameManager.java +++ b/src/java/com/threerings/parlor/game/server/GameManager.java @@ -607,6 +607,9 @@ public class GameManager extends PlaceManager // make a note of this player's oid _playerOids[pidx] = caller.getOid(); + + // this player is not necessarily ready to play yet + _pendingOids.add(caller.getOid()); } /** @@ -617,6 +620,9 @@ public class GameManager extends PlaceManager { playerInRoom(caller); + // This player is no longer pending + _pendingOids.remove(caller.getOid()); + // if everyone is now ready to go, get things underway if (allPlayersReady()) { playersAllHere(); @@ -644,9 +650,10 @@ public class GameManager extends PlaceManager */ public boolean playerIsReady (int pidx) { - return (!_gameobj.isOccupiedPlayer(pidx) || // unoccupied slot - _playerOids[pidx] != 0 || // player is ready - isAI(pidx)); // player is AI + return (!_gameobj.isOccupiedPlayer(pidx) || // unoccupied slot + // player is ready + (_playerOids[pidx] != 0 && !_pendingOids.contains(_playerOids[pidx])) || + isAI(pidx)); // player is AI } /** @@ -767,6 +774,9 @@ public class GameManager extends PlaceManager // instantiate a player oid array which we'll fill in later _playerOids = new int[getPlayerSlots()]; + // instantiate the pending player list + _pendingOids = new ArrayIntSet(); + // give delegates a chance to do their thing super.didStartup(); @@ -1285,6 +1295,9 @@ public class GameManager extends PlaceManager /** The oids of our player and AI body objects. */ protected int[] _playerOids; + /** The list of players that have arrived in the room, but are not ready to play. */ + protected ArrayIntSet _pendingOids; + /** If AIs are present, contains their configuration, or null at human player indexes. */ protected GameAI[] _AIs;