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