diff --git a/src/java/com/threerings/whirled/client/SceneDirector.java b/src/java/com/threerings/whirled/client/SceneDirector.java index 14ddd92c4..d6b5c742e 100644 --- a/src/java/com/threerings/whirled/client/SceneDirector.java +++ b/src/java/com/threerings/whirled/client/SceneDirector.java @@ -1,5 +1,5 @@ // -// $Id: SceneDirector.java,v 1.8 2001/12/04 00:30:27 mdb Exp $ +// $Id: SceneDirector.java,v 1.9 2001/12/14 01:51:45 mdb Exp $ package com.threerings.whirled.client; @@ -304,10 +304,8 @@ public class SceneDirector * to enter. */ protected SceneModel _pendingModel; - /** - * The id of the scene for which we have an outstanding moveTo - * request, or -1 if we have no outstanding request. - */ + /** The id of the scene for which we have an outstanding moveTo + * request, or -1 if we have no outstanding request. */ protected int _pendingSceneId = -1; /** The id of the scene we previously occupied. */ diff --git a/src/java/com/threerings/whirled/server/SceneManager.java b/src/java/com/threerings/whirled/server/SceneManager.java index 38e07e2e1..8acc6215c 100644 --- a/src/java/com/threerings/whirled/server/SceneManager.java +++ b/src/java/com/threerings/whirled/server/SceneManager.java @@ -1,5 +1,5 @@ // -// $Id: SceneManager.java,v 1.8 2001/11/12 20:56:56 mdb Exp $ +// $Id: SceneManager.java,v 1.9 2001/12/14 01:51:46 mdb Exp $ package com.threerings.whirled.server; @@ -40,12 +40,25 @@ public class SceneManager extends PlaceManager * Called by the scene registry once the scene manager has been * created (and initialized), but before it is started up. */ - protected void postInit ( + protected void setSceneData ( RuntimeScene scene, SceneModel model, SceneRegistry screg) { _scene = scene; _model = model; _screg = screg; + + // let derived classes react to the receipt of scene data + gotSceneData(); + } + + /** + * A method that can be overridden by derived classes to perform + * initialization processing after we receive our scene information + * but before we're started up (and hence registered as an active + * place). + */ + protected void gotSceneData () + { } /** diff --git a/src/java/com/threerings/whirled/server/SceneRegistry.java b/src/java/com/threerings/whirled/server/SceneRegistry.java index e50d18b47..cb705ab3e 100644 --- a/src/java/com/threerings/whirled/server/SceneRegistry.java +++ b/src/java/com/threerings/whirled/server/SceneRegistry.java @@ -1,5 +1,5 @@ // -// $Id: SceneRegistry.java,v 1.11 2001/12/13 07:23:25 mdb Exp $ +// $Id: SceneRegistry.java,v 1.12 2001/12/14 01:51:46 mdb Exp $ package com.threerings.whirled.server; @@ -194,7 +194,7 @@ public class SceneRegistry // stuff; we'll somehow need to convey configuration // information for the scene to the scene manager, but for now // let's punt - scmgr.postInit(scene, model, this); + scmgr.setSceneData(scene, model, this); // when the scene manager completes its startup procedings, it // will call back to the scene registry and let us know that diff --git a/src/java/com/threerings/whirled/spot/client/SpotSceneDirector.java b/src/java/com/threerings/whirled/spot/client/SpotSceneDirector.java index 1f2fa9ff3..950963047 100644 --- a/src/java/com/threerings/whirled/spot/client/SpotSceneDirector.java +++ b/src/java/com/threerings/whirled/spot/client/SpotSceneDirector.java @@ -1,5 +1,5 @@ // -// $Id: SpotSceneDirector.java,v 1.1 2001/12/14 00:12:32 mdb Exp $ +// $Id: SpotSceneDirector.java,v 1.2 2001/12/14 01:51:46 mdb Exp $ package com.threerings.whirled.spot.client; @@ -22,6 +22,24 @@ import com.threerings.whirled.spot.data.Location; public class SpotSceneDirector extends SceneDirector implements SpotCodes { + /** + * This is used to communicate back to the caller of {@link + * #changeLocation}. + */ + public static interface ChangeObserver + { + /** + * Indicates that the requested location change succeeded. + */ + public void locationChangeSucceeded (int locationId); + + /** + * Indicates that the requested location change failed and + * provides a reason code explaining the failure. + */ + public void locationChangeFailed (int locationId, String reason); + } + /** * Creates a new spot scene director with the specified context. * @@ -39,9 +57,15 @@ public class SpotSceneDirector extends SceneDirector /** * Issues a request to change our location within the scene to the - * location identified by the specified id. + * location identified by the specified id. Most client entities find + * out about location changes via changes to the occupant info data, + * but the initiator of a location change request can be notified of + * its success or failure, primarily so that it can act in + * anticipation of a successful location change (like by starting a + * sprite moving toward the new location), but backtrack if it finds + * out that the location change failed. */ - public void changeLocation (int locationId) + public void changeLocation (int locationId, ChangeObserver obs) { // refuse if there's a pending location change if (_pendingLocId != -1) { @@ -76,6 +100,7 @@ public class SpotSceneDirector extends SceneDirector // make a note that we're changing to this location _pendingLocId = locationId; + _changeObserver = obs; // and send the location change request SpotService.changeLoc(_ctx.getClient(), _sceneId, locationId, this); } @@ -85,6 +110,17 @@ public class SpotSceneDirector extends SceneDirector */ public void handleChangeLocSucceeded (int invid) { + ChangeObserver obs = _changeObserver; + int locId = _pendingLocId; + + // clear out our pending location info + _pendingLocId = -1; + _changeObserver = null; + + // if we had an observer, let them know things went well + if (obs != null) { + obs.locationChangeSucceeded(locId); + } } /** @@ -92,9 +128,24 @@ public class SpotSceneDirector extends SceneDirector */ public void handleChangeLocFailed (int invid, String reason) { + ChangeObserver obs = _changeObserver; + int locId = _pendingLocId; + + // clear out our pending location info + _pendingLocId = -1; + _changeObserver = null; + + // if we had an observer, let them know things went well + if (obs != null) { + obs.locationChangeFailed(locId, reason); + } } /** The location id on which we have an outstanding change location * request. */ protected int _pendingLocId = -1; + + /** An entity that wants to know if a requested location change + * succeded or failed. */ + protected ChangeObserver _changeObserver; }