Widening.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@326 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2007-06-23 02:00:20 +00:00
parent b452746dc2
commit d895c99484
@@ -53,8 +53,7 @@ import com.threerings.whirled.spot.data.SpotCodes;
import com.threerings.whirled.spot.data.SpotScene; import com.threerings.whirled.spot.data.SpotScene;
/** /**
* Extends the standard scene director with facilities to move between * Extends the standard scene director with facilities to move between locations within a scene.
* locations within a scene.
*/ */
public class SpotSceneDirector extends BasicDirector public class SpotSceneDirector extends BasicDirector
implements Subscriber, AttributeChangeListener implements Subscriber, AttributeChangeListener
@@ -62,12 +61,11 @@ public class SpotSceneDirector extends BasicDirector
private static const log :Log = Log.getLog(SpotSceneDirector); private static const log :Log = Log.getLog(SpotSceneDirector);
/** /**
* Creates a new spot scene director with the specified context and * Creates a new spot scene director with the specified context and which will cooperate with
* which will cooperate with the supplied scene director. * the supplied scene director.
* *
* @param ctx the active client context. * @param ctx the active client context.
* @param locdir the location director with which we will be * @param locdir the location director with which we will be cooperating.
* cooperating.
* @param scdir the scene director with which we will be cooperating. * @param scdir the scene director with which we will be cooperating.
*/ */
public function SpotSceneDirector ( public function SpotSceneDirector (
@@ -79,15 +77,14 @@ public class SpotSceneDirector extends BasicDirector
_scdir = scdir; _scdir = scdir;
// wire ourselves up to hear about leave place notifications // wire ourselves up to hear about leave place notifications
locdir.addLocationObserver(new LocationAdapter(null, locdir.addLocationObserver(new LocationAdapter(null, function (place :PlaceObject) :void {
function (place :PlaceObject) :void { handleDeparture();
handleDeparture(); }));
}));
} }
/** /**
* Configures this spot scene director with a chat director, with * Configures this spot scene director with a chat director, with which it will coordinate to
* which it will coordinate to implement cluster chatting. * implement cluster chatting.
*/ */
public function setChatDirector (chatdir :ChatDirector) :void public function setChatDirector (chatdir :ChatDirector) :void
{ {
@@ -95,8 +92,8 @@ public class SpotSceneDirector extends BasicDirector
} }
/** /**
* Returns our current location unless we have a location change * Returns our current location unless we have a location change pending, in which case our
* pending, in which case our pending location is returned. * pending location is returned.
*/ */
public function getIntendedLocation () :Location public function getIntendedLocation () :Location
{ {
@@ -104,57 +101,49 @@ public class SpotSceneDirector extends BasicDirector
} }
/** /**
* Requests that this client move to the location specified by the * Requests that this client move to the location specified by the supplied portal id. A
* supplied portal id. A request will be made and when the response is * request will be made and when the response is received, the location observers will be
* received, the location observers will be notified of success or * notified of success or failure.
* failure.
* *
* @return true if the request was issued, false if it was rejected by * @return true if the request was issued, false if it was rejected by a location observer or
* a location observer or because we have another request outstanding. * because we have another request outstanding.
*/ */
public function traversePortal ( public function traversePortal (
portalId :int, portalId :int, rl :com.threerings.util.ResultListener = null) :Boolean
rl :com.threerings.util.ResultListener = null) :Boolean
{ {
// look up the destination scene and location // look up the destination scene and location
var scene :SpotScene = (_scdir.getScene() as SpotScene); var scene :SpotScene = (_scdir.getScene() as SpotScene);
if (scene == null) { if (scene == null) {
log.warning("Requested to traverse portal when we have " + log.warning("Requested to traverse portal when we have no scene " +
"no scene [portalId=" + portalId + "]."); "[portalId=" + portalId + "].");
return false; return false;
} }
// sanity check the server's notion of what scene we're in with // sanity check the server's notion of what scene we're in with our notion of it
// our notion of it
var sceneId :int = _scdir.getScene().getId(); var sceneId :int = _scdir.getScene().getId();
var sbobj :ScenedBodyObject = var sbobj :ScenedBodyObject = (_wctx.getClient().getClientObject() as ScenedBodyObject);
(_wctx.getClient().getClientObject() as ScenedBodyObject);
if (sceneId != sbobj.getSceneId()) { if (sceneId != sbobj.getSceneId()) {
log.warning("Client and server differ in opinion of what scene " + log.warning("Client and server differ in opinion of what scene we're in " +
"we're in [sSceneId=" + sbobj.getSceneId() + "[sSceneId=" + sbobj.getSceneId() + ", cSceneId=" + sceneId + "].");
", cSceneId=" + sceneId + "].");
return false; return false;
} }
// find the portal they're talking about // find the portal they're talking about
var dest :Portal = scene.getPortal(portalId); var dest :Portal = scene.getPortal(portalId);
if (dest == null) { if (dest == null) {
log.warning("Requested to traverse non-existent portal " + log.warning("Requested to traverse non-existent portal [portalId=" + portalId +
"[portalId=" + portalId + ", portals=" + scene.getPortals() + ", portals=" + scene.getPortals() + "].");
"].");
return false; return false;
} }
// prepare to move to this scene (sets up pending data) // prepare to move to this scene (sets up pending data)
if (!_scdir.prepareMoveTo(dest.targetSceneId, rl)) { if (!_scdir.prepareMoveTo(dest.targetSceneId, rl)) {
log.info("Portal traversal vetoed by scene director " + log.info("Portal traversal vetoed by scene director [portalId=" + portalId + "].");
"[portalId=" + portalId + "].");
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 sceneVer :int = 0; var sceneVer :int = 0;
var pendingModel :SceneModel = _scdir.getPendingModel(); var pendingModel :SceneModel = _scdir.getPendingModel();
if (pendingModel != null) { if (pendingModel != null) {
@@ -162,34 +151,29 @@ public class SpotSceneDirector extends BasicDirector
} }
// issue a traversePortal request // issue a traversePortal request
log.info("Issuing traversePortal(" + log.info("Issuing traversePortal(" + sceneId + ", " + dest + ", " + sceneVer + ").");
sceneId + ", " + dest + ", " + sceneVer + ")."); _sservice.traversePortal(_wctx.getClient(), sceneId, portalId, sceneVer, _scdir);
_sservice.traversePortal(
_wctx.getClient(), sceneId, portalId, sceneVer, _scdir);
return true; return true;
} }
/** /**
* Issues a request to change our location within the scene to the * Issues a request to change our location within the scene to the specified location.
* specified location.
* *
* @param loc the new location to which to move. * @param loc the new location to which to move.
* @param listener will be notified of success or failure. Most client * @param listener will be notified of success or failure. Most client entities find out about
* entities find out about location changes via changes to the * location changes via changes to the occupant info data, but the initiator of a location
* occupant info data, but the initiator of a location change request * change request can be notified of its success or failure, primarily so that it can act in
* can be notified of its success or failure, primarily so that it can * anticipation of a successful location change (like by starting a sprite moving toward the
* act in anticipation of a successful location change (like by * new location), but backtrack if it finds out that the location change failed.
* starting a sprite moving toward the new location), but backtrack if
* it finds out that the location change failed.
*/ */
public function changeLocation ( public function changeLocation (
loc :Location, listener :com.threerings.util.ResultListener) :void loc :Location, listener :com.threerings.util.ResultListener) :void
{ {
// refuse if there's a pending location change or if we're already // refuse if there's a pending location change or if we're already at the specified
// at the specified location // location
if (loc.equivalent(_location)) { if (loc.equivalent(_location)) {
log.info("Not going to " + loc + "; we're at " + _location + log.info("Not going to " + loc + "; we're at " + _location +
" and we're headed to " + _pendingLoc + "."); " and we're headed to " + _pendingLoc + ".");
if (listener != null) { if (listener != null) {
// This isn't really a failure, it's just a no-op. // This isn't really a failure, it's just a no-op.
listener.requestCompleted(_location); listener.requestCompleted(_location);
@@ -199,7 +183,7 @@ public class SpotSceneDirector extends BasicDirector
if (_pendingLoc != null) { if (_pendingLoc != null) {
log.info("Not going to " + loc + "; we're at " + _location + log.info("Not going to " + loc + "; we're at " + _location +
" and we're headed to " + _pendingLoc + "."); " and we're headed to " + _pendingLoc + ".");
if (listener != null) { if (listener != null) {
// Already moving, best thing to do is ignore it. // Already moving, best thing to do is ignore it.
listener.requestCompleted(_pendingLoc); listener.requestCompleted(_pendingLoc);
@@ -209,8 +193,8 @@ public class SpotSceneDirector extends BasicDirector
var scene :SpotScene = (_scdir.getScene() as SpotScene); var scene :SpotScene = (_scdir.getScene() as SpotScene);
if (scene == null) { if (scene == null) {
log.warning("Requested to change locations, but we're not " + log.warning("Requested to change locations, but we're not currently in any scene " +
"currently in any scene [loc=" + loc + "]."); "[loc=" + loc + "].");
if (listener != null) { if (listener != null) {
listener.requestFailed(new Error("m.cant_get_there")); listener.requestFailed(new Error("m.cant_get_there"));
} }
@@ -218,8 +202,7 @@ public class SpotSceneDirector extends BasicDirector
} }
var sceneId :int = _scdir.getScene().getId(); var sceneId :int = _scdir.getScene().getId();
log.info("Sending changeLocation request [scid=" + sceneId + log.info("Sending changeLocation request [scid=" + sceneId + ", loc=" + loc + "].");
", loc=" + loc + "].");
_pendingLoc = (loc.clone() as Location); _pendingLoc = (loc.clone() as Location);
var clist :ConfirmAdapter = new ConfirmAdapter( var clist :ConfirmAdapter = new ConfirmAdapter(
@@ -240,20 +223,19 @@ public class SpotSceneDirector extends BasicDirector
} }
/** /**
* Issues a request to join the cluster associated with the specified * Issues a request to join the cluster associated with the specified user (starting one if
* user (starting one if necessary). * necessary).
* *
* @param froid the bodyOid of another user; the calling user will * @param froid the bodyOid of another user; the calling user will be made to join the target
* be made to join the target user's cluster. * user's cluster.
* @param listener will be notified of success or failure. * @param listener will be notified of success or failure.
*/ */
public function joinCluster ( public function joinCluster (froid :int, listener :com.threerings.util.ResultListener) :void
froid :int, listener :com.threerings.util.ResultListener) :void
{ {
var scene :SpotScene = (_scdir.getScene() as SpotScene); var scene :SpotScene = (_scdir.getScene() as SpotScene);
if (scene == null) { if (scene == null) {
log.warning("Requested to join cluster, but we're not " + log.warning("Requested to join cluster, but we're not currently in any scene " +
"currently in any scene [froid=" + froid + "]."); "[froid=" + froid + "].");
if (listener != null) { if (listener != null) {
listener.requestFailed(new Error("m.cant_get_there")); listener.requestFailed(new Error("m.cant_get_there"));
} }
@@ -276,27 +258,27 @@ public class SpotSceneDirector extends BasicDirector
} }
/** /**
* Sends a chat message to the other users in the cluster to which the * Sends a chat message to the other users in the cluster to which the location that we
* location that we currently occupy belongs. * currently occupy belongs.
* *
* @return true if a cluster speak message was delivered, false if we * @return true if a cluster speak message was delivered, false if we are not in a valid
* are not in a valid cluster and refused to deliver the request. * cluster and refused to deliver the request.
*/ */
public function requestClusterSpeak ( public function requestClusterSpeak (
message :String, mode :int = ChatCodes.DEFAULT_MODE) :Boolean message :String, mode :int = ChatCodes.DEFAULT_MODE) :Boolean
{ {
// make sure we're currently in a scene // make sure we're currently in a scene
var scene :SpotScene = (_scdir.getScene() as SpotScene); var scene :SpotScene = (_scdir.getScene() as SpotScene);
if (scene == null) { if (scene == null) {
log.warning("Requested to speak to cluster, but we're not " + log.warning("Requested to speak to cluster, but we're not currently in any scene " +
"currently in any scene [message=" + message + "]."); "[message=" + message + "].");
return false; return false;
} }
// make sure we're part of a cluster // make sure we're part of a cluster
if (_self.getClusterOid() <= 0) { if (_self.getClusterOid() <= 0) {
log.info("Ignoring cluster speak as we're not in a cluster " + log.info("Ignoring cluster speak as we're not in a cluster " +
"[cloid=" + _self.getClusterOid() + "]."); "[cloid=" + _self.getClusterOid() + "].");
return false; return false;
} }
@@ -320,8 +302,7 @@ public class SpotSceneDirector extends BasicDirector
// it's our new cluster! // it's our new cluster!
_clobj = object; _clobj = object;
if (_chatdir != null) { if (_chatdir != null) {
_chatdir.addAuxiliarySource(object, _chatdir.addAuxiliarySource(object, SpotCodes.CLUSTER_CHAT_TYPE);
SpotCodes.CLUSTER_CHAT_TYPE);
} }
} }
} }
@@ -329,15 +310,14 @@ public class SpotSceneDirector extends BasicDirector
// documentation inherited from interface // documentation inherited from interface
public function requestFailed (oid :int, cause :ObjectAccessError) :void public function requestFailed (oid :int, cause :ObjectAccessError) :void
{ {
log.warning("Unable to subscribe to cluster chat object " + log.warning("Unable to subscribe to cluster chat object [oid=" + oid +
"[oid=" + oid + ", cause=" + cause + "]."); ", cause=" + cause + "].");
} }
// documentation inherited from interface // documentation inherited from interface
public function attributeChanged (event :AttributeChangedEvent) :void public function attributeChanged (event :AttributeChangedEvent) :void
{ {
if (event.getName() == _self.getClusterField() && if (event.getName() == _self.getClusterField() && event.getValue() != event.getOldValue()) {
event.getValue() != event.getOldValue()) {
maybeUpdateCluster(); maybeUpdateCluster();
} }
} }
@@ -404,14 +384,13 @@ public class SpotSceneDirector extends BasicDirector
} }
/** /**
* Checks to see if our cluster has changed and does the necessary * Checks to see if our cluster has changed and does the necessary subscription machinations if
* subscription machinations if necessary. * necessary.
*/ */
protected function maybeUpdateCluster () :void protected function maybeUpdateCluster () :void
{ {
var cloid :int = _self.getClusterOid(); var cloid :int = _self.getClusterOid();
if ((_clobj == null && cloid <= 0) || if ((_clobj == null && cloid <= 0) || (_clobj != null && cloid == _clobj.getOid())) {
(_clobj != null && cloid == _clobj.getOid())) {
// our cluster didn't change, we can stop now // our cluster didn't change, we can stop now
return; return;
} }
@@ -428,15 +407,13 @@ public class SpotSceneDirector extends BasicDirector
} }
/** /**
* Convenience routine to unwire chat for and unsubscribe from our * Convenience routine to unwire chat for and unsubscribe from our current cluster, if any.
* current cluster, if any.
* *
* @param force clear the cluster even if we're still apparently in it. * @param force clear the cluster even if we're still apparently in it.
*/ */
protected function clearCluster (force :Boolean) :void protected function clearCluster (force :Boolean) :void
{ {
if (_clobj != null && if (_clobj != null && (force || (_clobj.getOid() != _self.getClusterOid()))) {
(force || (_clobj.getOid() != _self.getClusterOid()))) {
if (_chatdir != null) { if (_chatdir != null) {
_chatdir.removeAuxiliarySource(_clobj); _chatdir.removeAuxiliarySource(_clobj);
} }
@@ -464,8 +441,7 @@ public class SpotSceneDirector extends BasicDirector
/** The location we currently occupy. */ /** The location we currently occupy. */
protected var _location :Location; protected var _location :Location;
/** The location to which we have an outstanding change location /** The location to which we have an outstanding change location request. */
* request. */
protected var _pendingLoc :Location; protected var _pendingLoc :Location;
/** The cluster chat object for the cluster we currently occupy. */ /** The cluster chat object for the cluster we currently occupy. */