From 9e6e07ea6142e441e768019b989a9b3905ee054a Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 5 Feb 2002 22:12:42 +0000 Subject: [PATCH] Extracted the simulator server services out into an implementable interface so that we can replace the server with a more sophisticated one when running the simulator. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@938 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../micasa/simulator/client/SimulatorApp.java | 10 +++- .../micasa/simulator/server/SimpleServer.java | 30 ++++++++++ .../simulator/server/SimulatorManager.java | 10 ++-- .../simulator/server/SimulatorServer.java | 59 +++++-------------- 4 files changed, 60 insertions(+), 49 deletions(-) create mode 100644 src/java/com/threerings/micasa/simulator/server/SimpleServer.java diff --git a/src/java/com/threerings/micasa/simulator/client/SimulatorApp.java b/src/java/com/threerings/micasa/simulator/client/SimulatorApp.java index 1d6eddd37..de1d6a47b 100644 --- a/src/java/com/threerings/micasa/simulator/client/SimulatorApp.java +++ b/src/java/com/threerings/micasa/simulator/client/SimulatorApp.java @@ -1,5 +1,5 @@ // -// $Id: SimulatorApp.java,v 1.2 2002/01/16 02:59:08 mdb Exp $ +// $Id: SimulatorApp.java,v 1.3 2002/02/05 22:12:42 mdb Exp $ package com.threerings.micasa.simulator.client; @@ -15,6 +15,7 @@ import com.threerings.presents.net.UsernamePasswordCreds; import com.threerings.micasa.Log; import com.threerings.micasa.simulator.data.SimulatorInfo; +import com.threerings.micasa.simulator.server.SimpleServer; import com.threerings.micasa.simulator.server.SimulatorServer; /** @@ -26,7 +27,7 @@ public class SimulatorApp public void init (String[] args) throws Exception { // create the server - SimulatorServer server = new SimulatorServer(); + SimulatorServer server = createSimulatorServer(); server.init(); _serverThread = new ServerThread(server); @@ -49,6 +50,11 @@ public class SimulatorApp _frame.setController(ctrl); } + protected SimulatorServer createSimulatorServer () + { + return new SimpleServer(); + } + protected SimulatorFrame createSimulatorFrame () { return new SimpleFrame(); diff --git a/src/java/com/threerings/micasa/simulator/server/SimpleServer.java b/src/java/com/threerings/micasa/simulator/server/SimpleServer.java new file mode 100644 index 000000000..f9abb073e --- /dev/null +++ b/src/java/com/threerings/micasa/simulator/server/SimpleServer.java @@ -0,0 +1,30 @@ +// +// $Id: SimpleServer.java,v 1.1 2002/02/05 22:12:42 mdb Exp $ + +package com.threerings.micasa.simulator.server; + +import com.threerings.crowd.data.BodyObject; +import com.threerings.crowd.server.CrowdServer; + +/** + * A simple simulator server implementation that extends the crowd server + * and provides no special functionality. + */ +public class SimpleServer extends CrowdServer + implements SimulatorServer +{ + /** + * Called by the simulator manager to map a username to a particular + * body object. This should only be called from the dobjmgr thread. + * + *

This is copied from {@link CrowdServer#mapBody} as that + * implementation is protected and cannot be referenced by classes in + * the simulator package, but we know what we're doing and so we + * knowingly expose this functionality to other classes in our + * package. + */ + public void fakeBodyMapping (String username, BodyObject bodobj) + { + _bodymap.put(username, bodobj); + } +} diff --git a/src/java/com/threerings/micasa/simulator/server/SimulatorManager.java b/src/java/com/threerings/micasa/simulator/server/SimulatorManager.java index 4cf80d48b..8fd8b251f 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.5 2002/02/05 20:27:07 mdb Exp $ +// $Id: SimulatorManager.java,v 1.6 2002/02/05 22:12:42 mdb Exp $ package com.threerings.micasa.simulator.server; @@ -49,7 +49,7 @@ public class SimulatorManager */ public void init (Config config, InvocationManager invmgr, PlaceRegistry plreg, ClientManager clmgr, - RootDObjectManager omgr) + RootDObjectManager omgr, SimulatorServer simserv) { // register our simulator provider SimulatorProvider sprov = new SimulatorProvider(this); @@ -59,6 +59,7 @@ public class SimulatorManager _plreg = plreg; _clmgr = clmgr; _omgr = omgr; + _simserv = simserv; } /** @@ -125,7 +126,7 @@ public class SimulatorManager bobj.username = "simulant" + (_sims.size() + 1); // map the simulant into the server body set - SimulatorServer.mapBody(bobj.username, bobj); + _simserv.fakeBodyMapping(bobj.username, bobj); // hold onto it for later game creation _sims.add(bobj); @@ -171,7 +172,7 @@ public class SimulatorManager // give the simulant its body BodyObject bobj = (BodyObject)_sims.get(ii - 1); - sim.init(bobj, _config); + sim.init(bobj, _config, _omgr); // give the simulant a chance to engage in place antics sim.willEnterPlace(_gobj); @@ -214,4 +215,5 @@ public class SimulatorManager protected PlaceRegistry _plreg; protected ClientManager _clmgr; protected RootDObjectManager _omgr; + protected SimulatorServer _simserv; } diff --git a/src/java/com/threerings/micasa/simulator/server/SimulatorServer.java b/src/java/com/threerings/micasa/simulator/server/SimulatorServer.java index ad24e2aba..95b0dc986 100644 --- a/src/java/com/threerings/micasa/simulator/server/SimulatorServer.java +++ b/src/java/com/threerings/micasa/simulator/server/SimulatorServer.java @@ -1,61 +1,34 @@ // -// $Id: SimulatorServer.java,v 1.4 2002/02/05 20:27:07 mdb Exp $ +// $Id: SimulatorServer.java,v 1.5 2002/02/05 22:12:42 mdb Exp $ package com.threerings.micasa.simulator.server; import com.threerings.crowd.data.BodyObject; -import com.threerings.crowd.server.CrowdServer; - -import com.threerings.micasa.Log; /** - * This class is the main entry point and general organizer of everything - * that goes on in the Simulator game server process. + * The simulator manager needs a mechanism for faking body object + * registrations, which is provided by implementations of this interface. */ -public class SimulatorServer extends CrowdServer +public interface SimulatorServer { - /** The simulator manager in operation on this server. */ - public static SimulatorManager simmgr = new SimulatorManager(); + /** + * Called to initialize this server instance. + * + * @exception Exception thrown if anything goes wrong initializing the + * server. + */ + public void init () throws Exception; /** - * Initializes all of the server services and prepares for operation. + * Called to perform the main body of server processing. This is + * called from the server thread and should do the simulator server's + * primary business. */ - public void init () - throws Exception - { - // do the base server initialization - super.init(); - - // initialize the manager - simmgr.init(config, invmgr, plreg, clmgr, omgr); - - Log.info("Simulator server initialized."); - } + public void run (); /** * Called by the simulator manager to map a username to a particular * body object. This should only be called from the dobjmgr thread. - * - *

This is copied from {@link CrowdServer#mapBody} as that - * implementation is protected and cannot be referenced by classes in - * the simulator package, but we know what we're doing and so we - * knowingly expose this functionality to other classes in our - * package. */ - protected static void mapBody (String username, BodyObject bodobj) - { - _bodymap.put(username, bodobj); - } - - public static void main (String[] args) - { - SimulatorServer server = new SimulatorServer(); - try { - server.init(); - server.run(); - } catch (Exception e) { - Log.warning("Unable to initialize server."); - Log.logStackTrace(e); - } - } + public void fakeBodyMapping (String username, BodyObject bodobj); }