Restructured things to work with the new mechanism for creating distributed
objects. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@53 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -26,29 +26,30 @@ import com.threerings.presents.dobj.AttributeChangedEvent;
|
||||
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.crowd.server.PlaceManager;
|
||||
import com.threerings.crowd.server.PlaceRegistry;
|
||||
|
||||
import com.threerings.parlor.game.data.GameObject;
|
||||
|
||||
/**
|
||||
* An abstract convenience class used server-side to keep an eye on a game
|
||||
* and perform a one-time game-over activity when the game ends. Classes
|
||||
* that care to make use of the game watcher should create an instance,
|
||||
* implement {@link #gameDidEnd}, and pass the instance to the place
|
||||
* registry in the call to {@link PlaceRegistry#createPlace} when the
|
||||
* puzzle is created.
|
||||
* An abstract convenience class used server-side to keep an eye on a game and
|
||||
* perform a one-time game-over activity when the game ends. Classes that care
|
||||
* to make use of the game watcher should create an instance with their newly
|
||||
* created {@link GameObject} and implement {@link #gameDidEnd}.
|
||||
*/
|
||||
public abstract class GameWatcher
|
||||
implements PlaceRegistry.CreationObserver, AttributeChangeListener
|
||||
implements AttributeChangeListener
|
||||
{
|
||||
// documentation inherited
|
||||
public void placeCreated (PlaceObject place, PlaceManager pmgr)
|
||||
public void init (PlaceManager plmgr)
|
||||
{
|
||||
_gameobj = (GameObject)place;
|
||||
init((GameObject)plmgr.getPlaceObject());
|
||||
}
|
||||
|
||||
public void init (GameObject gameobj)
|
||||
{
|
||||
_gameobj = gameobj;
|
||||
_gameobj.addListener(this);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
// from interface AttributeChangeListener
|
||||
public void attributeChanged (AttributeChangedEvent event)
|
||||
{
|
||||
if (event.getName().equals(GameObject.STATE)) {
|
||||
@@ -66,8 +67,8 @@ public abstract class GameWatcher
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the game ends to give derived classes a chance to
|
||||
* engage in their game-over antics.
|
||||
* Called when the game ends to give derived classes a chance to engage in
|
||||
* their game-over antics.
|
||||
*/
|
||||
protected abstract void gameDidEnd (GameObject gameobj);
|
||||
|
||||
|
||||
@@ -206,13 +206,10 @@ public class ParlorManager
|
||||
invite.invitee.getVisibleName(),
|
||||
invite.inviter.getVisibleName() };
|
||||
|
||||
// create the game manager and begin it's initialization
|
||||
// process. the game manager will take care of notifying the
|
||||
// players that the game has been created once it has been
|
||||
// started up (which is done by the place registry once the
|
||||
// game object creation has completed)
|
||||
GameManager gmgr = (GameManager)
|
||||
_plreg.createPlace(invite.config, null);
|
||||
// create the game manager and begin it's initialization process;
|
||||
// the game manager will take care of notifying the players that
|
||||
// the game has been created
|
||||
_plreg.createPlace(invite.config);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.warning("Unable to create game manager [invite=" + invite +
|
||||
|
||||
@@ -181,14 +181,11 @@ public class ParlorProvider
|
||||
config.players = new Name[] { user.getVisibleName() };
|
||||
}
|
||||
|
||||
// create the game manager and begin its initialization
|
||||
// process
|
||||
GameManager gmgr = (GameManager)
|
||||
CrowdServer.plreg.createPlace(config, null);
|
||||
// create the game manager and begin its initialization process
|
||||
CrowdServer.plreg.createPlace(config);
|
||||
|
||||
// the game manager will take care of notifying the player
|
||||
// that the game has been created once it has been started up;
|
||||
// but we let the caller know that we processed their request
|
||||
// the game manager will notify the player that their game is
|
||||
// "ready", but tell the caller that we processed their request
|
||||
listener.requestProcessed();
|
||||
|
||||
} catch (InstantiationException ie) {
|
||||
|
||||
@@ -40,7 +40,6 @@ import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.crowd.server.CrowdServer;
|
||||
import com.threerings.crowd.server.PlaceManager;
|
||||
import com.threerings.crowd.server.PlaceRegistry;
|
||||
|
||||
import com.threerings.parlor.Log;
|
||||
import com.threerings.parlor.data.ParlorCodes;
|
||||
@@ -261,14 +260,9 @@ public class TableManager
|
||||
// fill the players array into the game config
|
||||
table.config.players = table.getPlayers();
|
||||
|
||||
PlaceRegistry.CreationObserver obs =
|
||||
new PlaceRegistry.CreationObserver() {
|
||||
public void placeCreated (PlaceObject plobj, PlaceManager pmgr) {
|
||||
gameCreated(table, plobj);
|
||||
}
|
||||
};
|
||||
try {
|
||||
CrowdServer.plreg.createPlace(table.config, obs);
|
||||
PlaceManager pmgr = CrowdServer.plreg.createPlace(table.config);
|
||||
gameCreated(table, (GameObject)pmgr.getPlaceObject());
|
||||
} catch (Throwable t) {
|
||||
Log.warning("Failed to create manager for game " +
|
||||
"[config=" + table.config + "]: " + t);
|
||||
@@ -277,16 +271,16 @@ public class TableManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when our game has been created, we take this opportunity to
|
||||
* clean up the table and transition it to "in play" mode.
|
||||
* Called when our game has been created, we take this opportunity to clean
|
||||
* up the table and transition it to "in play" mode.
|
||||
*/
|
||||
protected void gameCreated (Table table, PlaceObject plobj)
|
||||
protected void gameCreated (Table table, GameObject gameobj)
|
||||
{
|
||||
// update the table with the newly created game object
|
||||
table.gameOid = plobj.getOid();
|
||||
table.gameOid = gameobj.getOid();
|
||||
|
||||
// configure the privacy of the game
|
||||
((GameObject) plobj).setIsPrivate(table.tconfig.privateTable);
|
||||
gameobj.setIsPrivate(table.tconfig.privateTable);
|
||||
|
||||
// clear the occupant to table mappings as this game is underway
|
||||
for (int i = 0; i < table.bodyOids.length; i++) {
|
||||
@@ -295,7 +289,7 @@ public class TableManager
|
||||
|
||||
// add an object death listener to unmap the table when the game
|
||||
// finally goes away
|
||||
plobj.addListener(_gameDeathListener);
|
||||
gameobj.addListener(_gameDeathListener);
|
||||
|
||||
// and then update the lobby object that contains the table
|
||||
_tlobj.updateTables(table);
|
||||
|
||||
Reference in New Issue
Block a user