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:
@@ -24,6 +24,7 @@ package com.threerings.micasa.lobby;
|
||||
import java.util.Properties;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.crowd.server.PlaceManager;
|
||||
import com.threerings.micasa.Log;
|
||||
|
||||
@@ -44,8 +45,8 @@ public class LobbyManager extends PlaceManager
|
||||
_gameIdent = getConfigValue(config, "ugi");
|
||||
_name = getConfigValue(config, "name");
|
||||
|
||||
// keep this for later
|
||||
_lobreg = lobreg;
|
||||
// let the lobby registry know that we're up and running
|
||||
lobreg.lobbyReady(_plobj.getOid(), _gameIdent, _name);
|
||||
|
||||
Log.info("Lobby manager initialized [ident=" + _gameIdent +
|
||||
", name=" + _name + "].");
|
||||
@@ -64,19 +65,10 @@ public class LobbyManager extends PlaceManager
|
||||
return value;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected Class getPlaceObjectClass ()
|
||||
@Override // from PlaceManager
|
||||
protected PlaceObject createPlaceObject ()
|
||||
{
|
||||
return LobbyObject.class;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void didStartup ()
|
||||
{
|
||||
super.didStartup();
|
||||
|
||||
// let the lobby registry know that we're up and running
|
||||
_lobreg.lobbyReady(_plobj.getOid(), _gameIdent, _name);
|
||||
return new LobbyObject();
|
||||
}
|
||||
|
||||
/** The universal game identifier for the game matchmade by this
|
||||
@@ -85,7 +77,4 @@ public class LobbyManager extends PlaceManager
|
||||
|
||||
/** The human readable name of this lobby. */
|
||||
protected String _name;
|
||||
|
||||
/** A reference to the lobby registry. */
|
||||
protected LobbyRegistry _lobreg;
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ public class LobbyRegistry
|
||||
// lobbyReady() when it has obtained a reference to its lobby
|
||||
// object and is ready to roll
|
||||
LobbyManager lobmgr = (LobbyManager)
|
||||
MiCasaServer.plreg.createPlace(config, null);
|
||||
MiCasaServer.plreg.createPlace(config);
|
||||
lobmgr.init(this, props);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -34,7 +34,6 @@ import com.threerings.presents.server.InvocationManager;
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.crowd.server.PlaceManager;
|
||||
import com.threerings.crowd.server.PlaceRegistry.CreationObserver;
|
||||
import com.threerings.crowd.server.PlaceRegistry;
|
||||
|
||||
import com.threerings.parlor.game.data.GameAI;
|
||||
@@ -83,7 +82,7 @@ public class SimulatorManager
|
||||
new CreateGameTask(source, config, simClass, playerCount);
|
||||
}
|
||||
|
||||
public class CreateGameTask implements CreationObserver
|
||||
public class CreateGameTask
|
||||
{
|
||||
public CreateGameTask (
|
||||
BodyObject source, GameConfig config, String simClass,
|
||||
@@ -97,10 +96,8 @@ public class SimulatorManager
|
||||
|
||||
try {
|
||||
// create the game manager and begin its 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)
|
||||
// process. the game manager will take care of notifying the
|
||||
// players that the game has been created
|
||||
|
||||
// configure the game config with the player names
|
||||
config.players = new Name[_playerCount];
|
||||
@@ -108,23 +105,16 @@ public class SimulatorManager
|
||||
for (int ii = 1; ii < _playerCount; ii++) {
|
||||
config.players[ii] = new Name("simulant" + ii);
|
||||
}
|
||||
|
||||
// we needn't hang around and wait for game object
|
||||
// creation if it's just us
|
||||
CreationObserver obs = (_playerCount == 1) ? null : this;
|
||||
_gmgr = (GameManager)_plreg.createPlace(config, obs);
|
||||
_gmgr = (GameManager)_plreg.createPlace(config);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.warning("Unable to create game manager [e=" + e + "].");
|
||||
Log.logStackTrace(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void placeCreated (PlaceObject place, PlaceManager pmgr)
|
||||
{
|
||||
// cast the place to the game object for the game we're creating
|
||||
_gobj = (GameObject)place;
|
||||
_gobj = (GameObject)_gmgr.getPlaceObject();
|
||||
|
||||
// determine the AI player skill level
|
||||
byte skill;
|
||||
@@ -142,19 +132,15 @@ public class SimulatorManager
|
||||
// resolve the simulant body objects
|
||||
ClientResolutionListener listener = new ClientResolutionListener()
|
||||
{
|
||||
public void clientResolved (Name username, ClientObject clobj)
|
||||
{
|
||||
public void clientResolved (Name username, ClientObject clobj) {
|
||||
// hold onto the body object for later game creation
|
||||
_sims.add(clobj);
|
||||
|
||||
// create the game if we've received all body objects
|
||||
if (_sims.size() == (_playerCount - 1)) {
|
||||
createSimulants();
|
||||
}
|
||||
}
|
||||
|
||||
public void resolutionFailed (Name username, Exception cause)
|
||||
{
|
||||
public void resolutionFailed (Name username, Exception cause) {
|
||||
Log.warning("Unable to create simulant body object " +
|
||||
"[error=" + cause + "].");
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -30,6 +30,8 @@ import com.threerings.presents.server.InvocationManager;
|
||||
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.crowd.server.CrowdServer;
|
||||
import com.threerings.crowd.server.PlaceManager;
|
||||
import com.threerings.crowd.server.PlaceRegistry;
|
||||
|
||||
import com.threerings.whirled.Log;
|
||||
import com.threerings.whirled.data.Scene;
|
||||
@@ -142,17 +144,16 @@ public class SceneRegistry
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the specified scene be resolved, which means loaded
|
||||
* into the server and initialized if the scene is not currently
|
||||
* active. The supplied callback instance will be notified, on the
|
||||
* dobjmgr thread, when the scene has been resolved. If the scene is
|
||||
* already active, it will be notified immediately (before the call to
|
||||
* {@link #resolveScene} returns).
|
||||
* Requests that the specified scene be resolved, which means loaded into
|
||||
* the server and initialized if the scene is not currently active. The
|
||||
* supplied callback instance will be notified, on the dobjmgr thread, when
|
||||
* the scene has been resolved. If the scene is already active, it will be
|
||||
* notified immediately (before the call to {@link #resolveScene} returns).
|
||||
*
|
||||
* @param sceneId the id of the scene to resolve.
|
||||
* @param target a reference to a callback instance that will be
|
||||
* notified when the scene has been resolved (which may be immediately
|
||||
* if the scene is already active).
|
||||
* @param target a reference to a callback instance that will be notified
|
||||
* when the scene has been resolved (which may be immediately if the scene
|
||||
* is already active).
|
||||
*/
|
||||
public void resolveScene (int sceneId, ResolutionListener target)
|
||||
{
|
||||
@@ -239,7 +240,7 @@ public class SceneRegistry
|
||||
* Called when the scene resolution has completed successfully.
|
||||
*/
|
||||
protected void processSuccessfulResolution (
|
||||
SceneModel model, UpdateList updates)
|
||||
SceneModel model, final UpdateList updates)
|
||||
{
|
||||
// now that the scene is loaded, we can create a scene manager for
|
||||
// it. that will be initialized by the place registry and when
|
||||
@@ -248,17 +249,21 @@ public class SceneRegistry
|
||||
|
||||
try {
|
||||
// first create our scene instance
|
||||
Scene scene = _scfact.createScene(
|
||||
final Scene scene = _scfact.createScene(
|
||||
model, _confact.createPlaceConfig(model));
|
||||
|
||||
// now create our scene manager
|
||||
SceneManager scmgr = (SceneManager)
|
||||
CrowdServer.plreg.createPlace(scene.getPlaceConfig(), null);
|
||||
scmgr.setSceneData(scene, updates, this);
|
||||
CrowdServer.plreg.createPlace(scene.getPlaceConfig(),
|
||||
new PlaceRegistry.PreStartupHook() {
|
||||
public void invoke (PlaceManager pmgr) {
|
||||
((SceneManager)pmgr).setSceneData(
|
||||
scene, updates, SceneRegistry.this);
|
||||
}
|
||||
});
|
||||
|
||||
// when the scene manager completes its startup procedings, it
|
||||
// will call back to the scene registry and let us know that
|
||||
// we can turn the penders loose
|
||||
// when the scene manager completes its startup procedings, it will
|
||||
// call back to the scene registry and let us know that we can turn
|
||||
// the penders loose
|
||||
|
||||
} catch (Exception e) {
|
||||
// so close, but no cigar
|
||||
|
||||
@@ -462,11 +462,29 @@ public class SpotSceneManager extends SceneManager
|
||||
* one another.
|
||||
*/
|
||||
protected class ClusterRecord extends HashIntMap
|
||||
implements Subscriber
|
||||
{
|
||||
public ClusterRecord ()
|
||||
{
|
||||
CrowdServer.omgr.createObject(ClusterObject.class, this);
|
||||
_clobj = CrowdServer.omgr.registerObject(new ClusterObject());
|
||||
_clusters.put(_clobj.getOid(), this);
|
||||
|
||||
// let any mapped users know about our cluster
|
||||
Iterator iter = values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
ClusteredBodyObject body = (ClusteredBodyObject)iter.next();
|
||||
body.setClusterOid(_clobj.getOid());
|
||||
_clobj.addToOccupants(((BodyObject)body).getOid());
|
||||
}
|
||||
|
||||
// configure our cluster record and publish it
|
||||
_cluster.clusterOid = _clobj.getOid();
|
||||
_ssobj.addToClusters(_cluster);
|
||||
|
||||
// if we didn't manage to add our creating user when we first
|
||||
// started up, there's no point in our sticking around
|
||||
if (size() == 0) {
|
||||
destroy(true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean addBody (BodyObject body)
|
||||
@@ -565,44 +583,6 @@ public class SpotSceneManager extends SceneManager
|
||||
return _cluster;
|
||||
}
|
||||
|
||||
public void objectAvailable (DObject object)
|
||||
{
|
||||
// keep this feller around
|
||||
_clobj = (ClusterObject)object;
|
||||
_clusters.put(_clobj.getOid(), this);
|
||||
|
||||
// let any mapped users know about our cluster
|
||||
Iterator iter = values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
ClusteredBodyObject body = (ClusteredBodyObject)iter.next();
|
||||
body.setClusterOid(_clobj.getOid());
|
||||
_clobj.addToOccupants(((BodyObject)body).getOid());
|
||||
}
|
||||
|
||||
// configure our cluster record and publish it
|
||||
_cluster.clusterOid = _clobj.getOid();
|
||||
_ssobj.addToClusters(_cluster);
|
||||
|
||||
// if we didn't manage to add our creating user when we first
|
||||
// started up, there's no point in our sticking around
|
||||
if (size() == 0) {
|
||||
destroy(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void requestFailed (int oid, ObjectAccessException cause)
|
||||
{
|
||||
Log.warning("Aiya! Failed to create cluster object " +
|
||||
"[cause=" + cause + ", penders=" + size() + "].");
|
||||
|
||||
// let any mapped users know that we're hosed
|
||||
Iterator iter = values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
ClusteredBodyObject body = (ClusteredBodyObject)iter.next();
|
||||
body.setClusterOid(-1);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString ()
|
||||
{
|
||||
return "[cluster=" + _cluster + ", size=" + size() + "]";
|
||||
|
||||
Reference in New Issue
Block a user