8376b6e9fa
because it's general purpose. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@273 542714f4-19e9-0310-aa3c-eee0fc999fb1
78 lines
1.8 KiB
Java
78 lines
1.8 KiB
Java
//
|
|
// $Id: TileManager.java,v 1.15 2001/08/16 23:14:20 mdb Exp $
|
|
|
|
package com.threerings.media.tile;
|
|
|
|
import java.awt.*;
|
|
import java.awt.image.BufferedImage;
|
|
import java.util.ArrayList;
|
|
|
|
import com.samskivert.util.IntMap;
|
|
|
|
import com.threerings.media.Log;
|
|
|
|
/**
|
|
* The <code>TileManager</code> class provides a simplified interface
|
|
* for retrieving and caching tiles.
|
|
*
|
|
* @see TileSetManager
|
|
*/
|
|
public class TileManager
|
|
{
|
|
/**
|
|
* Initialize the tile manager with the given
|
|
* <code>TileSetManager</code> object.
|
|
*
|
|
* @param tilesetmgr the tileset manager.
|
|
*/
|
|
public TileManager (TileSetManager tilesetmgr)
|
|
{
|
|
_tilesetmgr = tilesetmgr;
|
|
}
|
|
|
|
/**
|
|
* Return the <code>Tile</code> object for the specified tileset
|
|
* and tile id.
|
|
*
|
|
* @param tsid the tileset id.
|
|
* @param tid the tile id.
|
|
*
|
|
* @return the tile object.
|
|
*/
|
|
public Tile getTile (int tsid, int tid)
|
|
{
|
|
// the fully unique tile id is the conjoined tile set and tile id
|
|
int utid = (tsid << 16) | tid;
|
|
|
|
// look the tile up in our hash
|
|
Tile tile = (Tile) _tiles.get(utid);
|
|
if (tile != null) {
|
|
// Log.info("Retrieved tile from cache [tsid=" + tsid +
|
|
// ", tid=" + tid + "].");
|
|
return tile;
|
|
}
|
|
|
|
// retrieve the tile from the tileset
|
|
tile = _tilesetmgr.getTile(tsid, tid);
|
|
_tiles.put(utid, tile);
|
|
|
|
// Log.info("Loaded tile into cache [tsid="+tsid+", tid="+tid+"].");
|
|
|
|
return tile;
|
|
}
|
|
|
|
/**
|
|
* Return the TileSetManager that the TileManager is using.
|
|
*/
|
|
public TileSetManager getTileSetManager ()
|
|
{
|
|
return _tilesetmgr;
|
|
}
|
|
|
|
/** Cache of tiles that have been requested thus far. */
|
|
protected IntMap _tiles = new IntMap();
|
|
|
|
/** The tileset manager. */
|
|
protected TileSetManager _tilesetmgr;
|
|
}
|