Added bodyWillLeave() to go with bodyWillEnter() for great symmetry and
justice. Cleaned up some other stuff in the process. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5620 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -32,7 +32,6 @@ public class BodyLocal extends ClientLocal
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The time at which the {@link BodyObject#status} field was last updated.
|
* The time at which the {@link BodyObject#status} field was last updated.
|
||||||
* This is only available on the server.
|
|
||||||
*/
|
*/
|
||||||
public long statusTime;
|
public long statusTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,28 +115,19 @@ public class LocationManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PlaceObject plobj = pmgr.getPlaceObject();
|
source.startTransaction();
|
||||||
|
|
||||||
// the doubly nested try catch is to prevent failure if one or the other of the
|
|
||||||
// transactions fails to start
|
|
||||||
plobj.startTransaction();
|
|
||||||
try {
|
try {
|
||||||
source.startTransaction();
|
// remove them from any previous location
|
||||||
try {
|
leaveOccupiedPlace(source);
|
||||||
// remove them from any previous location
|
|
||||||
leaveOccupiedPlace(source);
|
|
||||||
|
|
||||||
// let the place manager know that we're coming in
|
// let the place manager know that we're coming in
|
||||||
pmgr.bodyWillEnter(source);
|
pmgr.bodyWillEnter(source);
|
||||||
|
|
||||||
// let the body object know that it's going in
|
// let the body object know that it's going in
|
||||||
source.willEnterPlace(place, plobj);
|
source.willEnterPlace(place, pmgr.getPlaceObject());
|
||||||
|
|
||||||
} finally {
|
|
||||||
source.commitTransaction();
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
plobj.commitTransaction();
|
source.commitTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
@@ -154,42 +145,22 @@ public class LocationManager
|
|||||||
public void leaveOccupiedPlace (BodyObject source)
|
public void leaveOccupiedPlace (BodyObject source)
|
||||||
{
|
{
|
||||||
Place oldloc = source.location;
|
Place oldloc = source.location;
|
||||||
int bodoid = source.getOid();
|
|
||||||
|
|
||||||
// nothing to do if they weren't previously in some location
|
|
||||||
if (oldloc == null) {
|
if (oldloc == null) {
|
||||||
|
return; // nothing to do if they weren't previously in some location
|
||||||
|
}
|
||||||
|
|
||||||
|
PlaceManager pmgr = _plreg.getPlaceManager(oldloc.placeOid);
|
||||||
|
if (pmgr == null) {
|
||||||
|
log.warning("Body requested to leave no longer existent place?",
|
||||||
|
"boid", source.getOid(), "place", oldloc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove them from the occupant list
|
// tell the place manager that they're on the way out
|
||||||
PlaceObject plobj = null;
|
pmgr.bodyWillLeave(source);
|
||||||
try {
|
|
||||||
plobj = (PlaceObject)_omgr.getObject(oldloc.placeOid);
|
|
||||||
if (plobj != null) {
|
|
||||||
Integer key = Integer.valueOf(bodoid);
|
|
||||||
plobj.startTransaction();
|
|
||||||
try {
|
|
||||||
// remove their occupant info (which is keyed on oid)
|
|
||||||
plobj.removeFromOccupantInfo(key);
|
|
||||||
// and remove them from the occupant list
|
|
||||||
plobj.removeFromOccupants(bodoid);
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
plobj.commitTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
log.info("Body's prior location no longer around? [boid=" + bodoid +
|
|
||||||
", place=" + oldloc + "].");
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (ClassCastException cce) {
|
|
||||||
log.warning("Body claims to occupy non-PlaceObject!? [boid=" + bodoid +
|
|
||||||
", place=" + oldloc + ", error=" + cce + "].");
|
|
||||||
}
|
|
||||||
|
|
||||||
// clear out their location
|
// clear out their location
|
||||||
source.didLeavePlace(plobj);
|
source.didLeavePlace(pmgr.getPlaceObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -312,7 +312,10 @@ public class PlaceManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is called to inform the manager that a body is on the way in.
|
* This is called to inform the manager that a body is on the way in. This is called at the
|
||||||
|
* very beginning of the entry process before the client is informed that it is allowed to
|
||||||
|
* enter. This will be followed by a call to {@link #bodyEntered} once all events relating to
|
||||||
|
* body entry have been processed.
|
||||||
*/
|
*/
|
||||||
public void bodyWillEnter (BodyObject body)
|
public void bodyWillEnter (BodyObject body)
|
||||||
{
|
{
|
||||||
@@ -328,6 +331,23 @@ public class PlaceManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to inform a manager that a body is about to leave this place. This will be followed
|
||||||
|
* by a call to {@link #bodyLeft} once all events relating to body entry have been processed.
|
||||||
|
*/
|
||||||
|
public void bodyWillLeave (BodyObject body)
|
||||||
|
{
|
||||||
|
_plobj.startTransaction();
|
||||||
|
try {
|
||||||
|
// remove their occupant info (which is keyed on oid)
|
||||||
|
_plobj.removeFromOccupantInfo(body.getOid());
|
||||||
|
// and remove them from the occupant list
|
||||||
|
_plobj.removeFromOccupants(body.getOid());
|
||||||
|
} finally {
|
||||||
|
_plobj.commitTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a particular message handler instance to be used when processing message events
|
* Registers a particular message handler instance to be used when processing message events
|
||||||
* with the specified name.
|
* with the specified name.
|
||||||
|
|||||||
Reference in New Issue
Block a user