Finished up handling of bodies moving from place to place. Added callback

methods into PlaceManager that can be overridden to do things when bodies
enter or leave a place.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@175 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-08-04 01:13:36 +00:00
parent c1dd28330f
commit e52ab9a739
3 changed files with 81 additions and 3 deletions
@@ -1,5 +1,5 @@
//
// $Id: BodyObject.dobj,v 1.2 2001/08/03 02:14:41 mdb Exp $
// $Id: BodyObject.dobj,v 1.3 2001/08/04 01:13:36 mdb Exp $
package com.threerings.cocktail.party.data;
@@ -10,13 +10,27 @@ public class BodyObject extends ClientObject
/** The field name of the <code>username</code> field. */
public static final String USERNAME = "username";
/** The field name of the <code>location</code> field. */
public static final String LOCATION = "location";
/**
* The username associated with this body object.
*/
public String username;
/**
* The oid of the place currently occupied by this body or -1 if they
* currently occupy no place.
*/
public int location = -1;
public void setUsername (String username)
{
requestAttributeChange(USERNAME, username);
}
public void setLocation (int location)
{
requestAttributeChange(LOCATION, new Integer(location));
}
}
@@ -1,5 +1,5 @@
//
// $Id: LocationProvider.java,v 1.1 2001/07/23 21:14:27 mdb Exp $
// $Id: LocationProvider.java,v 1.2 2001/08/04 01:13:36 mdb Exp $
package com.threerings.cocktail.party.server;
@@ -28,9 +28,41 @@ public class LocationProvider extends InvocationProvider
return createResponse("MoveFailed", "m.no_such_place");
}
// acquire a lock on the body object to ensure that rapid fire
// moveto requests don't break things
if (!source.acquireLock("moveToLock")) {
// if we're still locked, a previous moveTo request hasn't
// been fully processed
return createResponse("MoveFailed", "m.move_in_progress");
}
// find out if they were previously in some other location
if (source.location != -1) {
// remove them from the occupant list of the previous location
try {
PlaceObject pold = (PlaceObject)
CherServer.omgr.getObject(source.location);
pold.removeFromOccupants(source.getOid());
} catch (ClassCastException cce) {
Log.warning("Body claims to be at location which " +
"references non-PlaceObject!? " +
"[boid=" + source.getOid() +
", poid=" + source.location + "].");
}
}
// add the body object id to the place object's occupant list
PlaceObject place = (PlaceObject)pobj;
place.addToOccupants(source.getOid());
// set their new location
source.setLocation(place.getOid());
// and finally queue up a lock release event to release the lock
// once all these events are processed
source.releaseLock("moveToLock");
return createResponse("MoveSucceeded");
}
}
@@ -1,5 +1,5 @@
//
// $Id: PlaceManager.java,v 1.6 2001/08/03 02:14:41 mdb Exp $
// $Id: PlaceManager.java,v 1.7 2001/08/04 01:13:36 mdb Exp $
package com.threerings.cocktail.party.server;
@@ -7,6 +7,8 @@ import java.util.HashMap;
import java.util.Properties;
import com.threerings.cocktail.cher.dobj.*;
import com.threerings.cocktail.party.Log;
import com.threerings.cocktail.party.data.PlaceObject;
/**
@@ -76,6 +78,24 @@ public class PlaceManager implements Subscriber
{
}
/**
* Called when a body object enters this place.
*/
protected void bodyEntered (int bodyOid)
{
Log.info("Body entered [ploid=" + _plobj.getOid() +
", oid=" + bodyOid + "].");
}
/**
* Called when a body object leaves this place.
*/
protected void bodyLeft (int bodyOid)
{
Log.info("Body left [ploid=" + _plobj.getOid() +
", oid=" + bodyOid + "].");
}
/**
* Registers a particular message handler instance to be used when
* processing message events with the specified name.
@@ -125,6 +145,18 @@ public class PlaceManager implements Subscriber
if (handler != null) {
handler.handleEvent(mevt, (PlaceObject)target);
}
} else if (event instanceof ObjectAddedEvent) {
ObjectAddedEvent oae = (ObjectAddedEvent)event;
if (oae.getName().equals(PlaceObject.OCCUPANTS)) {
bodyEntered(oae.getOid());
}
} else if (event instanceof ObjectRemovedEvent) {
ObjectRemovedEvent ore = (ObjectRemovedEvent)event;
if (ore.getName().equals(PlaceObject.OCCUPANTS)) {
bodyLeft(ore.getOid());
}
}
return true;