Modified gameDidStart() and gameDidEnd() to take place after the game
state transition event has been processed. This ensures that any events posted up to (and during) the call to startGame() or endGame() are dispatched before we invoke code that reacts to that change in game state. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@593 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
//
|
//
|
||||||
// $Id: GameManager.java,v 1.14 2001/10/24 01:00:54 mdb Exp $
|
// $Id: GameManager.java,v 1.15 2001/11/07 03:21:42 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.parlor.game;
|
package com.threerings.parlor.game;
|
||||||
|
|
||||||
|
import com.threerings.presents.dobj.AttributeChangeListener;
|
||||||
|
import com.threerings.presents.dobj.AttributeChangedEvent;
|
||||||
import com.threerings.presents.dobj.MessageEvent;
|
import com.threerings.presents.dobj.MessageEvent;
|
||||||
|
|
||||||
import com.threerings.crowd.data.BodyObject;
|
import com.threerings.crowd.data.BodyObject;
|
||||||
@@ -24,7 +26,8 @@ import com.threerings.parlor.client.ParlorCodes;
|
|||||||
* bodies in that location.
|
* bodies in that location.
|
||||||
*/
|
*/
|
||||||
public class GameManager
|
public class GameManager
|
||||||
extends PlaceManager implements ParlorCodes, GameCodes
|
extends PlaceManager
|
||||||
|
implements ParlorCodes, GameCodes, AttributeChangeListener
|
||||||
{
|
{
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
protected Class getPlaceObjectClass ()
|
protected Class getPlaceObjectClass ()
|
||||||
@@ -132,8 +135,10 @@ public class GameManager
|
|||||||
// transition the game to started
|
// transition the game to started
|
||||||
_gameobj.setState(GameObject.IN_PLAY);
|
_gameobj.setState(GameObject.IN_PLAY);
|
||||||
|
|
||||||
// and let the derived class do its post-start stuff
|
// wait until we hear the game state transition on the game object
|
||||||
gameDidStart();
|
// to invoke our game did start code so that we can be sure that
|
||||||
|
// any events dispatched on the game object prior to or during the
|
||||||
|
// call to startGame() have been dispatched
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,10 +152,10 @@ public class GameManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called right after the game start notification was delivered.
|
* Called after the game start notification was dispatched. Derived
|
||||||
* Derived classes should override this to perform whatever
|
* classes can override this to put whatever wheels they might need
|
||||||
* machinations are necessary to start the game in motion (if anything
|
* into motion now that the game is started (if anything other than
|
||||||
* other than issuing the game start notification is necessary).
|
* issuing the game start notification is necessary).
|
||||||
*/
|
*/
|
||||||
protected void gameDidStart ()
|
protected void gameDidStart ()
|
||||||
{
|
{
|
||||||
@@ -168,8 +173,10 @@ public class GameManager
|
|||||||
// transition to the game over state
|
// transition to the game over state
|
||||||
_gameobj.setState(GameObject.GAME_OVER);
|
_gameobj.setState(GameObject.GAME_OVER);
|
||||||
|
|
||||||
// do our post-game stuff
|
// wait until we hear the game state transition on the game object
|
||||||
gameDidEnd();
|
// to invoke our game over code so that we can be sure that any
|
||||||
|
// final events dispatched on the game object prior to the call to
|
||||||
|
// endGame() have been dispatched
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,6 +189,24 @@ public class GameManager
|
|||||||
// calculate ratings and all that...
|
// calculate ratings and all that...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
public void attributeChanged (AttributeChangedEvent event)
|
||||||
|
{
|
||||||
|
if (event.getName().equals(GameObject.STATE)) {
|
||||||
|
switch (event.getIntValue()) {
|
||||||
|
case GameObject.IN_PLAY:
|
||||||
|
// now we do our start of game processing
|
||||||
|
gameDidStart();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GameObject.GAME_OVER:
|
||||||
|
// now we do our end of game processing
|
||||||
|
gameDidEnd();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Handles player ready notifications. */
|
/** Handles player ready notifications. */
|
||||||
protected class PlayerReadyHandler implements MessageHandler
|
protected class PlayerReadyHandler implements MessageHandler
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user