From ec3fb4023a78d8202d65dd8495f43537c9fce77a Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sun, 18 May 2008 11:30:45 +0000 Subject: [PATCH] Allow the BodyObject to play along when we enter and leave a place. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5108 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/crowd/data/BodyObject.java | 25 ++++++++++++++++++- .../crowd/server/LocationProvider.java | 17 +++++++------ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/java/com/threerings/crowd/data/BodyObject.java b/src/java/com/threerings/crowd/data/BodyObject.java index 056d95647..577541c36 100644 --- a/src/java/com/threerings/crowd/data/BodyObject.java +++ b/src/java/com/threerings/crowd/data/BodyObject.java @@ -129,11 +129,34 @@ public class BodyObject extends ClientObject * Creates a blank occupant info instance that will used to publish information about the * various bodies occupying a place. */ - public OccupantInfo createOccupantInfo (PlaceObject placeObject) + public OccupantInfo createOccupantInfo (PlaceObject plobj) { return new OccupantInfo(this); } + /** + * Called when this body is about to enter the specified place. Configures our {@link + * #location} field. + * + * @param place the identifying information for the place we are entering. + * @param plobj the distributed object for the place we are entering. + */ + public void willEnterPlace (Place place, PlaceObject plobj) + { + setLocation(place); + } + + /** + * Called when this body has left its occupied place. Clears our {@link #location} field. + * + * @param plobj the distributed object for the place we just departed. This might be null if + * the place object has been destroyed. + */ + public void didLeavePlace (PlaceObject plobj) + { + setLocation(null); + } + // documentation inherited public void applyToListeners (ListenerOp op) { diff --git a/src/java/com/threerings/crowd/server/LocationProvider.java b/src/java/com/threerings/crowd/server/LocationProvider.java index 19fc927e4..311d2b58c 100644 --- a/src/java/com/threerings/crowd/server/LocationProvider.java +++ b/src/java/com/threerings/crowd/server/LocationProvider.java @@ -144,7 +144,7 @@ public class LocationProvider pmgr.buildOccupantInfo(source); // set the body's new location - source.setLocation(place); + source.willEnterPlace(place, plobj); // add the body oid to the place object's occupant list plobj.addToOccupants(bodoid); @@ -179,19 +179,20 @@ public class LocationProvider } // remove them from the occupant list + PlaceObject plobj = null; try { - PlaceObject pold = (PlaceObject)_omgr.getObject(oldloc.placeOid); - if (pold != null) { + plobj = (PlaceObject)_omgr.getObject(oldloc.placeOid); + if (plobj != null) { Integer key = Integer.valueOf(bodoid); - pold.startTransaction(); + plobj.startTransaction(); try { // remove their occupant info (which is keyed on oid) - pold.removeFromOccupantInfo(key); + plobj.removeFromOccupantInfo(key); // and remove them from the occupant list - pold.removeFromOccupants(bodoid); + plobj.removeFromOccupants(bodoid); } finally { - pold.commitTransaction(); + plobj.commitTransaction(); } } else { @@ -205,7 +206,7 @@ public class LocationProvider } // clear out their location - source.setLocation(null); + source.didLeavePlace(plobj); } /**