Fixed up image loading to use the now-non-static ImageManager class.

Modified TileManager to store the height of a tile in the Tile
object's member data when the tile is initially created since we
would like to be able to reference it speedily.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@63 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-07-18 22:45:35 +00:00
parent c4654e2a11
commit f91e1b41d1
11 changed files with 84 additions and 54 deletions
+5 -5
View File
@@ -1,19 +1,19 @@
//
// $Id: Tile.java,v 1.4 2001/07/18 21:45:42 shaper Exp $
// $Id: Tile.java,v 1.5 2001/07/18 22:45:35 shaper Exp $
package com.threerings.miso.tile;
import java.awt.Image;
import java.awt.image.BufferedImage;
/**
* A tile represents a single square in a single layer in a scene.
*/
public class Tile
{
public BufferedImage img; // the tile image
public short tsid; // the tile set identifier
public short tid; // the tile identifier within the set
public Image img; // the tile image
public short tsid; // the tile set identifier
public short tid; // the tile identifier within the set
public short height; // the tile height in pixels
// height and width of a tile image in pixels
public static final int HEIGHT = 16;
@@ -1,5 +1,5 @@
//
// $Id: TileManager.java,v 1.6 2001/07/18 21:45:42 shaper Exp $
// $Id: TileManager.java,v 1.7 2001/07/18 22:45:35 shaper Exp $
package com.threerings.miso.tile;
@@ -9,6 +9,7 @@ import com.samskivert.util.ConfigUtil;
import com.samskivert.util.IntMap;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ArrayList;
@@ -60,19 +61,12 @@ public class TileManager
return tile;
}
// retrieve the tileset containing the tile
TileSet tset = _tsmgr.getTileSet(tsid);
if (tset == null) {
Log.warning("Can't create tile due to unknown tileset " +
"[tsid=" + tsid + ", tid=" + tid + "].");
return null;
}
// retrieve the tile image from the tileset
tile = new Tile(tsid, tid);
if ((tile.img = tset.getTileImage(tid)) == null) {
if ((tile.img = _tsmgr.getTileImage(tsid, tid)) == null) {
Log.warning("Null tile image [tsid="+tsid+", tid="+tid+"].");
}
tile.height = (short)((BufferedImage)tile.img).getHeight();
_tiles.put(utid, tile);
@@ -1,5 +1,5 @@
//
// $Id: TileSet.java,v 1.7 2001/07/18 21:45:42 shaper Exp $
// $Id: TileSet.java,v 1.8 2001/07/18 22:45:35 shaper Exp $
package com.threerings.miso.tile;
@@ -62,11 +62,11 @@ public class TileSet
* Return the image corresponding to the specified tile id within
* this tile set.
*/
public BufferedImage getTileImage (int tid)
public Image getTileImage (ImageManager imgr, int tid)
{
// load the full tile image if we don't already have it
if (_imgTiles == null) {
if ((_imgTiles = ImageManager.getImage(_imgFile)) == null) {
if ((_imgTiles = imgr.getImage(_imgFile)) == null) {
Log.warning("Failed to retrieve full tileset image " +
"[file=" + _imgFile + "].");
return null;
@@ -89,8 +89,8 @@ public class TileSet
// ", ty=" + ty + "].");
// crop the tile-sized image chunk from the full image
return ImageManager.getImageCropped(_imgTiles, tx, ty,
Tile.WIDTH, _rowHeight[ridx]);
return imgr.getImageCropped(_imgTiles, tx, ty,
Tile.WIDTH, _rowHeight[ridx]);
}
/**
@@ -1,8 +1,9 @@
//
// $Id: TileSetManager.java,v 1.4 2001/07/18 21:45:42 shaper Exp $
// $Id: TileSetManager.java,v 1.5 2001/07/18 22:45:35 shaper Exp $
package com.threerings.miso.tile;
import java.awt.Image;
import java.io.InputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -14,6 +15,11 @@ public interface TileSetManager
*/
public TileSet getTileSet (int tsid);
/**
* Return the image corresponding to the specified tileset and tile id.
*/
public Image getTileImage (int tsid, int tid);
/**
* Return a list of all tilesets available for use.
*/
@@ -1,20 +1,34 @@
//
// $Id: TileSetManagerImpl.java,v 1.3 2001/07/18 21:45:42 shaper Exp $
// $Id: TileSetManagerImpl.java,v 1.4 2001/07/18 22:45:35 shaper Exp $
package com.threerings.miso.tile;
import com.threerings.media.ImageManager;
import com.samskivert.util.IntMap;
import java.awt.Image;
import java.util.ArrayList;
import java.util.Enumeration;
public abstract class TileSetManagerImpl implements TileSetManager
{
public TileSetManagerImpl (ImageManager imgr)
{
_imgr = imgr;
}
public TileSet getTileSet (int tsid)
{
return (TileSet)_tilesets.get(tsid);
}
public Image getTileImage (int tsid, int tid)
{
TileSet tset = getTileSet(tsid);
return (tset != null) ? tset.getTileImage(_imgr, tid) : null;
}
public ArrayList getTileSets ()
{
int size = _tilesets.size();
@@ -35,5 +49,6 @@ public abstract class TileSetManagerImpl implements TileSetManager
return _tilesets.size();
}
protected ImageManager _imgr;
protected IntMap _tilesets = new IntMap();
}