Zones! Scenes can be grouped into zones which are traversed via a

higher-level mechanism. Zones provide zone summaries which can be used to
generate maps of the zones on the client.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@727 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-12-04 00:31:58 +00:00
parent 9de32d32ea
commit 0748521613
9 changed files with 589 additions and 0 deletions
@@ -0,0 +1,42 @@
//
// $Id: ZoneManager.java,v 1.1 2001/12/04 00:31:58 mdb Exp $
package com.threerings.whirled.zone.server;
import com.threerings.whirled.zone.data.ZoneSummary;
/**
* A zone is a collection of scenes organized into a connected group. A
* user can wander around within a zone, moving from scene to scene via
* the standard mechanisms. To move between zones, they must use a special
* mechanism (like at the dock, they can move from an island zone into
* their ship zone; or they can move from an island zone into their house
* zone). A zone provides scene summary information that can be used to
* display a map of the zone to the client.
*/
public interface ZoneManager
{
/**
* Used to notify requesters when an asynchronous zone load has
* completed (successfully or not).
*/
public static interface ResolutionListener
{
/**
* Called when a zone was successfully resolved.
*/
public void zoneWasResolved (ZoneSummary summary);
/**
* Called when a zone failed to resolve.
*/
public void zoneFailedToResolve (int zoneId, Exception reason);
}
/**
* Resolves and delivers the scene summary information for the
* requested zone. Zone resolution is an asynchronous process, which
* necessitates this callback-style interface.
*/
public void resolveZone (int zoneId, ResolutionListener listener);
}
@@ -0,0 +1,177 @@
//
// $Id: ZoneProvider.java,v 1.1 2001/12/04 00:31:58 mdb Exp $
package com.threerings.whirled.zone.server;
import com.threerings.presents.server.InvocationProvider;
import com.threerings.presents.server.ServiceFailedException;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.crowd.server.LocationProvider;
import com.threerings.whirled.Log;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.server.SceneRegistry;
import com.threerings.whirled.server.SceneManager;
import com.threerings.whirled.zone.client.ZoneCodes;
import com.threerings.whirled.zone.data.ZoneSummary;
import com.threerings.whirled.zone.data.ZonedBodyObject;
/**
* Provides zone related services which are presently the ability to move
* from zone to zone.
*/
public class ZoneProvider
extends InvocationProvider implements ZoneCodes
{
/**
* Constructs a zone provider that will interoperate with the supplied
* zone and scene registries. A system that wishes to use the zone
* services must instantiate a zone provider and register it with the
* invocation services.
*/
public ZoneProvider (ZoneRegistry zonereg, SceneRegistry screg)
{
_zonereg = zonereg;
_screg = screg;
}
/**
* Processes a request from a client to move to a scene in a new zone.
*
* @param source the user requesting the move.
* @param invid the invocation id of the request.
* @param zoneId the identifier of the new zone.
* @param sceneId the identifier of the new scene.
* @param sceneVew the version of the scene model currently held by
* the client.
*/
public void handleMoveToRequest (BodyObject source, int invid,
int zoneId, int sceneId, int sceneVer)
{
// look up the zone manager for the zone
ZoneManager zmgr = _zonereg.getZoneManager(zoneId);
if (zmgr == null) {
Log.warning("Requested to enter a zone for which we have no " +
"manager [user=" + source +
", zoneId=" + zoneId + "].");
sendResponse(source, invid, MOVE_FAILED_RESPONSE, NO_SUCH_ZONE);
return;
}
// make sure they're not already in that zone
if (((ZonedBodyObject)source).getZoneId() == zoneId) {
sendResponse(source, invid, MOVE_FAILED_RESPONSE, ALREADY_THERE);
return;
}
// avoid cluttering up the method declaration with final keywords
final BodyObject fsource = source;
final int finvid = invid;
final int fsceneId = sceneId;
final int fsceneVer = sceneVer;
// resolve the zone!
ZoneManager.ResolutionListener zl = new ZoneManager.ResolutionListener()
{
public void zoneWasResolved (ZoneSummary summary) {
continueMoveToRequest(fsource, finvid, summary,
fsceneId, fsceneVer);
}
public void zoneFailedToResolve (int zoneId, Exception reason) {
Log.warning("Unable to resolve zone [zoneId=" + zoneId +
", reason=" + reason + "].");
sendResponse(fsource, finvid,
MOVE_FAILED_RESPONSE, NO_SUCH_ZONE);
}
};
zmgr.resolveZone(zoneId, zl);
}
/**
* This is called after we have resolved our zone.
*/
protected void continueMoveToRequest (
BodyObject source, int invid, ZoneSummary summary,
int sceneId, int sceneVer)
{
// avoid cluttering up the method declaration with final keywords
final BodyObject fsource = source;
final int finvid = invid;
final ZoneSummary fsum = summary;
final int fsceneVer = sceneVer;
// create a callback object that will handle the resolution or
// failed resolution of the scene
SceneRegistry.ResolutionListener rl =
new SceneRegistry.ResolutionListener()
{
public void sceneWasResolved (SceneManager scmgr) {
finishMoveToRequest(fsource, finvid, fsum, scmgr, fsceneVer);
}
public void sceneFailedToResolve (int sceneId, Exception reason) {
Log.warning("Unable to resolve scene [sceneid=" + sceneId +
", reason=" + reason + "].");
// pretend like the scene doesn't exist to the client
sendResponse(fsource, finvid,
MOVE_FAILED_RESPONSE, NO_SUCH_PLACE);
}
};
// make sure the scene they are headed to is actually loaded into
// the server
_screg.resolveScene(sceneId, rl);
}
/**
* This is called after the scene to which we are moving is guaranteed
* to have been loaded into the server.
*/
protected void finishMoveToRequest (
BodyObject source, int invid, ZoneSummary summary,
SceneManager scmgr, int sceneVersion)
{
// move to the place object associated with this scene
PlaceObject plobj = scmgr.getPlaceObject();
int ploid = plobj.getOid();
try {
// try doing the actual move
PlaceConfig config = LocationProvider.moveTo(source, ploid);
// now that we've finally moved, we can update the user object
// with the new zone id
((ZonedBodyObject)source).setZoneId(summary.zoneId);
// check to see if they need a newer version of the scene data
SceneModel model = scmgr.getSceneModel();
if (sceneVersion < model.version) {
// then send the moveTo response
sendResponse(source, invid, MOVE_SUCCEEDED_PLUS_UPDATE_RESPONSE,
new Object[] { new Integer(ploid), config,
summary, model });
} else {
// then send the moveTo response
sendResponse(source, invid, MOVE_SUCCEEDED_RESPONSE,
new Integer(ploid), config, summary);
}
} catch (ServiceFailedException sfe) {
sendResponse(source, invid,
MOVE_FAILED_RESPONSE, sfe.getMessage());
}
}
/** The zone registry with which we communicate. */
protected ZoneRegistry _zonereg;
/** The scene registry with which we communicate. */
protected SceneRegistry _screg;
}
@@ -0,0 +1,54 @@
//
// $Id: ZoneRegistry.java,v 1.1 2001/12/04 00:31:58 mdb Exp $
package com.threerings.whirled.zone.server;
import com.samskivert.util.Config;
import com.samskivert.util.HashIntMap;
import com.threerings.whirled.Log;
/**
* The zone registry takes care of mapping zone requests to the
* appropriate registered zone manager.
*/
public class ZoneRegistry
{
/**
* Creates a zone manager with the supplied configuration.
*/
public ZoneRegistry (Config config)
{
}
/**
* Registers the supplied zone manager as the manager for the
* specified zone type. Zone types are 7 bits and managers are
* responsible for making sure they don't use a zone type that
* collides with another manager (given that we have only three zone
* types at present, this doesn't seem unreasonable).
*/
public void registerZoneManager (byte zoneType, ZoneManager manager)
{
ZoneManager old = (ZoneManager)_managers.get(zoneType);
if (old != null) {
Log.warning("Zone manager already registered with requested " +
"type [type=" + zoneType + ", old=" + old +
", new=" + manager + "].");
} else {
_managers.put(zoneType, manager);
}
}
/**
* Returns the zone manager that handles the specified zone id.
*/
public ZoneManager getZoneManager (int zoneId)
{
int zoneType = (0xFF000000 & zoneId) >> 24;
return (ZoneManager)_managers.get(zoneType);
}
/** A table of zone managers. */
protected HashIntMap _managers = new HashIntMap();
}