From d57adeca1cb6d0ad098de145bf0c9f5ada0f83e6 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 3 Dec 2005 03:05:06 +0000 Subject: [PATCH] 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 --- .../com/threerings/crowd/data/BodyObject.java | 9 ++++ .../threerings/crowd/data/OccupantInfo.java | 28 ++++++++--- .../threerings/crowd/server/PlaceManager.java | 48 ++++++------------- .../stage/data/StageOccupantInfo.java | 12 +++++ .../stage/server/StageSceneManager.java | 6 --- .../whirled/spot/server/SpotSceneManager.java | 8 ++-- 6 files changed, 62 insertions(+), 49 deletions(-) diff --git a/src/java/com/threerings/crowd/data/BodyObject.java b/src/java/com/threerings/crowd/data/BodyObject.java index 4d5eb2dd4..90997f78e 100644 --- a/src/java/com/threerings/crowd/data/BodyObject.java +++ b/src/java/com/threerings/crowd/data/BodyObject.java @@ -120,6 +120,15 @@ public class BodyObject extends ClientObject 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 public void applyToListeners (ListenerOp op) { diff --git a/src/java/com/threerings/crowd/data/OccupantInfo.java b/src/java/com/threerings/crowd/data/OccupantInfo.java index d9c63ef2a..a1b4af0bc 100644 --- a/src/java/com/threerings/crowd/data/OccupantInfo.java +++ b/src/java/com/threerings/crowd/data/OccupantInfo.java @@ -26,18 +26,18 @@ import com.threerings.util.Name; import com.threerings.presents.dobj.DSet; +import com.threerings.crowd.data.BodyObject; + /** * The occupant info object contains all of the information about an * 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 * updated when bodies enter and exit a place. * - *

A system that builds upon the Crowd framework can extend this class - * to include extra information about their occupants. They will need to - * be sure to return the proper class from {@link - * com.threerings.crowd.server.PlaceManager#getOccupantInfoClass} and - * populate their occupant info in {@link - * com.threerings.crowd.server.PlaceManager#populateOccupantInfo}. + *

A system that builds upon the Crowd framework can extend this class to + * include extra information about their occupants. They will need to provide a + * derived {@link BodyObject} that creates and configures their occupant info + * in {@link BodyObject#createOccupantInfo}. * *

Note also that this class implements {@link Cloneable} which means * that if derived classes add non-primitive attributes, they are @@ -68,6 +68,22 @@ public class OccupantInfo extends SimpleStreamableObject /** The status of this occupant. */ 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. */ public int getBodyOid () { diff --git a/src/java/com/threerings/crowd/server/PlaceManager.java b/src/java/com/threerings/crowd/server/PlaceManager.java index 02d968d4d..6d7346391 100644 --- a/src/java/com/threerings/crowd/server/PlaceManager.java +++ b/src/java/com/threerings/crowd/server/PlaceManager.java @@ -343,39 +343,24 @@ public class PlaceManager { 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 - * 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. + * services when a body enters a place. If a derived class wishes to + * perform custom actions when an occupant is being inserted into a room, + * 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) { try { // create a new occupant info instance - OccupantInfo info = (OccupantInfo) - getOccupantInfoClass(body).newInstance(); + OccupantInfo info = body.createOccupantInfo(); - // configure it with the appropriate values - populateOccupantInfo(info, body); - - // insert the occupant info into our canonical table - _occInfo.put(info.getBodyOid(), info); + // insert the occupant info into our canonical table; this is done + // in a method so that derived classes + insertOccupantInfo(info, body); // clone the canonical copy and insert it into the DSet _plobj.addToOccupantInfo((OccupantInfo)info.clone()); @@ -404,17 +389,14 @@ public class PlaceManager } /** - * Derived classes should override this method if they are making use - * of a derived occupant info class. They should call the super - * implementation and then populate the occupant info fields in their - * extended object. + * Called when an occupant is being added to this place. This will be + * before the call to {@link #bodyEntered} and gives the derived class a + * chance to set up additional information about the occupant that might + * 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 - info.bodyOid = new Integer(body.getOid()); - info.username = body.getVisibleName(); - info.status = body.status; + _occInfo.put(info.getBodyOid(), info); } /** diff --git a/src/java/com/threerings/stage/data/StageOccupantInfo.java b/src/java/com/threerings/stage/data/StageOccupantInfo.java index 25be04f78..c2c5d9868 100644 --- a/src/java/com/threerings/stage/data/StageOccupantInfo.java +++ b/src/java/com/threerings/stage/data/StageOccupantInfo.java @@ -21,6 +21,7 @@ package com.threerings.stage.data; +import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.data.OccupantInfo; /** @@ -28,6 +29,17 @@ import com.threerings.crowd.data.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 * clustered with, false if they are "busy". This means that a user diff --git a/src/java/com/threerings/stage/server/StageSceneManager.java b/src/java/com/threerings/stage/server/StageSceneManager.java index d8d8b8fc7..beb40d379 100644 --- a/src/java/com/threerings/stage/server/StageSceneManager.java +++ b/src/java/com/threerings/stage/server/StageSceneManager.java @@ -264,12 +264,6 @@ public class StageSceneManager extends SpotSceneManager return StageSceneObject.class; } - // documentation inherited - protected Class getOccupantInfoClass (BodyObject body) - { - return StageOccupantInfo.class; - } - // documentation inherited protected void bodyLeft (int bodyOid) { diff --git a/src/java/com/threerings/whirled/spot/server/SpotSceneManager.java b/src/java/com/threerings/whirled/spot/server/SpotSceneManager.java index 154b07db3..684fd85e6 100644 --- a/src/java/com/threerings/whirled/spot/server/SpotSceneManager.java +++ b/src/java/com/threerings/whirled/spot/server/SpotSceneManager.java @@ -172,12 +172,12 @@ public class SpotSceneManager extends SceneManager } // 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 - // assign them their starting location in the scene + // we don't actually populate their occupant info, but instead assign + // them their starting location in the scene int portalId = _enterers.remove(body.getOid()); Portal entry; if (portalId != -1) {