com.threerings.miso.client
Class SceneBlock

java.lang.Object
  extended by com.threerings.miso.client.SceneBlock

public class SceneBlock
extends Object

Contains the base and object tile information on a particular rectangular region of a scene.


Field Summary
protected  BaseTile[] _base
          Our base tiles.
protected  Rectangle _bounds
          The bounds of (in tile coordinates) of this block.
protected  boolean[] _covered
          Indicates whether our tiles are covered by an object.
protected  TileSet _defset
          Used to return a tile where we have none.
protected  Polygon _footprint
          A polygon bounding the footprint of this block.
protected  BaseTile[] _fringe
          Our fringe tiles.
protected  MisoSceneMetrics _metrics
           
protected  MisoSceneModel _model
           
protected  SceneBlock[] _neighbors
          Our neighbors in the eight cardinal directions.
protected  SceneObject[] _objects
          Info on our objects.
protected  Rectangle _obounds
          The bounds (in screen coords) of all objects rendered by this block.
protected  MisoScenePanel _panel
          The panel for which we contain a block or null if we aren't backed by a panel.
protected  Rectangle _sbounds
          The bounds (in screen coords) of all images rendered by this block.
protected  TileManager _tileMgr
           
protected  boolean _visi
          A debug flag indicating whether we were visible at creation.
protected  boolean _wasAbandoned
          If we discovered we were no longer needed in our last call to resolve.
protected static int[] DX
           
protected static int[] DY
           
 
Constructor Summary
SceneBlock(MisoSceneModel model, MisoSceneMetrics metrics, TileManager tileMgr, int tx, int ty, int width, int height)
           
SceneBlock(MisoScenePanel panel, int tx, int ty, int width, int height)
          Creates a scene block belonging to panel in preparation for its later resolution.
 
Method Summary
 boolean addObject(ObjectInfo info)
          Adds the supplied object to this block.
protected  int blockKey(int tx, int ty)
          Computes the key for the block that holds the specified tile.
 boolean canTraverse(Object traverser, int tx, int ty)
          Returns true if the specified traverser can traverse the specified tile (which is assumed to be in the bounds of this scene block).
protected  BaseTile computeFringeTile(int tx, int ty)
          Computes the fringe tile for the specified coordinate.
 void computeMemoryUsage(Map<Tile.Key,BaseTile> bases, Set<BaseTile> fringes, Map<Tile.Key,ObjectTile> objects, long[] usage)
          Computes the memory usage of the base and object tiles in this scene block; registering counted tiles in the hash map so that other blocks can be sure not to double count them.
 boolean deleteObject(ObjectInfo info)
          Removes the specified object from this block.
 BaseTile getBaseTile(int tx, int ty)
          Returns the base tile at the specified coordinates or null if there's no tile at said coordinates.
 Rectangle getBounds()
          Returns the bounds of this block, in tile coordinates.
 Polygon getFootprint()
          Returns the screen-coordinate polygon bounding the footprint of this block.
 BaseTile getFringeTile(int tx, int ty)
          Returns the fringe tile at the specified coordinates or null if there's no tile at said coordinates.
 Rectangle getObjectBounds()
          Returns the bounds of the screen coordinate rectangle that contains all pixels that are drawn on by all objects (but not base tiles) in this block.
 SceneObject[] getObjects()
          Returns an array of all resolved scene objects in this block.
 Rectangle getScreenBounds()
          Returns the bounds of the screen coordinate rectangle that contains all pixels that are drawn on by all tiles and objects in this block.
protected  int index(int tx, int ty)
          Returns the index into our arrays of the specified tile.
 boolean isResolved()
          Returns true if this block has been resolved, false if not.
protected  SceneObject makeSceneObject(ObjectInfo info)
           
protected  int neighborKey(int dx, int dy)
          Computes the key of our neighbor.
 boolean resolve()
          This method is called by the SceneBlockResolver on the block resolution thread to allow us to load up our image data without blocking the AWT thread.
protected  void setCovered(int tx, int ty)
          Indicates that this tile is covered by an object footprint.
protected  void setCovered(Map<Integer,SceneBlock> blocks, SceneObject scobj)
          Sets the footprint of this object tile
 void setVisiBlock(boolean visi)
          Makes a note that this block was considered to be visible at the time it was created.
 String toString()
           
protected  void update(Map<Integer,SceneBlock> blocks)
          Links this block to its neighbors; informs neighboring blocks of object coverage.
 void updateBaseTile(int fqTileId, int tx, int ty)
          Informs this scene block that the specified base tile has been changed.
 void updateFringe(int tx, int ty)
          Instructs this block to recompute its fringe at the specified location.
protected  void wasResolved()
          This is called by the SceneBlockResolver on the AWT thread when our resolution has completed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_panel

protected MisoScenePanel _panel
The panel for which we contain a block or null if we aren't backed by a panel.


_metrics

protected MisoSceneMetrics _metrics

_model

protected MisoSceneModel _model

_tileMgr

protected TileManager _tileMgr

_bounds

protected Rectangle _bounds
The bounds of (in tile coordinates) of this block.


_sbounds

protected Rectangle _sbounds
The bounds (in screen coords) of all images rendered by this block.


_obounds

protected Rectangle _obounds
The bounds (in screen coords) of all objects rendered by this block.


_footprint

protected Polygon _footprint
A polygon bounding the footprint of this block.


_defset

protected TileSet _defset
Used to return a tile where we have none.


_base

protected BaseTile[] _base
Our base tiles.


_fringe

protected BaseTile[] _fringe
Our fringe tiles.


_covered

protected boolean[] _covered
Indicates whether our tiles are covered by an object.


_objects

protected SceneObject[] _objects
Info on our objects.


_neighbors

protected SceneBlock[] _neighbors
Our neighbors in the eight cardinal directions.


_visi

protected boolean _visi
A debug flag indicating whether we were visible at creation.


_wasAbandoned

protected boolean _wasAbandoned
If we discovered we were no longer needed in our last call to resolve.


DX

protected static final int[] DX

DY

protected static final int[] DY
Constructor Detail

SceneBlock

public SceneBlock(MisoScenePanel panel,
                  int tx,
                  int ty,
                  int width,
                  int height)
Creates a scene block belonging to panel in preparation for its later resolution.


SceneBlock

public SceneBlock(MisoSceneModel model,
                  MisoSceneMetrics metrics,
                  TileManager tileMgr,
                  int tx,
                  int ty,
                  int width,
                  int height)
Method Detail

setVisiBlock

public void setVisiBlock(boolean visi)
Makes a note that this block was considered to be visible at the time it was created. This is purely for debugging purposes.


resolve

public boolean resolve()
This method is called by the SceneBlockResolver on the block resolution thread to allow us to load up our image data without blocking the AWT thread.


makeSceneObject

protected SceneObject makeSceneObject(ObjectInfo info)

computeFringeTile

protected BaseTile computeFringeTile(int tx,
                                     int ty)
Computes the fringe tile for the specified coordinate.


wasResolved

protected void wasResolved()
This is called by the SceneBlockResolver on the AWT thread when our resolution has completed. We inform our containing panel.


isResolved

public boolean isResolved()
Returns true if this block has been resolved, false if not.


getBounds

public Rectangle getBounds()
Returns the bounds of this block, in tile coordinates.


getScreenBounds

public Rectangle getScreenBounds()
Returns the bounds of the screen coordinate rectangle that contains all pixels that are drawn on by all tiles and objects in this block.


getObjectBounds

public Rectangle getObjectBounds()
Returns the bounds of the screen coordinate rectangle that contains all pixels that are drawn on by all objects (but not base tiles) in this block. Note: this will return null if the block has no objects.


getFootprint

public Polygon getFootprint()
Returns the screen-coordinate polygon bounding the footprint of this block.


getObjects

public SceneObject[] getObjects()
Returns an array of all resolved scene objects in this block.


getBaseTile

public BaseTile getBaseTile(int tx,
                            int ty)
Returns the base tile at the specified coordinates or null if there's no tile at said coordinates.


getFringeTile

public BaseTile getFringeTile(int tx,
                              int ty)
Returns the fringe tile at the specified coordinates or null if there's no tile at said coordinates.


updateBaseTile

public void updateBaseTile(int fqTileId,
                           int tx,
                           int ty)
Informs this scene block that the specified base tile has been changed.


updateFringe

public void updateFringe(int tx,
                         int ty)
Instructs this block to recompute its fringe at the specified location.


addObject

public boolean addObject(ObjectInfo info)
Adds the supplied object to this block. Coverage is not computed for the added object, a subsequent call to update(java.util.Map) will be needed.

Returns:
true if the object was added, false if it was not because another object of the same type already occupies that location.

deleteObject

public boolean deleteObject(ObjectInfo info)
Removes the specified object from this block. Coverage is not recomputed, so a subsequent call to update(java.util.Map) will be needed.

Returns:
true if the object was deleted, false if it was not found in our object list.

canTraverse

public boolean canTraverse(Object traverser,
                           int tx,
                           int ty)
Returns true if the specified traverser can traverse the specified tile (which is assumed to be in the bounds of this scene block).


computeMemoryUsage

public void computeMemoryUsage(Map<Tile.Key,BaseTile> bases,
                               Set<BaseTile> fringes,
                               Map<Tile.Key,ObjectTile> objects,
                               long[] usage)
Computes the memory usage of the base and object tiles in this scene block; registering counted tiles in the hash map so that other blocks can be sure not to double count them. Base tile usage is placed into the zeroth array element, fringe tile usage into the first and object tile usage into the second.


toString

public String toString()
Overrides:
toString in class Object

index

protected final int index(int tx,
                          int ty)
Returns the index into our arrays of the specified tile.


update

protected void update(Map<Integer,SceneBlock> blocks)
Links this block to its neighbors; informs neighboring blocks of object coverage.


neighborKey

protected final int neighborKey(int dx,
                                int dy)
Computes the key of our neighbor.


blockKey

protected final int blockKey(int tx,
                             int ty)
Computes the key for the block that holds the specified tile.


setCovered

protected void setCovered(Map<Integer,SceneBlock> blocks,
                          SceneObject scobj)
Sets the footprint of this object tile


setCovered

protected void setCovered(int tx,
                          int ty)
Indicates that this tile is covered by an object footprint.