New occupant info handling facilities that prevent rapid fire modifiers

from stepping on one anothers' toes.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1676 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-09-13 00:20:43 +00:00
parent 530188e5f2
commit 335ef8eb05
5 changed files with 79 additions and 22 deletions
@@ -1,5 +1,5 @@
//
// $Id: LocationProvider.java,v 1.16 2002/08/14 19:07:49 mdb Exp $
// $Id: LocationProvider.java,v 1.17 2002/09/13 00:20:43 mdb Exp $
package com.threerings.crowd.server;
@@ -107,12 +107,9 @@ public class LocationProvider
// remove them from any previous location
leaveOccupiedPlace(source);
// generate a new occupant info record and add it to the
// target location
OccupantInfo info = pmgr.buildOccupantInfo(source);
if (info != null) {
place.addToOccupantInfo(info);
}
// generate a new occupant info record (which will add it
// to the target location)
pmgr.buildOccupantInfo(source);
// set the body's new location
source.setLocation(place.getOid());
@@ -1,5 +1,5 @@
//
// $Id: PlaceManager.java,v 1.32 2002/08/14 19:07:49 mdb Exp $
// $Id: PlaceManager.java,v 1.33 2002/09/13 00:20:43 mdb Exp $
package com.threerings.crowd.server;
@@ -7,6 +7,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import com.samskivert.util.HashIntMap;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationManager;
@@ -86,6 +88,38 @@ public class PlaceManager
return _plobj;
}
/**
* Returns the occupant info record for the user with the specified
* body oid, if they are an occupant of this room. Returns null
* otherwise.
*/
public OccupantInfo getOccupantInfo (int bodyOid)
{
return (OccupantInfo)_occInfo.get(bodyOid);
}
/**
* Updates the occupant info for this room occupant. <em>Note:</em>
* This must be used rather than setting the occupant info directly to
* avoid possible complications due to rapid fire changes to a user's
* occupant info. The occupant info record supplied to this method
* must be one returned from {@link #getOccupantInfo}. For example:
*
* <pre>
* OccupantInfo info = _plmgr.getOccupantInfo(bodyOid);
* // ... modifications made to 'info'
* _plmgr.updateOccupantInfo(info);
* </pre>
*/
public void updateOccupantInfo (OccupantInfo occInfo)
{
// update the canonical copy
_occInfo.put(occInfo.getBodyOid(), occInfo);
// clone the canonical copy and send out an event updating the
// distributed set with that clone
_plobj.updateOccupantInfo((OccupantInfo)occInfo.clone());
}
/**
* A place manager derived class is likely to have a corresponding
* derived class of {@link com.threerings.crowd.data.PlaceObject} that
@@ -216,19 +250,28 @@ public class PlaceManager
}
/**
* Builds an occupant info record for the specified body object. This
* is called by the location services when a body enters a place. It
* should not be overridden by derived classes, they should override
* {@link #populateOccupantInfo}, which is set up for that sort of
* thing.
* Builds an occupant info record for the specified body object and
* inserts it into our place object. This is called by the location
* services when a body enters a place. It should not be overridden by
* derived classes, they should override {@link
* #populateOccupantInfo}, which is set up for that sort of thing.
*/
public OccupantInfo buildOccupantInfo (BodyObject body)
{
// create a new occupant info instance
try {
// create a new occupant info instance
OccupantInfo info = (OccupantInfo)
getOccupantInfoClass(body).newInstance();
// configure it with the appropriate values
populateOccupantInfo(info, body);
// insert the occupant info into our canonical table
_occInfo.put(info.getBodyOid(), info);
// and insert it into the place object
_plobj.addToOccupantInfo(info);
return info;
} catch (Exception e) {
@@ -294,6 +337,9 @@ public class PlaceManager
_plobj.removeFromOccupantInfo(key);
}
// clear out their canonical (local) occupant info record
_occInfo.remove(bodyOid);
// let our delegates know what's up
applyToDelegates(new DelegateOp() {
public void apply (PlaceManagerDelegate delegate) {
@@ -484,4 +530,7 @@ public class PlaceManager
/** A list of the delegates in use by this manager. */
protected ArrayList _delegates;
/** Used to keep a canonical copy of the occupant info records. */
protected HashIntMap _occInfo = new HashIntMap();
}