Big fat bernie OccupantInfo revamp. Now:

- OccupantInfo is created by the BodyObject
- the BodyObject is passed to the OI constructor and it uses information
  therefrom to configure itself
- the PlaceManager are no longer responsible for indicating the type of
  OccupantInfo to use or how to populate it.

This makes much more sense as the same type of OccupantInfo is generally used
across the entire system and it's annoying to have to have every PlaceMaanger
derived class know the type of OccupantInfo to create and know how to
initialize it. The one drawback is that only information from the BodyObject
can be used to populate the OccupantInfo, unpublished server-side only
information cannot be used (unless its stuffed into a transient field in the
BodyObject).


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3774 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2005-12-03 03:05:06 +00:00
parent 15ea2134e3
commit d57adeca1c
6 changed files with 62 additions and 49 deletions
@@ -120,6 +120,15 @@ public class BodyObject extends ClientObject
return username; return username;
} }
/**
* Creates a blank occupant info instance that will used to publish
* information about the various bodies occupying a place.
*/
public OccupantInfo createOccupantInfo ()
{
return new OccupantInfo(this);
}
// documentation inherited // documentation inherited
public void applyToListeners (ListenerOp op) public void applyToListeners (ListenerOp op)
{ {
@@ -26,18 +26,18 @@ import com.threerings.util.Name;
import com.threerings.presents.dobj.DSet; import com.threerings.presents.dobj.DSet;
import com.threerings.crowd.data.BodyObject;
/** /**
* The occupant info object contains all of the information about an * The occupant info object contains all of the information about an
* occupant of a place that should be shared with other occupants of the * occupant of a place that should be shared with other occupants of the
* place. These objects are stored in the place object itself and are * place. These objects are stored in the place object itself and are
* updated when bodies enter and exit a place. * updated when bodies enter and exit a place.
* *
* <p> A system that builds upon the Crowd framework can extend this class * <p> A system that builds upon the Crowd framework can extend this class to
* to include extra information about their occupants. They will need to * include extra information about their occupants. They will need to provide a
* be sure to return the proper class from {@link * derived {@link BodyObject} that creates and configures their occupant info
* com.threerings.crowd.server.PlaceManager#getOccupantInfoClass} and * in {@link BodyObject#createOccupantInfo}.
* populate their occupant info in {@link
* com.threerings.crowd.server.PlaceManager#populateOccupantInfo}.
* *
* <p> Note also that this class implements {@link Cloneable} which means * <p> Note also that this class implements {@link Cloneable} which means
* that if derived classes add non-primitive attributes, they are * that if derived classes add non-primitive attributes, they are
@@ -68,6 +68,22 @@ public class OccupantInfo extends SimpleStreamableObject
/** The status of this occupant. */ /** The status of this occupant. */
public byte status = ACTIVE; public byte status = ACTIVE;
/**
* Creates an occupant info with information from the specified occupant's
* body object.
*/
public OccupantInfo (BodyObject body)
{
bodyOid = new Integer(body.getOid());
username = body.getVisibleName();
status = body.status;
}
/** A blank constructor used for unserialization. */
public OccupantInfo ()
{
}
/** Access to the body object id as an int. */ /** Access to the body object id as an int. */
public int getBodyOid () public int getBodyOid ()
{ {
@@ -343,39 +343,24 @@ public class PlaceManager
{ {
return null; return null;
} }
/**
* Returns the appropriate derived class of {@link OccupantInfo} that
* will be used to provide occupant info for this body. An occupant
* info record is created when a body enters a place.
*
* @param body the body that is entering the place and for whom we are
* creating an occupant info record.
*/
protected Class getOccupantInfoClass (BodyObject body)
{
return OccupantInfo.class;
}
/** /**
* Builds an occupant info record for the specified body object and * Builds an {@link OccupantInfo} record for the specified body object and
* inserts it into our place object. This is called by the location * 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 * services when a body enters a place. If a derived class wishes to
* derived classes, they should override {@link * perform custom actions when an occupant is being inserted into a room,
* #populateOccupantInfo}, which is set up for that sort of thing. * they should override {@link #insertOccupantInfo}, if they want to react
* to a body having entered, they should override {@link #bodyEntered}.
*/ */
public OccupantInfo buildOccupantInfo (BodyObject body) public OccupantInfo buildOccupantInfo (BodyObject body)
{ {
try { try {
// create a new occupant info instance // create a new occupant info instance
OccupantInfo info = (OccupantInfo) OccupantInfo info = body.createOccupantInfo();
getOccupantInfoClass(body).newInstance();
// configure it with the appropriate values // insert the occupant info into our canonical table; this is done
populateOccupantInfo(info, body); // in a method so that derived classes
insertOccupantInfo(info, body);
// insert the occupant info into our canonical table
_occInfo.put(info.getBodyOid(), info);
// clone the canonical copy and insert it into the DSet // clone the canonical copy and insert it into the DSet
_plobj.addToOccupantInfo((OccupantInfo)info.clone()); _plobj.addToOccupantInfo((OccupantInfo)info.clone());
@@ -404,17 +389,14 @@ public class PlaceManager
} }
/** /**
* Derived classes should override this method if they are making use * Called when an occupant is being added to this place. This will be
* of a derived occupant info class. They should call the super * before the call to {@link #bodyEntered} and gives the derived class a
* implementation and then populate the occupant info fields in their * chance to set up additional information about the occupant that might
* extended object. * not be tracked in the occupant info.
*/ */
protected void populateOccupantInfo (OccupantInfo info, BodyObject body) protected void insertOccupantInfo (OccupantInfo info, BodyObject body)
{ {
// the base occupant info is only their name and connection status _occInfo.put(info.getBodyOid(), info);
info.bodyOid = new Integer(body.getOid());
info.username = body.getVisibleName();
info.status = body.status;
} }
/** /**
@@ -21,6 +21,7 @@
package com.threerings.stage.data; package com.threerings.stage.data;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.data.OccupantInfo; import com.threerings.crowd.data.OccupantInfo;
/** /**
@@ -28,6 +29,17 @@ import com.threerings.crowd.data.OccupantInfo;
*/ */
public class StageOccupantInfo extends OccupantInfo public class StageOccupantInfo extends OccupantInfo
{ {
/** Creates a new instance for the specified body. */
public StageOccupantInfo (BodyObject body)
{
super(body);
}
/** Creates a blank instance for unserialization. */
public StageOccupantInfo ()
{
}
/** /**
* Should return true if the occupant in question is available to be * Should return true if the occupant in question is available to be
* clustered with, false if they are "busy". This means that a user * clustered with, false if they are "busy". This means that a user
@@ -264,12 +264,6 @@ public class StageSceneManager extends SpotSceneManager
return StageSceneObject.class; return StageSceneObject.class;
} }
// documentation inherited
protected Class getOccupantInfoClass (BodyObject body)
{
return StageOccupantInfo.class;
}
// documentation inherited // documentation inherited
protected void bodyLeft (int bodyOid) protected void bodyLeft (int bodyOid)
{ {
@@ -172,12 +172,12 @@ public class SpotSceneManager extends SceneManager
} }
// documentation inherited // documentation inherited
protected void populateOccupantInfo (OccupantInfo info, BodyObject body) protected void insertOccupantInfo (OccupantInfo info, BodyObject body)
{ {
super.populateOccupantInfo(info, body); super.insertOccupantInfo(info, body);
// we don't actually populate their occupant info, but instead // we don't actually populate their occupant info, but instead assign
// assign them their starting location in the scene // them their starting location in the scene
int portalId = _enterers.remove(body.getOid()); int portalId = _enterers.remove(body.getOid());
Portal entry; Portal entry;
if (portalId != -1) { if (portalId != -1) {