diff --git a/src/java/com/threerings/micasa/simulator/server/Simulant.java b/src/java/com/threerings/micasa/simulator/server/Simulant.java index 11fe7a841..fd8aecd3b 100644 --- a/src/java/com/threerings/micasa/simulator/server/Simulant.java +++ b/src/java/com/threerings/micasa/simulator/server/Simulant.java @@ -1,26 +1,63 @@ // -// $Id: Simulant.java,v 1.1 2001/12/19 09:32:02 shaper Exp $ +// $Id: Simulant.java,v 1.2 2001/12/19 23:30:47 shaper Exp $ package com.threerings.micasa.simulator.client; +import com.threerings.presents.dobj.MessageEvent; + import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.data.PlaceObject; -public abstract class Simulant +import com.threerings.parlor.game.GameCodes; +import com.threerings.parlor.game.GameConfig; + +import com.threerings.micasa.simulator.server.SimulatorServer; + +public abstract class Simulant implements GameCodes { /** - * Sets the body object associated with this simulant. + * Initializes the simulant with a body object and the game config for + * the game they'll be engaged in. */ - public void setBodyObject (BodyObject self) + public void init (BodyObject self, GameConfig config) { _self = self; + _config = config; } /** * Called when the simulant is about to enter the room in which it - * will be doing all of its business. + * will be doing all of its business. Default implementation + * immediately notifies the game manager that the simulant is ready to + * play. Sub-classes may wish to override this to do things like + * subscribe to the game object, but should be sure to call this + * method when they're finished to give the game manager the go-ahead + * to proceed. */ - public abstract void willEnterPlace (PlaceObject plobj); + public void willEnterPlace (PlaceObject plobj) + { + // let the game manager know that the simulant's ready + MessageEvent mevt = new MessageEvent( + plobj.getOid(), PLAYER_READY_NOTIFICATION, null); + postEvent(mevt); + } + + /** + * Posts the given message event to the server. Since the simulant + * resides within the server itself, it has no available client + * distributed object manager and so we must set up the source oid + * ourselves before sending it on its merry way. Sub-classes should + * accordingly be sure to make use of this method to send any + * messages. + */ + protected void postEvent (MessageEvent mevt) + { + mevt.setSourceOid(_self.getOid()); + SimulatorServer.omgr.postEvent(mevt); + } + + /** The game config object. */ + protected GameConfig _config; /** Our body object. */ protected BodyObject _self; diff --git a/src/java/com/threerings/micasa/simulator/server/SimulatorManager.java b/src/java/com/threerings/micasa/simulator/server/SimulatorManager.java index 26361ae98..d5bd3f255 100644 --- a/src/java/com/threerings/micasa/simulator/server/SimulatorManager.java +++ b/src/java/com/threerings/micasa/simulator/server/SimulatorManager.java @@ -1,5 +1,5 @@ // -// $Id: SimulatorManager.java,v 1.2 2001/12/19 10:02:53 shaper Exp $ +// $Id: SimulatorManager.java,v 1.3 2001/12/19 23:30:47 shaper Exp $ package com.threerings.micasa.simulator.server; @@ -8,7 +8,6 @@ import java.util.ArrayList; import com.samskivert.util.Config; import com.threerings.presents.dobj.DObject; -import com.threerings.presents.dobj.MessageEvent; import com.threerings.presents.dobj.ObjectAccessException; import com.threerings.presents.dobj.Subscriber; import com.threerings.presents.server.InvocationManager; @@ -21,7 +20,6 @@ import com.threerings.crowd.server.PlaceManager; import com.threerings.crowd.server.PlaceRegistry; import com.threerings.crowd.server.PlaceRegistry.CreationObserver; -import com.threerings.parlor.game.GameCodes; import com.threerings.parlor.game.GameConfig; import com.threerings.parlor.game.GameManager; import com.threerings.parlor.game.GameObject; @@ -35,7 +33,7 @@ import com.threerings.micasa.simulator.client.SimulatorCodes; * services on the server side. */ public class SimulatorManager - implements GameCodes, SimulatorCodes + implements SimulatorCodes { /** * Initializes the simulator manager manager. This should be called by @@ -71,6 +69,7 @@ public class SimulatorManager { // save off game request info _source = source; + _config = config; _simClass = simClass; _playerCount = playerCount; @@ -160,7 +159,7 @@ public class SimulatorManager // give the simulant its body BodyObject bobj = (BodyObject)_sims.get(ii - 1); - sim.setBodyObject(bobj); + sim.init(bobj, _config); // give the simulant a chance to engage in place antics sim.willEnterPlace(_gobj); @@ -174,12 +173,6 @@ public class SimulatorManager "[e=" + e + "]."); return; } - - // let the game manager know that the simulant's ready - MessageEvent mevt = new MessageEvent( - _gobj.getOid(), PLAYER_READY_NOTIFICATION, null); - mevt.setSourceOid(bobj.getOid()); - SimulatorServer.omgr.postEvent(mevt); } } @@ -198,6 +191,9 @@ public class SimulatorManager /** The simulant class instantiated on game creation. */ protected String _simClass; + /** The game config object. */ + protected GameConfig _config; + /** The body object of the player requesting the game creation. */ protected BodyObject _source; } diff --git a/src/java/com/threerings/micasa/simulator/server/SimulatorServer.java b/src/java/com/threerings/micasa/simulator/server/SimulatorServer.java index d21f17754..4e563da0d 100644 --- a/src/java/com/threerings/micasa/simulator/server/SimulatorServer.java +++ b/src/java/com/threerings/micasa/simulator/server/SimulatorServer.java @@ -1,10 +1,9 @@ // -// $Id: SimulatorServer.java,v 1.1 2001/12/19 09:32:02 shaper Exp $ +// $Id: SimulatorServer.java,v 1.2 2001/12/19 23:30:47 shaper Exp $ package com.threerings.micasa.simulator.server; import com.threerings.crowd.server.CrowdServer; -import com.threerings.parlor.server.ParlorManager; import com.threerings.micasa.Log; @@ -14,9 +13,6 @@ import com.threerings.micasa.Log; */ public class SimulatorServer extends CrowdServer { - /** The parlor manager in operation on this server. */ - public static ParlorManager parmgr = new ParlorManager(); - /** The simulator manager in operation on this server. */ public static SimulatorManager simmgr = new SimulatorManager(); @@ -29,8 +25,7 @@ public class SimulatorServer extends CrowdServer // do the base server initialization super.init(); - // initialize our managers - parmgr.init(config, invmgr); + // initialize the manager simmgr.init(config, invmgr); Log.info("Simulator server initialized.");