com.threerings.stage.server
Class StageSceneManager

java.lang.Object
  extended by com.threerings.crowd.server.PlaceManager
      extended by com.threerings.whirled.server.SceneManager
          extended by com.threerings.whirled.spot.server.SpotSceneManager
              extended by com.threerings.stage.server.StageSceneManager
All Implemented Interfaces:
ChatCodes, SpeakHandler.SpeakerValidator, LocationCodes, InvocationCodes, ChangeListener, MessageListener, InvocationProvider, StageSceneProvider, SceneCodes, SpotCodes

public class StageSceneManager
extends SpotSceneManager
implements StageSceneProvider

Defines extensions to the basic Stage scene manager specific to displaying isometric "stage" scenes (these may be indoor, outdoor or aboard a vessel).


Nested Class Summary
 
Nested classes/interfaces inherited from class com.threerings.whirled.spot.server.SpotSceneManager
SpotSceneManager.ClusterRecord
 
Nested classes/interfaces inherited from class com.threerings.crowd.server.PlaceManager
PlaceManager.DelegateOp, PlaceManager.MessageHandler
 
Field Summary
protected  ArrayList<Rectangle> _footprints
          Rectangles describing the footprints (in tile coordinates) of all of our scene objects.
protected  HashIntMap<Rectangle> _loners
          Rectangles containing a "footprint" for the users that aren't in any clusters.
protected  StageMisoSceneModel _mmodel
          Our miso scene data extracted for convenience and efficiency.
protected  HashSet<Point> _plocs
          Contains the (tile) coordinates of all of our portals.
protected  StageScene _sscene
          A casted reference to our scene data.
protected  StageSceneObject _ssobj
          A casted reference to our scene object.
protected static int[] PORTAL_DX
          Used by computeEnteringLocation(BodyObject,Portal,int).
protected static int[] PORTAL_DY
          Used by computeEnteringLocation(BodyObject,Portal,int).
protected static int[] TARGET_SIZE
          The dimensions of a cluster with the specified number of occupants.
protected static int[] X_OFF
          Used by canAddBody(com.threerings.whirled.spot.server.SpotSceneManager.ClusterRecord, com.threerings.crowd.data.BodyObject).
protected static int[] Y_OFF
          Used by canAddBody(com.threerings.whirled.spot.server.SpotSceneManager.ClusterRecord, com.threerings.crowd.data.BodyObject).
 
Fields inherited from class com.threerings.whirled.spot.server.SpotSceneManager
_clusters, _enterers
 
Fields inherited from class com.threerings.whirled.server.SceneManager
_invoker, _scene, _screg, _updates
 
Fields inherited from class com.threerings.crowd.server.PlaceManager
_bodyUpdater, _config, _deathListener, _delegates, _dispatcher, _dispatcherFinders, _injector, _invmgr, _locator, _marshallers, _msghandlers, _occInfo, _occListener, _omgr, _plobj, _registry, _shutdownInterval
 
Fields inherited from interface com.threerings.whirled.spot.data.SpotCodes
CLUSTER_CHAT_TYPE, CLUSTER_FULL, INVALID_LOCATION, LOCATION_OCCUPIED, NO_SUCH_CLUSTER, NO_SUCH_PORTAL
 
Fields inherited from interface com.threerings.crowd.chat.data.ChatCodes
BROADCAST_ACCESS, BROADCAST_MODE, CHAT_ACCESS, CHAT_CHANNEL_NOTIFICATION, CHAT_NOTIFICATION, DEFAULT_IDLE_TIME, DEFAULT_MODE, EMOTE_MODE, IDLE_TIME_KEY, LAST_MODE, PLACE_CHAT_TYPE, SHOUT_MODE, SUCCESS, THINK_MODE, USER_CHAT_TYPE, USER_DISCONNECTED, USER_NOT_ONLINE, XLATE_MODES
 
Fields inherited from interface com.threerings.whirled.data.SceneCodes
SCENE_UPDATE, WHIRLED_GROUP
 
Fields inherited from interface com.threerings.crowd.data.LocationCodes
ALREADY_THERE, MOVE_IN_PROGRESS, NO_SUCH_PLACE
 
Fields inherited from interface com.threerings.presents.data.InvocationCodes
ACCESS_DENIED, E_ACCESS_DENIED, E_INTERNAL_ERROR, GLOBAL_GROUP, INTERNAL_ERROR
 
Constructor Summary
StageSceneManager()
           
 
Method Summary
 void addObject(ClientObject caller, com.threerings.miso.data.ObjectInfo info, InvocationService.ConfirmListener listener)
          Handles a StageSceneService.addObject(com.threerings.miso.data.ObjectInfo, com.threerings.presents.client.InvocationService.ConfirmListener) request.
 boolean addObject(com.threerings.miso.data.ObjectInfo info, boolean killOverlap, boolean allowOverlap)
          Adds the supplied object to this scene.
protected  void bodyAdded(SpotSceneManager.ClusterRecord clrec, BodyObject body)
          Called when a user is added to a cluster.
protected  void bodyLeft(int bodyOid)
           
protected  void bodyRemoved(SpotSceneManager.ClusterRecord clrec, BodyObject body)
          Called when a user is removed from a cluster.
protected  boolean canAddBody(SpotSceneManager.ClusterRecord clrec, BodyObject body)
          Verifies that the specified cluster can be expanded to include another body.
protected  void checkCanCluster(BodyObject initiator, BodyObject target)
          Gives derived classes an opportunity to veto a user's attempt to start a cluster with another user.
protected  boolean checkContains(Iterable<? extends Rectangle> rects, int tx, int ty)
          Helper function for validateLocation(BodyObject,StageLocation,boolean).
protected  boolean checkEntry(com.threerings.miso.util.MisoSceneMetrics metrics, BodyObject body, int tx, int ty, StageLocation loc)
          Helper function for computeEnteringLocation(BodyObject,Portal,int).
protected  boolean checkIntersects(Iterable<? extends Rectangle> rects, Rectangle rect, Rectangle ignore)
          Helper function for canAddBody(com.threerings.whirled.spot.server.SpotSceneManager.ClusterRecord, com.threerings.crowd.data.BodyObject).
protected  boolean checkPortals(Rectangle rect)
          Helper function for canAddBody(com.threerings.whirled.spot.server.SpotSceneManager.ClusterRecord, com.threerings.crowd.data.BodyObject).
protected  boolean checkViolatesPassability(Rectangle rect)
          Helper function for canAddBody(com.threerings.whirled.spot.server.SpotSceneManager.ClusterRecord, com.threerings.crowd.data.BodyObject).
protected  SceneLocation computeEnteringLocation(BodyObject body, Portal entry, int minDistance)
          Returns an entering location for body somewhere at least minDistance tiles away from entry.
protected  SceneLocation computeEnteringLocation(BodyObject body, Portal from, Portal entry)
          Called when the supplied body is entering our scene via the specified portal.
protected  SceneLocation computeEnteringLocation(BodyObject body, StageLocation base, int minDistance)
          Returns an entering location for body somewhere at least minDistance tiles away from base.
protected  void computeFootprints()
          Computes the footprints of all objects and portals in this scene.
protected  PlaceObject createPlaceObject()
           
protected  void didStartup()
          We're fully ready to go, so now we register ourselves with the scene registry which will make us available to the clients and system at large.
 com.threerings.media.util.AStarPathUtil.TraversalPred getCanStandPred()
          Returns a traversal predicate for use with StageSceneUtil.findStandingSpot(java.awt.Rectangle, int, com.threerings.media.util.AStarPathUtil.TraversalPred, java.lang.Object, java.awt.Point, int) that validates whether a player can stand in the searched spots.
protected static SceneLocation getClosestLoc(List<SceneLocation> locs, SceneLocation optimalLocation)
          Locates and removes the location in the list closest to the supplied location.
protected  void gotSceneData(Object extras)
          A method that can be overridden by derived classes to perform initialization processing after we receive our scene information but before we're started up (and hence registered as an active place).
 boolean isPassable(int tx, int ty)
          Returns true if the specified tile coordinate is passable (the base tile is passable and it is not in the footprint of an object).
 boolean mayStandAtLocation(BodyObject source, StageLocation loc)
          Called by NPPs to determine whether or not they can stand at the specified location.
protected  void positionBody(Cluster cl, int bodyOid, List<SceneLocation> locs)
          Helper function for bodyAdded(com.threerings.whirled.spot.server.SpotSceneManager.ClusterRecord, com.threerings.crowd.data.BodyObject).
protected  void recordUpdate(SceneUpdate update, boolean tilesModified)
          Applies the supplied scene update to our runtime scene and then fires off an invocation unit to apply the update to the scene database.
 void removeObjects(ClientObject caller, com.threerings.miso.data.ObjectInfo[] info, InvocationService.ConfirmListener listener)
          Handles a StageSceneService.removeObjects(com.threerings.miso.data.ObjectInfo[], com.threerings.presents.client.InvocationService.ConfirmListener) request.
protected  void sceneTilesModified()
          Called when any change is made to a scene's base or object tiles (resulting in a change in the way the scene looks).
 void setColor(int classId, int colorId)
          Changes the default colorization for the specified color class.
protected  void updateLocation(BodyObject source, Location loc)
          Updates the location of the specified body.
protected  boolean validateLocation(BodyObject source, Location loc)
          Derived classes can override this method and validate that the specified body can stand in the requested location.
protected  boolean validateLocation(BodyObject source, StageLocation loc, boolean allowPortals)
          Helper function for mayStandAtLocation(com.threerings.crowd.data.BodyObject, com.threerings.stage.data.StageLocation) and validateLocation(BodyObject,Location).
 
Methods inherited from class com.threerings.whirled.spot.server.SpotSceneManager
addOccupantInfo, assignStartingLocation, clearEnteringBody, createClusterRecord, getCluster, handleChangeLoc, handleClusterMessageRequest, handleClusterSpeakRequest, handleJoinCluster, locationForBody, mapEnteringBody, mayTraversePortal, moveBodyToDefaultPortal, moveToDefaultPortal, removeFromCluster, willTraversePortal
 
Methods inherited from class com.threerings.whirled.server.SceneManager
didShutdown, getLocation, getScene, getUpdates, isPersistent, recordUpdate, setSceneData, toString, where
 
Methods inherited from class com.threerings.crowd.server.PlaceManager
addDelegate, addDispatcher, addProvider, applyToDelegates, applyToOccupants, bodyEntered, bodyUpdated, bodyWillEnter, bodyWillLeave, cancelShutdowner, checkPermissions, checkShutdownInterval, createSpeakHandler, didInit, getAccessController, getConfig, getPlaceObject, getPlaceObjectClass, idleUnloadPeriod, init, isValidSpeaker, messageReceived, permissionsFailed, placeBecameEmpty, ratifyBodyEntry, registerMessageHandler, shouldCreateSpeakService, shouldDeclareEmpty, shutdown, startup, toString, updateOccupantInfo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_ssobj

protected StageSceneObject _ssobj
A casted reference to our scene object.


_sscene

protected StageScene _sscene
A casted reference to our scene data.


_mmodel

protected StageMisoSceneModel _mmodel
Our miso scene data extracted for convenience and efficiency.


_footprints

protected ArrayList<Rectangle> _footprints
Rectangles describing the footprints (in tile coordinates) of all of our scene objects.


_loners

protected HashIntMap<Rectangle> _loners
Rectangles containing a "footprint" for the users that aren't in any clusters.


_plocs

protected HashSet<Point> _plocs
Contains the (tile) coordinates of all of our portals.


TARGET_SIZE

protected static final int[] TARGET_SIZE
The dimensions of a cluster with the specified number of occupants.


X_OFF

protected static final int[] X_OFF
Used by canAddBody(com.threerings.whirled.spot.server.SpotSceneManager.ClusterRecord, com.threerings.crowd.data.BodyObject).


Y_OFF

protected static final int[] Y_OFF
Used by canAddBody(com.threerings.whirled.spot.server.SpotSceneManager.ClusterRecord, com.threerings.crowd.data.BodyObject).


PORTAL_DX

protected static final int[] PORTAL_DX
Used by computeEnteringLocation(BodyObject,Portal,int).


PORTAL_DY

protected static final int[] PORTAL_DY
Used by computeEnteringLocation(BodyObject,Portal,int).

Constructor Detail

StageSceneManager

public StageSceneManager()
Method Detail

getCanStandPred

public com.threerings.media.util.AStarPathUtil.TraversalPred getCanStandPred()
Returns a traversal predicate for use with StageSceneUtil.findStandingSpot(java.awt.Rectangle, int, com.threerings.media.util.AStarPathUtil.TraversalPred, java.lang.Object, java.awt.Point, int) that validates whether a player can stand in the searched spots.


addObject

public boolean addObject(com.threerings.miso.data.ObjectInfo info,
                         boolean killOverlap,
                         boolean allowOverlap)
Adds the supplied object to this scene. A persistent update is generated and broadcast to all scene occupants. The update is stored in the repository for communication to future occupants of the scene and then entire complex process of changing our virtual game world is effected at the simple call of this single method.

Parameters:
killOverlap - if true, overlapping object will be removed, and the allowOverlap argument will be ignored.
allowOverlap - if true, overlapping objects will be allowed but one must be *very* careful to ensure that they know what they are doing (i.e. the objects have render priorities that correctly handle the overlap).
Returns:
true if the object was added, false if the add was rejected because the object overlaps an existing scene object.

setColor

public void setColor(int classId,
                     int colorId)
Changes the default colorization for the specified color class. A persistent update is generated and broadcast to all scene occupants. The update is stored in the repository for communication to future occupants of the scene and then entire complex process of changing our virtual game world is effected at the simple call of this single method.


isPassable

public boolean isPassable(int tx,
                          int ty)
Returns true if the specified tile coordinate is passable (the base tile is passable and it is not in the footprint of an object).


mayStandAtLocation

public boolean mayStandAtLocation(BodyObject source,
                                  StageLocation loc)
Called by NPPs to determine whether or not they can stand at the specified location.


addObject

public void addObject(ClientObject caller,
                      com.threerings.miso.data.ObjectInfo info,
                      InvocationService.ConfirmListener listener)
               throws InvocationException
Description copied from interface: StageSceneProvider
Handles a StageSceneService.addObject(com.threerings.miso.data.ObjectInfo, com.threerings.presents.client.InvocationService.ConfirmListener) request.

Specified by:
addObject in interface StageSceneProvider
Throws:
InvocationException

removeObjects

public void removeObjects(ClientObject caller,
                          com.threerings.miso.data.ObjectInfo[] info,
                          InvocationService.ConfirmListener listener)
                   throws InvocationException
Description copied from interface: StageSceneProvider
Handles a StageSceneService.removeObjects(com.threerings.miso.data.ObjectInfo[], com.threerings.presents.client.InvocationService.ConfirmListener) request.

Specified by:
removeObjects in interface StageSceneProvider
Throws:
InvocationException

gotSceneData

protected void gotSceneData(Object extras)
Description copied from class: SceneManager
A method that can be overridden by derived classes to perform initialization processing after we receive our scene information but before we're started up (and hence registered as an active place).

Overrides:
gotSceneData in class SpotSceneManager
Parameters:
extras - optional additional information supplied by the repository when the scene was loaded, or null if the repository provided no extras.

recordUpdate

protected void recordUpdate(SceneUpdate update,
                            boolean tilesModified)
Applies the supplied scene update to our runtime scene and then fires off an invocation unit to apply the update to the scene database. Finally the update is "recorded" which broadcasts the update to all occupants of the scene and stores the update so that it can be provided as a patch to future scene visitors.


sceneTilesModified

protected void sceneTilesModified()
Called when any change is made to a scene's base or object tiles (resulting in a change in the way the scene looks). If any sneaky business need be done to deal with said addition, it can be handled here.


didStartup

protected void didStartup()
Description copied from class: SceneManager
We're fully ready to go, so now we register ourselves with the scene registry which will make us available to the clients and system at large.

Overrides:
didStartup in class SpotSceneManager

createPlaceObject

protected PlaceObject createPlaceObject()
Overrides:
createPlaceObject in class PlaceManager

bodyLeft

protected void bodyLeft(int bodyOid)
Overrides:
bodyLeft in class SpotSceneManager

updateLocation

protected void updateLocation(BodyObject source,
                              Location loc)
Description copied from class: SpotSceneManager
Updates the location of the specified body.

Overrides:
updateLocation in class SpotSceneManager

computeFootprints

protected void computeFootprints()
Computes the footprints of all objects and portals in this scene. This is done when we are first resolved and following any modifications to the scene's tile data.


validateLocation

protected boolean validateLocation(BodyObject source,
                                   StageLocation loc,
                                   boolean allowPortals)
Helper function for mayStandAtLocation(com.threerings.crowd.data.BodyObject, com.threerings.stage.data.StageLocation) and validateLocation(BodyObject,Location).


checkContains

protected boolean checkContains(Iterable<? extends Rectangle> rects,
                                int tx,
                                int ty)
Helper function for validateLocation(BodyObject,StageLocation,boolean).


computeEnteringLocation

protected SceneLocation computeEnteringLocation(BodyObject body,
                                                Portal from,
                                                Portal entry)
Description copied from class: SpotSceneManager
Called when the supplied body is entering our scene via the specified portal. The default location is the one associated with the portal, but derived classes may wish to adjust this.

Overrides:
computeEnteringLocation in class SpotSceneManager
from - the portal the body followed to get to this scene (or null).
entry - the portal referenced by the from portal's targetPortalId or the scene's default entrance if the from portal did not exist or had no target portal.

computeEnteringLocation

protected SceneLocation computeEnteringLocation(BodyObject body,
                                                Portal entry,
                                                int minDistance)
Returns an entering location for body somewhere at least minDistance tiles away from entry.


computeEnteringLocation

protected SceneLocation computeEnteringLocation(BodyObject body,
                                                StageLocation base,
                                                int minDistance)
Returns an entering location for body somewhere at least minDistance tiles away from base.


checkEntry

protected boolean checkEntry(com.threerings.miso.util.MisoSceneMetrics metrics,
                             BodyObject body,
                             int tx,
                             int ty,
                             StageLocation loc)
Helper function for computeEnteringLocation(BodyObject,Portal,int).


validateLocation

protected boolean validateLocation(BodyObject source,
                                   Location loc)
Description copied from class: SpotSceneManager
Derived classes can override this method and validate that the specified body can stand in the requested location. The default implementation returns true in all circumstances; stand where ye may!

Overrides:
validateLocation in class SpotSceneManager

canAddBody

protected boolean canAddBody(SpotSceneManager.ClusterRecord clrec,
                             BodyObject body)
Description copied from class: SpotSceneManager
Verifies that the specified cluster can be expanded to include another body.

Overrides:
canAddBody in class SpotSceneManager

checkIntersects

protected boolean checkIntersects(Iterable<? extends Rectangle> rects,
                                  Rectangle rect,
                                  Rectangle ignore)
Helper function for canAddBody(com.threerings.whirled.spot.server.SpotSceneManager.ClusterRecord, com.threerings.crowd.data.BodyObject).


checkPortals

protected boolean checkPortals(Rectangle rect)
Helper function for canAddBody(com.threerings.whirled.spot.server.SpotSceneManager.ClusterRecord, com.threerings.crowd.data.BodyObject).


checkViolatesPassability

protected boolean checkViolatesPassability(Rectangle rect)
Helper function for canAddBody(com.threerings.whirled.spot.server.SpotSceneManager.ClusterRecord, com.threerings.crowd.data.BodyObject).


bodyAdded

protected void bodyAdded(SpotSceneManager.ClusterRecord clrec,
                         BodyObject body)
Description copied from class: SpotSceneManager
Called when a user is added to a cluster. The scene manager implementation should take this opportunity to rearrange everyone in the cluster appropriately for the new size.

Overrides:
bodyAdded in class SpotSceneManager

positionBody

protected void positionBody(Cluster cl,
                            int bodyOid,
                            List<SceneLocation> locs)
Helper function for bodyAdded(com.threerings.whirled.spot.server.SpotSceneManager.ClusterRecord, com.threerings.crowd.data.BodyObject).


bodyRemoved

protected void bodyRemoved(SpotSceneManager.ClusterRecord clrec,
                           BodyObject body)
Description copied from class: SpotSceneManager
Called when a user is removed from a cluster. The scene manager implementation should take this opportunity to rearrange everyone in the cluster appropriately for the new size.

Overrides:
bodyRemoved in class SpotSceneManager

checkCanCluster

protected void checkCanCluster(BodyObject initiator,
                               BodyObject target)
                        throws InvocationException
Description copied from class: SpotSceneManager
Gives derived classes an opportunity to veto a user's attempt to start a cluster with another user. If the attempt should be vetoed, this method should throw an InvocationException indicating the reason for veto.

Overrides:
checkCanCluster in class SpotSceneManager
Throws:
InvocationException

getClosestLoc

protected static SceneLocation getClosestLoc(List<SceneLocation> locs,
                                             SceneLocation optimalLocation)
Locates and removes the location in the list closest to the supplied location.