Give scene managers the opportunity to do something when a player

traverses a portal and give them the ability to position the player other
than on top of the entering portal when entering.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2412 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2003-04-17 19:17:07 +00:00
parent 025cb91668
commit 3de98670db
3 changed files with 42 additions and 15 deletions
@@ -1,5 +1,5 @@
//
// $Id: SceneProvider.java,v 1.15 2003/02/12 07:23:31 mdb Exp $
// $Id: SceneProvider.java,v 1.16 2003/04/17 19:17:07 mdb Exp $
package com.threerings.whirled.server;
@@ -85,7 +85,7 @@ public class SceneProvider
/**
* Moves the supplied body into the supplied (already resolved) scene
* and informs the supplied listener if the move is successfuly.
* and informs the supplied listener if the move is successful.
*
* @exception InvocationException thrown if a failure occurs
* attempting to move the user into the place associated with the
@@ -1,5 +1,5 @@
//
// $Id: SpotProvider.java,v 1.17 2003/03/26 02:06:06 mdb Exp $
// $Id: SpotProvider.java,v 1.18 2003/04/17 19:17:07 mdb Exp $
package com.threerings.whirled.spot.server;
@@ -64,9 +64,9 @@ public class SpotProvider
final SceneMoveListener flistener = listener;
// obtain the source scene
SpotSceneManager smgr = (SpotSceneManager)
final SpotSceneManager srcmgr = (SpotSceneManager)
_screg.getSceneManager(sceneId);
if (smgr == null) {
if (srcmgr == null) {
Log.warning("Traverse portal missing source scene " +
"[user=" + fsource.who() + ", sceneId=" + sceneId +
", portalId=" + portalId + "].");
@@ -74,11 +74,11 @@ public class SpotProvider
}
// obtain the destination scene and location id
SpotScene rss = (SpotScene)smgr.getScene();
SpotScene rss = (SpotScene)srcmgr.getScene();
final Portal fdest = rss.getPortal(portalId);
// give the source scene manager a chance to do access control
String errmsg = smgr.mayTraversePortal(fsource, fdest);
String errmsg = srcmgr.mayTraversePortal(fsource, fdest);
if (errmsg != null) {
throw new InvocationException(errmsg);
}
@@ -86,7 +86,7 @@ public class SpotProvider
// make sure this portal has valid info
if (fdest == null || !fdest.isValid()) {
Log.warning("Traverse portal with invalid portal " +
"[user=" + fsource.who() + ", scene=" + smgr.where() +
"[user=" + fsource.who() + ", scene=" + srcmgr.where() +
", pid=" + portalId + ", portal=" + fdest +
", portals=" + StringUtil.toString(rss.getPortals()) +
"].");
@@ -97,6 +97,10 @@ public class SpotProvider
SceneRegistry.ResolutionListener rl =
new SceneRegistry.ResolutionListener() {
public void sceneWasResolved (SceneManager scmgr) {
// let the source manager know that this guy is
// departing via the specified portal
srcmgr.willTraversePortal(fsource, fdest);
SpotSceneManager sscmgr = (SpotSceneManager)scmgr;
finishTraversePortalRequest(
fsource, sscmgr, fsceneVer, fdest, flistener);
@@ -119,20 +123,21 @@ public class SpotProvider
* to have been loaded into the server.
*/
protected void finishTraversePortalRequest (
BodyObject source, SpotSceneManager scmgr, int sceneVer,
BodyObject source, SpotSceneManager destmgr, int sceneVer,
Portal dest, SceneMoveListener listener)
{
// let the destination scene manager know that we're coming in
scmgr.mapEnteringBody(source, dest.targetPortalId);
destmgr.mapEnteringBody(source, dest.targetPortalId);
try {
// move to the place object associated with this scene
_screg.sceneprov.effectSceneMove(source, scmgr, sceneVer, listener);
_screg.sceneprov.effectSceneMove(
source, destmgr, sceneVer, listener);
} catch (InvocationException sfe) {
listener.requestFailed(sfe.getMessage());
// and let the destination scene manager know that we're no
// longer coming in
scmgr.clearEnteringBody(source);
destmgr.clearEnteringBody(source);
}
}
@@ -1,5 +1,5 @@
//
// $Id: SpotSceneManager.java,v 1.39 2003/03/30 19:45:58 mdb Exp $
// $Id: SpotSceneManager.java,v 1.40 2003/04/17 19:17:07 mdb Exp $
package com.threerings.whirled.spot.server;
@@ -94,6 +94,18 @@ public class SpotSceneManager extends SceneManager
return null;
}
/**
* This is called to let this scene manager know that the user is
* about to traverse the specified portal. The default implementation
* relocates the user to the location associated with the portal. It
* is still possible that the traversal will fail, so don't do
* anything too crazy.
*/
public void willTraversePortal (BodyObject body, Portal portal)
{
updateLocation(body, portal.getLocation());
}
// documentation inherited
protected void didStartup ()
{
@@ -153,8 +165,18 @@ public class SpotSceneManager extends SceneManager
// create a scene location for them located on the entrance portal
// but facing the opposite direction
_ssobj.addToOccupantLocs(
new SceneLocation(entry.getOppLocation(), body.getOid()));
_ssobj.addToOccupantLocs(computeEnteringLocation(body, entry));
}
/**
* Called when the supplied body is entering our scene via the
* specified portal. The default location is the one associated with
* the portal, but derived classes may wish to adjust this.
*/
protected SceneLocation computeEnteringLocation (
BodyObject body, Portal entry)
{
return new SceneLocation(entry.getOppLocation(), body.getOid());
}
/**