com.threerings.tudey.client.util
Class SceneMap

java.lang.Object
  extended by com.threerings.tudey.client.util.SceneMap
All Implemented Interfaces:
PlaceView, TudeySceneModel.Observer

public class SceneMap
extends Object
implements PlaceView, TudeySceneModel.Observer

Maintains a simple map of the scene than can be rendered to the UI.


Field Summary
protected  SoftReference<ByteBuffer> _buf
          Buffer to reuse.
protected  Coord _coord
          Reusable coordinate object.
protected  TudeyContext _ctx
          The application context.
protected  List<SpaceElement> _elements
          Holds elements during intersection testing.
protected  byte[] _floorColor
          The RGBA color to use for floors.
protected  TextureUnit[] _masked
          Reusable texture unit array for masked rendering.
protected  Polygon _quad
          Used to store tile shapes for intersecting testing.
protected  Rectangle _region
          Region object to reuse.
protected  TudeySceneModel _sceneModel
          The scene model.
protected  Map<Coord,Texture2D> _textures
          The map textures.
protected  CoordIntMap _types
          Stores the "type" of each location (empty, floor, wall, etc).
protected  TextureUnit[] _unmasked
          Reusable texture unit array for unmasked rendering.
protected  TudeySceneView _view
          The scene view.
protected  byte[] _wallColor
          The RGBA color to use for walls.
protected static byte[] EMPTY_COLOR
          The color to use for empty locations.
protected static int TEXTURE_MASK
          The mask for texture locations.
protected static int TEXTURE_POT
          The size of the map textures as a power of two.
protected static int TEXTURE_SIZE
          The size of the map textures.
 
Constructor Summary
SceneMap(TudeyContext ctx, TudeySceneView view)
          Creates a new scene map.
 
Method Summary
protected  void addEntry(TudeySceneModel.Entry entry, boolean retexture)
          Adds the specified entry to the map.
protected  void build()
          Builds the map.
protected  void buildTexture(int tx, int ty)
          Builds and maps the texture at the specified coordinates.
 void didLeavePlace(PlaceObject plobj)
           
 void entryAdded(TudeySceneModel.Entry entry)
          Notes that an entry has been added to the scene.
 void entryRemoved(TudeySceneModel.Entry oentry)
          Notes that an entry has been removed from the scene.
 void entryUpdated(TudeySceneModel.Entry oentry, TudeySceneModel.Entry nentry)
          Notes that an entry has been updated within the scene.
protected  ByteBuffer getBuffer(int size)
          Retrieves/creates a byte buffer of the requested size.
protected static byte[] getBytes(Color4f color)
          Converts the specified color into a byte array.
protected  void putColor(ByteBuffer buf, int type)
          Puts the color corresponding to the specified type into the supplied buffer.
protected  void removeEntry(TudeySceneModel.Entry entry, boolean retexture)
          Removes the specified entry from the map.
 void render(float sx, float sy, float swidth, float sheight, int tx, int ty, int twidth, int theight, float alpha, Image mask)
          Renders a section of the map.
 void setColors(Color4f floor, Color4f wall)
          Sets the colors to use to represent floors and walls.
protected  void update(int x, int y, boolean retexture)
          Updates the specified location.
protected  void updateQuad(int x, int y)
          Updates the coordinates of the quad to encompass the specified grid cell.
protected  void updateTexture(int x, int y, int type)
          Updates the texture at the specified coordinates.
 void willEnterPlace(PlaceObject plobj)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_ctx

protected TudeyContext _ctx
The application context.


_view

protected TudeySceneView _view
The scene view.


_sceneModel

protected TudeySceneModel _sceneModel
The scene model.


_types

protected CoordIntMap _types
Stores the "type" of each location (empty, floor, wall, etc).


_textures

protected Map<Coord,Texture2D> _textures
The map textures.


_floorColor

protected byte[] _floorColor
The RGBA color to use for floors.


_wallColor

protected byte[] _wallColor
The RGBA color to use for walls.


_unmasked

protected TextureUnit[] _unmasked
Reusable texture unit array for unmasked rendering.


_masked

protected TextureUnit[] _masked
Reusable texture unit array for masked rendering.


_coord

protected Coord _coord
Reusable coordinate object.


_region

protected Rectangle _region
Region object to reuse.


_quad

protected Polygon _quad
Used to store tile shapes for intersecting testing.


_buf

protected SoftReference<ByteBuffer> _buf
Buffer to reuse.


_elements

protected List<SpaceElement> _elements
Holds elements during intersection testing.


TEXTURE_POT

protected static final int TEXTURE_POT
The size of the map textures as a power of two.

See Also:
Constant Field Values

TEXTURE_SIZE

protected static final int TEXTURE_SIZE
The size of the map textures.

See Also:
Constant Field Values

TEXTURE_MASK

protected static final int TEXTURE_MASK
The mask for texture locations.

See Also:
Constant Field Values

EMPTY_COLOR

protected static final byte[] EMPTY_COLOR
The color to use for empty locations.

Constructor Detail

SceneMap

public SceneMap(TudeyContext ctx,
                TudeySceneView view)
Creates a new scene map.

Method Detail

setColors

public void setColors(Color4f floor,
                      Color4f wall)
Sets the colors to use to represent floors and walls.


render

public void render(float sx,
                   float sy,
                   float swidth,
                   float sheight,
                   int tx,
                   int ty,
                   int twidth,
                   int theight,
                   float alpha,
                   Image mask)
Renders a section of the map.


willEnterPlace

public void willEnterPlace(PlaceObject plobj)
Specified by:
willEnterPlace in interface PlaceView

didLeavePlace

public void didLeavePlace(PlaceObject plobj)
Specified by:
didLeavePlace in interface PlaceView

entryAdded

public void entryAdded(TudeySceneModel.Entry entry)
Description copied from interface: TudeySceneModel.Observer
Notes that an entry has been added to the scene.

Specified by:
entryAdded in interface TudeySceneModel.Observer

entryUpdated

public void entryUpdated(TudeySceneModel.Entry oentry,
                         TudeySceneModel.Entry nentry)
Description copied from interface: TudeySceneModel.Observer
Notes that an entry has been updated within the scene.

Specified by:
entryUpdated in interface TudeySceneModel.Observer

entryRemoved

public void entryRemoved(TudeySceneModel.Entry oentry)
Description copied from interface: TudeySceneModel.Observer
Notes that an entry has been removed from the scene.

Specified by:
entryRemoved in interface TudeySceneModel.Observer

build

protected void build()
Builds the map.


addEntry

protected void addEntry(TudeySceneModel.Entry entry,
                        boolean retexture)
Adds the specified entry to the map.

Parameters:
retexture - if true, update the texture as well.

removeEntry

protected void removeEntry(TudeySceneModel.Entry entry,
                           boolean retexture)
Removes the specified entry from the map.

Parameters:
retexture - if true, update the texture as well.

update

protected void update(int x,
                      int y,
                      boolean retexture)
Updates the specified location.

Parameters:
retexture - if true, update the texture as well.

updateQuad

protected void updateQuad(int x,
                          int y)
Updates the coordinates of the quad to encompass the specified grid cell.


updateTexture

protected void updateTexture(int x,
                             int y,
                             int type)
Updates the texture at the specified coordinates.


buildTexture

protected void buildTexture(int tx,
                            int ty)
Builds and maps the texture at the specified coordinates.


putColor

protected void putColor(ByteBuffer buf,
                        int type)
Puts the color corresponding to the specified type into the supplied buffer.


getBuffer

protected ByteBuffer getBuffer(int size)
Retrieves/creates a byte buffer of the requested size.


getBytes

protected static byte[] getBytes(Color4f color)
Converts the specified color into a byte array.