Oh the vast sweeping changes, and they're not even close to complete, but
things compile and most things run so this is a good time to checkpoint. Let me recall: - Refactored the whole scene deal. - Revamped the XML parser stuff (now uses Digester). - Rethought the tile management. - Started tile bundle stuff. - Wrote some tests. - Did a bit of Mike-ification. Onward and moreward. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@621 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,23 +1,54 @@
|
||||
//
|
||||
// $Id: BaseTile.java,v 1.1 2001/10/08 21:04:25 shaper Exp $
|
||||
// $Id: BaseTile.java,v 1.2 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import java.awt.Image;
|
||||
import com.threerings.media.tile.Tile;
|
||||
|
||||
/**
|
||||
* The miso tile class extends the base tile class to add support for
|
||||
* tile passability.
|
||||
* Extends the base tile class to add support for tile passability.
|
||||
*
|
||||
* @see MisoTileSet
|
||||
*/
|
||||
public class MisoTile extends Tile
|
||||
{
|
||||
/** Whether the tile is passable. */
|
||||
public boolean passable;
|
||||
|
||||
public MisoTile (int tsid, int tid)
|
||||
/**
|
||||
* Constructs a new miso tile with the specified image. Passability
|
||||
* will be assumed to be true.
|
||||
*/
|
||||
public MisoTile (Image image)
|
||||
{
|
||||
super(tsid, tid);
|
||||
super(image);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new miso tile with the specified passability.
|
||||
*/
|
||||
public MisoTile (Image image, boolean passable)
|
||||
{
|
||||
super(image);
|
||||
_passable = passable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not this tile can be walked upon by character
|
||||
* sprites.
|
||||
*/
|
||||
public boolean isPassable ()
|
||||
{
|
||||
return _passable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not this tile can be walked upon by character
|
||||
* sprites.
|
||||
*/
|
||||
public void setPassable (boolean passable)
|
||||
{
|
||||
_passable = passable;
|
||||
}
|
||||
|
||||
/** Whether the tile is passable. */
|
||||
protected boolean _passable = true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// $Id: BaseTileLayer.java,v 1.1 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
/**
|
||||
* The miso tile layer class is a convenience class provided to simplify
|
||||
* the management of a two-dimensional array of miso tiles. It takes care
|
||||
* of dereferencing the tile array efficiently with methods that the Java
|
||||
* compiler should inline, and prevents the caller from having to do the
|
||||
* indexing multiplication by hand every time.
|
||||
*
|
||||
* <p> This is equivalent to {@link TileLayer} except that it contains
|
||||
* {@link MisoTile} instances. For efficiency's sake, we don't extend
|
||||
* that class but instead provide a direct implementation.
|
||||
*/
|
||||
public final class MisoTileLayer
|
||||
{
|
||||
/**
|
||||
* Constructs a miso tile layer instance with the supplied tiles,
|
||||
* width and height. The tiles should exist in row-major format (the
|
||||
* first row of tiles followed by the second and so on).
|
||||
*
|
||||
* @exception IllegalArgumentException thrown if the size of the tiles
|
||||
* array does not match the specified width and height.
|
||||
*/
|
||||
public MisoTileLayer (MisoTile[] tiles, int width, int height)
|
||||
{
|
||||
// sanity check
|
||||
if (tiles.length != width*height) {
|
||||
String errmsg = "tiles.length != width*height";
|
||||
throw new IllegalArgumentException(errmsg);
|
||||
}
|
||||
|
||||
_tiles = tiles;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width of the layer in tiles.
|
||||
*/
|
||||
public int getWidth ()
|
||||
{
|
||||
return _width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height of the layer in tiles.
|
||||
*/
|
||||
public int getHeight ()
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the tile at the specified row and column. Bounds checking
|
||||
* is not done. Note that the parameters are column first, followed by
|
||||
* row (x, y order rather than row, column order).
|
||||
*/
|
||||
public MisoTile getTile (int column, int row)
|
||||
{
|
||||
return _tiles[row*_width+column];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tile at the specified row and column. Bounds checking is
|
||||
* not done. Note that the parameters are column first, followed by
|
||||
* row (x, y order rather than row, column order).
|
||||
*/
|
||||
public void setTile (int column, int row, MisoTile tile)
|
||||
{
|
||||
_tiles[row*_width+column] = tile;
|
||||
}
|
||||
|
||||
/** Our tiles array. */
|
||||
private MisoTile[] _tiles;
|
||||
|
||||
/** The number of tiles in a row. */
|
||||
private int _width;
|
||||
|
||||
/** The number of rows. */
|
||||
private int _height;
|
||||
}
|
||||
@@ -1,81 +1,36 @@
|
||||
//
|
||||
// $Id: BaseTileSet.java,v 1.5 2001/11/08 03:04:45 mdb Exp $
|
||||
// $Id: BaseTileSet.java,v 1.6 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.Image;
|
||||
|
||||
import com.samskivert.util.HashIntMap;
|
||||
|
||||
import com.threerings.media.ImageManager;
|
||||
import com.threerings.media.tile.*;
|
||||
|
||||
import com.threerings.miso.scene.MisoScene;
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.media.tile.SwissArmyTileSet;
|
||||
|
||||
/**
|
||||
* The miso tile set extends the swiss army tile set to add support for
|
||||
* tile passability. Passability is used to determine whether {@link
|
||||
* com.threerings.miso.scene.Traverser} objects can traverse a particular
|
||||
* tile in a {@link MisoScene}.
|
||||
* tile in a scene.
|
||||
*/
|
||||
public class MisoTileSet extends SwissArmyTileSet
|
||||
{
|
||||
/**
|
||||
* Constructs a Miso tileset with the swiss army tile set
|
||||
* configuration information and additional information about tile
|
||||
* passability.
|
||||
*
|
||||
* @param layer the layer to which this tileset is assigned.
|
||||
* @param passable info on each tile indicating whether or not the
|
||||
* tile is passable (can be walked on by sprites).
|
||||
*
|
||||
* @see SwissArmyTileSet#SwissArmyTileSet
|
||||
* Sets the passability information for the tiles in this tileset.
|
||||
* Each entry in the array corresponds to the tile at that tile index.
|
||||
*/
|
||||
public MisoTileSet (
|
||||
ImageManager imgmgr, String imgFile, String name, int tsid,
|
||||
int[] tileCount, int[] rowWidth, int[] rowHeight,
|
||||
Point offsetPos, Point gapDist, int layer, int[] passable)
|
||||
public void setPassability (boolean[] passable)
|
||||
{
|
||||
super(imgmgr, imgFile, name, tsid, tileCount,
|
||||
rowWidth, rowHeight, offsetPos, gapDist);
|
||||
|
||||
_layer = layer;
|
||||
_passable = passable;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Tile createTile (int tid)
|
||||
public Tile createTile (Image image, int tileIndex)
|
||||
{
|
||||
// only create miso tiles for the base layer
|
||||
if (_layer != MisoScene.LAYER_BASE) {
|
||||
return super.createTile(tid);
|
||||
}
|
||||
|
||||
return new MisoTile(_tsid, tid);
|
||||
return new MisoTile(image, _passable[tileIndex]);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void populateTile (Tile tile)
|
||||
{
|
||||
super.populateTile(tile);
|
||||
|
||||
if (tile instanceof MisoTile) {
|
||||
// set the tile's passability, defaulting to passable if this
|
||||
// tileset has no passability specified
|
||||
((MisoTile)tile).passable =
|
||||
(_passable == null || (_passable[tile.tid] == 1));
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public int getLayerIndex ()
|
||||
{
|
||||
return _layer;
|
||||
}
|
||||
|
||||
/** The miso scene layer the tiles are intended for. */
|
||||
protected int _layer;
|
||||
|
||||
/** Whether each tile is passable. */
|
||||
protected int _passable[];
|
||||
protected boolean[] _passable;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ShadowTile.java,v 1.2 2001/10/17 22:22:03 shaper Exp $
|
||||
// $Id: ShadowTile.java,v 1.3 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
@@ -7,10 +7,9 @@ import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
|
||||
/**
|
||||
* The shadow tile extends miso tile to provide an always-impassable
|
||||
* tile that has no display image. Shadow tiles are intended for
|
||||
* placement in the footprint of {@link
|
||||
* com.threerings.media.tile.ObjectTile} objects.
|
||||
* The shadow tile extends miso tile to provide an always-impassable tile
|
||||
* that has no display image. Shadow tiles are intended for placement in
|
||||
* the footprint of {@link com.threerings.media.tile.ObjectTile} objects.
|
||||
*/
|
||||
public class ShadowTile extends MisoTile
|
||||
{
|
||||
@@ -22,14 +21,14 @@ public class ShadowTile extends MisoTile
|
||||
*/
|
||||
public ShadowTile (int x, int y)
|
||||
{
|
||||
super(SHADOW_TSID, SHADOW_TID);
|
||||
super(null);
|
||||
|
||||
// save the coordinates of our parent object tile
|
||||
ox = x;
|
||||
oy = y;
|
||||
|
||||
// shadow tiles are always impassable
|
||||
passable = false;
|
||||
_passable = false;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -37,10 +36,4 @@ public class ShadowTile extends MisoTile
|
||||
{
|
||||
// paint nothing as we're naught but a measly shadow of a tile
|
||||
}
|
||||
|
||||
/** The shadow tile set id. */
|
||||
protected static final int SHADOW_TSID = -1;
|
||||
|
||||
/** The shadow tile id. */
|
||||
protected static final int SHADOW_TID = -1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// $Id: BaseTileSetRuleSet.java,v 1.1 2001/11/18 04:09:23 mdb Exp $
|
||||
|
||||
package com.threerings.media.tile.xml;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.apache.commons.digester.Digester;
|
||||
|
||||
import com.threerings.media.tile.TileSet;
|
||||
import com.threerings.media.tile.xml.SwissArmyTileSetRuleSet;
|
||||
import com.threerings.miso.tile.MisoTileSet;
|
||||
|
||||
/**
|
||||
* Parses {@link MisoTileSet} instances from a tileset description. A
|
||||
* uniform tileset description looks like so:
|
||||
*
|
||||
* <pre>
|
||||
* <tileset name="Sample Miso Tileset">
|
||||
* <imgpath>path/to/image.png</imgpath>
|
||||
* <!-- the width of each tile in pixels -->
|
||||
* <width>64</width>
|
||||
* <!-- the height of each tile in pixels -->
|
||||
* <height>48</height>
|
||||
* <!-- the total number of tiles in the set -->
|
||||
* <tileCount>16</tileCount>
|
||||
* </tileset>
|
||||
* </pre>
|
||||
*/
|
||||
public class MisoTileSetRuleSet extends SwissArmyTileSetRuleSet
|
||||
{
|
||||
/**
|
||||
* Constructs a uniform tileset rule set that will match tilesets with
|
||||
* the specified prefix. See the documentation for {@link
|
||||
* TileSetRuleSet#TileSetruleSet} for more info on matching.
|
||||
*/
|
||||
public MisoTileSetRuleSet (String prefix)
|
||||
{
|
||||
super(prefix);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void addRuleInstances (Digester digester)
|
||||
{
|
||||
super.addRuleInstances(digester);
|
||||
|
||||
digester.addCallMethod(
|
||||
_prefix + "/tileset/width", "setWidth", 0,
|
||||
new Class[] { java.lang.Integer.TYPE });
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected TileSet createTileSet (Attributes attributes)
|
||||
{
|
||||
// we use uniform tilesets
|
||||
return new MisoTileSet();
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
//
|
||||
// $Id: XMLMisoTileSetParser.java,v 1.6 2001/11/08 03:04:45 mdb Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import org.xml.sax.*;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.media.ImageManager;
|
||||
import com.threerings.media.tile.*;
|
||||
|
||||
import com.threerings.miso.scene.util.MisoSceneUtil;
|
||||
|
||||
/**
|
||||
* Extends the base XML tile set parser to construct {@link
|
||||
* MisoTileSet} tilesets that provide additional functionality
|
||||
* specific to the miso layer.
|
||||
*/
|
||||
public class XMLMisoTileSetParser extends XMLTileSetParser
|
||||
{
|
||||
// documentation inherited
|
||||
public XMLMisoTileSetParser (ImageManager imgmgr)
|
||||
{
|
||||
super(imgmgr);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void startElement (
|
||||
String uri, String localName, String qName, Attributes attributes)
|
||||
{
|
||||
super.startElement(uri, localName, qName, attributes);
|
||||
|
||||
if (qName.equals("tileset")) {
|
||||
String val = attributes.getValue("layer");
|
||||
_layer = MisoSceneUtil.getLayerIndex(val);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void finishElement (
|
||||
String uri, String localName, String qName, String data)
|
||||
{
|
||||
super.finishElement(uri, localName, qName, data);
|
||||
|
||||
if (qName.equals("passable")) {
|
||||
_passable = StringUtil.parseIntArray(data);
|
||||
|
||||
} else if (qName.equals("tileset")) {
|
||||
_passable = null;
|
||||
_layer = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected TileSet createTileSet ()
|
||||
{
|
||||
if (_info.isObjectSet) {
|
||||
return new ObjectTileSet(
|
||||
_imgmgr, _info.imgFile, _info.name, _info.tsid,
|
||||
_info.tileCount, _info.rowWidth, _info.rowHeight,
|
||||
_info.offsetPos, _info.gapDist, _info.objects);
|
||||
|
||||
} else {
|
||||
return new MisoTileSet(
|
||||
_imgmgr, _info.imgFile, _info.name, _info.tsid,
|
||||
_info.tileCount, _info.rowWidth, _info.rowHeight,
|
||||
_info.offsetPos, _info.gapDist, _layer, _passable);
|
||||
}
|
||||
}
|
||||
|
||||
/** Info on whether or not the tiles are passable (can be walked on by
|
||||
* sprites). */
|
||||
protected int[] _passable;
|
||||
|
||||
/** The layer to which the tiles are assigned. */
|
||||
protected int _layer = -1;
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
//
|
||||
// $Id: XMLTileSetRepository.java,v 1.2 2001/11/02 02:52:16 shaper Exp $
|
||||
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import com.samskivert.util.Config;
|
||||
import com.samskivert.util.HashIntMap;
|
||||
|
||||
import com.threerings.media.ImageManager;
|
||||
import com.threerings.media.tile.*;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.util.MisoUtil;
|
||||
|
||||
/**
|
||||
* Extends general tile set repository functionality to read tile set
|
||||
* descriptions from an XML file.
|
||||
*/
|
||||
public class XMLTileSetRepository implements TileSetRepository
|
||||
{
|
||||
// documentation inherited
|
||||
public void init (Config config, ImageManager imgmgr)
|
||||
{
|
||||
// get the tile set description file path
|
||||
String fname = config.getValue(TILESETS_KEY, DEFAULT_TILESETS);
|
||||
|
||||
// load the tilesets from the XML description file
|
||||
try {
|
||||
XMLMisoTileSetParser p = new XMLMisoTileSetParser(imgmgr);
|
||||
p.loadTileSets(fname, _tilesets);
|
||||
} catch (IOException ioe) {
|
||||
Log.warning("Exception loading tile sets [ioe=" + ioe + "].");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public TileSet getTileSet (int tsid)
|
||||
throws NoSuchTileSetException
|
||||
{
|
||||
TileSet tset = (TileSet)_tilesets.get(tsid);
|
||||
if (tset == null) {
|
||||
throw new NoSuchTileSetException(tsid);
|
||||
}
|
||||
|
||||
return tset;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Iterator enumerateTileSets ()
|
||||
{
|
||||
return Collections.unmodifiableMap(_tilesets).values().iterator();
|
||||
}
|
||||
|
||||
/** The config key for the tileset description file. */
|
||||
protected static final String TILESETS_KEY =
|
||||
MisoUtil.CONFIG_KEY + ".tilesets";
|
||||
|
||||
/** The default tileset description file. */
|
||||
protected static final String DEFAULT_TILESETS =
|
||||
"rsrc/config/miso/tilesets.xml";
|
||||
|
||||
/** The available tilesets keyed by tileset id. */
|
||||
protected HashIntMap _tilesets = new HashIntMap();
|
||||
}
|
||||
Reference in New Issue
Block a user