Nixed my earlier fiddling and replaced it with a sensible addition to the turn
game logic which is that we won't try to start the next turn if the game reports being over. If we still see problems with infinite loops in GG games, then we'll reinstate the fiddling. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@28 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -61,4 +61,10 @@ public interface TurnGameObject
|
|||||||
* Returns the array of player names involved in the game.
|
* Returns the array of player names involved in the game.
|
||||||
*/
|
*/
|
||||||
public Name[] getPlayers ();
|
public Name[] getPlayers ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the game is in play, false if not. If a game is not in
|
||||||
|
* play after a turn has ended, the next turn will not be started.
|
||||||
|
*/
|
||||||
|
public boolean isInPlay ();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,19 +33,18 @@ import com.threerings.parlor.game.server.GameManagerDelegate;
|
|||||||
import com.threerings.parlor.turn.data.TurnGameObject;
|
import com.threerings.parlor.turn.data.TurnGameObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the server-side turn-based game processing for a turn based
|
* Performs the server-side turn-based game processing for a turn based game.
|
||||||
* game. Game managers which wish to make use of the turn services must
|
* Game managers which wish to make use of the turn services must implement
|
||||||
* implement {@link TurnGameManager} and either create an instance of this
|
* {@link TurnGameManager} and either create an instance of this class, or an
|
||||||
* class, or an instance of a derivation which customizes the behavior,
|
* instance of a derivation which customizes the behavior, either of which
|
||||||
* either of which would be passed to {@link GameManager#addDelegate} to
|
* would be passed to {@link GameManager#addDelegate} to be activated.
|
||||||
* be activated.
|
|
||||||
*/
|
*/
|
||||||
public class TurnGameManagerDelegate extends GameManagerDelegate
|
public class TurnGameManagerDelegate extends GameManagerDelegate
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructs a delegate that will manage the turn game state and call
|
* Constructs a delegate that will manage the turn game state and call back
|
||||||
* back to the supplied {@link TurnGameManager} implementation to let
|
* to the supplied {@link TurnGameManager} implementation to let it in on
|
||||||
* it in on the progression of the game.
|
* the progression of the game.
|
||||||
*/
|
*/
|
||||||
public TurnGameManagerDelegate (TurnGameManager tgmgr)
|
public TurnGameManagerDelegate (TurnGameManager tgmgr)
|
||||||
{
|
{
|
||||||
@@ -54,11 +53,11 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the index of the current turn holder as configured in the
|
* Returns the index of the current turn holder as configured in the game
|
||||||
* game object.
|
* object.
|
||||||
*
|
*
|
||||||
* @return the index into the players array of the current turn holder
|
* @return the index into the players array of the current turn holder or
|
||||||
* or <code>-1</code> if there is no current turn holder.
|
* <code>-1</code> if there is no current turn holder.
|
||||||
*/
|
*/
|
||||||
public int getTurnHolderIndex ()
|
public int getTurnHolderIndex ()
|
||||||
{
|
{
|
||||||
@@ -81,15 +80,14 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to start the next turn. It calls {@link
|
* Called to start the next turn. It calls {@link
|
||||||
* TurnGameManager#turnWillStart} to allow our owning manager to
|
* TurnGameManager#turnWillStart} to allow our owning manager to perform
|
||||||
* perform any pre-start turn processing, sets the turn holder that
|
* any pre-start turn processing, sets the turn holder that was configured
|
||||||
* was configured either when the game started or when finishing up
|
* either when the game started or when finishing up the last turn, and
|
||||||
* the last turn, and then calls {@link TurnGameManager#turnDidStart}
|
* then calls {@link TurnGameManager#turnDidStart} to allow the manager to
|
||||||
* to allow the manager to perform any post-start turn
|
* perform any post-start turn processing. This assumes that a valid turn
|
||||||
* processing. This assumes that a valid turn holder has been
|
* holder has been assigned. If some pre-game preparation needs to take
|
||||||
* assigned. If some pre-game preparation needs to take place in a
|
* place in a non-turn-based manner, this function should not be called
|
||||||
* non-turn-based manner, this function should not be called until it
|
* until it is time to start the first turn.
|
||||||
* is time to start the first turn.
|
|
||||||
*/
|
*/
|
||||||
public void startTurn ()
|
public void startTurn ()
|
||||||
{
|
{
|
||||||
@@ -120,19 +118,22 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to end the turn. Whatever indication a game manager has that
|
* Called to end the turn. Whatever indication a game manager has that the
|
||||||
* the turn has ended (probably the submission of a valid move of some
|
* turn has ended (probably the submission of a valid move of some sort by
|
||||||
* sort by the turn holding player), it should call this function to
|
* the turn holding player), it should call this function to cause this
|
||||||
* cause this turn to end and the next to begin.
|
* turn to end and the next to begin.
|
||||||
*
|
*
|
||||||
* <p> If the next turn should not be started immediately after this
|
* <p> If the game is no longer in play (see {@link TurnGame#isInPlay})
|
||||||
* turn, the game manager should arrange for {@link
|
* after having called {@link TurnGameManager#turnDidEnd} and {@link
|
||||||
* #setNextTurnHolder} to set the {@link #_turnIdx} field to
|
* #setNextTurnHolder}, then the next turn will not automatically be
|
||||||
* <code>-1</code> which will cause us not to start the next turn. It
|
* started.
|
||||||
* can then call {@link GameManager#endGame} if the game is over or do
|
*
|
||||||
* whatever else it needs to do outside the context of the turn flow.
|
* <p> If the game is in play, but the next turn should not be started
|
||||||
* To start things back up again it would set {@link #_turnIdx} to the
|
* immediately, the game manager should have {@link #setNextTurnHolder} set
|
||||||
* next turn holder and call {@link #startTurn} itself.
|
* the {@link #_turnIdx} field to <code>-1</code> which will cause us to
|
||||||
|
* not start the next turn. To start things back up again it would set
|
||||||
|
* {@link #_turnIdx} to the next turn holder and call {@link #startTurn}
|
||||||
|
* itself.
|
||||||
*/
|
*/
|
||||||
public void endTurn ()
|
public void endTurn ()
|
||||||
{
|
{
|
||||||
@@ -142,19 +143,9 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
// figure out who's up next
|
// figure out who's up next
|
||||||
setNextTurnHolder();
|
setNextTurnHolder();
|
||||||
|
|
||||||
// and start the next turn if desired
|
// and start the next turn if appropriate
|
||||||
if (_turnIdx != -1) {
|
if (_turnGame.isInPlay() && _turnIdx != -1) {
|
||||||
// prevent infinite loops if the game manager decides to
|
startTurn();
|
||||||
// unwittingly call endTurn() in turnDidStart()
|
|
||||||
if (_startingTurn) {
|
|
||||||
Log.warning("Refusing to start looping in endTurn() " +
|
|
||||||
"[game=" + where() + "].");
|
|
||||||
Thread.dumpStack();
|
|
||||||
} else {
|
|
||||||
_startingTurn = true;
|
|
||||||
startTurn();
|
|
||||||
}
|
|
||||||
_startingTurn = false;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// otherwise, clear out the turn holder
|
// otherwise, clear out the turn holder
|
||||||
@@ -253,8 +244,4 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
/** The player index of the current turn holder or <code>-1</code> if
|
/** The player index of the current turn holder or <code>-1</code> if
|
||||||
* it's no one's turn. */
|
* it's no one's turn. */
|
||||||
protected int _turnIdx = -1;
|
protected int _turnIdx = -1;
|
||||||
|
|
||||||
/** Used to avoid infinite loops in buggy game managers that call endTurn()
|
|
||||||
* from startTurn(). */
|
|
||||||
protected boolean _startingTurn;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user