diff --git a/src/java/com/threerings/media/tile/Tile.java b/src/java/com/threerings/media/tile/Tile.java
index 2a5c04c81..80f281771 100644
--- a/src/java/com/threerings/media/tile/Tile.java
+++ b/src/java/com/threerings/media/tile/Tile.java
@@ -1,5 +1,5 @@
//
-// $Id: Tile.java,v 1.8 2001/07/28 01:31:51 shaper Exp $
+// $Id: Tile.java,v 1.9 2001/08/13 19:54:39 shaper Exp $
package com.threerings.miso.tile;
@@ -25,9 +25,13 @@ public class Tile
/** The tile height in pixels. */
public short height;
+ /** Whether the tile is passable. */
+ public boolean passable;
+
/**
* Construct a new tile with the specified identifiers. Intended
- * only for use by the TileManager. Do not use this method.
+ * only for use by the TileManager. Do not call this
+ * method.
*
* @see TileManager#getTile
*/
diff --git a/src/java/com/threerings/media/tile/TileManager.java b/src/java/com/threerings/media/tile/TileManager.java
index 4588c98b3..52c8eb3ce 100644
--- a/src/java/com/threerings/media/tile/TileManager.java
+++ b/src/java/com/threerings/media/tile/TileManager.java
@@ -1,5 +1,5 @@
//
-// $Id: TileManager.java,v 1.13 2001/08/13 15:00:24 shaper Exp $
+// $Id: TileManager.java,v 1.14 2001/08/13 19:54:39 shaper Exp $
package com.threerings.miso.tile;
@@ -52,15 +52,8 @@ public class TileManager
return tile;
}
- // retrieve the tile image from the tileset
- tile = new Tile(tsid, tid);
- if ((tile.img = _tilesetmgr.getTileImage(tsid, tid)) == null) {
- Log.warning("Null tile image [tsid="+tsid+", tid="+tid+"].");
- }
- BufferedImage bimg = (BufferedImage)tile.img;
- tile.height = (short)bimg.getHeight();
- tile.width = (short)bimg.getWidth();
-
+ // 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+"].");
diff --git a/src/java/com/threerings/media/tile/TileSet.java b/src/java/com/threerings/media/tile/TileSet.java
index 0179f3b8e..aac8684cc 100644
--- a/src/java/com/threerings/media/tile/TileSet.java
+++ b/src/java/com/threerings/media/tile/TileSet.java
@@ -1,5 +1,5 @@
//
-// $Id: TileSet.java,v 1.12 2001/07/28 01:35:06 shaper Exp $
+// $Id: TileSet.java,v 1.13 2001/08/13 19:54:39 shaper Exp $
package com.threerings.miso.tile;
@@ -13,23 +13,23 @@ import com.threerings.media.ImageManager;
/**
* A tileset stores information on a single logical set of tiles. It
- * provides a clean interface for the TileManager to retrieve
- * individual tile images from a particular tile in the tileset.
+ * provides a clean interface for the TileSetManager to
+ * retrieve individual tiles from the tileset.
*
- *
Tiles are retrieved from the tile set by the TileManager, and - * are referenced by their tile id (essentially the tile number, - * assuming the tile at the top-left of the image is tile id 0 and - * tiles are numbered left to right, top to bottom, in ascending - * order. + *
Tiles are referenced by their tile id. The tile id is
+ * essentially the tile number, assuming the tile at the top-left of
+ * the image is tile id 0 and tiles are numbered left to right, top to
+ * bottom, in ascending order.
*/
public class TileSet
{
/**
- * Construct a new TileSet object with the given parameters.
+ * Construct a new TileSet object.
*/
- public TileSet (String name, int tsid, String imgFile,
- int[] rowWidth, int[] rowHeight, int[] tileCount,
- Point offsetPos, Point gapDist)
+ public TileSet (
+ String name, int tsid, String imgFile,
+ int[] rowWidth, int[] rowHeight, int[] tileCount, int[] passable,
+ Point offsetPos, Point gapDist)
{
_name = name;
_tsid = tsid;
@@ -37,12 +37,14 @@ public class TileSet
_rowWidth = rowWidth;
_rowHeight = rowHeight;
_tileCount = tileCount;
+ _passable = passable;
_offsetPos = offsetPos;
_gapDist = gapDist;
// determine the total number of tiles in the set
- for (int ii = 0; ii < _tileCount.length; ii++)
+ for (int ii = 0; ii < _tileCount.length; ii++) {
_numTiles += _tileCount[ii];
+ }
}
/**
@@ -72,12 +74,17 @@ public class TileSet
/**
* Return the image corresponding to the specified tile id within
* this tile set.
+ *
+ * @param imgmgr the image manager.
+ * @param tid the tile id.
+ *
+ * @return the tile image.
*/
- public Image getTileImage (ImageManager imgr, int tid)
+ protected Image getTileImage (ImageManager imgmgr, int tid)
{
// load the full tile image if we don't already have it
if (_imgTiles == null) {
- if ((_imgTiles = imgr.getImage(_imgFile)) == null) {
+ if ((_imgTiles = imgmgr.getImage(_imgFile)) == null) {
Log.warning("Failed to retrieve full tileset image " +
"[file=" + _imgFile + "].");
return null;
@@ -108,37 +115,53 @@ public class TileSet
// ", ty=" + ty + "].");
// crop the tile-sized image chunk from the full image
- return imgr.getImageCropped(
+ return imgmgr.getImageCropped(
_imgTiles, tx, ty, _rowWidth[ridx], _rowHeight[ridx]);
}
+ /**
+ * Return the Tile object from this tileset
+ * corresponding to the specified tile id. The tile image is
+ * retrieved from the given image manager.
+ *
+ * @param imgmgr the image manager.
+ * @param tid the tile identifier.
+ *
+ * @return the tile object.
+ */
+ public Tile getTile (ImageManager imgmgr, int tid)
+ {
+ // create the tile object
+ Tile tile = new Tile(_tsid, tid);
+
+ // retrieve the tile image
+ tile.img = getTileImage(imgmgr, tid);
+ if (tile.img == null) {
+ Log.warning("Null tile image " +
+ "[tsid=" + _tsid + ", tid=" + tid + "].");
+ }
+
+ // populate the tile's dimensions
+ BufferedImage bimg = (BufferedImage)tile.img;
+ tile.height = (short)bimg.getHeight();
+ tile.width = (short)bimg.getWidth();
+
+ // and its passability
+ tile.passable = (_passable[tid] == 1);
+
+ return tile;
+ }
+
/**
* Return a string representation of the tileset information.
*/
public String toString ()
{
StringBuffer buf = new StringBuffer();
-
buf.append("[name=").append(_name);
buf.append(", file=").append(_imgFile);
buf.append(", tsid=").append(_tsid);
buf.append(", numtiles=").append(_numTiles);
-
- buf.append(", rowwidth=");
- StringUtil.toString(buf, _rowWidth);
-
- buf.append(", rowheight=");
- StringUtil.toString(buf, _rowHeight);
-
- buf.append(", tilecount=");
- StringUtil.toString(buf, _tileCount);
-
- buf.append(", offsetpos=(").append(_offsetPos.x);
- buf.append(", ").append(_offsetPos.y).append(")");
-
- buf.append(", gapdist=(").append(_gapDist.x);
- buf.append(", ").append(_gapDist.y).append(")");
-
return buf.append("]").toString();
}
@@ -160,6 +183,9 @@ public class TileSet
/** The number of tiles in each row. */
protected int _tileCount[];
+ /** Whether each tile is passable. */
+ protected int _passable[];
+
/**
* The offset distance (x, y) in pixels from the top-left of the
* image to the start of the first tile image.
diff --git a/src/java/com/threerings/media/tile/TileSetManager.java b/src/java/com/threerings/media/tile/TileSetManager.java
index f54aa6317..121d7ac53 100644
--- a/src/java/com/threerings/media/tile/TileSetManager.java
+++ b/src/java/com/threerings/media/tile/TileSetManager.java
@@ -1,5 +1,5 @@
//
-// $Id: TileSetManager.java,v 1.10 2001/08/13 15:00:24 shaper Exp $
+// $Id: TileSetManager.java,v 1.11 2001/08/13 19:54:39 shaper Exp $
package com.threerings.miso.tile;
@@ -46,14 +46,15 @@ public interface TileSetManager
public TileSet getTileSet (int tsid);
/**
- * Return the image corresponding to the specified tileset and tile id.
+ * Return the tile object corresponding to the specified tileset
+ * and tile id.
*
* @param tsid the tileset identifier.
* @param tid the tile identifier.
*
- * @return the tile image.
+ * @return the tile object.
*/
- public Image getTileImage (int tsid, int tid);
+ public Tile getTile (int tsid, int tid);
/**
* Return the total number of tilesets available for use.
diff --git a/src/java/com/threerings/media/tile/TileSetManagerImpl.java b/src/java/com/threerings/media/tile/TileSetManagerImpl.java
index 740e45a0b..541d24df1 100644
--- a/src/java/com/threerings/media/tile/TileSetManagerImpl.java
+++ b/src/java/com/threerings/media/tile/TileSetManagerImpl.java
@@ -1,5 +1,5 @@
//
-// $Id: TileSetManagerImpl.java,v 1.8 2001/07/23 22:31:48 shaper Exp $
+// $Id: TileSetManagerImpl.java,v 1.9 2001/08/13 19:54:39 shaper Exp $
package com.threerings.miso.tile;
@@ -10,13 +10,15 @@ import java.util.Enumeration;
import com.samskivert.util.*;
import com.threerings.media.ImageManager;
+import com.threerings.miso.Log;
public abstract class TileSetManagerImpl implements TileSetManager
{
/**
- * Initialize the TileSetManager with a Config object to obtain
- * configuration information and an ImageManager object for use in
- * retrieving tile images.
+ * Initialize the TileSetManager.
+ *
+ * @param config the config object.
+ * @param imgmgr the image manager.
*/
public void init (Config config, ImageManager imgmgr)
{
@@ -35,10 +37,10 @@ public abstract class TileSetManagerImpl implements TileSetManager
return (TileSet)_tilesets.get(tsid);
}
- public Image getTileImage (int tsid, int tid)
+ public Tile getTile (int tsid, int tid)
{
TileSet tset = getTileSet(tsid);
- return (tset != null) ? tset.getTileImage(_imgmgr, tid) : null;
+ return (tset == null) ? null : tset.getTile(_imgmgr, tid);
}
public ArrayList getAllTileSets ()
@@ -53,7 +55,12 @@ public abstract class TileSetManagerImpl implements TileSetManager
return _tilesets.size();
}
+ /** The config object. */
protected Config _config;
+
+ /** The image manager. */
protected ImageManager _imgmgr;
+
+ /** The available tilesets keyed by tileset id. */
protected IntMap _tilesets = new IntMap();
}
diff --git a/src/java/com/threerings/media/tile/XMLTileSetParser.java b/src/java/com/threerings/media/tile/XMLTileSetParser.java
index b0358858f..a0bf9e10d 100644
--- a/src/java/com/threerings/media/tile/XMLTileSetParser.java
+++ b/src/java/com/threerings/media/tile/XMLTileSetParser.java
@@ -1,5 +1,5 @@
//
-// $Id: XMLTileSetParser.java,v 1.10 2001/08/13 15:00:24 shaper Exp $
+// $Id: XMLTileSetParser.java,v 1.11 2001/08/13 19:54:39 shaper Exp $
package com.threerings.miso.tile;
@@ -61,6 +61,14 @@ public class XMLTileSetParser extends DefaultHandler
} else if (qName.equals("tilecount")) {
_tsTileCount = StringUtil.parseIntArray(str);
+ // calculate the total number of tiles in the tileset
+ for (int ii = 0; ii < _tsTileCount.length; ii++) {
+ _tsNumTiles += _tsTileCount[ii];
+ }
+
+ } else if (qName.equals("passable")) {
+ _tsPassable = StringUtil.parseIntArray(str);
+
} else if (qName.equals("offsetpos")) {
getPoint(str, _tsOffsetPos);
@@ -68,15 +76,7 @@ public class XMLTileSetParser extends DefaultHandler
getPoint(str, _tsGapDist);
} else if (qName.equals("tileset")) {
- // construct the tileset object on tag close
- TileSet tset = new TileSet(
- _tsName, _tsTsid, _tsImgFile, _tsRowWidth, _tsRowHeight,
- _tsTileCount, _tsOffsetPos, _tsGapDist);
-
- _tilesets.add(tset);
-
- // prepare to read another tileset object
- init();
+ constructTileSet();
}
// note that we're not within a tag to avoid considering any
@@ -87,6 +87,28 @@ public class XMLTileSetParser extends DefaultHandler
_chars = new StringBuffer();
}
+ protected void constructTileSet ()
+ {
+ // if passability is unspecified, default to all passable
+ if (_tsPassable == null) {
+ _tsPassable = new int[_tsNumTiles];
+ for (int ii = 0; ii < _tsNumTiles; ii++) {
+ _tsPassable[ii] = 1;
+ }
+ }
+
+ // construct the tileset object on tag close
+ TileSet tset = new TileSet(
+ _tsName, _tsTsid, _tsImgFile,
+ _tsRowWidth, _tsRowHeight, _tsTileCount, _tsPassable,
+ _tsOffsetPos, _tsGapDist);
+
+ _tilesets.add(tset);
+
+ // prepare to read another tileset object
+ init();
+ }
+
public void characters (char ch[], int start, int length)
{
// bail if we're not within a meaningful tag
@@ -128,6 +150,8 @@ public class XMLTileSetParser extends DefaultHandler
{
_tsOffsetPos = new Point();
_tsGapDist = new Point();
+ _tsPassable = null;
+ _tsNumTiles = 0;
_chars = new StringBuffer();
}
@@ -156,6 +180,7 @@ public class XMLTileSetParser extends DefaultHandler
protected String _tsName;
protected int _tsTsid;
protected String _tsImgFile;
- protected int[] _tsRowWidth, _tsRowHeight, _tsTileCount;
+ protected int[] _tsRowWidth, _tsRowHeight, _tsTileCount, _tsPassable;
+ protected int _tsNumTiles;
protected Point _tsOffsetPos, _tsGapDist;
}
diff --git a/tests/rsrc/config/miso/tilesets.xml b/tests/rsrc/config/miso/tilesets.xml
index e7b577d85..6163e924d 100644
--- a/tests/rsrc/config/miso/tilesets.xml
+++ b/tests/rsrc/config/miso/tilesets.xml
@@ -1,6 +1,6 @@
-
+
@@ -51,6 +51,7 @@