Similarly stay where we are on a failed move if we didn't leave our current
location in trying to get there. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@500 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -67,7 +67,7 @@ public class SceneDirector extends BasicDirector
|
|||||||
* Should instruct the client to move the last known working location (as well as clean up
|
* Should instruct the client to move the last known working location (as well as clean up
|
||||||
* after the failed moveTo request).
|
* after the failed moveTo request).
|
||||||
*/
|
*/
|
||||||
public void recoverMoveTo (int sceneId);
|
public void recoverMoveTo (int previousSceneId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -327,12 +327,8 @@ public class SceneDirector extends BasicDirector
|
|||||||
// from interface SceneService.SceneMoveListener
|
// from interface SceneService.SceneMoveListener
|
||||||
public void requestFailed (String reason)
|
public void requestFailed (String reason)
|
||||||
{
|
{
|
||||||
// clear out our pending request oid
|
|
||||||
int sceneId = _pendingSceneId;
|
|
||||||
_pendingSceneId = -1;
|
|
||||||
|
|
||||||
// let our observers know that something has gone horribly awry
|
// let our observers know that something has gone horribly awry
|
||||||
_locdir.failedToMoveTo(sceneId, reason);
|
_locdir.failedToMoveTo(_pendingSceneId, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -394,15 +390,21 @@ public class SceneDirector extends BasicDirector
|
|||||||
// from interface LocationDirector.FailureHandler
|
// from interface LocationDirector.FailureHandler
|
||||||
public void recoverFailedMove (int placeId)
|
public void recoverFailedMove (int placeId)
|
||||||
{
|
{
|
||||||
|
// if we're currently in a scene, then just stay there
|
||||||
|
if (_sceneId > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// we'll need this momentarily
|
// we'll need this momentarily
|
||||||
int sceneId = _sceneId;
|
int justAttemptedSceneId = _pendingSceneId;
|
||||||
|
_pendingSceneId = -1;
|
||||||
|
|
||||||
// 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 we just tried to go),
|
// if we were previously somewhere (and that somewhere isn't where 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 != justAttemptedSceneId) {
|
||||||
// if we have a move handler use that
|
// if we have a move handler use that
|
||||||
if (_moveHandler != null) {
|
if (_moveHandler != null) {
|
||||||
_moveHandler.recoverMoveTo(_previousSceneId);
|
_moveHandler.recoverMoveTo(_previousSceneId);
|
||||||
|
|||||||
@@ -40,23 +40,20 @@ import com.threerings.whirled.zone.data.ZoneSummary;
|
|||||||
import com.threerings.whirled.zone.util.ZoneUtil;
|
import com.threerings.whirled.zone.util.ZoneUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The zone director augments the scene services with the notion of zones.
|
* The zone director augments the scene services with the notion of zones. Zones are
|
||||||
* Zones are self-contained, connected groups of scenes. The normal scene
|
* self-contained, connected groups of scenes. The normal scene director services can be used to
|
||||||
* director services can be used to move from scene to scene, but moving
|
* move from scene to scene, but moving to a new zone requires a special move request which can be
|
||||||
* to a new zone requires a special move request which can be accomplished
|
* accomplished via the zone director. The zone director also makes available the zone summary
|
||||||
* via the zone director. The zone director also makes available the zone
|
* which provides information on the zone which can be used to generate an overview map or similar.
|
||||||
* summary which provides information on the zone which can be used to
|
|
||||||
* generate an overview map or similar.
|
|
||||||
*/
|
*/
|
||||||
public class ZoneDirector extends BasicDirector
|
public class ZoneDirector extends BasicDirector
|
||||||
implements ZoneReceiver, ZoneService.ZoneMoveListener,
|
implements ZoneReceiver, ZoneService.ZoneMoveListener,
|
||||||
SceneDirector.MoveHandler
|
SceneDirector.MoveHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructs a zone director with the supplied context, and delegate
|
* Constructs a zone director with the supplied context, and delegate scene director (which the
|
||||||
* scene director (which the zone director will coordinate with when
|
* zone director will coordinate with when moving from scene to scene). A zone director is
|
||||||
* moving from scene to scene). A zone director is required on the
|
* required on the client side for systems that wish to use the zone services.
|
||||||
* client side for systems that wish to use the zone services.
|
|
||||||
*/
|
*/
|
||||||
public ZoneDirector (WhirledContext ctx, SceneDirector scdir)
|
public ZoneDirector (WhirledContext ctx, SceneDirector scdir)
|
||||||
{
|
{
|
||||||
@@ -71,9 +68,8 @@ public class ZoneDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the summary for the zone currently occupied by the client
|
* Returns the summary for the zone currently occupied by the client or null if the client does
|
||||||
* or null if the client does not currently occupy a zone (not a
|
* not currently occupy a zone (not a normal situation).
|
||||||
* normal situation).
|
|
||||||
*/
|
*/
|
||||||
public ZoneSummary getZoneSummary ()
|
public ZoneSummary getZoneSummary ()
|
||||||
{
|
{
|
||||||
@@ -81,8 +77,8 @@ public class ZoneDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a zone observer to the list. This observer will subsequently
|
* Adds a zone observer to the list. This observer will subsequently be notified of effected
|
||||||
* be notified of effected and failed zone changes.
|
* and failed zone changes.
|
||||||
*/
|
*/
|
||||||
public void addZoneObserver (ZoneObserver observer)
|
public void addZoneObserver (ZoneObserver observer)
|
||||||
{
|
{
|
||||||
@@ -98,9 +94,9 @@ public class ZoneDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests that this client move the specified scene in the specified
|
* Requests that this client move the specified scene in the specified zone. A request will be
|
||||||
* zone. A request will be made and when the response is received, the
|
* made and when the response is received, the location observers will be notified of success
|
||||||
* location observers will be notified of success or failure.
|
* or failure.
|
||||||
*/
|
*/
|
||||||
public boolean moveTo (int zoneId, int sceneId)
|
public boolean moveTo (int zoneId, int sceneId)
|
||||||
{
|
{
|
||||||
@@ -108,9 +104,9 @@ public class ZoneDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests that this client move the specified scene in the specified
|
* Requests that this client move the specified scene in the specified zone. A request will be
|
||||||
* zone. A request will be made and when the response is received, the
|
* made and when the response is received, the location observers will be notified of success
|
||||||
* location observers will be notified of success or failure.
|
* or failure.
|
||||||
*/
|
*/
|
||||||
public boolean moveTo (int zoneId, int sceneId, ResultListener rl)
|
public boolean moveTo (int zoneId, int sceneId, ResultListener rl)
|
||||||
{
|
{
|
||||||
@@ -121,25 +117,23 @@ public class ZoneDirector extends BasicDirector
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the requested zone is the same as our current zone, we just
|
// if the requested zone is the same as our current zone, we just want a regular old moveTo
|
||||||
// want a regular old moveTo request
|
// request
|
||||||
if (_summary != null && zoneId == _summary.zoneId) {
|
if (_summary != null && zoneId == _summary.zoneId) {
|
||||||
return _scdir.moveTo(sceneId);
|
return _scdir.moveTo(sceneId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, we make a zoned moveTo request; prepare to move to
|
// otherwise, we make a zoned moveTo request; prepare to move to this scene (sets up
|
||||||
// this scene (sets up pending data)
|
// pending data)
|
||||||
if (!_scdir.prepareMoveTo(sceneId, rl)) {
|
if (!_scdir.prepareMoveTo(sceneId, rl)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// let our zone observers know that we're attempting to switch
|
// let our zone observers know that we're attempting to switch zones
|
||||||
// zones
|
|
||||||
notifyObservers(Integer.valueOf(zoneId));
|
notifyObservers(Integer.valueOf(zoneId));
|
||||||
|
|
||||||
// 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
|
|
||||||
int sceneVers = 0;
|
int sceneVers = 0;
|
||||||
SceneModel pendingModel = _scdir.getPendingModel();
|
SceneModel pendingModel = _scdir.getPendingModel();
|
||||||
if (pendingModel != null) {
|
if (pendingModel != null) {
|
||||||
@@ -170,18 +164,14 @@ public class ZoneDirector extends BasicDirector
|
|||||||
_previousZoneId = -1;
|
_previousZoneId = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// from interface ZoneService.ZoneMoveListener
|
||||||
* Called in response to a successful {@link ZoneService#moveTo}
|
public void moveSucceeded (int placeId, PlaceConfig config, ZoneSummary summary)
|
||||||
* request.
|
|
||||||
*/
|
|
||||||
public void moveSucceeded (
|
|
||||||
int placeId, PlaceConfig config, ZoneSummary summary)
|
|
||||||
{
|
{
|
||||||
if (_summary != null) {
|
if (_summary != null) {
|
||||||
// keep track of our previous zone info
|
// keep track of our previous zone info
|
||||||
_previousZoneId = _summary.zoneId;
|
_previousZoneId = _summary.zoneId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep track of the summary
|
// keep track of the summary
|
||||||
_summary = summary;
|
_summary = summary;
|
||||||
|
|
||||||
@@ -192,14 +182,9 @@ public class ZoneDirector extends BasicDirector
|
|||||||
notifyObservers(summary);
|
notifyObservers(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// from interface ZoneService.ZoneMoveListener
|
||||||
* Called in response to a successful {@link ZoneService#moveTo}
|
|
||||||
* request when our cached scene was out of date and the server
|
|
||||||
* determined that we needed some updates.
|
|
||||||
*/
|
|
||||||
public void moveSucceededWithUpdates (
|
public void moveSucceededWithUpdates (
|
||||||
int placeId, PlaceConfig config, ZoneSummary summary,
|
int placeId, PlaceConfig config, ZoneSummary summary, SceneUpdate[] updates)
|
||||||
SceneUpdate[] updates)
|
|
||||||
{
|
{
|
||||||
// keep track of the summary
|
// keep track of the summary
|
||||||
_summary = summary;
|
_summary = summary;
|
||||||
@@ -211,11 +196,7 @@ public class ZoneDirector extends BasicDirector
|
|||||||
notifyObservers(summary);
|
notifyObservers(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// from interface ZoneService.ZoneMoveListener
|
||||||
* Called in response to a successful {@link ZoneService#moveTo}
|
|
||||||
* request when our cached scene was out of date and the server
|
|
||||||
* determined that we needed an updated copy.
|
|
||||||
*/
|
|
||||||
public void moveSucceededWithScene (
|
public void moveSucceededWithScene (
|
||||||
int placeId, PlaceConfig config, ZoneSummary summary, SceneModel model)
|
int placeId, PlaceConfig config, ZoneSummary summary, SceneModel model)
|
||||||
{
|
{
|
||||||
@@ -229,9 +210,7 @@ public class ZoneDirector extends BasicDirector
|
|||||||
notifyObservers(summary);
|
notifyObservers(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// from interface ZoneService.ZoneMoveListener
|
||||||
* Called in response to a failed zoned <code>moveTo</code> request.
|
|
||||||
*/
|
|
||||||
public void requestFailed (String reason)
|
public void requestFailed (String reason)
|
||||||
{
|
{
|
||||||
// let the scene director cope
|
// let the scene director cope
|
||||||
@@ -261,29 +240,28 @@ public class ZoneDirector extends BasicDirector
|
|||||||
moveTo(zoneId, sceneId, null);
|
moveTo(zoneId, sceneId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// from SceneDirector.MoveHandler
|
||||||
* Called when something breaks down after successfully completely a
|
public void recoverMoveTo (int previousSceneId)
|
||||||
* <code>moveTo</code> request.
|
|
||||||
*/
|
|
||||||
public void recoverMoveTo (int sceneId)
|
|
||||||
{
|
{
|
||||||
if (_previousZoneId != -1) {
|
if (_summary != null) {
|
||||||
moveTo(_previousZoneId, sceneId);
|
return; // if we're currently somewhere, just stay there
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise if we were previously in a zone/scene, try going back there
|
||||||
|
if (_previousZoneId != -1) {
|
||||||
|
moveTo(_previousZoneId, previousSceneId);
|
||||||
} else {
|
} else {
|
||||||
_scdir.moveTo(sceneId);
|
_scdir.moveTo(previousSceneId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies observers of success or failure, depending on the type of
|
* Notifies observers of success or failure, depending on the type of object provided as data.
|
||||||
* object provided as data.
|
|
||||||
*/
|
*/
|
||||||
protected void notifyObservers (Object data)
|
protected void notifyObservers (Object data)
|
||||||
{
|
{
|
||||||
// let our observers know that all is well on the western front
|
// let our observers know that all is well on the western front
|
||||||
for (int i = 0; i < _observers.size(); i++) {
|
for (ZoneObserver obs : _observers) {
|
||||||
ZoneObserver obs = (ZoneObserver)_observers.get(i);
|
|
||||||
try {
|
try {
|
||||||
if (data instanceof Integer) {
|
if (data instanceof Integer) {
|
||||||
obs.zoneWillChange(((Integer)data).intValue());
|
obs.zoneWillChange(((Integer)data).intValue());
|
||||||
@@ -294,8 +272,8 @@ public class ZoneDirector extends BasicDirector
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
Log.warning("Zone observer choked during notification " +
|
Log.warning("Zone observer choked during notification [data=" + data +
|
||||||
"[data=" + data + ", obs=" + obs + "].");
|
", obs=" + obs + "].");
|
||||||
Log.logStackTrace(t);
|
Log.logStackTrace(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -310,12 +288,11 @@ public class ZoneDirector extends BasicDirector
|
|||||||
/** Provides access to zone services. */
|
/** Provides access to zone services. */
|
||||||
protected ZoneService _zservice;
|
protected ZoneService _zservice;
|
||||||
|
|
||||||
/** A reference to the zone summary for the currently occupied
|
/** A reference to the zone summary for the currently occupied zone. */
|
||||||
* zone. */
|
|
||||||
protected ZoneSummary _summary;
|
protected ZoneSummary _summary;
|
||||||
|
|
||||||
/** Our zone observer list. */
|
/** Our zone observer list. */
|
||||||
protected ArrayList _observers = new ArrayList();
|
protected ArrayList<ZoneObserver> _observers = new ArrayList<ZoneObserver>();
|
||||||
|
|
||||||
/** Our previous zone id. */
|
/** Our previous zone id. */
|
||||||
protected int _previousZoneId = -1;
|
protected int _previousZoneId = -1;
|
||||||
|
|||||||
@@ -38,11 +38,22 @@ public interface ZoneService extends InvocationService
|
|||||||
/** Used to deliver responses to {@link #moveTo} requests. */
|
/** Used to deliver responses to {@link #moveTo} requests. */
|
||||||
public static interface ZoneMoveListener extends InvocationListener
|
public static interface ZoneMoveListener extends InvocationListener
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Called in response to a successful {@link #moveTo} request.
|
||||||
|
*/
|
||||||
public void moveSucceeded (int placeId, PlaceConfig config, ZoneSummary summary);
|
public void moveSucceeded (int placeId, PlaceConfig config, ZoneSummary summary);
|
||||||
|
|
||||||
public void moveSucceededWithUpdates (
|
/**
|
||||||
int placeId, PlaceConfig config, ZoneSummary summary, SceneUpdate[] updates);
|
* Called in response to a successful {@link #moveTo} request when our cached scene was out
|
||||||
|
* of date and the server determined that we needed some updates.
|
||||||
|
*/
|
||||||
|
public void moveSucceededWithUpdates (
|
||||||
|
int placeId, PlaceConfig config, ZoneSummary summary, SceneUpdate[] updates);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called in response to a successful {@link #moveTo} request when our cached scene was out
|
||||||
|
* of date and the server determined that we needed an updated copy.
|
||||||
|
*/
|
||||||
public void moveSucceededWithScene (
|
public void moveSucceededWithScene (
|
||||||
int placeId, PlaceConfig config, ZoneSummary summary, SceneModel model);
|
int placeId, PlaceConfig config, ZoneSummary summary, SceneModel model);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user