Wired up rest of location change stuff.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@776 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-12-14 01:51:46 +00:00
parent b9b0d9cd69
commit 8e27b7e740
4 changed files with 74 additions and 12 deletions
@@ -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;
}