com.threerings.media.tile
Class TileManager

java.lang.Object
  extended by com.threerings.media.tile.TileManager
Direct Known Subclasses:
MisoTileManager

public class TileManager
extends Object

The tile manager provides a simplified interface for retrieving and caching tiles. Tiles can be loaded in two different ways. An application can load a tileset by hand, specifying the path to the tileset image and all of the tileset metadata necessary for extracting the image tiles, or it can provide a tileset repository which loads up tilesets using whatever repository mechanism is implemented by the supplied repository. In the latter case, tilesets are loaded by a unique identifier.

Loading tilesets by hand is intended for things like toolbar icons or games with a single set of tiles (think Stratego, for example). Loading tilesets from a repository supports games with vast numbers of tiles to which more tiles may be added on the fly (think the tiles for an isometric-display graphical MUD).


Field Summary
protected  ImageProvider _defaultProvider
          Used to load tileset images from the default resource source.
protected  Map<String,SoftReference<UniformTileSet>> _handcache
          A cache of tilesets that have been loaded by hand.
protected  ImageManager _imgr
          The entity through which we decode and cache images.
protected  TileSetRepository _setrep
          The tile set repository.
 
Constructor Summary
TileManager(ImageManager imgr)
          Creates a tile manager and provides it with a reference to the image manager from which it will load tileset images.
 
Method Summary
 void clearCache()
          Clears any cached tilesets.
 ImageProvider getImageProvider(String rset)
          Returns an image provider that will load images from the specified resource set.
 Tile getTile(int fqTileId)
          Returns the Tile object with the specified fully qualified tile id.
 Tile getTile(int tileSetId, int tileIndex, TileSet.Colorizer rizer)
          Returns the Tile object from the specified tileset at the specified index.
 Tile getTile(int fqTileId, TileSet.Colorizer rizer)
          Returns the Tile object with the specified fully qualified tile id.
 TileSet getTileSet(int tileSetId)
          Returns the tileset with the specified id.
 TileSet getTileSet(String name)
          Returns the tileset with the specified name.
 TileSetRepository getTileSetRepository()
          Returns the tileset repository currently in use.
protected  UniformTileSet loadCachedTileSet(String bundle, String imgPath, int width, int height)
          Used to load and cache tilesets loaded via loadTileSet(java.lang.String, int, int).
 UniformTileSet loadTileSet(ImageProvider improv, String improvKey, String imgPath, int width, int height)
           
 UniformTileSet loadTileSet(String imgPath, int width, int height)
          Loads up a tileset from the specified image with the specified metadata parameters.
 UniformTileSet loadTileSet(String rset, String imgPath, int width, int height)
          Loads up a tileset from the specified image (located in the specified resource set) with the specified metadata parameters.
 void setTileSetRepository(TileSetRepository setrep)
          Sets the tileset repository that will be used by the tile manager when tiles are requested by tileset id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_imgr

protected ImageManager _imgr
The entity through which we decode and cache images.


_handcache

protected Map<String,SoftReference<UniformTileSet>> _handcache
A cache of tilesets that have been loaded by hand.


_setrep

protected TileSetRepository _setrep
The tile set repository.


_defaultProvider

protected ImageProvider _defaultProvider
Used to load tileset images from the default resource source.

Constructor Detail

TileManager

public TileManager(ImageManager imgr)
Creates a tile manager and provides it with a reference to the image manager from which it will load tileset images.

Parameters:
imgr - the image manager via which the tile manager will decode and cache images.
Method Detail

loadTileSet

public UniformTileSet loadTileSet(String imgPath,
                                  int width,
                                  int height)
Loads up a tileset from the specified image with the specified metadata parameters.


loadTileSet

public UniformTileSet loadTileSet(String rset,
                                  String imgPath,
                                  int width,
                                  int height)
Loads up a tileset from the specified image (located in the specified resource set) with the specified metadata parameters.


loadTileSet

public UniformTileSet loadTileSet(ImageProvider improv,
                                  String improvKey,
                                  String imgPath,
                                  int width,
                                  int height)

getImageProvider

public ImageProvider getImageProvider(String rset)
Returns an image provider that will load images from the specified resource set.


loadCachedTileSet

protected UniformTileSet loadCachedTileSet(String bundle,
                                           String imgPath,
                                           int width,
                                           int height)
Used to load and cache tilesets loaded via loadTileSet(java.lang.String, int, int).


clearCache

public void clearCache()
Clears any cached tilesets.


setTileSetRepository

public void setTileSetRepository(TileSetRepository setrep)
Sets the tileset repository that will be used by the tile manager when tiles are requested by tileset id.


getTileSetRepository

public TileSetRepository getTileSetRepository()
Returns the tileset repository currently in use.


getTileSet

public TileSet getTileSet(int tileSetId)
                   throws NoSuchTileSetException
Returns the tileset with the specified id. Tilesets are fetched from the tileset repository supplied via setTileSetRepository(com.threerings.media.tile.TileSetRepository), and are subsequently cached.

Parameters:
tileSetId - the unique identifier for the desired tileset.
Throws:
NoSuchTileSetException - thrown if no tileset exists with the specified id or if an underlying error occurs with the tileset repository's persistence mechanism.

getTileSet

public TileSet getTileSet(String name)
                   throws NoSuchTileSetException
Returns the tileset with the specified name.

Throws:
NoSuchTileSetException - if no tileset with the specified name is available via our configured tile set repository.

getTile

public Tile getTile(int fqTileId)
             throws NoSuchTileSetException
Returns the Tile object with the specified fully qualified tile id.

Throws:
NoSuchTileSetException
See Also:
TileUtil.getFQTileId(int, int)

getTile

public Tile getTile(int fqTileId,
                    TileSet.Colorizer rizer)
             throws NoSuchTileSetException
Returns the Tile object with the specified fully qualified tile id. The supplied colorizer will be used to recolor the tile.

Throws:
NoSuchTileSetException
See Also:
TileUtil.getFQTileId(int, int)

getTile

public Tile getTile(int tileSetId,
                    int tileIndex,
                    TileSet.Colorizer rizer)
             throws NoSuchTileSetException
Returns the Tile object from the specified tileset at the specified index.

Parameters:
tileSetId - the tileset id.
tileIndex - the index of the tile to be retrieved.
Returns:
the tile object.
Throws:
NoSuchTileSetException