com.threerings.miso.data
Class SparseMisoSceneModel

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

public class SparseMisoSceneModel
extends MisoSceneModel

Contains miso scene data that is broken up into NxN tile sections.


Nested Class Summary
static interface SparseMisoSceneModel.ObjectVisitor
          An interface that allows external entities to "visit" and inspect every object in this scene.
static class SparseMisoSceneModel.Section
          Contains information on a section of this scene.
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
com.threerings.io.Streamable.Closure
 
Field Summary
protected  StreamableHashMap<Integer,SparseMisoSceneModel.Section> _sections
          Contains our sections in row major order.
 int defTileSet
          The tileset to use when we have no tile data.
 short sheight
          The dimensions of a section of our scene.
 short swidth
          The dimensions of a section of our scene.
 
Constructor Summary
SparseMisoSceneModel()
          Creates a blank model suitable for unserialization.
SparseMisoSceneModel(int swidth, int sheight)
          Creates a scene model with the specified bounds.
 
Method Summary
 boolean addObject(ObjectInfo info)
          Adds an object to this scene.
 SparseMisoSceneModel clone()
           
 void getAllObjects(ArrayList<ObjectInfo> list)
          Adds all ObjectInfo records in this scene to the supplied list.
 int getBaseTileId(int col, int row)
          Returns the fully qualified tile id of the base tile at the specified coordinates.
 int getDefaultBaseTileSet()
          Scene models can return a default tileset to be used when no base tile data exists for a particular tile.
 void getInterestingObjects(ArrayList<ObjectInfo> list)
          Adds all interesting ObjectInfo records in this scene to the supplied list.
 void getObjects(Rectangle region, ObjectSet set)
          Populates the supplied object set with info on all objects whose origin falls in the requested region.
protected  SparseMisoSceneModel.Section getSection(int x, int y, boolean create)
          Returns the section for the specified tile coordinate.
 Iterator<SparseMisoSceneModel.Section> getSections()
          Don't call this method!
protected  int key(int x, int y)
          Returns the key for the specified section.
 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 setDefaultBaseTileSet(int tileSetId)
          Updates the default base tileset id for this scene.
 void setSection(SparseMisoSceneModel.Section section)
          Don't call this method!
protected  void toString(StringBuilder buf)
           
 void updateObject(ObjectInfo info)
          Updates an object in this scene.
 void visitObjects(SparseMisoSceneModel.ObjectVisitor visitor)
          Informs the supplied visitor of each object in this scene.
 void visitObjects(SparseMisoSceneModel.ObjectVisitor visitor, boolean interestingOnly)
          Informs the supplied visitor of each object in this scene.
 
Methods inherited from class com.threerings.io.SimpleStreamableObject
toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

swidth

public short swidth
The dimensions of a section of our scene.


sheight

public short sheight
The dimensions of a section of our scene.


defTileSet

public int defTileSet
The tileset to use when we have no tile data.


_sections

protected StreamableHashMap<Integer,SparseMisoSceneModel.Section> _sections
Contains our sections in row major order.

Constructor Detail

SparseMisoSceneModel

public SparseMisoSceneModel(int swidth,
                            int sheight)
Creates a scene model with the specified bounds.

Parameters:
swidth - the width of a single section (in tiles).
sheight - the height of a single section (in tiles).

SparseMisoSceneModel

public SparseMisoSceneModel()
Creates a blank model suitable for unserialization.

Method Detail

getInterestingObjects

public void getInterestingObjects(ArrayList<ObjectInfo> list)
Adds all interesting ObjectInfo records in this scene to the supplied list.


getAllObjects

public void getAllObjects(ArrayList<ObjectInfo> list)
Adds all ObjectInfo records in this scene to the supplied list.


visitObjects

public void visitObjects(SparseMisoSceneModel.ObjectVisitor visitor)
Informs the supplied visitor of each object in this scene.


visitObjects

public void visitObjects(SparseMisoSceneModel.ObjectVisitor visitor,
                         boolean interestingOnly)
Informs the supplied visitor of each object in this scene.

Parameters:
interestingOnly - if true, only the interesting objects will be visited.

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.

setDefaultBaseTileSet

public void setDefaultBaseTileSet(int tileSetId)
Description copied from class: MisoSceneModel
Updates the default base tileset id for this scene.

Overrides:
setDefaultBaseTileSet in class MisoSceneModel

getDefaultBaseTileSet

public int getDefaultBaseTileSet()
Description copied from class: MisoSceneModel
Scene models can return a default tileset to be used when no base tile data exists for a particular tile.

Overrides:
getDefaultBaseTileSet in class MisoSceneModel

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.

setSection

public void setSection(SparseMisoSceneModel.Section section)
Don't call this method! This is only public so that the scene parser can construct a scene from raw data. If only Java supported class friendship.


getSections

public Iterator<SparseMisoSceneModel.Section> getSections()
Don't call this method! This is only public so that the scene writer can generate XML from the raw scene data.


toString

protected void toString(StringBuilder buf)
Overrides:
toString in class com.threerings.io.SimpleStreamableObject

key

protected final int key(int x,
                        int y)
Returns the key for the specified section.


getSection

protected final SparseMisoSceneModel.Section getSection(int x,
                                                        int y,
                                                        boolean create)
Returns the section for the specified tile coordinate.


clone

public SparseMisoSceneModel clone()
Overrides:
clone in class MisoSceneModel