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:
@@ -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;
|
||||
|
||||
@@ -10,11 +10,12 @@ import java.util.List;
|
||||
|
||||
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.miso.Log;
|
||||
import com.threerings.miso.scene.util.ClusterUtil;
|
||||
|
||||
import com.threerings.miso.tile.MisoTile;
|
||||
|
||||
/**
|
||||
@@ -24,71 +25,55 @@ import com.threerings.miso.tile.MisoTile;
|
||||
*/
|
||||
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
|
||||
* initialized to contain tiles of the specified default tileset and
|
||||
* tile id.
|
||||
*
|
||||
* @param model the iso scene view model.
|
||||
* @param tilemgr the tile manager.
|
||||
* @param deftsid the default tileset id.
|
||||
* @param deftid the default tile id.
|
||||
* @param deftile the default tile.
|
||||
*/
|
||||
public MisoSceneImpl (IsoSceneViewModel model, TileManager tilemgr,
|
||||
int deftsid, int deftid)
|
||||
public MisoSceneImpl (IsoSceneViewModel model, MisoTile deftile)
|
||||
{
|
||||
_model = model;
|
||||
_tilemgr = tilemgr;
|
||||
_deftile = deftile;
|
||||
|
||||
_sid = SID_INVALID;
|
||||
_name = DEF_SCENE_NAME;
|
||||
baseTiles = new MisoTile[_model.scenewid][_model.scenehei];
|
||||
fringeTiles = new Tile[_model.scenewid][_model.scenehei];
|
||||
objectTiles = new ObjectTile[_model.scenewid][_model.scenehei];
|
||||
tiles = new Tile[][][] { baseTiles, fringeTiles, objectTiles };
|
||||
|
||||
_locations = new ArrayList();
|
||||
_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;
|
||||
initBaseTiles();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public String getName ()
|
||||
{
|
||||
return _name;
|
||||
return name;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -109,10 +94,32 @@ public class MisoSceneImpl implements EditableMisoScene
|
||||
return null;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public MisoTile[][][] getTiles ()
|
||||
public Tile[][][] 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
|
||||
@@ -124,19 +131,19 @@ public class MisoSceneImpl implements EditableMisoScene
|
||||
// documentation inherited
|
||||
public List getLocations ()
|
||||
{
|
||||
return _locations;
|
||||
return locations;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public List getClusters ()
|
||||
{
|
||||
return _clusters;
|
||||
return clusters;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public List getPortals ()
|
||||
{
|
||||
return _portals;
|
||||
return portals;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -160,7 +167,7 @@ public class MisoSceneImpl implements EditableMisoScene
|
||||
// documentation inherited
|
||||
public void setName (String name)
|
||||
{
|
||||
_name = name;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -180,12 +187,12 @@ public class MisoSceneImpl implements EditableMisoScene
|
||||
public void updateLocation (Location loc, int clusteridx)
|
||||
{
|
||||
// add the location if it's not already present
|
||||
if (!_locations.contains(loc)) {
|
||||
_locations.add(loc);
|
||||
if (!locations.contains(loc)) {
|
||||
locations.add(loc);
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// 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 " +
|
||||
"[portal=" + portal + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
// 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
|
||||
// the portal list
|
||||
return;
|
||||
}
|
||||
|
||||
// remove from any possible cluster
|
||||
ClusterUtil.remove(_clusters, loc);
|
||||
ClusterUtil.remove(clusters, loc);
|
||||
|
||||
// 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 ()
|
||||
{
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("[name=").append(_name);
|
||||
buf.append("[name=").append(name);
|
||||
buf.append(", sid=").append(_sid);
|
||||
buf.append(", locations=").append(StringUtil.toString(_locations));
|
||||
buf.append(", clusters=").append(StringUtil.toString(_clusters));
|
||||
buf.append(", portals=").append(StringUtil.toString(_portals));
|
||||
buf.append(", locations=").append(StringUtil.toString(locations));
|
||||
buf.append(", clusters=").append(StringUtil.toString(clusters));
|
||||
buf.append(", portals=").append(StringUtil.toString(portals));
|
||||
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. */
|
||||
protected static final String DEF_SCENE_NAME = "Untitled Scene";
|
||||
|
||||
/** The scene name. */
|
||||
protected String _name;
|
||||
|
||||
/** The unique scene id. */
|
||||
protected int _sid;
|
||||
protected int _sid = SID_INVALID;
|
||||
|
||||
/** The scene version. */
|
||||
protected int _version;
|
||||
|
||||
/** The tiles comprising the scene. */
|
||||
public MisoTile[][][] _tiles;
|
||||
|
||||
/** The default entrance portal. */
|
||||
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. */
|
||||
protected MisoTile _deftile;
|
||||
|
||||
/** The iso scene view data 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;
|
||||
|
||||
@@ -12,7 +12,6 @@ import java.util.ArrayList;
|
||||
|
||||
import com.threerings.media.sprite.*;
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.media.tile.TileManager;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.scene.util.AStarPathUtil;
|
||||
@@ -28,14 +27,11 @@ public class IsoSceneView implements SceneView
|
||||
/**
|
||||
* Construct an <code>IsoSceneView</code> object.
|
||||
*
|
||||
* @param tilemgr the tile manager.
|
||||
* @param spritemgr the sprite manager.
|
||||
* @param model the data model.
|
||||
*/
|
||||
public IsoSceneView (TileManager tilemgr, SpriteManager spritemgr,
|
||||
IsoSceneViewModel model)
|
||||
public IsoSceneView (SpriteManager spritemgr, IsoSceneViewModel model)
|
||||
{
|
||||
_tilemgr = tilemgr;
|
||||
_spritemgr = spritemgr;
|
||||
|
||||
setModel(model);
|
||||
@@ -174,7 +170,9 @@ public class IsoSceneView implements SceneView
|
||||
for (int xx = 0; xx < _model.scenewid; xx++) {
|
||||
|
||||
// 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
|
||||
Polygon poly = _polys[xx][yy];
|
||||
@@ -183,15 +181,17 @@ public class IsoSceneView implements SceneView
|
||||
for (int kk = 0; kk < MisoScene.NUM_LAYERS; kk++) {
|
||||
|
||||
// get the tile at these coordinates and layer
|
||||
Tile tile = tiles[xx][yy][kk];
|
||||
if (tile == null) continue;
|
||||
Tile tile = tiles[kk][xx][yy];
|
||||
if (tile == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// offset the image y-position by the tile-specific height
|
||||
int ypos = poly.ypoints[0] - _model.tilehhei -
|
||||
(tile.height - _model.tilehei);
|
||||
|
||||
// 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
|
||||
@@ -204,7 +204,9 @@ public class IsoSceneView implements SceneView
|
||||
}
|
||||
|
||||
// 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++) {
|
||||
// grab the tile we're rendering
|
||||
Tile tile = tiles[tx][ty][kk];
|
||||
if (tile == null) continue;
|
||||
Tile tile = tiles[kk][tx][ty];
|
||||
if (tile == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Polygon poly = _polys[tx][ty];
|
||||
|
||||
// determine screen y-position, accounting for
|
||||
// tile image height
|
||||
int ypos = screenY - (tile.height - _model.tilehei);
|
||||
|
||||
// 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
|
||||
// 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
|
||||
@@ -505,7 +511,9 @@ public class IsoSceneView implements SceneView
|
||||
}
|
||||
|
||||
// do nothing if the tile's already dirty
|
||||
if (_dirty[x][y]) return;
|
||||
if (_dirty[x][y]) {
|
||||
return;
|
||||
}
|
||||
|
||||
// mark the tile dirty
|
||||
_numDirty++;
|
||||
@@ -543,7 +551,7 @@ public class IsoSceneView implements SceneView
|
||||
// get a reasonable path from start to end
|
||||
List tilepath =
|
||||
AStarPathUtil.getPath(
|
||||
_scene.getTiles(), _model.scenewid, _model.scenehei,
|
||||
_scene.getBaseLayer(), _model.scenewid, _model.scenehei,
|
||||
sprite, stpos.x, stpos.y, tbx, tby);
|
||||
if (tilepath == null) {
|
||||
return null;
|
||||
@@ -624,7 +632,4 @@ public class IsoSceneView implements SceneView
|
||||
|
||||
/** The sprite manager. */
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.media.tile.ObjectTile;
|
||||
import com.threerings.miso.tile.MisoTile;
|
||||
|
||||
/**
|
||||
@@ -40,38 +42,58 @@ public interface MisoScene
|
||||
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 ();
|
||||
|
||||
/**
|
||||
* Return the locations in this scene. The locations list should
|
||||
* contain all locations and portals in the scene. The list returned
|
||||
* by this method should <em>not</em> be modified.
|
||||
* Returns the locations in this scene. The locations list should
|
||||
* contain all locations and portals in the scene. The list
|
||||
* returned by this method should <em>not</em> be modified.
|
||||
*/
|
||||
public List getLocations ();
|
||||
|
||||
/**
|
||||
* Return the clusters in this scene. The clusters will reference all
|
||||
* of the locations that are clustered. The list returned by this
|
||||
* method should <em>not</em> be modified.
|
||||
* Returns the clusters in this scene. The clusters will reference
|
||||
* all of the locations that are clustered. The list returned by
|
||||
* this method should <em>not</em> be modified.
|
||||
*/
|
||||
public List getClusters ();
|
||||
|
||||
/**
|
||||
* Return the portals associated with this scene. Portals should never
|
||||
* be part of a cluster. The list returned by this method should
|
||||
* <em>not</em> be modified.
|
||||
* Returns the portals associated with this scene. Portals should
|
||||
* never be part of a cluster. The list returned by this method
|
||||
* should <em>not</em> be modified.
|
||||
*/
|
||||
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 ();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.List;
|
||||
|
||||
import com.threerings.media.sprite.DirtyRectList;
|
||||
import com.threerings.media.sprite.Path;
|
||||
import com.threerings.media.tile.Tile;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
@@ -9,7 +9,6 @@ import javax.swing.*;
|
||||
|
||||
import com.samskivert.util.Config;
|
||||
import com.threerings.media.sprite.*;
|
||||
import com.threerings.media.tile.TileManager;
|
||||
import com.threerings.miso.util.MisoUtil;
|
||||
|
||||
/**
|
||||
@@ -23,14 +22,13 @@ public class SceneViewPanel
|
||||
/**
|
||||
* Construct the panel and initialize it with a context.
|
||||
*/
|
||||
public SceneViewPanel (Config config, TileManager tilemgr,
|
||||
SpriteManager spritemgr)
|
||||
public SceneViewPanel (Config config, SpriteManager spritemgr)
|
||||
{
|
||||
// create the data model for the scene view
|
||||
_smodel = new IsoSceneViewModel(config);
|
||||
|
||||
// create the scene view
|
||||
_view = newSceneView(tilemgr, spritemgr, _smodel);
|
||||
_view = newSceneView(spritemgr, _smodel);
|
||||
|
||||
// set our attributes for optimal display performance
|
||||
setDoubleBuffered(false);
|
||||
@@ -41,9 +39,9 @@ public class SceneViewPanel
|
||||
* Constructs the underlying scene view implementation.
|
||||
*/
|
||||
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;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class AStarPathUtil
|
||||
* @return the list of points in the path.
|
||||
*/
|
||||
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)
|
||||
{
|
||||
AStarInfo info = new AStarInfo(tiles, tilewid, tilehei, trav, bx, by);
|
||||
@@ -109,8 +109,7 @@ public class AStarPathUtil
|
||||
}
|
||||
|
||||
// skip node if it's impassable
|
||||
// TODO: fix hard-coded consideration of only the base layer
|
||||
if (!info.trav.canTraverse(info.tiles[x][y][0])) {
|
||||
if (!info.trav.canTraverse(info.tiles[x][y])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -198,7 +197,7 @@ public class AStarPathUtil
|
||||
class AStarInfo
|
||||
{
|
||||
/** The array of tiles being traversed. */
|
||||
public MisoTile tiles[][][];
|
||||
public MisoTile tiles[][];
|
||||
|
||||
/** The tile array dimensions. */
|
||||
public int tilewid, tilehei;
|
||||
@@ -219,7 +218,7 @@ class AStarInfo
|
||||
public int destx, desty;
|
||||
|
||||
public AStarInfo (
|
||||
MisoTile tiles[][][], int tilewid, int tilehei, Traverser trav,
|
||||
MisoTile tiles[][], int tilewid, int tilehei, Traverser trav,
|
||||
int destx, int desty)
|
||||
{
|
||||
// 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;
|
||||
|
||||
@@ -15,6 +15,31 @@ public class MisoSceneUtil
|
||||
/** String translations of each tile layer name. */
|
||||
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
|
||||
* if no location is currently present at that location.
|
||||
@@ -74,4 +99,7 @@ public class MisoSceneUtil
|
||||
{
|
||||
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;
|
||||
|
||||
import com.threerings.media.tile.*;
|
||||
|
||||
import com.threerings.miso.scene.MisoScene;
|
||||
|
||||
/**
|
||||
* The miso tile set class extends the base tile set class to add
|
||||
* 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
|
||||
* com.threerings.miso.scene.MisoScene}.
|
||||
*/
|
||||
public class MisoTileSet extends TileSet
|
||||
public class MisoTileSet extends TileSetImpl
|
||||
{
|
||||
public MisoTileSet ()
|
||||
{
|
||||
_model = new MisoTileSetModel();
|
||||
}
|
||||
/** The miso scene layer the tiles are intended for. */
|
||||
public int layer;
|
||||
|
||||
/** Whether each tile is passable. */
|
||||
public int passable[];
|
||||
|
||||
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
|
||||
// tileset has no passability specified
|
||||
int passable[] = ((MisoTileSetModel)_model).passable;
|
||||
tile.passable = (passable == null || (passable[tid] == 1));
|
||||
|
||||
return tile;
|
||||
return new MisoTile(tsid, tid);
|
||||
}
|
||||
|
||||
protected static class MisoTileSetModel extends TileSetModel
|
||||
protected void populateTile (Tile tile)
|
||||
{
|
||||
/** Whether each tile is passable. */
|
||||
public int passable[];
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.threerings.media.sprite.MultiFrameImage;
|
||||
import com.threerings.media.sprite.Sprite;
|
||||
import com.threerings.media.tile.*;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.scene.AmbulatorySprite;
|
||||
|
||||
/**
|
||||
@@ -28,19 +29,27 @@ public class TileUtil
|
||||
*
|
||||
* @return the array of multi-frame sprite images.
|
||||
*/
|
||||
public static MultiFrameImage[] getAmbulatorySpriteFrames (
|
||||
TileManager tilemgr, int tsid)
|
||||
public static MultiFrameImage[]
|
||||
getAmbulatorySpriteFrames (TileManager tilemgr, int tsid)
|
||||
{
|
||||
MultiFrameImage[] anims = new MultiFrameImage[Sprite.NUM_DIRECTIONS];
|
||||
|
||||
for (int ii = 0; ii < Sprite.NUM_DIRECTIONS; ii++) {
|
||||
Tile[] tiles = new Tile[NUM_DIR_FRAMES];
|
||||
for (int jj = 0; jj < NUM_DIR_FRAMES; jj++) {
|
||||
int idx = (ii * NUM_DIR_FRAMES) + jj;
|
||||
tiles[jj] = tilemgr.getTile(tsid, idx);
|
||||
}
|
||||
anims[ii] = new MultiTileImage(tiles);
|
||||
}
|
||||
try {
|
||||
for (int ii = 0; ii < Sprite.NUM_DIRECTIONS; ii++) {
|
||||
Tile[] tiles = new Tile[NUM_DIR_FRAMES];
|
||||
for (int jj = 0; jj < NUM_DIR_FRAMES; jj++) {
|
||||
int idx = (ii * NUM_DIR_FRAMES) + jj;
|
||||
tiles[jj] = tilemgr.getTile(tsid, idx);
|
||||
}
|
||||
|
||||
anims[ii] = new MultiTileImage(tiles);
|
||||
}
|
||||
|
||||
} catch (TileException te) {
|
||||
Log.warning("Exception retrieving ambulatory sprite tiles " +
|
||||
"[te=" + te + "].");
|
||||
return null;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
import org.xml.sax.*;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.threerings.media.tile.*;
|
||||
import com.threerings.miso.scene.util.MisoSceneUtil;
|
||||
|
||||
/**
|
||||
* Extends the base XML tile set parser to construct {@link
|
||||
@@ -14,17 +16,30 @@ import com.threerings.media.tile.*;
|
||||
*/
|
||||
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)
|
||||
{
|
||||
super.finishElement(qName, str);
|
||||
|
||||
if (qName.equals("passable")) {
|
||||
((MisoTileSet.MisoTileSetModel)_model).passable =
|
||||
StringUtil.parseIntArray(str);
|
||||
((MisoTileSet)_tset).passable = StringUtil.parseIntArray(str);
|
||||
}
|
||||
}
|
||||
|
||||
protected TileSet createTileSet ()
|
||||
// documentation inherited
|
||||
protected TileSetImpl createTileSet ()
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import com.samskivert.util.*;
|
||||
import com.samskivert.xml.XMLUtil;
|
||||
|
||||
import com.threerings.media.tile.*;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
@@ -43,10 +44,7 @@ public class XMLSceneParser extends DefaultHandler
|
||||
|
||||
} else if (_tag.equals("row")) {
|
||||
_info.rownum = getInt(attributes.getValue("rownum"));
|
||||
|
||||
// get the column start value if present
|
||||
String strcs = attributes.getValue("colstart");
|
||||
if (strcs != null) _info.colstart = getInt(strcs);
|
||||
_info.colstart = getInt(attributes.getValue("colstart"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,11 +54,13 @@ public class XMLSceneParser extends DefaultHandler
|
||||
// for the elements we're tracking at this point, so proceed
|
||||
// with saving off element values for use when we construct
|
||||
// the scene object.
|
||||
String str = _chars.toString().trim();
|
||||
|
||||
if (qName.equals("name")) {
|
||||
_info.name = _chars.toString().trim();
|
||||
_info.scene.name = str;
|
||||
|
||||
} else if (qName.equals("version")) {
|
||||
int version = getInt(_chars.toString());
|
||||
int version = getInt(str);
|
||||
if (version < 0 || version > XMLSceneVersion.VERSION) {
|
||||
Log.warning(
|
||||
"Unrecognized scene file format version, will attempt " +
|
||||
@@ -70,27 +70,22 @@ public class XMLSceneParser extends DefaultHandler
|
||||
}
|
||||
|
||||
} else if (qName.equals("locations")) {
|
||||
int vals[] = StringUtil.parseIntArray(_chars.toString());
|
||||
_info.locations = toLocationsList(vals);
|
||||
int vals[] = StringUtil.parseIntArray(str);
|
||||
addLocations(_info.scene.locations, vals);
|
||||
|
||||
} else if (qName.equals("cluster")) {
|
||||
int vals[] = StringUtil.parseIntArray(_chars.toString());
|
||||
_info.clusters.add(toCluster(_info.locations, vals));
|
||||
int vals[] = StringUtil.parseIntArray(str);
|
||||
_info.scene.clusters.add(toCluster(_info.scene.locations, vals));
|
||||
|
||||
} else if (qName.equals("portals")) {
|
||||
String vals[] = StringUtil.parseStringArray(_chars.toString());
|
||||
_info.portals = toPortalList(_info.locations, vals);
|
||||
String vals[] = StringUtil.parseStringArray(str);
|
||||
addPortals(_info.scene.portals, _info.scene.locations, vals);
|
||||
|
||||
} else if (qName.equals("row")) {
|
||||
if (_info.lnum == MisoScene.LAYER_BASE) {
|
||||
readRowData(_info, _chars.toString());
|
||||
} else {
|
||||
readSparseRowData(_info, _chars.toString());
|
||||
}
|
||||
addTileRow(_info, str);
|
||||
|
||||
} else if (qName.equals("scene")) {
|
||||
// construct the scene object on tag close
|
||||
_info.constructScene(_tilemgr);
|
||||
// nothing for now
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
protected void readRowData (SceneInfo info, String data)
|
||||
throws TileException
|
||||
{
|
||||
int[] vals = StringUtil.parseIntArray(data);
|
||||
|
||||
@@ -133,9 +147,10 @@ public class XMLSceneParser extends DefaultHandler
|
||||
}
|
||||
|
||||
// create the tile objects in the tile array
|
||||
Tile[][] tiles = info.scene.getTiles(info.lnum);
|
||||
for (int xx = 0; xx < vals.length; xx += 2) {
|
||||
MisoTile tile = (MisoTile)_tilemgr.getTile(vals[xx], vals[xx + 1]);
|
||||
info.tiles[xx / 2][info.rownum][info.lnum] = tile;
|
||||
Tile tile = _tilemgr.getTile(vals[xx], vals[xx + 1]);
|
||||
tiles[xx / 2][info.rownum] = tile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,6 +166,7 @@ public class XMLSceneParser extends DefaultHandler
|
||||
* @param data the tile data.
|
||||
*/
|
||||
protected void readSparseRowData (SceneInfo info, String data)
|
||||
throws TileException
|
||||
{
|
||||
int[] vals = StringUtil.parseIntArray(data);
|
||||
|
||||
@@ -164,10 +180,11 @@ public class XMLSceneParser extends DefaultHandler
|
||||
}
|
||||
|
||||
// create the tile objects in the tile array
|
||||
Tile[][] tiles = info.scene.getTiles(info.lnum);
|
||||
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);
|
||||
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
|
||||
* <code>Location</code> objects represented therein, constructed
|
||||
* from each successive triplet of values as (x, y, orientation)
|
||||
* in the integer array.
|
||||
* Given an array of integer values, add the <code>Location</code>
|
||||
* objects represented therein to the given list, constructed from
|
||||
* each successive triplet of values as (x, y, orientation) in the
|
||||
* integer array.
|
||||
*
|
||||
* @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
|
||||
if ((vals.length % 3) != 0) return null;
|
||||
if ((vals.length % 3) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// read in all of the locations and add to the list
|
||||
ArrayList list = new ArrayList();
|
||||
for (int ii = 0; ii < vals.length; ii += 3) {
|
||||
Location loc = new Location(
|
||||
vals[ii], vals[ii+1], vals[ii+2]);
|
||||
list.add(loc);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array of string values, return a list of
|
||||
* <code>Portal</code> objects constructed from each successive
|
||||
* triplet of values as (locidx, portal name) in the array. The
|
||||
* list of <code>Location</code> objects must have already been
|
||||
* fully read previously.
|
||||
* Given an array of string values, add the <code>Portal</code>
|
||||
* objects constructed from each successive triplet of values as
|
||||
* (locidx, portal name) in the array to the given portal list.
|
||||
* The list of <code>Location</code> objects must have already
|
||||
* been fully read previously.
|
||||
*
|
||||
* <p> This is something of a hack since we perhaps ought to parse
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* @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
|
||||
if ((vals.length % 2) != 0) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
// read in all of the portals
|
||||
ArrayList portals = new ArrayList();
|
||||
for (int ii = 0; ii < vals.length; ii += 2) {
|
||||
int locidx = getInt(vals[ii]);
|
||||
|
||||
@@ -253,8 +266,6 @@ public class XMLSceneParser extends DefaultHandler
|
||||
// upgrade the corresponding location in the location list
|
||||
locs.set(locidx, portal);
|
||||
}
|
||||
|
||||
return portals;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,7 +275,7 @@ public class XMLSceneParser extends DefaultHandler
|
||||
protected int getInt (String str)
|
||||
{
|
||||
try {
|
||||
return Integer.parseInt(str);
|
||||
return (str == null) ? -1 : Integer.parseInt(str);
|
||||
} catch (NumberFormatException nfe) {
|
||||
Log.warning("Malformed integer value [str=" + str + "].");
|
||||
return -1;
|
||||
@@ -329,25 +340,16 @@ public class XMLSceneParser extends DefaultHandler
|
||||
/** Temporary storage of scene info while parsing. */
|
||||
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
|
||||
{
|
||||
/** The scene name. */
|
||||
public String name;
|
||||
|
||||
/** 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 scene populated with data while parsing. */
|
||||
public MisoSceneImpl scene;
|
||||
|
||||
/** The current layer number being processed. */
|
||||
public int lnum;
|
||||
@@ -358,20 +360,9 @@ public class XMLSceneParser extends DefaultHandler
|
||||
/** The column at which the current row data begins. */
|
||||
public int colstart;
|
||||
|
||||
/** The scene object constructed once all scene info is parsed. */
|
||||
public EditableMisoScene scene;
|
||||
|
||||
public SceneInfo ()
|
||||
{
|
||||
int width = _model.scenewid, height = _model.scenehei;
|
||||
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);
|
||||
scene = new MisoSceneImpl(_model, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -211,7 +211,7 @@ public class XMLSceneWriter extends DataWriter
|
||||
|
||||
int numtiles = colstart + len;
|
||||
for (int ii = colstart; ii < numtiles; ii++) {
|
||||
Tile tile = tiles[ii][rownum][lnum];
|
||||
Tile tile = tiles[lnum][ii][rownum];
|
||||
if (tile == null) {
|
||||
Log.warning("Null tile [x=" + ii + ", rownum=" + rownum +
|
||||
", lnum=" + lnum + "].");
|
||||
@@ -277,7 +277,7 @@ public class XMLSceneWriter extends DataWriter
|
||||
Tile[][][] tiles = scene.getTiles();
|
||||
int start = -1, len = 0;
|
||||
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 (start == -1) {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user