com.threerings.miso.data
Class SimpleMisoSceneModel

java.lang.Object
  extended by com.threerings.io.SimpleStreamableObject
      extended by com.threerings.miso.data.MisoSceneModel
          extended by com.threerings.miso.data.SimpleMisoSceneModel
All Implemented Interfaces:
com.threerings.io.Streamable, Cloneable

public class SimpleMisoSceneModel
extends MisoSceneModel

Contains miso scene data for a scene that is assumed to be reasonably simple and small, such that all base tile data for the entire scene can be stored in a single contiguous array.

Additionally, it makes the assumption that the single model will be used to display a scene on a rectangular screen (dimensions defined by vwidth and vheight) and further optimizes the base tile array to obviate the need to store tile data for things that fall outside the bounds of the screen.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
com.threerings.io.Streamable.Closure
 
Field Summary
 int[] baseTileIds
          The combined tile ids (tile set id and tile id) in compressed format.
 short height
          The height of this scene in tiles.
 ObjectInfo[] objectInfo
          Information records for the "interesting" objects in the object layer.
 int[] objectTileIds
          The combined tile ids (tile set id and tile id) of the "uninteresting" tiles in the object layer.
 short[] objectXs
          The x coordinate of the "uninteresting" tiles in the object layer.
 short[] objectYs
          The y coordinate of the "uninteresting" tiles in the object layer.
 int vheight
          The viewport height in tiles.
 int vwidth
          The viewport width in tiles.
 short width
          The width of this scene in tiles.
 
Constructor Summary
SimpleMisoSceneModel()
          Creates a completely uninitialized model suitable for little more than unserialization.
SimpleMisoSceneModel(int width, int height, int vwidth, int vheight)
          Creates a blank scene model with the specified dimensions.
 
Method Summary
 boolean addObject(ObjectInfo info)
          Adds an object to this scene.
protected  void allocateBaseTileArray()
          Allocate the base tile array.
 SimpleMisoSceneModel clone()
           
 int getBaseTileId(int col, int row)
          Returns the fully qualified tile id of the base tile at the specified coordinates.
protected  int getIndex(int x, int y)
          Get the index into the baseTileIds[] for the specified x and y coordinates, or return -1 if the specified coordinates are outside of the viewable area.
 void getObjects(Rectangle region, ObjectSet set)
          Populates the supplied object set with info on all objects whose origin falls in the requested region.
static void populateObjects(SimpleMisoSceneModel model, List<ObjectInfo> ilist, List<ObjectInfo> ulist)
          Populates the interesting and uninteresting parts of a miso scene model given lists of ObjectInfo records for each.
 boolean removeObject(ObjectInfo info)
          Removes the specified object from the scene.
 boolean setBaseTile(int fqBaseTileId, int col, int row)
          Updates the tile at the specified location in the base layer.
 void updateObject(ObjectInfo info)
          Updates an object in this scene.
 
Methods inherited from class com.threerings.miso.data.MisoSceneModel
getDefaultBaseTileSet, setDefaultBaseTileSet
 
Methods inherited from class com.threerings.io.SimpleStreamableObject
toString, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

width

public short width
The width of this scene in tiles.


height

public short height
The height of this scene in tiles.


vwidth

public int vwidth
The viewport width in tiles.


vheight

public int vheight
The viewport height in tiles.


baseTileIds

public int[] baseTileIds
The combined tile ids (tile set id and tile id) in compressed format. Don't go poking around in here, use the accessor methods.


objectTileIds

public int[] objectTileIds
The combined tile ids (tile set id and tile id) of the "uninteresting" tiles in the object layer.


objectXs

public short[] objectXs
The x coordinate of the "uninteresting" tiles in the object layer.


objectYs

public short[] objectYs
The y coordinate of the "uninteresting" tiles in the object layer.


objectInfo

public ObjectInfo[] objectInfo
Information records for the "interesting" objects in the object layer.

Constructor Detail

SimpleMisoSceneModel

public SimpleMisoSceneModel()
Creates a completely uninitialized model suitable for little more than unserialization.


SimpleMisoSceneModel

public SimpleMisoSceneModel(int width,
                            int height,
                            int vwidth,
                            int vheight)
Creates a blank scene model with the specified dimensions.

Method Detail

getBaseTileId

public int getBaseTileId(int col,
                         int row)
Description copied from class: MisoSceneModel
Returns the fully qualified tile id of the base tile at the specified coordinates. -1 will be returned if there is no tile at the specified coordinate.

Specified by:
getBaseTileId in class MisoSceneModel

setBaseTile

public boolean setBaseTile(int fqBaseTileId,
                           int col,
                           int row)
Description copied from class: MisoSceneModel
Updates the tile at the specified location in the base layer.

Note that if there are fringe tiles associated with this scene, calling this method may result in the surrounding fringe tiles being cleared and subsequently recalculated. This should not be called on a displaying scene unless you know what you are doing.

Specified by:
setBaseTile in class MisoSceneModel
Parameters:
fqBaseTileId - the fully-qualified tile id (@see TileUtil#getFQTileId}) of the tile to set.
col - the x-coordinate of the tile to set.
row - the y-coordinate of the tile to set.
Returns:
false if the specified tile coordinates are outside of the scene and the tile was not saved, true otherwise.

getObjects

public void getObjects(Rectangle region,
                       ObjectSet set)
Description copied from class: MisoSceneModel
Populates the supplied object set with info on all objects whose origin falls in the requested region.

Specified by:
getObjects in class MisoSceneModel

addObject

public boolean addObject(ObjectInfo info)
Description copied from class: MisoSceneModel
Adds an object to this scene.

Specified by:
addObject in class MisoSceneModel
Returns:
true if the object was added, false if the add was rejected due to being a duplicate.

updateObject

public void updateObject(ObjectInfo info)
Description copied from class: MisoSceneModel
Updates an object in this scene.

Specified by:
updateObject in class MisoSceneModel

removeObject

public boolean removeObject(ObjectInfo info)
Description copied from class: MisoSceneModel
Removes the specified object from the scene.

Specified by:
removeObject in class MisoSceneModel
Returns:
true if it was removed, false if the object was not in the scene.

clone

public SimpleMisoSceneModel clone()
Overrides:
clone in class MisoSceneModel

getIndex

protected int getIndex(int x,
                       int y)
Get the index into the baseTileIds[] for the specified x and y coordinates, or return -1 if the specified coordinates are outside of the viewable area. Assumption: The viewable area is centered and aligned as far to the top of the isometric scene as possible, such that the upper-left corner is at the point where the tiles (0, vwid) and (0, vwid-1) touch. The upper-right corner is at the point where the tiles (vwid-1, 0) and (vwid, 0) touch. The viewable area is made up of "fat" rows and "thin" rows. The fat rows display one more tile than the thin rows because their first and last tiles are halfway off the viewable area. The thin rows are fully contained within the viewable area except for the first and last thin rows, which display only their bottom and top halves, respectively. Note that #fatrows == #thinrows - 1;


allocateBaseTileArray

protected void allocateBaseTileArray()
Allocate the base tile array.


populateObjects

public static void populateObjects(SimpleMisoSceneModel model,
                                   List<ObjectInfo> ilist,
                                   List<ObjectInfo> ulist)
Populates the interesting and uninteresting parts of a miso scene model given lists of ObjectInfo records for each.