Finished up implementation of portal traversal back-end.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@781 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-12-14 23:12:39 +00:00
parent 17ad791035
commit efd1a69caa
6 changed files with 292 additions and 16 deletions
@@ -1,21 +1,27 @@
//
// $Id: SpotCodes.java,v 1.1 2001/12/14 00:12:32 mdb Exp $
// $Id: SpotCodes.java,v 1.2 2001/12/14 23:12:39 mdb Exp $
package com.threerings.whirled.spot.client;
import com.threerings.crowd.chat.ChatCodes;
import com.threerings.crowd.client.LocationCodes;
import com.threerings.whirled.client.SceneCodes;
/**
* Contains codes used by the Spot invocation services.
*/
public interface SpotCodes extends ChatCodes, LocationCodes
public interface SpotCodes extends ChatCodes, SceneCodes
{
/** The module name for the Spot services. */
public static final String MODULE_NAME = "whirled!spot";
/** The message identifier for a cluster speak request message. */
public static final String CLUSTER_SPEAK_REQUEST = "cspkreq";
/** The message identifier for a traversePortal request. Such a
* request generates a moveTo response rather than a specialized
* response. */
public static final String TRAVERSE_PORTAL_REQUEST = "TraversePortal";
/** An error code indicating that the portal specified in a
* traversePortal request does not exist. */
public static final String NO_SUCH_PORTAL = "m.no_such_portal";
/** The message identifier for a changeLoc request. */
public static final String CHANGE_LOC_REQUEST = "ChangeLoc";
@@ -34,4 +40,7 @@ public interface SpotCodes extends ChatCodes, LocationCodes
/** An error code indicating that a location is occupied. Usually
* generated by a failed changeLoc request. */
public static final String LOCATION_OCCUPIED = "m.location_occupied";
/** The message identifier for a cluster speak request message. */
public static final String CLUSTER_SPEAK_REQUEST = "cspkreq";
}
@@ -1,5 +1,5 @@
//
// $Id: SpotSceneDirector.java,v 1.2 2001/12/14 01:51:46 mdb Exp $
// $Id: SpotSceneDirector.java,v 1.3 2001/12/14 23:12:39 mdb Exp $
package com.threerings.whirled.spot.client;
@@ -14,6 +14,7 @@ import com.threerings.whirled.util.WhirledContext;
import com.threerings.whirled.spot.Log;
import com.threerings.whirled.spot.data.Location;
import com.threerings.whirled.spot.data.Portal;
/**
* Extends the standard scene director with facilities to move between
@@ -55,6 +56,59 @@ public class SpotSceneDirector extends SceneDirector
super(ctx, screp, dsfact);
}
/**
* Requests that this client move to the location specified by the
* supplied portal id. A request will be made and when the response is
* received, the location observers will be notified of success or
* failure.
*/
public void traversePortal (int portalId)
{
// look up the destination scene and location
if (_scene == null) {
Log.warning("Requested to traverse portal when we have " +
"no scene [portalId=" + portalId + "].");
return;
}
// find the portal they're talking about
int targetSceneId = -1, targetLocId = -1;
DisplaySpotScene ds = (DisplaySpotScene)_scene;
Iterator portals = ds.getPortals().iterator();
while (portals.hasNext()) {
Portal portal = (Portal)portals.next();
if (portal.locationId == portalId) {
targetSceneId = portal.targetSceneId;
targetLocId = portal.targetLocId;
}
}
// make sure we found the portal
if (targetSceneId == -1) {
Log.warning("Requested to traverse non-existent portal " +
"[portalId=" + portalId +
", portals=" +
StringUtil.toString(ds.getPortals().iterator()) + "].");
}
// prepare to move to this scene (sets up pending data)
if (!prepareMoveTo(targetSceneId)) {
return;
}
// 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
int sceneVer = 0;
if (_pendingModel != null) {
sceneVer = _pendingModel.version;
}
// issue a traversePortal request
SpotService.traversePortal(
_ctx.getClient(), _sceneId, portalId, sceneVer, this);
}
/**
* Issues a request to change our location within the scene to the
* location identified by the specified id. Most client entities find
@@ -1,5 +1,5 @@
//
// $Id: SpotService.java,v 1.1 2001/12/14 00:12:32 mdb Exp $
// $Id: SpotService.java,v 1.2 2001/12/14 23:12:39 mdb Exp $
package com.threerings.whirled.spot.client;
@@ -10,14 +10,31 @@ import com.threerings.whirled.spot.Log;
/**
* Provides a mechanism by which the client can request to move between
* locations within a scene. These services should not be used directly,
* locations within a scene and between scenes (taking exit and entry
* locations into account). These services should not be used directly,
* but instead should be accessed via the {@link SpotSceneDirector}.
*/
public class SpotService implements SpotCodes
{
/**
* Requests that that this client's body be made to occupy the
* specified location.
* Requests to traverse the specified portal.
*/
public static void traversePortal (
Client client, int sceneId, int portalId, int sceneVer,
SpotSceneDirector rsptarget)
{
InvocationDirector invdir = client.getInvocationDirector();
Object[] args = new Object[] {
new Integer(sceneId), new Integer(portalId),
new Integer(sceneVer) };
invdir.invoke(MODULE_NAME, TRAVERSE_PORTAL_REQUEST, args, rsptarget);
Log.info("Sent traversePortal request [sceneId=" + sceneId +
", portalId=" + portalId + ", sceneVer=" + sceneVer + "].");
}
/**
* Requests that this client's body be made to occupy the specified
* location.
*/
public static void changeLoc (Client client, int sceneId, int locationId,
SpotSceneDirector rsptarget)