From 6a77a7e1f1a2a7534477b0c2803e465a241e4ea4 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 13 Jul 2007 19:57:46 +0000 Subject: [PATCH] Widening. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@353 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../whirled/client/SceneDirector.as | 173 ++++++++---------- 1 file changed, 72 insertions(+), 101 deletions(-) diff --git a/src/as/com/threerings/whirled/client/SceneDirector.as b/src/as/com/threerings/whirled/client/SceneDirector.as index 7637e570..0a1074a2 100644 --- a/src/as/com/threerings/whirled/client/SceneDirector.as +++ b/src/as/com/threerings/whirled/client/SceneDirector.as @@ -49,20 +49,17 @@ import com.threerings.whirled.util.WhirledContext; import com.threerings.whirled.data.SceneUpdate; /** - * The scene director is the client's interface to all things scene - * related. It interfaces with the scene repository to ensure that scene - * objects are available when the client enters a particular scene. It - * handles moving from scene to scene (it coordinates with the {@link - * LocationDirector} in order to do this). + * The scene director is the client's interface to all things scene related. It interfaces with the + * scene repository to ensure that scene objects are available when the client enters a particular + * scene. It handles moving from scene to scene (it coordinates with the {@link LocationDirector} + * in order to do this). * - *

Note that when the scene director is in use instead of the location - * director, scene ids instead of place oids will be supplied to {@link - * LocationObserver#locationMayChange} and {@link + *

Note that when the scene director is in use instead of the location director, scene ids + * instead of place oids will be supplied to {@link LocationObserver#locationMayChange} and {@link * LocationObserver#locationChangeFailed}. */ public class SceneDirector extends BasicDirector - implements LocationDirector_FailureHandler, - SceneReceiver, SceneService_SceneMoveListener + implements LocationDirector_FailureHandler, SceneReceiver, SceneService_SceneMoveListener { private static const log :Log = Log.getLog(SceneDirector); @@ -70,19 +67,16 @@ public class SceneDirector extends BasicDirector * Creates a new scene director with the specified context. * * @param ctx the active client context. - * @param locdir the location director in use on the client, with - * which the scene director will coordinate when changing location. - * @param screp the entity from which the scene director will load - * scene data from the local client scene storage. This may be null - * when the SceneDirector is constructed, but it should be - * supplied via {@link #setSceneRepository} prior to really using - * this director. - * @param fact the factory that knows which derivation of {@link - * Scene} to create for the current system. + * @param locdir the location director in use on the client, with which the scene director will + * coordinate when changing location. + * @param screp the entity from which the scene director will load scene data from the local + * client scene storage. This may be null when the SceneDirector is constructed, but it should + * be supplied via {@link #setSceneRepository} prior to really using this director. + * @param fact the factory that knows which derivation of {@link Scene} to create for the + * current system. */ - public function SceneDirector ( - ctx :WhirledContext, locdir :LocationDirector, - screp :SceneRepository, fact :SceneFactory) + public function SceneDirector (ctx :WhirledContext, locdir :LocationDirector, + screp :SceneRepository, fact :SceneFactory) { super(ctx); @@ -92,13 +86,12 @@ public class SceneDirector extends BasicDirector setSceneRepository(screp); _fact = fact; - // set ourselves up as a failure handler with the location - // director because we need to do special processing + // set ourselves up as a failure handler with the location director because we need to do + // special processing _locdir.setFailureHandler(this); // register for scene notifications - _wctx.getClient().getInvocationDirector().registerReceiver( - new SceneDecoder(this)); + _wctx.getClient().getInvocationDirector().registerReceiver(new SceneDecoder(this)); } /** @@ -111,8 +104,8 @@ public class SceneDirector extends BasicDirector } /** - * Returns the display scene object associated with the scene we - * currently occupy or null if we currently occupy no scene. + * Returns the display scene object associated with the scene we currently occupy or null if we + * currently occupy no scene. */ public function getScene () :Scene { @@ -120,13 +113,11 @@ public class SceneDirector extends BasicDirector } /** - * Requests that this client move the specified scene. A request will - * be made and when the response is received, the location observers - * will be notified of success or failure. + * Requests that this client move the specified scene. A request will be made and when the + * response is received, the location observers will be notified of success or failure. * - * @return true if the move to request was issued, false if it was - * rejected by a location observer or because we have another request - * outstanding. + * @return true if the move to request was issued, false if it was rejected by a location + * observer or because we have another request outstanding. */ public function moveTo (sceneId :int) :Boolean { @@ -138,8 +129,7 @@ public class SceneDirector extends BasicDirector // sanity-check the destination scene id if (sceneId == _sceneId) { - log.warning("Refusing request to move to the same scene " + - "[sceneId=" + sceneId + "]."); + log.warning("Refusing request to move to the same scene [sceneId=" + sceneId + "]."); return false; } @@ -148,9 +138,8 @@ public class SceneDirector extends BasicDirector return false; } - // check the version of our cached copy of the scene to which - // we're requesting to move; if we were unable to load it, assume - // a cached version of zero + // check the version of our cached copy of the scene to which we're requesting to move; if + // we were unable to load it, assume a cached version of zero var sceneVers :int = 0; if (_pendingModel != null) { sceneVers = _pendingModel.version; @@ -163,41 +152,36 @@ public class SceneDirector extends BasicDirector } /** - * Prepares to move to the requested scene. The location observers are - * asked to ratify the move and our pending scene mode is loaded from - * the scene repository. This can be called by cooperating directors - * that need to coopt the moveTo process. + * Prepares to move to the requested scene. The location observers are asked to ratify the move + * and our pending scene mode is loaded from the scene repository. This can be called by + * cooperating directors that need to coopt the moveTo process. */ public function prepareMoveTo (sceneId :int, rl :ResultListener) :Boolean { - // first check to see if our observers are happy with this move - // request + // first check to see if our observers are happy with this move request if (!_locdir.mayMoveTo(sceneId, rl)) { return false; } - // we need to call this both to mark that we're issuing a move - // request and to check to see if the last issued request should - // be considered stale + // we need to call this both to mark that we're issuing a move request and to check to see + // if the last issued request should be considered stale var refuse :Boolean = _locdir.checkRepeatMove(); // complain if we're over-writing a pending request if (_pendingSceneId != -1) { if (refuse) { log.warning("Refusing moveTo; We have a request outstanding " + - "[psid=" + _pendingSceneId + - ", nsid=" + sceneId + "]."); + "[psid=" + _pendingSceneId + ", nsid=" + sceneId + "]."); return false; } else { - log.warning("Overriding stale moveTo request " + - "[psid=" + _pendingSceneId + + log.warning("Overriding stale moveTo request [psid=" + _pendingSceneId + ", nsid=" + sceneId + "]."); } } - // load up the pending scene so that we can communicate it's most - // recent version to the server + // load up the pending scene so that we can communicate it's most recent version to the + // server _pendingModel = loadSceneModel(sceneId); // make a note of our pending scene id @@ -208,11 +192,9 @@ public class SceneDirector extends BasicDirector } /** - * Returns the model loaded in preparation for a scene - * transition. This is made available only for cooperating directors - * which may need to coopt the scene transition process. The pending - * model is only valid immediately following a call to {@link - * #prepareMoveTo}. + * Returns the model loaded in preparation for a scene transition. This is made available only + * for cooperating directors which may need to coopt the scene transition process. The pending + * model is only valid immediately following a call to {@link #prepareMoveTo}. */ public function getPendingModel () :SceneModel { @@ -222,13 +204,12 @@ public class SceneDirector extends BasicDirector // documentation inherited from interface SceneService_SceneMoveListener public function moveSucceeded (placeId :int, config :PlaceConfig) :void { - // our move request was successful, deal with subscribing to our - // new place object + // our move request was successful, deal with subscribing to our new place object _locdir.didMoveTo(placeId, config); - // since we're committed to moving to the new scene, we'll - // parallelize and go ahead and load up the new scene now rather - // than wait until subscription to our place object succeeds + // since we're committed to moving to the new scene, we'll parallelize and go ahead and + // load up the new scene now rather than wait until subscription to our place object + // succeeds // keep track of our previous scene info _previousSceneId = _sceneId; @@ -245,19 +226,17 @@ public class SceneDirector extends BasicDirector // complain if we didn't find a scene if (_model == null) { - log.warning("Aiya! Unable to load scene [sid=" + _sceneId + - ", plid=" + placeId + "]."); + log.warning("Aiya! Unable to load scene [sid=" + _sceneId + ", plid=" + placeId + "]."); return; } - // and finally create a display scene instance with the model and - // the place config + // and finally create a display scene instance with the model and the place config _scene = _fact.createScene(_model, config); } // documentation inherited from interface SceneService_SceneMoveListener public function moveSucceededWithUpdates ( - placeId :int, config :PlaceConfig, updates :Array) :void + placeId :int, config :PlaceConfig, updates :Array) :void { log.info("Got updates [placeId=" + placeId + ", config=" + config + ", updates=" + updates + "]."); @@ -270,8 +249,7 @@ public class SceneDirector extends BasicDirector update.validate(model); } catch (ise :IllegalOperationError) { log.warning("Scene update failed validation [model=" + model + - ", update=" + update + - ", error=" + ise.message + "]."); + ", update=" + update + ", error=" + ise.message + "]."); failure = true; break; } @@ -297,9 +275,9 @@ public class SceneDirector extends BasicDirector log.logStackTrace(ioe); } - // act as if the scene move failed, though we'll be in a funny - // state because the server thinks we've changed scenes, but - // the client can try again without its booched scene model + // act as if the scene move failed, though we'll be in a funny state because the server + // thinks we've changed scenes, but the client can try again without its booched scene + // model requestFailed(InvocationCodes.INTERNAL_ERROR); return; } @@ -315,9 +293,8 @@ public class SceneDirector extends BasicDirector public function moveSucceededWithScene ( placeId :int, config :PlaceConfig, model :SceneModel) :void { - log.info("Got updated scene model [placeId=" + placeId + - ", config=" + config + ", scene=" + model.sceneId + "/" + - model.name + "/" + model.version + "]."); + log.info("Got updated scene model [placeId=" + placeId + ", config=" + config + + ", scene=" + model.sceneId + "/" + model.name + "/" + model.version + "]."); // update the model in the repository persistSceneModel(model); @@ -341,8 +318,7 @@ public class SceneDirector extends BasicDirector } /** - * Called by SceneController instances to tell us about an update - * to the current scene. + * Called by SceneController instances to tell us about an update to the current scene. */ public function updateReceived (update :SceneUpdate) :void { @@ -351,8 +327,7 @@ public class SceneDirector extends BasicDirector } /** - * Called to clean up our place and scene state information when we - * leave a scene. + * Called to clean up our place and scene state information when we leave a scene. */ public function didLeaveScene () :void { @@ -381,11 +356,10 @@ public class SceneDirector extends BasicDirector public function setMoveHandler (handler :SceneDirector_MoveHandler) :void { if (_moveHandler != null) { - log.warning("Requested to set move handler, but we've " + - "already got one. The conflicting entities will " + - "likely need to perform more sophisticated " + - "coordination to deal with failures. " + - "[old=" + _moveHandler + ", new=" + handler + "]."); + log.warning("Requested to set move handler, but we've already got one. The " + + "conflicting entities will likely need to perform more sophisticated " + + "coordination to deal with failures. [old=" + _moveHandler + + ", new=" + handler + "]."); } else { _moveHandler = handler; @@ -393,8 +367,8 @@ public class SceneDirector extends BasicDirector } /** - * Called when something breaks down in the process of performing a - * moveTo request. + * Called when something breaks down in the process of performing a moveTo + * request. */ public function recoverFailedMove (placeId :int) :void { @@ -404,8 +378,8 @@ public class SceneDirector extends BasicDirector // clear out our now bogus scene tracking info clearScene(); - // if we were previously somewhere (and that somewhere isn't where - // we just tried to go), try going back to that happy place + // if we were previously somewhere (and that somewhere isn't where we just tried to go), + // try going back to that happy place if (_previousSceneId != -1 && _previousSceneId != sceneId) { // if we have a move handler use that if (_moveHandler != null) { @@ -418,8 +392,8 @@ public class SceneDirector extends BasicDirector } /** - * Clears out our current scene information and releases the scene - * model for the loaded scene back to the cache. + * Clears out our current scene information and releases the scene model for the loaded scene + * back to the cache. */ protected function clearScene () :void { @@ -432,8 +406,8 @@ public class SceneDirector extends BasicDirector } /** - * Loads a scene from the repository. If the scene is cached, it will - * be returned from the cache instead. + * Loads a scene from the repository. If the scene is cached, it will be returned from the + * cache instead. */ protected function loadSceneModel (sceneId :int) :SceneModel { @@ -451,8 +425,7 @@ public class SceneDirector extends BasicDirector } catch (ioe :IOError) { // complain first, then return null - log.warning("Error loading scene [scid=" + sceneId + - ", error=" + ioe + "]."); + log.warning("Error loading scene [scid=" + sceneId + ", error=" + ioe + "]."); } } @@ -467,9 +440,8 @@ public class SceneDirector extends BasicDirector try { _screp.storeSceneModel(model); } catch (ioe :IOError) { - log.warning("Failed to update repository with updated scene " + - "[sceneId=" + model.sceneId + ", nvers=" + model.version + - "]."); + log.warning("Failed to update repository with updated scene [sceneId=" + model.sceneId + + ", nvers=" + model.version + "]."); log.logStackTrace(ioe); } } @@ -528,8 +500,7 @@ public class SceneDirector extends BasicDirector /** The id of the scene we currently occupy. */ protected var _sceneId :int = -1; - /** Our most recent copy of the scene model for the scene we're about - * to enter. */ + /** Our most recent copy of the scene model for the scene we're about to enter. */ protected var _pendingModel :SceneModel; /** The id of the scene for which we have an outstanding moveTo