From a213847eea5c1b7441239e6e941ae9e86be18496 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 30 Jun 2005 00:02:13 +0000 Subject: [PATCH] Added leavePlace() for games where you are sometimes not in any "place" at all. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3638 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../crowd/client/LocationDirector.java | 17 +++++++++++++++++ .../crowd/client/LocationService.java | 7 ++++++- .../crowd/data/LocationMarshaller.java | 13 ++++++++++++- .../crowd/server/LocationDispatcher.java | 6 ++++++ .../crowd/server/LocationProvider.java | 9 +++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/java/com/threerings/crowd/client/LocationDirector.java b/src/java/com/threerings/crowd/client/LocationDirector.java index e51a6ee11..e0e5e0a51 100644 --- a/src/java/com/threerings/crowd/client/LocationDirector.java +++ b/src/java/com/threerings/crowd/client/LocationDirector.java @@ -188,6 +188,23 @@ public class LocationDirector extends BasicDirector } } + /** + * Issues a request to leave our current location. + * + * @return true if we were able to leave, false if we are in the + * middle of moving somewhere and can't yet leave. + */ + public boolean leavePlace () + { + if (_pendingPlaceId != -1) { + return false; + } + + _lservice.leavePlace(_ctx.getClient()); + didLeavePlace(); + return true; + } + /** * This can be called by cooperating directors that need to coopt the * moving process to extend it in some way or other. In such diff --git a/src/java/com/threerings/crowd/client/LocationService.java b/src/java/com/threerings/crowd/client/LocationService.java index 7d3ff51b6..f65fa1997 100644 --- a/src/java/com/threerings/crowd/client/LocationService.java +++ b/src/java/com/threerings/crowd/client/LocationService.java @@ -1,5 +1,5 @@ // -// $Id: LocationService.java,v 1.9 2004/08/27 02:12:33 mdb Exp $ +// $Id$ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -57,4 +57,9 @@ public interface LocationService extends InvocationService * failure. */ public void moveTo (Client client, int placeId, MoveListener listener); + + /** + * Requests that we leave our current place and move to nowhere land. + */ + public void leavePlace (Client client); } diff --git a/src/java/com/threerings/crowd/data/LocationMarshaller.java b/src/java/com/threerings/crowd/data/LocationMarshaller.java index 2fd7883bd..b632a6bea 100644 --- a/src/java/com/threerings/crowd/data/LocationMarshaller.java +++ b/src/java/com/threerings/crowd/data/LocationMarshaller.java @@ -68,8 +68,19 @@ public class LocationMarshaller extends InvocationMarshaller } } + /** The method id used to dispatch {@link #leavePlace} requests. */ + public static final int LEAVE_PLACE = 1; + + // documentation inherited from interface + public void leavePlace (Client arg1) + { + sendRequest(arg1, LEAVE_PLACE, new Object[] { + + }); + } + /** The method id used to dispatch {@link #moveTo} requests. */ - public static final int MOVE_TO = 1; + public static final int MOVE_TO = 2; // documentation inherited from interface public void moveTo (Client arg1, int arg2, LocationService.MoveListener arg3) diff --git a/src/java/com/threerings/crowd/server/LocationDispatcher.java b/src/java/com/threerings/crowd/server/LocationDispatcher.java index f56c2f1bd..7c07d0313 100644 --- a/src/java/com/threerings/crowd/server/LocationDispatcher.java +++ b/src/java/com/threerings/crowd/server/LocationDispatcher.java @@ -56,6 +56,12 @@ public class LocationDispatcher extends InvocationDispatcher throws InvocationException { switch (methodId) { + case LocationMarshaller.LEAVE_PLACE: + ((LocationProvider)provider).leavePlace( + source + ); + return; + case LocationMarshaller.MOVE_TO: ((LocationProvider)provider).moveTo( source, diff --git a/src/java/com/threerings/crowd/server/LocationProvider.java b/src/java/com/threerings/crowd/server/LocationProvider.java index dc159c7ba..7a28223b2 100644 --- a/src/java/com/threerings/crowd/server/LocationProvider.java +++ b/src/java/com/threerings/crowd/server/LocationProvider.java @@ -75,6 +75,15 @@ public class LocationProvider listener.moveSucceeded(moveTo((BodyObject)caller, placeId)); } + /** + * Requests that we leave our current place and move to nowhere land. + */ + public void leavePlace (ClientObject caller) + throws InvocationException + { + leaveOccupiedPlace((BodyObject)caller); + } + /** * Moves the specified body from whatever location they currently * occupy to the location identified by the supplied place id.