Initial work on support for objects whose images span multiple tiles.

Made TileSet an interface.  Throw exceptions for unknown tile or tile
set requests.  General clean-up and documentation.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@427 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-10-11 00:41:27 +00:00
parent 5c79f8f082
commit ad7b64d4a1
30 changed files with 811 additions and 521 deletions
@@ -0,0 +1,24 @@
//
// $Id: NoSuchTileException.java,v 1.1 2001/10/11 00:41:26 shaper Exp $
package com.threerings.media.tile;
/**
* Thrown when an attempt is made to retrieve a non-existent tile from the
* tile manager.
*/
public class NoSuchTileException extends TileException
{
public NoSuchTileException (int tid)
{
super("No such tile [tid=" + tid + "]");
_tid = tid;
}
public int getTileId ()
{
return _tid;
}
protected int _tid;
}
@@ -0,0 +1,24 @@
//
// $Id: NoSuchTileSetException.java,v 1.1 2001/10/11 00:41:26 shaper Exp $
package com.threerings.media.tile;
/**
* Thrown when an attempt is made to retrieve a non-existent tile set
* from the tile set manager.
*/
public class NoSuchTileSetException extends TileException
{
public NoSuchTileSetException (int tsid)
{
super("No such tile set [tsid=" + tsid + "]");
_tsid = tsid;
}
public int getTileSetId ()
{
return _tsid;
}
protected int _tsid;
}
@@ -0,0 +1,40 @@
//
// $Id: ObjectTile.java,v 1.1 2001/10/11 00:41:26 shaper Exp $
package com.threerings.media.tile;
import java.awt.Graphics2D;
import java.awt.Shape;
/**
* An object tile extends the base tile to provide support for objects
* whose image spans more than one tile. The object has dimensions
* that represent its footprint or "shadow", which the scene
* containing the tile can reference to do things like make the
* footprint tiles impassable.
*/
public class ObjectTile extends Tile
{
/** The object footprint dimensions in unit tile units. */
public int baseWidth, baseHeight;
/**
* Constructs a new object tile.
*/
public ObjectTile (int tsid, int tid, int baseWidth, int baseHeight)
{
super(tsid, tid);
this.baseWidth = baseWidth;
this.baseHeight = baseHeight;
}
// documentation inherited
public void paint (Graphics2D gfx, Shape dest)
{
super.paint(gfx, dest);
// TODO: draw the object image offset to account for its
// actual dimensions
}
}
+12 -2
View File
@@ -1,9 +1,9 @@
// //
// $Id: Tile.java,v 1.13 2001/10/08 21:04:25 shaper Exp $ // $Id: Tile.java,v 1.14 2001/10/11 00:41:26 shaper Exp $
package com.threerings.media.tile; package com.threerings.media.tile;
import java.awt.Image; import java.awt.*;
/** /**
* A tile represents a single square in a single layer in a scene. * A tile represents a single square in a single layer in a scene.
@@ -48,6 +48,16 @@ public class Tile
return ((int)tsid << 16) | tid; return ((int)tsid << 16) | tid;
} }
/**
* Render the tile into the given rectangle in the given graphics
* context.
*/
public void paint (Graphics2D gfx, Shape dest)
{
Rectangle bounds = dest.getBounds();
gfx.drawImage(img, bounds.x, bounds.y, null);
}
/** /**
* Return a string representation of the tile information. * Return a string representation of the tile information.
*/ */
@@ -0,0 +1,15 @@
//
// $Id: TileException.java,v 1.1 2001/10/11 00:41:26 shaper Exp $
package com.threerings.media.tile;
/**
* Thrown when an error occurs while working with tiles.
*/
public class TileException extends Exception
{
public TileException (String message)
{
super(message);
}
}
@@ -1,5 +1,5 @@
// //
// $Id: TileManager.java,v 1.17 2001/09/28 00:44:31 shaper Exp $ // $Id: TileManager.java,v 1.18 2001/10/11 00:41:26 shaper Exp $
package com.threerings.media.tile; package com.threerings.media.tile;
@@ -39,6 +39,7 @@ public class TileManager
* @return the tile object, or null if an error occurred. * @return the tile object, or null if an error occurred.
*/ */
public Tile getTile (int tsid, int tid) public Tile getTile (int tsid, int tid)
throws NoSuchTileSetException, NoSuchTileException
{ {
// the fully unique tile id is the conjoined tile set and tile id // the fully unique tile id is the conjoined tile set and tile id
int utid = (tsid << 16) | tid; int utid = (tsid << 16) | tid;
+7 -188
View File
@@ -1,14 +1,8 @@
// //
// $Id: TileSet.java,v 1.16 2001/10/08 21:04:25 shaper Exp $ // $Id: TileSet.java,v 1.17 2001/10/11 00:41:26 shaper Exp $
package com.threerings.media.tile; package com.threerings.media.tile;
import java.awt.Image;
import java.awt.Point;
import java.awt.image.*;
import com.samskivert.util.StringUtil;
import com.threerings.media.Log;
import com.threerings.media.ImageManager; import com.threerings.media.ImageManager;
/** /**
@@ -21,90 +15,25 @@ import com.threerings.media.ImageManager;
* the image is tile id 0 and tiles are numbered left to right, top to * the image is tile id 0 and tiles are numbered left to right, top to
* bottom, in ascending order. * bottom, in ascending order.
*/ */
public class TileSet public interface TileSet
{ {
/**
* Construct a new <code>TileSet</code> object.
*/
public TileSet ()
{
_model = new TileSetModel();
}
/** /**
* Return the tileset identifier. * Return the tileset identifier.
*/ */
public int getId () public int getId ();
{
return _model.tsid;
}
/** /**
* Return the tileset name. * Return the tileset name.
*/ */
public String getName () public String getName ();
{
return _model.name;
}
/** /**
* Return the number of tiles in the tileset. * Return the number of tiles in the tileset.
*/ */
public int getNumTiles () public int getNumTiles ();
{
return _model.numTiles;
}
/** /**
* Return the image corresponding to the specified tile id within * Returns the {@link Tile} object from this tileset corresponding
* this tile set.
*
* @param imgmgr the image manager.
* @param tid the tile id.
*
* @return the tile image.
*/
protected Image getTileImage (ImageManager imgmgr, int tid)
{
// load the full tile image if we don't already have it
if (_imgTiles == null) {
if ((_imgTiles = imgmgr.getImage(_model.imgFile)) == null) {
Log.warning("Failed to retrieve full tileset image " +
"[file=" + _model.imgFile + "].");
return null;
}
}
// find the row number containing the sought-after tile
int ridx, tcount, ty, tx;
ridx = tcount = 0;
// start tile image position at image start offset
tx = _model.offsetPos.x;
ty = _model.offsetPos.y;
while ((tcount += _model.tileCount[ridx]) < tid + 1) {
// increment tile image position by row height and gap distance
ty += (_model.rowHeight[ridx++] + _model.gapDist.y);
}
// determine the horizontal index of this tile in the row
int xidx = tid - (tcount - _model.tileCount[ridx]);
// final image x-position is based on tile width and gap distance
tx += (xidx * (_model.rowWidth[ridx] + _model.gapDist.x));
// Log.info("Retrieving tile image [tid=" + tid + ", ridx=" +
// ridx + ", xidx=" + xidx + ", tx=" + tx +
// ", ty=" + ty + "].");
// crop the tile-sized image chunk from the full image
return imgmgr.getImageCropped(
_imgTiles, tx, ty, _model.rowWidth[ridx], _model.rowHeight[ridx]);
}
/**
* Return the {@link Tile} object from this tileset corresponding
* to the specified tile id, or <code>null</code> if no such tile * to the specified tile id, or <code>null</code> if no such tile
* id exists. The tile image is retrieved from the given image * id exists. The tile image is retrieved from the given image
* manager. * manager.
@@ -115,115 +44,5 @@ public class TileSet
* @return the tile object, or null if no such tile exists. * @return the tile object, or null if no such tile exists.
*/ */
public Tile getTile (ImageManager imgmgr, int tid) public Tile getTile (ImageManager imgmgr, int tid)
{ throws NoSuchTileException;
// bail if there's no such tile
if (tid > (_model.numTiles - 1)) {
return null;
}
// create the tile object
Tile tile = createTile(tid);
// retrieve the tile image
tile.img = getTileImage(imgmgr, tid);
if (tile.img == null) {
Log.warning("Null tile image " +
"[tsid=" + _model.tsid + ", tid=" + tid + "].");
}
// populate the tile's dimensions
BufferedImage bimg = (BufferedImage)tile.img;
tile.height = (short)bimg.getHeight();
tile.width = (short)bimg.getWidth();
return tile;
}
/**
* Returns the tile set model.
*/
public TileSetModel getModel ()
{
return _model;
}
/**
* Return a string representation of the tileset information.
*/
public String toString ()
{
return _model.toString();
}
/**
* Construct and return a new tile object for further population
* with tile-specific information.
*/
protected Tile createTile (int tid)
{
return new Tile(_model.tsid, tid);
}
/** The image containing all tile images for this set. */
protected Image _imgTiles;
/** The tile set data model. */
protected TileSetModel _model;
/**
* The model that details the attributes of each tile in a
* tileset. Storing the data separately from the tile set object
* itself allows for the wealth of information associated with a
* tile set to be more cleanly gathered and passed on to the tile
* set constructor by those that need to do so.
*/
public static class TileSetModel
{
/** The tileset name. */
public String name;
/** The tileset unique identifier. */
public int tsid;
/** The file containing the tile images. */
public String imgFile;
/** The width of the tiles in each row in pixels. */
public int[] rowWidth;
/** The height of the tiles in each row in pixels. */
public int[] rowHeight;
/** The number of tiles in each row. */
public int[] tileCount;
/** The number of tiles in the tileset. */
public int numTiles;
/**
* The offset distance (x, y) in pixels from the top-left of the
* image to the start of the first tile image.
*/
public Point offsetPos = new Point();
/**
* The distance (x, y) in pixels between each tile in each row
* horizontally, and between each row of tiles vertically.
*/
public Point gapDist = new Point();
public TileSetModel ()
{
}
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);
return buf.append("]").toString();
}
}
} }
@@ -0,0 +1,197 @@
//
// $Id: TileSetImpl.java,v 1.1 2001/10/11 00:41:26 shaper Exp $
package com.threerings.media.tile;
import java.awt.Image;
import java.awt.Point;
import java.awt.image.*;
import com.samskivert.util.HashIntMap;
import com.samskivert.util.StringUtil;
import com.threerings.media.Log;
import com.threerings.media.ImageManager;
// documentation inherited
public class TileSetImpl implements TileSet
{
/** The tileset name. */
public String name;
/** The tileset unique identifier. */
public int tsid;
/** The file containing the tile images. */
public String imgFile;
/** The width of the tiles in each row in pixels. */
public int[] rowWidth;
/** The height of the tiles in each row in pixels. */
public int[] rowHeight;
/** The number of tiles in each row. */
public int[] tileCount;
/** The number of tiles in the tileset. */
public int numTiles;
/** Mapping of object tile ids to object dimensions. */
public HashIntMap objects = new HashIntMap();
/**
* The offset distance (x, y) in pixels from the top-left of the
* image to the start of the first tile image.
*/
public Point offsetPos = new Point();
/**
* The distance (x, y) in pixels between each tile in each row
* horizontally, and between each row of tiles vertically.
*/
public Point gapDist = new Point();
// documentation inherited
public int getId ()
{
return tsid;
}
// documentation inherited
public String getName ()
{
return name;
}
// documentation inherited
public int getNumTiles ()
{
return numTiles;
}
// documentation inherited
public Tile getTile (ImageManager imgmgr, int tid)
throws NoSuchTileException
{
// bail if there's no such tile
if (tid < 0 || tid > (numTiles - 1)) {
throw new NoSuchTileException(tid);
}
// create and populate the tile object
Tile tile = createTile(tid);
// retrieve the tile image
tile.img = getTileImage(imgmgr, tile.tid);
if (tile.img == null) {
Log.warning("Null tile image [tile=" + tile + "].");
}
// populate the tile's dimensions
BufferedImage bimg = (BufferedImage)tile.img;
tile.height = (short)bimg.getHeight();
tile.width = (short)bimg.getWidth();
// allow sub-classes to fill in their tile information
populateTile(tile);
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);
return buf.append("]").toString();
}
/**
* Construct and return a new tile object for further population
* with tile-specific information. Derived classes can override
* this method to create their own sub-class of <code>Tile</code>.
*
* @param tid the tile id for the new tile.
*
* @return the new tile object.
*/
protected Tile createTile (int tid)
{
int size[] = (int[])objects.get(tid);
if (size != null) {
return new ObjectTile(tsid, tid, size[0], size[1]);
}
return new Tile(tsid, tid);
}
/**
* Populates the given tile object with its detailed tile
* information. Derived classes can override this method to add
* in their own tile information, but should be sure to call
* <code>super.populateTile()</code>.
*
* @param tile the tile to populate.
*/
protected void populateTile (Tile tile)
{
// nothing for now
}
/**
* Returns 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.
*/
protected Image getTileImage (ImageManager imgmgr, int tid)
{
// load the full tile image if we don't already have it
if (_imgTiles == null) {
if ((_imgTiles = imgmgr.getImage(imgFile)) == null) {
Log.warning("Failed to retrieve full tileset image " +
"[file=" + imgFile + "].");
return null;
}
}
// find the row number containing the sought-after tile
int ridx, tcount, ty, tx;
ridx = tcount = 0;
// start tile image position at image start offset
tx = offsetPos.x;
ty = offsetPos.y;
while ((tcount += tileCount[ridx]) < tid + 1) {
// increment tile image position by row height and gap distance
ty += (rowHeight[ridx++] + gapDist.y);
}
// determine the horizontal index of this tile in the row
int xidx = tid - (tcount - tileCount[ridx]);
// final image x-position is based on tile width and gap distance
tx += (xidx * (rowWidth[ridx] + gapDist.x));
// Log.info("Retrieving tile image [tid=" + tid + ", ridx=" +
// ridx + ", xidx=" + xidx + ", tx=" + tx +
// ", ty=" + ty + "].");
// crop the tile-sized image chunk from the full image
return imgmgr.getImageCropped(
_imgTiles, tx, ty, rowWidth[ridx], rowHeight[ridx]);
}
/** The image containing all tile images for this set. */
protected Image _imgTiles;
}
@@ -1,5 +1,5 @@
// //
// $Id: TileSetManager.java,v 1.12 2001/08/16 23:14:20 mdb Exp $ // $Id: TileSetManager.java,v 1.13 2001/10/11 00:41:26 shaper Exp $
package com.threerings.media.tile; package com.threerings.media.tile;
@@ -26,7 +26,8 @@ public interface TileSetManager
* @param tsid the tileset identifier. * @param tsid the tileset identifier.
* @return the number of tiles. * @return the number of tiles.
*/ */
public int getNumTilesInSet (int tsid); public int getNumTilesInSet (int tsid)
throws NoSuchTileSetException;
/** /**
* Return an <code>ArrayList</code> containing all * Return an <code>ArrayList</code> containing all
@@ -43,7 +44,8 @@ public interface TileSetManager
* @param tsid the tileset identifier. * @param tsid the tileset identifier.
* @return the tileset object. * @return the tileset object.
*/ */
public TileSet getTileSet (int tsid); public TileSet getTileSet (int tsid)
throws NoSuchTileSetException;
/** /**
* Return the tile object corresponding to the specified tileset * Return the tile object corresponding to the specified tileset
@@ -54,7 +56,8 @@ public interface TileSetManager
* *
* @return the tile object. * @return the tile object.
*/ */
public Tile getTile (int tsid, int tid); public Tile getTile (int tsid, int tid)
throws NoSuchTileSetException, NoSuchTileException;
/** /**
* Return the total number of tilesets available for use. * Return the total number of tilesets available for use.
@@ -1,5 +1,5 @@
// //
// $Id: TileSetManagerImpl.java,v 1.12 2001/09/17 05:18:21 mdb Exp $ // $Id: TileSetManagerImpl.java,v 1.13 2001/10/11 00:41:26 shaper Exp $
package com.threerings.media.tile; package com.threerings.media.tile;
@@ -28,20 +28,26 @@ public abstract class TileSetManagerImpl implements TileSetManager
} }
public int getNumTilesInSet (int tsid) public int getNumTilesInSet (int tsid)
throws NoSuchTileSetException
{ {
TileSet tset = getTileSet(tsid); return getTileSet(tsid).getNumTiles();
return (tset != null) ? tset.getNumTiles() : -1;
} }
public TileSet getTileSet (int tsid) public TileSet getTileSet (int tsid)
throws NoSuchTileSetException
{ {
return (TileSet)_tilesets.get(tsid); TileSet tset = (TileSet)_tilesets.get(tsid);
if (tset == null) {
throw new NoSuchTileSetException(tsid);
}
return tset;
} }
public Tile getTile (int tsid, int tid) public Tile getTile (int tsid, int tid)
throws NoSuchTileSetException, NoSuchTileException
{ {
TileSet tset = getTileSet(tsid); return getTileSet(tsid).getTile(_imgmgr, tid);
return (tset == null) ? null : tset.getTile(_imgmgr, tid);
} }
public ArrayList getAllTileSets () public ArrayList getAllTileSets ()
@@ -0,0 +1,46 @@
//
// $Id: TileUtil.java,v 1.1 2001/10/11 00:41:26 shaper Exp $
package com.threerings.media.tile;
import java.awt.Image;
import com.threerings.media.Log;
/**
* Miscellaneous utility routines for working with tiles.
*/
public class TileUtil
{
/**
* Returns the image associated with the given tile from the given
* tile manager, or null if an error occurred. Any exceptions
* that occur are logged.
*/
public static Image getTileImage (TileManager tilemgr, int tsid, int tid)
{
try {
Tile tile = tilemgr.getTile(tsid, tid);
return tile.img;
} catch (TileException te) {
Log.warning("Exception retrieving tile image [te=" + te + "].");
return null;
}
}
/**
* Returns the given tile from the given tile manager, or null if
* an error occurred. Any exceptions that occur are logged.
*/
public static Tile getTile (TileManager tilemgr, int tsid, int tid)
{
try {
return tilemgr.getTile(tsid, tid);
} catch (TileException te) {
Log.warning("Exception retrieving tile [te=" + te + "].");
return null;
}
}
}
@@ -1,5 +1,5 @@
// //
// $Id: XMLTileSetParser.java,v 1.15 2001/10/08 21:04:25 shaper Exp $ // $Id: XMLTileSetParser.java,v 1.16 2001/10/11 00:41:26 shaper Exp $
package com.threerings.media.tile; package com.threerings.media.tile;
@@ -35,27 +35,27 @@ public class XMLTileSetParser extends DefaultHandler
protected void finishElement (String qName, String str) protected void finishElement (String qName, String str)
{ {
if (qName.equals("imagefile")) { if (qName.equals("imagefile")) {
_model.imgFile = str; _tset.imgFile = str;
} else if (qName.equals("rowwidth")) { } else if (qName.equals("rowwidth")) {
_model.rowWidth = StringUtil.parseIntArray(str); _tset.rowWidth = StringUtil.parseIntArray(str);
} else if (qName.equals("rowheight")) { } else if (qName.equals("rowheight")) {
_model.rowHeight = StringUtil.parseIntArray(str); _tset.rowHeight = StringUtil.parseIntArray(str);
} else if (qName.equals("tilecount")) { } else if (qName.equals("tilecount")) {
_model.tileCount = StringUtil.parseIntArray(str); _tset.tileCount = StringUtil.parseIntArray(str);
// calculate the total number of tiles in the tileset // calculate the total number of tiles in the tileset
for (int ii = 0; ii < _model.tileCount.length; ii++) { for (int ii = 0; ii < _tset.tileCount.length; ii++) {
_model.numTiles += _model.tileCount[ii]; _tset.numTiles += _tset.tileCount[ii];
} }
} else if (qName.equals("offsetpos")) { } else if (qName.equals("offsetpos")) {
getPoint(str, _model.offsetPos); getPoint(str, _tset.offsetPos);
} else if (qName.equals("gapdist")) { } else if (qName.equals("gapdist")) {
getPoint(str, _model.gapDist); getPoint(str, _tset.gapDist);
} else if (qName.equals("tileset")) { } else if (qName.equals("tileset")) {
// construct the tileset on tag close and add it to the // construct the tileset on tag close and add it to the
@@ -67,19 +67,31 @@ public class XMLTileSetParser extends DefaultHandler
} }
} }
// documentation inherited
public void startElement (String uri, String localName, public void startElement (String uri, String localName,
String qName, Attributes attributes) String qName, Attributes attributes)
{ {
_tag = qName; _tag = qName;
if (_tag.equals("tileset")) { if (_tag.equals("tileset")) {
_model.tsid = getTileSetId(attributes.getValue("tsid")); _tset.tsid = getInt(attributes.getValue("tsid"));
String str = attributes.getValue("name"); String str = attributes.getValue("name");
_model.name = (str == null) ? DEF_NAME : str; _tset.name = (str == null) ? DEF_NAME : str;
} else if (_tag.equals("object")) {
// TODO: should we bother checking to make sure we only
// see <object> tags while within an <objects> tag?
int tid = getInt(attributes.getValue("tid"));
int wid = getInt(attributes.getValue("width"));
int hei = getInt(attributes.getValue("height"));
// add the object info to the tileset object hashtable
_tset.objects.put(tid, new int[] { wid, hei });
} }
} }
// documentation inherited
public void endElement (String uri, String localName, String qName) public void endElement (String uri, String localName, String qName)
{ {
// we know we've received the entirety of the character data // we know we've received the entirety of the character data
@@ -96,6 +108,7 @@ public class XMLTileSetParser extends DefaultHandler
_chars = new StringBuffer(); _chars = new StringBuffer();
} }
// documentation inherited
public void characters (char ch[], int start, int length) public void characters (char ch[], int start, int length)
{ {
// bail if we're not within a meaningful tag // bail if we're not within a meaningful tag
@@ -106,6 +119,7 @@ public class XMLTileSetParser extends DefaultHandler
_chars.append(ch, start, length); _chars.append(ch, start, length);
} }
// documentation inherited
public ArrayList loadTileSets (String fname) throws IOException public ArrayList loadTileSets (String fname) throws IOException
{ {
try { try {
@@ -141,15 +155,16 @@ public class XMLTileSetParser extends DefaultHandler
{ {
_chars = new StringBuffer(); _chars = new StringBuffer();
_tset = createTileSet(); _tset = createTileSet();
_model = _tset.getModel();
} }
/** /**
* Constructs and returns a new tile set object. * Constructs and returns a new tile set object. Derived classes
* may override this method to create their own sub-classes of the
* <code>TileSet</code> object.
*/ */
protected TileSet createTileSet () protected TileSetImpl createTileSet ()
{ {
return new TileSet(); return new TileSetImpl();
} }
/** /**
@@ -167,26 +182,19 @@ public class XMLTileSetParser extends DefaultHandler
} }
/** /**
* Returns the integer tileset id corresponding to the given * Returns the integer represented by the given string or -1 if an
* string, or <code>DEF_TSID</code> if an error occurred. * error occurred.
*/ */
protected int getTileSetId (String str) protected int getInt (String str)
{ {
if (str == null) {
return DEF_TSID;
}
try { try {
return Integer.parseInt(str); return (str == null) ? -1 : Integer.parseInt(str);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
Log.warning("Malformed integer tileset id [str=" + str + "]."); Log.warning("Malformed integer value [str=" + str + "].");
return DEF_TSID; return -1;
} }
} }
/** Default tileset id. */
protected static final int DEF_TSID = -1;
/** Default tileset name. */ /** Default tileset name. */
protected static final String DEF_NAME = "Untitled"; protected static final String DEF_NAME = "Untitled";
@@ -199,9 +207,6 @@ public class XMLTileSetParser extends DefaultHandler
/** Temporary storage of character data while parsing. */ /** Temporary storage of character data while parsing. */
protected StringBuffer _chars; protected StringBuffer _chars;
/** The tile set whose model is populated while parsing. */ /** The tile set populated while parsing. */
protected TileSet _tset; protected TileSetImpl _tset;
/** The tile set data model populated while parsing. */
protected TileSet.TileSetModel _model;
} }
@@ -1,5 +1,5 @@
// //
// $Id: DisplayMisoSceneImpl.java,v 1.38 2001/10/08 21:04:25 shaper Exp $ // $Id: DisplayMisoSceneImpl.java,v 1.39 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -10,11 +10,12 @@ import java.util.List;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
import com.threerings.media.tile.TileManager; import com.threerings.media.tile.*;
import com.threerings.whirled.data.Scene; import com.threerings.whirled.data.Scene;
import com.threerings.miso.Log; import com.threerings.miso.Log;
import com.threerings.miso.scene.util.ClusterUtil; import com.threerings.miso.scene.util.ClusterUtil;
import com.threerings.miso.tile.MisoTile; import com.threerings.miso.tile.MisoTile;
/** /**
@@ -24,71 +25,55 @@ import com.threerings.miso.tile.MisoTile;
*/ */
public class MisoSceneImpl implements EditableMisoScene public class MisoSceneImpl implements EditableMisoScene
{ {
/** The scene name. */
public String name = DEF_SCENE_NAME;
/** The locations within the scene. */
public ArrayList locations = new ArrayList();
/** The clusters within the scene. */
public ArrayList clusters = new ArrayList();
/** The portals to different scenes. */
public ArrayList portals = new ArrayList();
/** The base tiles in the scene. */
public MisoTile[][] baseTiles;
/** The fringe tiles in the scene. */
public Tile[][] fringeTiles;
/** The object tiles in the scene. */
public ObjectTile[][] objectTiles;
/** All tiles in the scene. */
public Tile[][][] tiles;
/** /**
* Construct a new miso scene object. The base layer tiles are * Construct a new miso scene object. The base layer tiles are
* initialized to contain tiles of the specified default tileset and * initialized to contain tiles of the specified default tileset and
* tile id. * tile id.
* *
* @param model the iso scene view model. * @param model the iso scene view model.
* @param tilemgr the tile manager. * @param deftile the default tile.
* @param deftsid the default tileset id.
* @param deftid the default tile id.
*/ */
public MisoSceneImpl (IsoSceneViewModel model, TileManager tilemgr, public MisoSceneImpl (IsoSceneViewModel model, MisoTile deftile)
int deftsid, int deftid)
{ {
_model = model; _model = model;
_tilemgr = tilemgr; _deftile = deftile;
_sid = SID_INVALID; baseTiles = new MisoTile[_model.scenewid][_model.scenehei];
_name = DEF_SCENE_NAME; fringeTiles = new Tile[_model.scenewid][_model.scenehei];
objectTiles = new ObjectTile[_model.scenewid][_model.scenehei];
tiles = new Tile[][][] { baseTiles, fringeTiles, objectTiles };
_locations = new ArrayList(); initBaseTiles();
_clusters = new ArrayList();
_portals = new ArrayList();
_tiles = new MisoTile[_model.scenewid][_model.scenehei][NUM_LAYERS];
_deftile = (MisoTile)_tilemgr.getTile(deftsid, deftid);
for (int xx = 0; xx < _model.scenewid; xx++) {
for (int yy = 0; yy < _model.scenehei; yy++) {
for (int ii = 0; ii < NUM_LAYERS; ii++) {
if (ii == LAYER_BASE) {
_tiles[xx][yy][ii] = _deftile;
}
}
}
}
}
/**
* Construct a new Miso scene object with the given values.
*
* @param model the iso scene view model.
* @param tilemgr the tile manager.
* @param name the scene name.
* @param locations the locations.
* @param portals the portals.
* @param tiles the tiles comprising the scene.
*/
public MisoSceneImpl (IsoSceneViewModel model, TileManager tilemgr,
String name, ArrayList locations,
ArrayList clusters, ArrayList portals,
MisoTile[][][] tiles)
{
_model = model;
_tilemgr = tilemgr;
_sid = SID_INVALID;
_name = name;
_locations = locations;
_clusters = clusters;
_portals = portals;
_tiles = tiles;
} }
// documentation inherited // documentation inherited
public String getName () public String getName ()
{ {
return _name; return name;
} }
// documentation inherited // documentation inherited
@@ -109,10 +94,32 @@ public class MisoSceneImpl implements EditableMisoScene
return null; return null;
} }
// documentation inherited public Tile[][][] getTiles ()
public MisoTile[][][] getTiles ()
{ {
return _tiles; return tiles;
}
public Tile[][] getTiles (int lnum)
{
return tiles[lnum];
}
// documentation inherited
public MisoTile[][] getBaseLayer ()
{
return baseTiles;
}
// documentation inherited
public Tile[][] getFringeLayer ()
{
return fringeTiles;
}
// documentation inherited
public ObjectTile[][] getObjectLayer ()
{
return objectTiles;
} }
// documentation inherited // documentation inherited
@@ -124,19 +131,19 @@ public class MisoSceneImpl implements EditableMisoScene
// documentation inherited // documentation inherited
public List getLocations () public List getLocations ()
{ {
return _locations; return locations;
} }
// documentation inherited // documentation inherited
public List getClusters () public List getClusters ()
{ {
return _clusters; return clusters;
} }
// documentation inherited // documentation inherited
public List getPortals () public List getPortals ()
{ {
return _portals; return portals;
} }
// documentation inherited // documentation inherited
@@ -160,7 +167,7 @@ public class MisoSceneImpl implements EditableMisoScene
// documentation inherited // documentation inherited
public void setName (String name) public void setName (String name)
{ {
_name = name; this.name = name;
} }
// documentation inherited // documentation inherited
@@ -180,12 +187,12 @@ public class MisoSceneImpl implements EditableMisoScene
public void updateLocation (Location loc, int clusteridx) public void updateLocation (Location loc, int clusteridx)
{ {
// add the location if it's not already present // add the location if it's not already present
if (!_locations.contains(loc)) { if (!locations.contains(loc)) {
_locations.add(loc); locations.add(loc);
} }
// update the cluster contents // update the cluster contents
ClusterUtil.regroup(_clusters, loc, clusteridx); ClusterUtil.regroup(clusters, loc, clusteridx);
} }
/** /**
@@ -201,14 +208,14 @@ public class MisoSceneImpl implements EditableMisoScene
updateLocation(portal, -1); updateLocation(portal, -1);
// don't allow adding a portal more than once // don't allow adding a portal more than once
if (_portals.contains(portal)) { if (portals.contains(portal)) {
Log.warning("Attempt to add already-existing portal " + Log.warning("Attempt to add already-existing portal " +
"[portal=" + portal + "]."); "[portal=" + portal + "].");
return; return;
} }
// add it to the list // add it to the list
_portals.add(portal); portals.add(portal);
} }
/** /**
@@ -221,17 +228,17 @@ public class MisoSceneImpl implements EditableMisoScene
public void removeLocation (Location loc) public void removeLocation (Location loc)
{ {
// remove from the location list // remove from the location list
if (!_locations.remove(loc)) { if (!locations.remove(loc)) {
// we didn't know about it, so it can't be in a cluster or // we didn't know about it, so it can't be in a cluster or
// the portal list // the portal list
return; return;
} }
// remove from any possible cluster // remove from any possible cluster
ClusterUtil.remove(_clusters, loc); ClusterUtil.remove(clusters, loc);
// remove from any possible existence on the portal list // remove from any possible existence on the portal list
_portals.remove(loc); portals.remove(loc);
} }
/** /**
@@ -240,47 +247,41 @@ public class MisoSceneImpl implements EditableMisoScene
public String toString () public String toString ()
{ {
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
buf.append("[name=").append(_name); buf.append("[name=").append(name);
buf.append(", sid=").append(_sid); buf.append(", sid=").append(_sid);
buf.append(", locations=").append(StringUtil.toString(_locations)); buf.append(", locations=").append(StringUtil.toString(locations));
buf.append(", clusters=").append(StringUtil.toString(_clusters)); buf.append(", clusters=").append(StringUtil.toString(clusters));
buf.append(", portals=").append(StringUtil.toString(_portals)); buf.append(", portals=").append(StringUtil.toString(portals));
return buf.append("]").toString(); return buf.append("]").toString();
} }
/**
* Initialize the base tile layer with the default tile.
*/
protected void initBaseTiles ()
{
for (int xx = 0; xx < _model.scenewid; xx++) {
for (int yy = 0; yy < _model.scenehei; yy++) {
baseTiles[xx][yy] = _deftile;
}
}
}
/** The default scene name. */ /** The default scene name. */
protected static final String DEF_SCENE_NAME = "Untitled Scene"; protected static final String DEF_SCENE_NAME = "Untitled Scene";
/** The scene name. */
protected String _name;
/** The unique scene id. */ /** The unique scene id. */
protected int _sid; protected int _sid = SID_INVALID;
/** The scene version. */ /** The scene version. */
protected int _version; protected int _version;
/** The tiles comprising the scene. */
public MisoTile[][][] _tiles;
/** The default entrance portal. */ /** The default entrance portal. */
protected Portal _entrance; protected Portal _entrance;
/** The locations within the scene. */
protected ArrayList _locations;
/** The clusters within the scene. */
protected ArrayList _clusters;
/** The portals to different scenes. */
protected ArrayList _portals;
/** The default tile for the base layer in the scene. */ /** The default tile for the base layer in the scene. */
protected MisoTile _deftile; protected MisoTile _deftile;
/** The iso scene view data model. */ /** The iso scene view data model. */
protected IsoSceneViewModel _model; protected IsoSceneViewModel _model;
/** The tile manager. */
protected TileManager _tilemgr;
} }
@@ -1,5 +1,5 @@
// //
// $Id: IsoSceneView.java,v 1.56 2001/09/28 01:31:32 mdb Exp $ // $Id: IsoSceneView.java,v 1.57 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -12,7 +12,6 @@ import java.util.ArrayList;
import com.threerings.media.sprite.*; import com.threerings.media.sprite.*;
import com.threerings.media.tile.Tile; import com.threerings.media.tile.Tile;
import com.threerings.media.tile.TileManager;
import com.threerings.miso.Log; import com.threerings.miso.Log;
import com.threerings.miso.scene.util.AStarPathUtil; import com.threerings.miso.scene.util.AStarPathUtil;
@@ -28,14 +27,11 @@ public class IsoSceneView implements SceneView
/** /**
* Construct an <code>IsoSceneView</code> object. * Construct an <code>IsoSceneView</code> object.
* *
* @param tilemgr the tile manager.
* @param spritemgr the sprite manager. * @param spritemgr the sprite manager.
* @param model the data model. * @param model the data model.
*/ */
public IsoSceneView (TileManager tilemgr, SpriteManager spritemgr, public IsoSceneView (SpriteManager spritemgr, IsoSceneViewModel model)
IsoSceneViewModel model)
{ {
_tilemgr = tilemgr;
_spritemgr = spritemgr; _spritemgr = spritemgr;
setModel(model); setModel(model);
@@ -174,7 +170,9 @@ public class IsoSceneView implements SceneView
for (int xx = 0; xx < _model.scenewid; xx++) { for (int xx = 0; xx < _model.scenewid; xx++) {
// skip this tile if it's not marked dirty // skip this tile if it's not marked dirty
if (!_dirty[xx][yy]) continue; if (!_dirty[xx][yy]) {
continue;
}
// get the tile's screen position // get the tile's screen position
Polygon poly = _polys[xx][yy]; Polygon poly = _polys[xx][yy];
@@ -183,15 +181,17 @@ public class IsoSceneView implements SceneView
for (int kk = 0; kk < MisoScene.NUM_LAYERS; kk++) { for (int kk = 0; kk < MisoScene.NUM_LAYERS; kk++) {
// get the tile at these coordinates and layer // get the tile at these coordinates and layer
Tile tile = tiles[xx][yy][kk]; Tile tile = tiles[kk][xx][yy];
if (tile == null) continue; if (tile == null) {
continue;
}
// offset the image y-position by the tile-specific height // offset the image y-position by the tile-specific height
int ypos = poly.ypoints[0] - _model.tilehhei - int ypos = poly.ypoints[0] - _model.tilehhei -
(tile.height - _model.tilehei); (tile.height - _model.tilehei);
// draw the tile image // draw the tile image
gfx.drawImage(tile.img, poly.xpoints[0], ypos, null); tile.paint(gfx, poly);
} }
// draw all sprites residing in the current tile // draw all sprites residing in the current tile
@@ -204,7 +204,9 @@ public class IsoSceneView implements SceneView
} }
// bail early if we know we've drawn all dirty tiles // bail early if we know we've drawn all dirty tiles
if (++numDrawn == _numDirty) break; if (++numDrawn == _numDirty) {
break;
}
} }
} }
} }
@@ -237,19 +239,23 @@ public class IsoSceneView implements SceneView
for (int kk = 0; kk < MisoScene.NUM_LAYERS; kk++) { for (int kk = 0; kk < MisoScene.NUM_LAYERS; kk++) {
// grab the tile we're rendering // grab the tile we're rendering
Tile tile = tiles[tx][ty][kk]; Tile tile = tiles[kk][tx][ty];
if (tile == null) continue; if (tile == null) {
continue;
}
Polygon poly = _polys[tx][ty];
// determine screen y-position, accounting for // determine screen y-position, accounting for
// tile image height // tile image height
int ypos = screenY - (tile.height - _model.tilehei); int ypos = screenY - (tile.height - _model.tilehei);
// draw the tile image at the appropriate screen position // draw the tile image at the appropriate screen position
gfx.drawImage(tile.img, screenX, ypos, null); tile.paint(gfx, poly);
// draw all sprites residing in the current tile // draw all sprites residing in the current tile
// TODO: simplify other tile positioning here to use poly // TODO: simplify other tile positioning here to use poly
_spritemgr.renderSprites(gfx, _polys[tx][ty]); _spritemgr.renderSprites(gfx, poly);
} }
// draw tile coordinates in each tile // draw tile coordinates in each tile
@@ -505,7 +511,9 @@ public class IsoSceneView implements SceneView
} }
// do nothing if the tile's already dirty // do nothing if the tile's already dirty
if (_dirty[x][y]) return; if (_dirty[x][y]) {
return;
}
// mark the tile dirty // mark the tile dirty
_numDirty++; _numDirty++;
@@ -543,7 +551,7 @@ public class IsoSceneView implements SceneView
// get a reasonable path from start to end // get a reasonable path from start to end
List tilepath = List tilepath =
AStarPathUtil.getPath( AStarPathUtil.getPath(
_scene.getTiles(), _model.scenewid, _model.scenehei, _scene.getBaseLayer(), _model.scenewid, _model.scenehei,
sprite, stpos.x, stpos.y, tbx, tby); sprite, stpos.x, stpos.y, tbx, tby);
if (tilepath == null) { if (tilepath == null) {
return null; return null;
@@ -624,7 +632,4 @@ public class IsoSceneView implements SceneView
/** The sprite manager. */ /** The sprite manager. */
protected SpriteManager _spritemgr; protected SpriteManager _spritemgr;
/** The tile manager. */
protected TileManager _tilemgr;
} }
@@ -1,10 +1,12 @@
// //
// $Id: MisoScene.java,v 1.4 2001/10/08 21:04:25 shaper Exp $ // $Id: MisoScene.java,v 1.5 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
import java.util.List; import java.util.List;
import com.threerings.media.tile.Tile;
import com.threerings.media.tile.ObjectTile;
import com.threerings.miso.tile.MisoTile; import com.threerings.miso.tile.MisoTile;
/** /**
@@ -40,38 +42,58 @@ public interface MisoScene
public String getName (); public String getName ();
/** /**
* Return the tiles that comprise this scene. * Returns an array of the tile layers that comprise the scene.
*/ */
public MisoTile[][][] getTiles (); public Tile[][][] getTiles ();
/** /**
* Return the default tile for the base layer of the scene. * Returns the tile layer for the specified layer index.
*/
public Tile[][] getTiles (int lnum);
/**
* Returns the tiles that comprise the base layer of this scene.
*/
public MisoTile[][] getBaseLayer ();
/**
* Returns the tiles that comprise the fringe layer of this scene.
*/
public Tile[][] getFringeLayer ();
/**
* Returns the tiles that comprise the object layer of this scene.
*/
public ObjectTile[][] getObjectLayer ();
/**
* Returns the default tile for the base layer of the scene.
*/ */
public MisoTile getDefaultTile (); public MisoTile getDefaultTile ();
/** /**
* Return the locations in this scene. The locations list should * Returns the locations in this scene. The locations list should
* contain all locations and portals in the scene. The list returned * contain all locations and portals in the scene. The list
* by this method should <em>not</em> be modified. * returned by this method should <em>not</em> be modified.
*/ */
public List getLocations (); public List getLocations ();
/** /**
* Return the clusters in this scene. The clusters will reference all * Returns the clusters in this scene. The clusters will reference
* of the locations that are clustered. The list returned by this * all of the locations that are clustered. The list returned by
* method should <em>not</em> be modified. * this method should <em>not</em> be modified.
*/ */
public List getClusters (); public List getClusters ();
/** /**
* Return the portals associated with this scene. Portals should never * Returns the portals associated with this scene. Portals should
* be part of a cluster. The list returned by this method should * never be part of a cluster. The list returned by this method
* <em>not</em> be modified. * should <em>not</em> be modified.
*/ */
public List getPortals (); public List getPortals ();
/** /**
* Return the portal that is the default entrance to this scene. * Returns the portal that is the default entrance to this scene.
*/ */
public Portal getEntrance (); public Portal getEntrance ();
} }
@@ -1,5 +1,5 @@
// //
// $Id: SceneView.java,v 1.15 2001/08/22 02:14:57 mdb Exp $ // $Id: SceneView.java,v 1.16 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -8,7 +8,6 @@ import java.util.List;
import com.threerings.media.sprite.DirtyRectList; import com.threerings.media.sprite.DirtyRectList;
import com.threerings.media.sprite.Path; import com.threerings.media.sprite.Path;
import com.threerings.media.tile.Tile;
/** /**
* The scene view interface provides an interface to be implemented by * The scene view interface provides an interface to be implemented by
@@ -1,5 +1,5 @@
// //
// $Id: SceneViewPanel.java,v 1.14 2001/09/21 02:30:35 mdb Exp $ // $Id: SceneViewPanel.java,v 1.15 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -9,7 +9,6 @@ import javax.swing.*;
import com.samskivert.util.Config; import com.samskivert.util.Config;
import com.threerings.media.sprite.*; import com.threerings.media.sprite.*;
import com.threerings.media.tile.TileManager;
import com.threerings.miso.util.MisoUtil; import com.threerings.miso.util.MisoUtil;
/** /**
@@ -23,14 +22,13 @@ public class SceneViewPanel
/** /**
* Construct the panel and initialize it with a context. * Construct the panel and initialize it with a context.
*/ */
public SceneViewPanel (Config config, TileManager tilemgr, public SceneViewPanel (Config config, SpriteManager spritemgr)
SpriteManager spritemgr)
{ {
// create the data model for the scene view // create the data model for the scene view
_smodel = new IsoSceneViewModel(config); _smodel = new IsoSceneViewModel(config);
// create the scene view // create the scene view
_view = newSceneView(tilemgr, spritemgr, _smodel); _view = newSceneView(spritemgr, _smodel);
// set our attributes for optimal display performance // set our attributes for optimal display performance
setDoubleBuffered(false); setDoubleBuffered(false);
@@ -41,9 +39,9 @@ public class SceneViewPanel
* Constructs the underlying scene view implementation. * Constructs the underlying scene view implementation.
*/ */
protected IsoSceneView newSceneView ( protected IsoSceneView newSceneView (
TileManager tmgr, SpriteManager smgr, IsoSceneViewModel model) SpriteManager smgr, IsoSceneViewModel model)
{ {
return new IsoSceneView(tmgr, smgr, model); return new IsoSceneView(smgr, model);
} }
/** /**
@@ -1,5 +1,5 @@
// //
// $Id: AStarPathUtil.java,v 1.5 2001/10/08 21:04:25 shaper Exp $ // $Id: AStarPathUtil.java,v 1.6 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.scene.util; package com.threerings.miso.scene.util;
@@ -43,7 +43,7 @@ public class AStarPathUtil
* @return the list of points in the path. * @return the list of points in the path.
*/ */
public static List getPath ( public static List getPath (
MisoTile tiles[][][], int tilewid, int tilehei, Traverser trav, MisoTile tiles[][], int tilewid, int tilehei, Traverser trav,
int ax, int ay, int bx, int by) int ax, int ay, int bx, int by)
{ {
AStarInfo info = new AStarInfo(tiles, tilewid, tilehei, trav, bx, by); AStarInfo info = new AStarInfo(tiles, tilewid, tilehei, trav, bx, by);
@@ -109,8 +109,7 @@ public class AStarPathUtil
} }
// skip node if it's impassable // skip node if it's impassable
// TODO: fix hard-coded consideration of only the base layer if (!info.trav.canTraverse(info.tiles[x][y])) {
if (!info.trav.canTraverse(info.tiles[x][y][0])) {
return; return;
} }
@@ -198,7 +197,7 @@ public class AStarPathUtil
class AStarInfo class AStarInfo
{ {
/** The array of tiles being traversed. */ /** The array of tiles being traversed. */
public MisoTile tiles[][][]; public MisoTile tiles[][];
/** The tile array dimensions. */ /** The tile array dimensions. */
public int tilewid, tilehei; public int tilewid, tilehei;
@@ -219,7 +218,7 @@ class AStarInfo
public int destx, desty; public int destx, desty;
public AStarInfo ( public AStarInfo (
MisoTile tiles[][][], int tilewid, int tilehei, Traverser trav, MisoTile tiles[][], int tilewid, int tilehei, Traverser trav,
int destx, int desty) int destx, int desty)
{ {
// save off references // save off references
@@ -1,5 +1,5 @@
// //
// $Id: MisoSceneUtil.java,v 1.2 2001/09/28 01:31:32 mdb Exp $ // $Id: MisoSceneUtil.java,v 1.3 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.scene.util; package com.threerings.miso.scene.util;
@@ -15,6 +15,31 @@ public class MisoSceneUtil
/** String translations of each tile layer name. */ /** String translations of each tile layer name. */
public static final String[] XLATE_LAYERS = { "Base", "Fringe", "Object" }; public static final String[] XLATE_LAYERS = { "Base", "Fringe", "Object" };
/**
* Returns the layer index number for the named layer. Layer
* names are looked up via <code>XLATE_LAYERS</code> and are
* case-insensitive.
*
* @param name the layer name.
*/
public static int getLayerIndex (String name)
{
if (name == null) {
return DEF_LAYER;
}
name = name.toLowerCase();
for (int ii = 0; ii < MisoScene.NUM_LAYERS; ii++) {
String b = MisoSceneUtil.XLATE_LAYERS[ii].toLowerCase();
if (name.equals(b)) {
return ii;
}
}
return DEF_LAYER;
}
/** /**
* Return the location object at the given full coordinates, or null * Return the location object at the given full coordinates, or null
* if no location is currently present at that location. * if no location is currently present at that location.
@@ -74,4 +99,7 @@ public class MisoSceneUtil
{ {
return ClusterUtil.getClusterIndex(scene.getClusters(), loc); return ClusterUtil.getClusterIndex(scene.getClusters(), loc);
} }
/** The default layer index for an unknown named layer. */
protected static final int DEF_LAYER = MisoScene.LAYER_BASE;
} }
@@ -1,10 +1,12 @@
// //
// $Id: BaseTileSet.java,v 1.1 2001/10/08 21:04:25 shaper Exp $ // $Id: BaseTileSet.java,v 1.2 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.tile; package com.threerings.miso.tile;
import com.threerings.media.tile.*; import com.threerings.media.tile.*;
import com.threerings.miso.scene.MisoScene;
/** /**
* The miso tile set class extends the base tile set class to add * The miso tile set class extends the base tile set class to add
* support for tile passability. Passability is used to determine * support for tile passability. Passability is used to determine
@@ -12,28 +14,33 @@ import com.threerings.media.tile.*;
* traverse a particular tile in a {@link * traverse a particular tile in a {@link
* com.threerings.miso.scene.MisoScene}. * com.threerings.miso.scene.MisoScene}.
*/ */
public class MisoTileSet extends TileSet public class MisoTileSet extends TileSetImpl
{ {
public MisoTileSet () /** The miso scene layer the tiles are intended for. */
{ public int layer;
_model = new MisoTileSetModel();
} /** Whether each tile is passable. */
public int passable[];
public Tile createTile (int tid) public Tile createTile (int tid)
{ {
MisoTile tile = new MisoTile(_model.tsid, tid); // only create miso tiles for the base layer
if (layer != MisoScene.LAYER_BASE) {
return super.createTile(tid);
}
// set the tile's passability, defaulting to passable if this return new MisoTile(tsid, tid);
// tileset has no passability specified
int passable[] = ((MisoTileSetModel)_model).passable;
tile.passable = (passable == null || (passable[tid] == 1));
return tile;
} }
protected static class MisoTileSetModel extends TileSetModel protected void populateTile (Tile tile)
{ {
/** Whether each tile is passable. */ super.populateTile(tile);
public int passable[];
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));
}
} }
} }
+20 -11
View File
@@ -1,5 +1,5 @@
// //
// $Id: TileUtil.java,v 1.5 2001/09/13 19:10:26 mdb Exp $ // $Id: TileUtil.java,v 1.6 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.tile; package com.threerings.miso.tile;
@@ -9,6 +9,7 @@ import com.threerings.media.sprite.MultiFrameImage;
import com.threerings.media.sprite.Sprite; import com.threerings.media.sprite.Sprite;
import com.threerings.media.tile.*; import com.threerings.media.tile.*;
import com.threerings.miso.Log;
import com.threerings.miso.scene.AmbulatorySprite; import com.threerings.miso.scene.AmbulatorySprite;
/** /**
@@ -28,19 +29,27 @@ public class TileUtil
* *
* @return the array of multi-frame sprite images. * @return the array of multi-frame sprite images.
*/ */
public static MultiFrameImage[] getAmbulatorySpriteFrames ( public static MultiFrameImage[]
TileManager tilemgr, int tsid) getAmbulatorySpriteFrames (TileManager tilemgr, int tsid)
{ {
MultiFrameImage[] anims = new MultiFrameImage[Sprite.NUM_DIRECTIONS]; MultiFrameImage[] anims = new MultiFrameImage[Sprite.NUM_DIRECTIONS];
for (int ii = 0; ii < Sprite.NUM_DIRECTIONS; ii++) { try {
Tile[] tiles = new Tile[NUM_DIR_FRAMES]; for (int ii = 0; ii < Sprite.NUM_DIRECTIONS; ii++) {
for (int jj = 0; jj < NUM_DIR_FRAMES; jj++) { Tile[] tiles = new Tile[NUM_DIR_FRAMES];
int idx = (ii * NUM_DIR_FRAMES) + jj; for (int jj = 0; jj < NUM_DIR_FRAMES; jj++) {
tiles[jj] = tilemgr.getTile(tsid, idx); int idx = (ii * NUM_DIR_FRAMES) + jj;
} tiles[jj] = tilemgr.getTile(tsid, idx);
anims[ii] = new MultiTileImage(tiles); }
}
anims[ii] = new MultiTileImage(tiles);
}
} catch (TileException te) {
Log.warning("Exception retrieving ambulatory sprite tiles " +
"[te=" + te + "].");
return null;
}
return anims; return anims;
} }
@@ -1,11 +1,13 @@
// //
// $Id: XMLMisoTileSetParser.java,v 1.1 2001/10/08 21:04:25 shaper Exp $ // $Id: XMLMisoTileSetParser.java,v 1.2 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.tile; package com.threerings.miso.tile;
import com.samskivert.util.StringUtil; import org.xml.sax.*;
import com.samskivert.util.StringUtil;
import com.threerings.media.tile.*; import com.threerings.media.tile.*;
import com.threerings.miso.scene.util.MisoSceneUtil;
/** /**
* Extends the base XML tile set parser to construct {@link * Extends the base XML tile set parser to construct {@link
@@ -14,17 +16,30 @@ import com.threerings.media.tile.*;
*/ */
public class XMLMisoTileSetParser extends XMLTileSetParser public class XMLMisoTileSetParser extends XMLTileSetParser
{ {
// 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");
((MisoTileSet)_tset).layer = MisoSceneUtil.getLayerIndex(val);
}
}
// documentation inherited
protected void finishElement (String qName, String str) protected void finishElement (String qName, String str)
{ {
super.finishElement(qName, str); super.finishElement(qName, str);
if (qName.equals("passable")) { if (qName.equals("passable")) {
((MisoTileSet.MisoTileSetModel)_model).passable = ((MisoTileSet)_tset).passable = StringUtil.parseIntArray(str);
StringUtil.parseIntArray(str);
} }
} }
protected TileSet createTileSet () // documentation inherited
protected TileSetImpl createTileSet ()
{ {
return new MisoTileSet(); return new MisoTileSet();
} }
@@ -1,5 +1,5 @@
// //
// $Id: XMLSceneParser.java,v 1.17 2001/10/08 21:04:25 shaper Exp $ // $Id: XMLSceneParser.java,v 1.18 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.scene.xml; package com.threerings.miso.scene.xml;
@@ -13,6 +13,7 @@ import org.xml.sax.helpers.DefaultHandler;
import com.samskivert.util.*; import com.samskivert.util.*;
import com.samskivert.xml.XMLUtil; import com.samskivert.xml.XMLUtil;
import com.threerings.media.tile.*; import com.threerings.media.tile.*;
import com.threerings.miso.Log; import com.threerings.miso.Log;
@@ -43,10 +44,7 @@ public class XMLSceneParser extends DefaultHandler
} else if (_tag.equals("row")) { } else if (_tag.equals("row")) {
_info.rownum = getInt(attributes.getValue("rownum")); _info.rownum = getInt(attributes.getValue("rownum"));
_info.colstart = getInt(attributes.getValue("colstart"));
// get the column start value if present
String strcs = attributes.getValue("colstart");
if (strcs != null) _info.colstart = getInt(strcs);
} }
} }
@@ -56,11 +54,13 @@ public class XMLSceneParser extends DefaultHandler
// for the elements we're tracking at this point, so proceed // for the elements we're tracking at this point, so proceed
// with saving off element values for use when we construct // with saving off element values for use when we construct
// the scene object. // the scene object.
String str = _chars.toString().trim();
if (qName.equals("name")) { if (qName.equals("name")) {
_info.name = _chars.toString().trim(); _info.scene.name = str;
} else if (qName.equals("version")) { } else if (qName.equals("version")) {
int version = getInt(_chars.toString()); int version = getInt(str);
if (version < 0 || version > XMLSceneVersion.VERSION) { if (version < 0 || version > XMLSceneVersion.VERSION) {
Log.warning( Log.warning(
"Unrecognized scene file format version, will attempt " + "Unrecognized scene file format version, will attempt " +
@@ -70,27 +70,22 @@ public class XMLSceneParser extends DefaultHandler
} }
} else if (qName.equals("locations")) { } else if (qName.equals("locations")) {
int vals[] = StringUtil.parseIntArray(_chars.toString()); int vals[] = StringUtil.parseIntArray(str);
_info.locations = toLocationsList(vals); addLocations(_info.scene.locations, vals);
} else if (qName.equals("cluster")) { } else if (qName.equals("cluster")) {
int vals[] = StringUtil.parseIntArray(_chars.toString()); int vals[] = StringUtil.parseIntArray(str);
_info.clusters.add(toCluster(_info.locations, vals)); _info.scene.clusters.add(toCluster(_info.scene.locations, vals));
} else if (qName.equals("portals")) { } else if (qName.equals("portals")) {
String vals[] = StringUtil.parseStringArray(_chars.toString()); String vals[] = StringUtil.parseStringArray(str);
_info.portals = toPortalList(_info.locations, vals); addPortals(_info.scene.portals, _info.scene.locations, vals);
} else if (qName.equals("row")) { } else if (qName.equals("row")) {
if (_info.lnum == MisoScene.LAYER_BASE) { addTileRow(_info, str);
readRowData(_info, _chars.toString());
} else {
readSparseRowData(_info, _chars.toString());
}
} else if (qName.equals("scene")) { } else if (qName.equals("scene")) {
// construct the scene object on tag close // nothing for now
_info.constructScene(_tilemgr);
} }
// note that we're not within a tag to avoid considering any // note that we're not within a tag to avoid considering any
@@ -111,6 +106,24 @@ public class XMLSceneParser extends DefaultHandler
_chars.append(ch, start, length); _chars.append(ch, start, length);
} }
/**
* Add the tiles described by the given data to the scene.
*/
protected void addTileRow (SceneInfo info, String data)
{
try {
if (info.lnum == MisoScene.LAYER_BASE) {
readRowData(info, data);
} else {
readSparseRowData(info, data);
}
} catch (TileException te) {
Log.warning("Exception reading scene tile data " +
"[te=" + te + "].");
}
}
/** /**
* Given a string of comma-delimited tuples as (tileset id, tile * Given a string of comma-delimited tuples as (tileset id, tile
* id), populate the scene info tile array with tiles to suit. * id), populate the scene info tile array with tiles to suit.
@@ -119,6 +132,7 @@ public class XMLSceneParser extends DefaultHandler
* @param data the tile data. * @param data the tile data.
*/ */
protected void readRowData (SceneInfo info, String data) protected void readRowData (SceneInfo info, String data)
throws TileException
{ {
int[] vals = StringUtil.parseIntArray(data); int[] vals = StringUtil.parseIntArray(data);
@@ -133,9 +147,10 @@ public class XMLSceneParser extends DefaultHandler
} }
// create the tile objects in the tile array // create the tile objects in the tile array
Tile[][] tiles = info.scene.getTiles(info.lnum);
for (int xx = 0; xx < vals.length; xx += 2) { for (int xx = 0; xx < vals.length; xx += 2) {
MisoTile tile = (MisoTile)_tilemgr.getTile(vals[xx], vals[xx + 1]); Tile tile = _tilemgr.getTile(vals[xx], vals[xx + 1]);
info.tiles[xx / 2][info.rownum][info.lnum] = tile; tiles[xx / 2][info.rownum] = tile;
} }
} }
@@ -151,6 +166,7 @@ public class XMLSceneParser extends DefaultHandler
* @param data the tile data. * @param data the tile data.
*/ */
protected void readSparseRowData (SceneInfo info, String data) protected void readSparseRowData (SceneInfo info, String data)
throws TileException
{ {
int[] vals = StringUtil.parseIntArray(data); int[] vals = StringUtil.parseIntArray(data);
@@ -164,10 +180,11 @@ public class XMLSceneParser extends DefaultHandler
} }
// create the tile objects in the tile array // create the tile objects in the tile array
Tile[][] tiles = info.scene.getTiles(info.lnum);
for (int xx = 0; xx < vals.length; xx += 2) { for (int xx = 0; xx < vals.length; xx += 2) {
MisoTile tile = (MisoTile)_tilemgr.getTile(vals[xx], vals[xx + 1]); Tile tile = _tilemgr.getTile(vals[xx], vals[xx + 1]);
int xidx = info.colstart + (xx / 2); int xidx = info.colstart + (xx / 2);
info.tiles[xidx][info.rownum][info.lnum] = tile; tiles[xidx][info.rownum] = tile;
} }
} }
@@ -191,37 +208,34 @@ public class XMLSceneParser extends DefaultHandler
} }
/** /**
* Given an array of integer values, return a list of the * Given an array of integer values, add the <code>Location</code>
* <code>Location</code> objects represented therein, constructed * objects represented therein to the given list, constructed from
* from each successive triplet of values as (x, y, orientation) * each successive triplet of values as (x, y, orientation) in the
* in the integer array. * integer array.
* *
* @param vals the integer values. * @param vals the integer values.
*
* @return the location list, or null if an error occurred.
*/ */
protected ArrayList toLocationsList (int[] vals) protected void addLocations (ArrayList list, int[] vals)
{ {
// make sure we have a seemingly-appropriate number of points // make sure we have a seemingly-appropriate number of points
if ((vals.length % 3) != 0) return null; if ((vals.length % 3) != 0) {
return;
}
// read in all of the locations and add to the list // read in all of the locations and add to the list
ArrayList list = new ArrayList();
for (int ii = 0; ii < vals.length; ii += 3) { for (int ii = 0; ii < vals.length; ii += 3) {
Location loc = new Location( Location loc = new Location(
vals[ii], vals[ii+1], vals[ii+2]); vals[ii], vals[ii+1], vals[ii+2]);
list.add(loc); list.add(loc);
} }
return list;
} }
/** /**
* Given an array of string values, return a list of * Given an array of string values, add the <code>Portal</code>
* <code>Portal</code> objects constructed from each successive * objects constructed from each successive triplet of values as
* triplet of values as (locidx, portal name) in the array. The * (locidx, portal name) in the array to the given portal list.
* list of <code>Location</code> objects must have already been * The list of <code>Location</code> objects must have already
* fully read previously. * been fully read previously.
* *
* <p> This is something of a hack since we perhaps ought to parse * <p> This is something of a hack since we perhaps ought to parse
* the original String into its constituent components ourselves, * the original String into its constituent components ourselves,
@@ -229,20 +243,19 @@ public class XMLSceneParser extends DefaultHandler
* <code>StringUtil.toString()</code> method to take care of * <code>StringUtil.toString()</code> method to take care of
* tokenizing things for us, so, there you have it. * tokenizing things for us, so, there you have it.
* *
* @param ArrayList the location list. * @param portals the portal list.
* @param locs the location list.
* @param vals the String values. * @param vals the String values.
*
* @return the portal list, or null if an error occurred.
*/ */
protected ArrayList toPortalList (ArrayList locs, String[] vals) protected void addPortals (
ArrayList portals, ArrayList locs, String[] vals)
{ {
// make sure we have an appropriate number of values // make sure we have an appropriate number of values
if ((vals.length % 2) != 0) { if ((vals.length % 2) != 0) {
return null; return;
} }
// read in all of the portals // read in all of the portals
ArrayList portals = new ArrayList();
for (int ii = 0; ii < vals.length; ii += 2) { for (int ii = 0; ii < vals.length; ii += 2) {
int locidx = getInt(vals[ii]); int locidx = getInt(vals[ii]);
@@ -253,8 +266,6 @@ public class XMLSceneParser extends DefaultHandler
// upgrade the corresponding location in the location list // upgrade the corresponding location in the location list
locs.set(locidx, portal); locs.set(locidx, portal);
} }
return portals;
} }
/** /**
@@ -264,7 +275,7 @@ public class XMLSceneParser extends DefaultHandler
protected int getInt (String str) protected int getInt (String str)
{ {
try { try {
return Integer.parseInt(str); return (str == null) ? -1 : Integer.parseInt(str);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
Log.warning("Malformed integer value [str=" + str + "]."); Log.warning("Malformed integer value [str=" + str + "].");
return -1; return -1;
@@ -329,25 +340,16 @@ public class XMLSceneParser extends DefaultHandler
/** Temporary storage of scene info while parsing. */ /** Temporary storage of scene info while parsing. */
protected SceneInfo _info; protected SceneInfo _info;
// TODO: allow specifying the entrance location for a scene in the
// editor, read/write to XML scene description files.
/** /**
* A class to hold temporary information on a scene. * A class to hold the information gathered while parsing.
*/ */
class SceneInfo class SceneInfo
{ {
/** The scene name. */ /** The scene populated with data while parsing. */
public String name; public MisoSceneImpl scene;
/** The location list. */
public ArrayList locations;
/** The portal list. */
public ArrayList portals;
/** The cluster list. */
public ArrayList clusters;
/** The tile array. */
public MisoTile[][][] tiles;
/** The current layer number being processed. */ /** The current layer number being processed. */
public int lnum; public int lnum;
@@ -358,20 +360,9 @@ public class XMLSceneParser extends DefaultHandler
/** The column at which the current row data begins. */ /** The column at which the current row data begins. */
public int colstart; public int colstart;
/** The scene object constructed once all scene info is parsed. */
public EditableMisoScene scene;
public SceneInfo () public SceneInfo ()
{ {
int width = _model.scenewid, height = _model.scenehei; scene = new MisoSceneImpl(_model, null);
tiles = new MisoTile[width][height][MisoScene.NUM_LAYERS];
clusters = new ArrayList();
}
public void constructScene (TileManager tilemgr)
{
scene = new MisoSceneImpl(
_model, tilemgr, name, locations, clusters, portals, tiles);
} }
} }
} }
@@ -1,5 +1,5 @@
// //
// $Id: XMLSceneWriter.java,v 1.14 2001/09/28 01:31:32 mdb Exp $ // $Id: XMLSceneWriter.java,v 1.15 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.scene.xml; package com.threerings.miso.scene.xml;
@@ -211,7 +211,7 @@ public class XMLSceneWriter extends DataWriter
int numtiles = colstart + len; int numtiles = colstart + len;
for (int ii = colstart; ii < numtiles; ii++) { for (int ii = colstart; ii < numtiles; ii++) {
Tile tile = tiles[ii][rownum][lnum]; Tile tile = tiles[lnum][ii][rownum];
if (tile == null) { if (tile == null) {
Log.warning("Null tile [x=" + ii + ", rownum=" + rownum + Log.warning("Null tile [x=" + ii + ", rownum=" + rownum +
", lnum=" + lnum + "]."); ", lnum=" + lnum + "].");
@@ -277,7 +277,7 @@ public class XMLSceneWriter extends DataWriter
Tile[][][] tiles = scene.getTiles(); Tile[][][] tiles = scene.getTiles();
int start = -1, len = 0; int start = -1, len = 0;
for (int xx = info[0]; xx < _model.scenewid; xx++) { for (int xx = info[0]; xx < _model.scenewid; xx++) {
Tile tile = tiles[xx][rownum][lnum]; Tile tile = tiles[lnum][xx][rownum];
if (tile == null) { if (tile == null) {
if (start == -1) { if (start == -1) {
continue; continue;
+9 -6
View File
@@ -1,5 +1,5 @@
// //
// $Id: Node.java,v 1.5 2001/08/28 23:50:45 shaper Exp $ // $Id: Node.java,v 1.6 2001/10/11 00:41:27 shaper Exp $
package com.threerings.nodemap; package com.threerings.nodemap;
@@ -37,6 +37,9 @@ public abstract class Node implements ToolTipProvider
* added to the node more than once. * added to the node more than once.
* *
* @param e the new edge. * @param e the new edge.
*
* @exception DuplicateEdgeException thrown if the node already
* contains the given edge.
*/ */
protected void addEdge (Edge e) throws DuplicateEdgeException protected void addEdge (Edge e) throws DuplicateEdgeException
{ {
@@ -50,7 +53,7 @@ public abstract class Node implements ToolTipProvider
} }
/** /**
* Return an <code>Iterator</code> object that iterates over the * Returns an <code>Iterator</code> object that iterates over the
* edges leaving this node. * edges leaving this node.
* *
* @return the iterator object. * @return the iterator object.
@@ -90,7 +93,7 @@ public abstract class Node implements ToolTipProvider
} }
/** /**
* Return whether the node contains the given point. * Returns whether the node contains the given point.
* *
* @param x the x-position. * @param x the x-position.
* @param y the y-position. * @param y the y-position.
@@ -104,7 +107,7 @@ public abstract class Node implements ToolTipProvider
} }
/** /**
* Return the node width in pixels. * Returns the node width in pixels.
*/ */
public int getWidth () public int getWidth ()
{ {
@@ -112,7 +115,7 @@ public abstract class Node implements ToolTipProvider
} }
/** /**
* Return the node height in pixels. * Returns the node height in pixels.
*/ */
public int getHeight () public int getHeight ()
{ {
@@ -192,7 +195,7 @@ public abstract class Node implements ToolTipProvider
public void handleMouseClicked (int x, int y) { } public void handleMouseClicked (int x, int y) { }
/** /**
* Return a string representation of this node. * Returns a string representation of this node.
*/ */
public String toString () public String toString ()
{ {
+21 -7
View File
@@ -1,5 +1,5 @@
// //
// $Id: NodeMap.java,v 1.4 2001/08/28 23:50:45 shaper Exp $ // $Id: NodeMap.java,v 1.5 2001/10/11 00:41:27 shaper Exp $
package com.threerings.nodemap; package com.threerings.nodemap;
@@ -36,7 +36,9 @@ public class NodeMap
public void layout () public void layout ()
{ {
// do nothing if we have no nodes // do nothing if we have no nodes
if (_nodes.size() == 0) return; if (_nodes.size() == 0) {
return;
}
// default to using the first node as the root // default to using the first node as the root
if (_root == null) { if (_root == null) {
@@ -54,7 +56,8 @@ public class NodeMap
} }
/** /**
* Calculate the bounding rectangle that wholly contains the node map. * Calculate the bounding rectangle that wholly contains the node
* map.
*/ */
protected void updateBounds () protected void updateBounds ()
{ {
@@ -126,6 +129,9 @@ public class NodeMap
* present in the node map more than once. * present in the node map more than once.
* *
* @param n the node to add. * @param n the node to add.
*
* @exception DuplicateNodeException thrown if the node already
* exists in the node map.
*/ */
public void addNode (Node n) throws DuplicateNodeException public void addNode (Node n) throws DuplicateNodeException
{ {
@@ -146,6 +152,11 @@ public class NodeMap
* *
* @param n the node. * @param n the node.
* @param e the edge to add. * @param e the edge to add.
*
* @exception NoSuchNodeException thrown if the given node does
* not exist in the node map.
* @exception DuplicateEdgeException thrown if the given node
* already contains the given edge.
*/ */
public void addEdge (Node n, Edge e) public void addEdge (Node n, Edge e)
throws NoSuchNodeException, DuplicateEdgeException throws NoSuchNodeException, DuplicateEdgeException
@@ -165,6 +176,9 @@ public class NodeMap
* present in the node map. * present in the node map.
* *
* @param n the root node. * @param n the root node.
*
* @exception NoSuchNodeException thrown if the given node does
* not exist in the node map.
*/ */
public void setRootNode (Node n) throws NoSuchNodeException public void setRootNode (Node n) throws NoSuchNodeException
{ {
@@ -177,7 +191,7 @@ public class NodeMap
} }
/** /**
* Return the dimensions of the node map in pixels. * Returns the dimensions of the node map in pixels.
*/ */
public Dimension getSize () public Dimension getSize ()
{ {
@@ -190,7 +204,7 @@ public class NodeMap
} }
/** /**
* Return the bounding rectangle of the node map. * Returns the bounding rectangle of the node map.
*/ */
public Rectangle getBounds () public Rectangle getBounds ()
{ {
@@ -204,7 +218,7 @@ public class NodeMap
* events. * events.
* *
* @param x the mouse x-coordinate. * @param x the mouse x-coordinate.
* @param y the ymouse y-coordinate. * @param y the mouse y-coordinate.
*/ */
public void handleMouseMoved (int x, int y) public void handleMouseMoved (int x, int y)
{ {
@@ -263,7 +277,7 @@ public class NodeMap
* Inform any affected nodes of mouse-clicked events. * Inform any affected nodes of mouse-clicked events.
* *
* @param x the mouse x-coordinate. * @param x the mouse x-coordinate.
* @param y the ymouse y-coordinate. * @param y the mouse y-coordinate.
*/ */
public void handleMouseClicked (int x, int y) public void handleMouseClicked (int x, int y)
{ {
@@ -1,5 +1,5 @@
// //
// $Id: NodeMapPanel.java,v 1.4 2001/09/28 00:46:54 shaper Exp $ // $Id: NodeMapPanel.java,v 1.5 2001/10/11 00:41:27 shaper Exp $
package com.threerings.nodemap; package com.threerings.nodemap;
@@ -20,7 +20,7 @@ public class NodeMapPanel extends JPanel
implements MouseListener, MouseMotionListener, ToolTipObserver implements MouseListener, MouseMotionListener, ToolTipObserver
{ {
/** /**
* Construct a node map panel. * Constructs a node map panel.
*/ */
public NodeMapPanel () public NodeMapPanel ()
{ {
@@ -28,7 +28,7 @@ public class NodeMapPanel extends JPanel
} }
/** /**
* Construct a node map panel that displays the given node map. * Constructs a node map panel that displays the given node map.
* *
* @param map the node map to display. * @param map the node map to display.
*/ */
@@ -39,7 +39,7 @@ public class NodeMapPanel extends JPanel
} }
/** /**
* Initialize the node map panel. * Initializes the node map panel.
*/ */
protected void init () protected void init ()
{ {
@@ -49,7 +49,7 @@ public class NodeMapPanel extends JPanel
} }
/** /**
* Set the node map displayed by this panel. * Sets the node map displayed by this panel.
* *
* @param map the node map to display. * @param map the node map to display.
*/ */
+12 -12
View File
@@ -1,33 +1,33 @@
<?xml version="1.0" standalone="yes"?> <?xml version="1.0" standalone="yes"?>
<!-- $Id: tilesets.xml,v 1.18 2001/09/28 03:46:01 shaper Exp $ --> <!-- $Id: tilesets.xml,v 1.19 2001/10/11 00:41:26 shaper Exp $ -->
<!-- Initial test tileset description data. --> <!-- Initial test tileset description data. -->
<tilesetgroup> <tilesetgroup>
<tileset tsid="1000" name="Ground"> <tileset tsid="1000" name="Ground" layer="Base">
<imagefile>media/miso/tiles/base.png</imagefile> <imagefile>media/miso/tiles/base.png</imagefile>
<rowheight>16, 16</rowheight> <rowheight>16, 16</rowheight>
<rowwidth>32, 32</rowwidth> <rowwidth>32, 32</rowwidth>
<tilecount>10, 10</tilecount> <tilecount>10, 10</tilecount>
</tileset> </tileset>
<tileset tsid="1001" name="Wall"> <tileset tsid="1001" name="Wall" layer="Object">
<imagefile>media/miso/tiles/wall.png</imagefile> <imagefile>media/miso/tiles/wall.png</imagefile>
<rowheight>45, 45</rowheight> <rowheight>45, 45</rowheight>
<rowwidth>32, 32</rowwidth> <rowwidth>32, 32</rowwidth>
<tilecount>3, 3</tilecount> <tilecount>3, 3</tilecount>
</tileset> </tileset>
<tileset tsid="1002" name="Icons"> <tileset tsid="1002" name="Icons" layer="Object">
<imagefile>media/miso/tiles/icons.png</imagefile> <imagefile>media/miso/tiles/icons.png</imagefile>
<rowheight>20, 49</rowheight> <rowheight>20, 49</rowheight>
<rowwidth>32, 32</rowwidth> <rowwidth>32, 32</rowwidth>
<tilecount>9, 2</tilecount> <tilecount>9, 2</tilecount>
</tileset> </tileset>
<tileset tsid="1003" name="Red Character"> <tileset tsid="1003" name="Red Character" layer="Fringe">
<imagefile>media/miso/tiles/character.png</imagefile> <imagefile>media/miso/tiles/character.png</imagefile>
<rowheight>94, 94, 94, 94, 94, 94, 94, 94</rowheight> <rowheight>94, 94, 94, 94, 94, 94, 94, 94</rowheight>
<rowwidth>94, 94, 94, 94, 94, 94, 94, 94</rowwidth> <rowwidth>94, 94, 94, 94, 94, 94, 94, 94</rowwidth>
@@ -36,7 +36,7 @@
<gapdist>39, 18</gapdist> <gapdist>39, 18</gapdist>
</tileset> </tileset>
<tileset tsid="1005" name="Yellow Character"> <tileset tsid="1005" name="Yellow Character" layer="Fringe">
<imagefile>media/miso/tiles/character-yellow.png</imagefile> <imagefile>media/miso/tiles/character-yellow.png</imagefile>
<rowheight>94, 94, 94, 94, 94, 94, 94, 94</rowheight> <rowheight>94, 94, 94, 94, 94, 94, 94, 94</rowheight>
<rowwidth>94, 94, 94, 94, 94, 94, 94, 94</rowwidth> <rowwidth>94, 94, 94, 94, 94, 94, 94, 94</rowwidth>
@@ -45,7 +45,7 @@
<gapdist>39, 18</gapdist> <gapdist>39, 18</gapdist>
</tileset> </tileset>
<tileset tsid="1006" name="Black Character"> <tileset tsid="1006" name="Black Character" layer="Fringe">
<imagefile>media/miso/tiles/character-black.png</imagefile> <imagefile>media/miso/tiles/character-black.png</imagefile>
<rowheight>94, 94, 94, 94, 94, 94, 94, 94</rowheight> <rowheight>94, 94, 94, 94, 94, 94, 94, 94</rowheight>
<rowwidth>94, 94, 94, 94, 94, 94, 94, 94</rowwidth> <rowwidth>94, 94, 94, 94, 94, 94, 94, 94</rowwidth>
@@ -54,7 +54,7 @@
<gapdist>39, 18</gapdist> <gapdist>39, 18</gapdist>
</tileset> </tileset>
<tileset tsid="1004" name="Sample"> <tileset tsid="1004" name="Sample" layer="Base">
<imagefile>media/miso/tiles/sample.png</imagefile> <imagefile>media/miso/tiles/sample.png</imagefile>
<rowheight>48</rowheight> <rowheight>48</rowheight>
<rowwidth>64</rowwidth> <rowwidth>64</rowwidth>
@@ -62,21 +62,21 @@
<passable>1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1</passable> <passable>1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1</passable>
</tileset> </tileset>
<tileset tsid="1007" name="Node Icons"> <tileset tsid="1007" name="Node Icons" layer="Fringe">
<imagefile>media/miso/tiles/node-icons.png</imagefile> <imagefile>media/miso/tiles/node-icons.png</imagefile>
<rowheight>16</rowheight> <rowheight>16</rowheight>
<rowwidth>16</rowwidth> <rowwidth>16</rowwidth>
<tilecount>8</tilecount> <tilecount>8</tilecount>
</tileset> </tileset>
<tileset tsid="1008" name="Editor Icons"> <tileset tsid="1008" name="Editor Icons" layer="Fringe">
<imagefile>media/miso/tiles/editor-icons.png</imagefile> <imagefile>media/miso/tiles/editor-icons.png</imagefile>
<rowheight>22</rowheight> <rowheight>22</rowheight>
<rowwidth>20</rowwidth> <rowwidth>20</rowwidth>
<tilecount>5</tilecount> <tilecount>5</tilecount>
</tileset> </tileset>
<tileset tsid="1009" name="Building"> <tileset tsid="1009" name="Building" layer="Object">
<imagefile>media/miso/tiles/building.png</imagefile> <imagefile>media/miso/tiles/building.png</imagefile>
<rowheight>240</rowheight> <rowheight>240</rowheight>
<rowwidth>64</rowwidth> <rowwidth>64</rowwidth>
@@ -84,7 +84,7 @@
<passable>0, 0, 0, 0, 0, 0</passable> <passable>0, 0, 0, 0, 0, 0</passable>
</tileset> </tileset>
<tileset tsid="1010" name="Sword Pieces"> <tileset tsid="1010" name="Sword Pieces" layer="Fringe">
<imagefile>media/miso/tiles/sword-pieces.png</imagefile> <imagefile>media/miso/tiles/sword-pieces.png</imagefile>
<rowheight>10</rowheight> <rowheight>10</rowheight>
<rowwidth>10</rowwidth> <rowwidth>10</rowwidth>
@@ -1,5 +1,5 @@
// //
// $Id: ViewerFrame.java,v 1.18 2001/09/13 19:10:26 mdb Exp $ // $Id: ViewerFrame.java,v 1.19 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.viewer; package com.threerings.miso.viewer;
@@ -12,6 +12,7 @@ import com.samskivert.swing.*;
import com.threerings.media.sprite.*; import com.threerings.media.sprite.*;
import com.threerings.media.tile.TileManager; import com.threerings.media.tile.TileManager;
import com.threerings.media.tile.TileException;
import com.threerings.miso.Log; import com.threerings.miso.Log;
import com.threerings.miso.scene.AmbulatorySprite; import com.threerings.miso.scene.AmbulatorySprite;
@@ -43,10 +44,7 @@ class ViewerFrame extends JFrame implements WindowListener
TileManager tilemgr = _ctx.getTileManager(); TileManager tilemgr = _ctx.getTileManager();
// add the test character sprite to the sprite manager // add the test character sprite to the sprite manager
MultiFrameImage[] anims = AmbulatorySprite sprite = createSprite(tilemgr, spritemgr);
TileUtil.getAmbulatorySpriteFrames(tilemgr, TSID_CHAR);
AmbulatorySprite sprite = new AmbulatorySprite(300, 300, anims);
spritemgr.addSprite(sprite);
// create a top-level panel to manage everything // create a top-level panel to manage everything
JPanel top = new JPanel(); JPanel top = new JPanel();
@@ -80,6 +78,17 @@ class ViewerFrame extends JFrame implements WindowListener
getContentPane().add(top, BorderLayout.CENTER); getContentPane().add(top, BorderLayout.CENTER);
} }
protected AmbulatorySprite createSprite (TileManager tilemgr,
SpriteManager spritemgr)
{
MultiFrameImage[] anims =
TileUtil.getAmbulatorySpriteFrames(tilemgr, TSID_CHAR);
AmbulatorySprite sprite = new AmbulatorySprite(300, 300, anims);
spritemgr.addSprite(sprite);
return sprite;
}
/** WindowListener interface methods */ /** WindowListener interface methods */
public void windowClosing (WindowEvent e) { public void windowClosing (WindowEvent e) {
@@ -1,5 +1,5 @@
// //
// $Id: ViewerSceneViewPanel.java,v 1.17 2001/10/08 21:04:26 shaper Exp $ // $Id: ViewerSceneViewPanel.java,v 1.18 2001/10/11 00:41:27 shaper Exp $
package com.threerings.miso.viewer; package com.threerings.miso.viewer;
@@ -26,7 +26,7 @@ public class ViewerSceneViewPanel extends SceneViewPanel
public ViewerSceneViewPanel ( public ViewerSceneViewPanel (
ViewerContext ctx, SpriteManager spritemgr, AmbulatorySprite sprite) ViewerContext ctx, SpriteManager spritemgr, AmbulatorySprite sprite)
{ {
super(ctx.getConfig(), ctx.getTileManager(), spritemgr); super(ctx.getConfig(), spritemgr);
_ctx = ctx; _ctx = ctx;
_sprite = sprite; _sprite = sprite;