Make the zone handling appropriately peer-aware. It's worth noting that due to adding moveRequiresServerSwitch() to ZoneService, this will break some things which use this.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@913 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Mike Thomas
2010-05-27 20:30:53 +00:00
parent c01ff63cd6
commit adeb3054d4
11 changed files with 519 additions and 14 deletions
@@ -7,6 +7,7 @@ import com.threerings.util.ResultListener;
import com.threerings.presents.client.BasicDirector;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.ClientEvent;
import com.threerings.presents.client.ConfirmAdapter;
import com.threerings.crowd.data.PlaceConfig;
@@ -97,22 +98,31 @@ public class ZoneDirector extends BasicDirector
return false;
}
_pendingZoneId = zoneId;
sendMoveRequest();
return true;
}
protected function sendMoveRequest () :void
{
// let our zone observers know that we're attempting to switch zones
notifyObservers(zoneId);
notifyObservers(_pendingZoneId);
// 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;
var sceneId :int = -1;
var pendingModel :SceneModel = _scdir.getPendingModel();
if (pendingModel != null) {
sceneVers = pendingModel.version;
}
// issue a moveTo request
log.info("Issuing zoned moveTo(" + ZoneUtil.toString(zoneId) +
log.info("Issuing zoned moveTo(" + ZoneUtil.toString(_pendingZoneId) +
", " + sceneId + ", " + sceneVers + ").");
_zservice.moveTo(zoneId, sceneId, sceneVers, this);
return true;
_zservice.moveTo(_pendingZoneId, sceneId, sceneVers, this);
}
override protected function fetchServices (client :Client) :void
@@ -141,6 +151,9 @@ public class ZoneDirector extends BasicDirector
// keep track of the summary
_summary = summary;
// We're not heading there any more.
_pendingZoneId = -1;
// pass the rest off to the standard scene transition code
_scdir.moveSucceeded(placeId, config);
@@ -156,6 +169,9 @@ public class ZoneDirector extends BasicDirector
// keep track of the summary
_summary = summary;
// We're not heading there any more.
_pendingZoneId = -1;
// pass the rest off to the standard scene transition code
_scdir.moveSucceededWithUpdates(placeId, config, updates);
@@ -170,6 +186,9 @@ public class ZoneDirector extends BasicDirector
// keep track of the summary
_summary = summary;
// We're not heading there any more.
_pendingZoneId = -1;
// pass the rest off to the standard scene transition code
_scdir.moveSucceededWithScene(placeId, config, model);
@@ -177,6 +196,17 @@ public class ZoneDirector extends BasicDirector
notifyObservers(summary);
}
// from interface ZoneService_ZoneMoveListener
public function moveRequiresServerSwitch (hostname :String, ports :TypedArray) :void
{
log.info("Zone switch requires server switch", "host", hostname, "ports", ports);
// ship on over to the other server
_wCtx.getClient().moveToServer(hostname, ports, new ConfirmAdapter(
function () :void { // succeeded
sendMoveRequest();
}, requestFailed));
}
// from interface ZoneService.ZoneMoveListener
public function requestFailed (reason :String) :void
{
@@ -215,6 +245,9 @@ public class ZoneDirector extends BasicDirector
return; // if we're currently somewhere, just stay there
}
// Not gonna get there, so clear it.
_pendingZoneId = -1;
// otherwise if we were previously in a zone/scene, try going back there
if (_previousZoneId != -1) {
moveTo(_previousZoneId, previousSceneId);
@@ -263,5 +296,8 @@ public class ZoneDirector extends BasicDirector
/** Our previous zone id. */
protected var _previousZoneId :int = -1;
/** Where we're headed. */
protected var _pendingZoneId :int = -1;
}
}
@@ -33,6 +33,9 @@ import com.threerings.whirled.zone.data.ZoneSummary;
public interface ZoneService_ZoneMoveListener
extends InvocationService_InvocationListener
{
// from Java ZoneService_ZoneMoveListener
function moveRequiresServerSwitch (arg1 :String, arg2 :TypedArray /* of int */) :void
// from Java ZoneService_ZoneMoveListener
function moveSucceeded (arg1 :int, arg2 :PlaceConfig, arg3 :ZoneSummary) :void
@@ -33,19 +33,27 @@ import com.threerings.whirled.zone.client.ZoneService_ZoneMoveListener;
public class ZoneMarshaller_ZoneMoveMarshaller
extends InvocationMarshaller_ListenerMarshaller
{
/** The method id used to dispatch <code>moveRequiresServerSwitch</code> responses. */
public static const MOVE_REQUIRES_SERVER_SWITCH :int = 1;
/** The method id used to dispatch <code>moveSucceeded</code> responses. */
public static const MOVE_SUCCEEDED :int = 1;
public static const MOVE_SUCCEEDED :int = 2;
/** The method id used to dispatch <code>moveSucceededWithScene</code> responses. */
public static const MOVE_SUCCEEDED_WITH_SCENE :int = 2;
public static const MOVE_SUCCEEDED_WITH_SCENE :int = 3;
/** The method id used to dispatch <code>moveSucceededWithUpdates</code> responses. */
public static const MOVE_SUCCEEDED_WITH_UPDATES :int = 3;
public static const MOVE_SUCCEEDED_WITH_UPDATES :int = 4;
// from InvocationMarshaller_ListenerMarshaller
override public function dispatchResponse (methodId :int, args :Array) :void
{
switch (methodId) {
case MOVE_REQUIRES_SERVER_SWITCH:
(listener as ZoneService_ZoneMoveListener).moveRequiresServerSwitch(
(args[0] as String), (args[1] as TypedArray /* of int */));
return;
case MOVE_SUCCEEDED:
(listener as ZoneService_ZoneMoveListener).moveSucceeded(
(args[0] as int), (args[1] as PlaceConfig), (args[2] as ZoneSummary));