Oh the vast sweeping changes, and they're not even close to complete, but
things compile and most things run so this is a good time to checkpoint. Let me recall: - Refactored the whole scene deal. - Revamped the XML parser stuff (now uses Digester). - Rethought the tile management. - Started tile bundle stuff. - Wrote some tests. - Did a bit of Mike-ification. Onward and moreward. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@621 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
//
|
||||
// $Id: Cluster.java,v 1.3 2001/09/28 01:24:54 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
/**
|
||||
* A <code>Cluster</code> is a gathering of <code>Location</code> objects
|
||||
* that represent a logical grouping for the purposes of display and
|
||||
* interaction in a scene.
|
||||
*
|
||||
* <p> This class is currently just a wrapper around an
|
||||
* <code>ArrayList</code>, but the theory is that we may soon want
|
||||
* more useful functionality encapsulated herein, and the
|
||||
* <code>Cluster</code> nomenclature is useful in any case.
|
||||
*/
|
||||
public class Cluster
|
||||
{
|
||||
/**
|
||||
* Construct a <code>Cluster</code> object.
|
||||
*/
|
||||
public Cluster ()
|
||||
{
|
||||
_locations = new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a location to the cluster.
|
||||
*
|
||||
* @param loc the location.
|
||||
*/
|
||||
public void add (Location loc)
|
||||
{
|
||||
_locations.add(loc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the cluster contains the given location.
|
||||
*
|
||||
* @param loc the location.
|
||||
*/
|
||||
public boolean contains (Location loc)
|
||||
{
|
||||
return _locations.contains(loc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the location from the cluster if present, and returns true
|
||||
* if the location was present, false if not.
|
||||
*
|
||||
* @param loc the location.
|
||||
*/
|
||||
public boolean remove (Location loc)
|
||||
{
|
||||
return _locations.remove(loc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of locations in the cluster.
|
||||
*/
|
||||
public int size ()
|
||||
{
|
||||
return _locations.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of locations that the cluster is made up of.
|
||||
*/
|
||||
public List getLocations ()
|
||||
{
|
||||
return _locations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of this object.
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
return StringUtil.toString(_locations);
|
||||
}
|
||||
|
||||
/** The list of locations in this cluster. */
|
||||
protected ArrayList _locations;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DirtyItemList.java,v 1.5 2001/10/30 16:16:01 shaper Exp $
|
||||
// $Id: DirtyItemList.java,v 1.6 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -93,8 +93,8 @@ public class DirtyItemList extends ArrayList
|
||||
ly = ry = oy;
|
||||
if (obj instanceof ObjectTile) {
|
||||
ObjectTile tile = (ObjectTile)obj;
|
||||
lx -= (tile.baseWidth - 1);
|
||||
ry -= (tile.baseHeight - 1);
|
||||
lx -= (tile.getBaseWidth() - 1);
|
||||
ry -= (tile.getBaseHeight() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// $Id: DisplayMisoScene.java,v 1.1 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import com.threerings.media.tile.ObjectTileLayer;
|
||||
import com.threerings.media.tile.TileLayer;
|
||||
import com.threerings.miso.tile.MisoTileLayer;
|
||||
|
||||
/**
|
||||
* Makes available the information from the {@link MisoSceneModel} in a
|
||||
* form that is amenable to actually displaying the scene in a user
|
||||
* interface. As with all display scene implementations, the information
|
||||
* provided is read-only and should never be modified by the caller.
|
||||
*/
|
||||
public interface DisplayMisoScene
|
||||
{
|
||||
/**
|
||||
* Returns the tiles that comprise the base layer of this scene. This
|
||||
* layer is read-only and not to be modified.
|
||||
*/
|
||||
public MisoTileLayer getBaseLayer ();
|
||||
|
||||
/**
|
||||
* Returns the tiles that comprise the fringe layer of this scene.
|
||||
* This layer is read-only and not to be modified.
|
||||
*/
|
||||
public TileLayer getFringeLayer ();
|
||||
|
||||
/**
|
||||
* Returns the tiles that comprise the object layer of this scene.
|
||||
* This layer is read-only and not to be modified.
|
||||
*/
|
||||
public ObjectTileLayer getObjectLayer ();
|
||||
}
|
||||
@@ -1,283 +1,121 @@
|
||||
//
|
||||
// $Id: DisplayMisoSceneImpl.java,v 1.43 2001/11/12 20:56:55 mdb Exp $
|
||||
// $Id: DisplayMisoSceneImpl.java,v 1.44 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.media.tile.*;
|
||||
import com.threerings.media.tile.NoSuchTileException;
|
||||
import com.threerings.media.tile.NoSuchTileSetException;
|
||||
import com.threerings.media.tile.ObjectTile;
|
||||
import com.threerings.media.tile.ObjectTileLayer;
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.media.tile.TileLayer;
|
||||
import com.threerings.media.tile.TileManager;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.scene.util.ClusterUtil;
|
||||
import com.threerings.miso.tile.MisoTile;
|
||||
import com.threerings.miso.tile.MisoTileLayer;
|
||||
import com.threerings.miso.tile.ShadowTile;
|
||||
|
||||
/**
|
||||
* A scene object represents the data model corresponding to a single
|
||||
* screen for game play. For instance, one scene might display a portion
|
||||
* of a street with several buildings scattered about on the periphery.
|
||||
* The default implementation of the {@link DisplayMisoScene} interface.
|
||||
*/
|
||||
public class MisoSceneImpl implements EditableMisoScene
|
||||
public class DisplayMisoSceneImpl
|
||||
implements DisplayMisoScene
|
||||
{
|
||||
/** 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 default entrance portal. */
|
||||
public Portal entrance;
|
||||
|
||||
/** 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.
|
||||
* Constructs an instance that will be used to display the supplied
|
||||
* miso scene data. The tiles identified by the scene model will be
|
||||
* loaded via the supplied tile manager.
|
||||
*
|
||||
* <em>Note:</em> Be sure to call {@link
|
||||
* #generateAllObjectShadows} before the scene is first used so
|
||||
* that the base layer will be properly populated with shadow
|
||||
* tiles in the footprint of all object tiles.
|
||||
* @param model the scene data that we'll be displaying.
|
||||
* @param tmgr the tile manager from which to load our tiles.
|
||||
*
|
||||
* @param model the iso scene view model.
|
||||
* @param deftile the default tile.
|
||||
* @exception NoSuchTileException thrown if the model references a
|
||||
* tile which is not available via the supplied tile manager.
|
||||
*/
|
||||
public MisoSceneImpl (IsoSceneViewModel model, MisoTile deftile)
|
||||
public DisplayMisoSceneImpl (MisoSceneModel model, TileManager tmgr)
|
||||
throws NoSuchTileException, NoSuchTileSetException
|
||||
{
|
||||
_model = model;
|
||||
_deftile = deftile;
|
||||
int swid = model.width;
|
||||
int shei = model.height;
|
||||
|
||||
// create the individual tile layer arrays
|
||||
baseTiles = new MisoTile[_model.scenewid][_model.scenehei];
|
||||
fringeTiles = new Tile[_model.scenewid][_model.scenehei];
|
||||
objectTiles = new ObjectTile[_model.scenewid][_model.scenehei];
|
||||
// create the individual tile layer objects
|
||||
_base = new MisoTileLayer(new MisoTile[swid*shei], swid, shei);
|
||||
_fringe = new TileLayer(new Tile[swid*shei], swid, shei);
|
||||
_object = new ObjectTileLayer(new ObjectTile[swid*shei], swid, shei);
|
||||
|
||||
// create the conjoined array for purely utilitarian purposes
|
||||
tiles = new Tile[][][] { baseTiles, fringeTiles, objectTiles };
|
||||
// populate the base and fringe layers
|
||||
for (int column = 0; column < shei; column++) {
|
||||
for (int row = 0; row < swid; row++) {
|
||||
// first do the base layer
|
||||
int tsid = model.baseTileIds[swid*row+column];
|
||||
if (tsid > 0) {
|
||||
int tid = (tsid & 0xFFFF);
|
||||
tsid >>= 16;
|
||||
// this is a bit magical, but the tile manager will
|
||||
// fetch tiles from the tileset repository and the
|
||||
// tile set id from which we request this tile must
|
||||
// map to a miso tile as provided by the repository,
|
||||
// so we just cast it to a miso tile and know that all
|
||||
// is well
|
||||
MisoTile mtile = (MisoTile)tmgr.getTile(tsid, tid);
|
||||
_base.setTile(column, row, mtile);
|
||||
}
|
||||
|
||||
// initialize the always-fully-populated base layer
|
||||
initBaseTiles();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public String getName ()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void setDefaultTile (MisoTile tile)
|
||||
{
|
||||
_deftile = tile;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void setTile (int lnum, int x, int y, Tile tile)
|
||||
{
|
||||
// if the tile being replaced is an object tile, clear out its
|
||||
// shadow tiles
|
||||
Tile otile = tiles[lnum][x][y];
|
||||
if (otile instanceof ObjectTile) {
|
||||
removeObjectShadow(x, y);
|
||||
// then the fringe layer
|
||||
tsid = model.fringeTileIds[swid*row+column];
|
||||
if (tsid > 0) {
|
||||
int tid = (tsid & 0xFFFF);
|
||||
tsid >>= 16;
|
||||
Tile tile = tmgr.getTile(tsid, tid);
|
||||
_fringe.setTile(column, row, tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// place the new tile
|
||||
tiles[lnum][x][y] = tile;
|
||||
// sanity check the object layer info
|
||||
int ocount = model.objectTileIds.length;
|
||||
if (ocount % 3 != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"model.objectTileIds.length % 3 != 0");
|
||||
}
|
||||
|
||||
// if the tile being placed is an object tile, create the
|
||||
// shadow tiles that lie in its footprint
|
||||
if (tile instanceof ObjectTile) {
|
||||
generateObjectShadow(x, y);
|
||||
// now populate the object layer
|
||||
for (int i = 0; i < ocount; i+= 3) {
|
||||
int row = model.objectTileIds[i];
|
||||
int col = model.objectTileIds[i+1];
|
||||
int tsid = model.objectTileIds[i+2];
|
||||
int tid = (tsid & 0xFFFF);
|
||||
tsid >>= 16;
|
||||
|
||||
// create the object tile and stick it into the appropriate
|
||||
// spot in the object layer
|
||||
ObjectTile otile = (ObjectTile)tmgr.getTile(tsid, tid);
|
||||
_object.setTile(col, row, otile);
|
||||
|
||||
// we have to generate a shadow for this object tile in the
|
||||
// base layer so that we can prevent sprites from walking on
|
||||
// the object
|
||||
generateObjectShadow(row, col);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public int getId ()
|
||||
public MisoTileLayer getBaseLayer ()
|
||||
{
|
||||
return _sid;
|
||||
return _base;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public int getVersion ()
|
||||
public TileLayer getFringeLayer ()
|
||||
{
|
||||
return _version;
|
||||
return _fringe;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public int[] getNeighborIds ()
|
||||
public ObjectTileLayer getObjectLayer ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Tile[][][] getTiles ()
|
||||
{
|
||||
return tiles;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
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
|
||||
public MisoTile getDefaultTile ()
|
||||
{
|
||||
return _deftile;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public List getLocations ()
|
||||
{
|
||||
return locations;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public List getClusters ()
|
||||
{
|
||||
return clusters;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public List getPortals ()
|
||||
{
|
||||
return portals;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Portal getEntrance ()
|
||||
{
|
||||
return entrance;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void setId (int sceneId)
|
||||
{
|
||||
_sid = sceneId;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void setVersion (int version)
|
||||
{
|
||||
_version = version;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void setName (String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void setEntrance (Portal entrance)
|
||||
{
|
||||
this.entrance = entrance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified location in the scene. If the cluster
|
||||
* index number is -1, the location will be removed from any
|
||||
* cluster it may reside in.
|
||||
*
|
||||
* @param loc the location.
|
||||
* @param clusteridx the cluster index number.
|
||||
*/
|
||||
public void updateLocation (Location loc, int clusteridx)
|
||||
{
|
||||
// add the location if it's not already present
|
||||
if (!locations.contains(loc)) {
|
||||
locations.add(loc);
|
||||
}
|
||||
|
||||
// update the cluster contents
|
||||
ClusterUtil.regroup(clusters, loc, clusteridx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the specified portal to the scene. Adds the portal to the
|
||||
* location list as well if it's not already present and removes
|
||||
* it from any cluster it may reside in.
|
||||
*
|
||||
* @param portal the portal.
|
||||
*/
|
||||
public void addPortal (Portal portal)
|
||||
{
|
||||
// make sure it's in the location list and absent from any cluster
|
||||
updateLocation(portal, -1);
|
||||
|
||||
// don't allow adding a portal more than once
|
||||
if (portals.contains(portal)) {
|
||||
Log.warning("Attempt to add already-existing portal " +
|
||||
"[portal=" + portal + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// add it to the list
|
||||
portals.add(portal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given location object from the location list, and from
|
||||
* any containing cluster. If the location is a portal, it is removed
|
||||
* from the portal list as well.
|
||||
*
|
||||
* @param loc the location object.
|
||||
*/
|
||||
public void removeLocation (Location loc)
|
||||
{
|
||||
// remove from the location list
|
||||
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);
|
||||
|
||||
// remove from any possible existence on the portal list
|
||||
portals.remove(loc);
|
||||
return _object;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,47 +124,15 @@ public class MisoSceneImpl implements EditableMisoScene
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer buf = new StringBuffer();
|
||||
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("[width=").append(_base.getWidth());
|
||||
buf.append(", height=").append(_base.getHeight());
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Place shadow tiles in the footprint of all object tiles in the
|
||||
* scene. This method should be called once the scene tiles are
|
||||
* fully populated, but before the scene is used in any other
|
||||
* meaningful capacity.
|
||||
*/
|
||||
public void generateAllObjectShadows ()
|
||||
{
|
||||
for (int xx = 0; xx < _model.scenewid; xx++) {
|
||||
for (int yy = 0; yy < _model.scenehei; yy++) {
|
||||
if (objectTiles[xx][yy] != null) {
|
||||
generateObjectShadow(xx, yy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Place shadow tiles in the footprint of the object tile at the
|
||||
* given coordinates in the scene. This method should be called
|
||||
* when an object tile is added to the scene.
|
||||
* Place shadow tiles in the footprint of the object tile at the given
|
||||
* coordinates in the scene. This method should be called when an
|
||||
* object tile is added to the scene.
|
||||
*
|
||||
* @param x the tile x-coordinate.
|
||||
* @param y the tile y-coordinate.
|
||||
@@ -336,19 +142,6 @@ public class MisoSceneImpl implements EditableMisoScene
|
||||
setObjectTileFootprint(x, y, new ShadowTile(x, y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove shadow tiles from the footprint of the object tile at
|
||||
* the given coordinates in the scene. This method should be
|
||||
* called when an object tile is removed from the scene.
|
||||
*
|
||||
* @param x the tile x-coordinate.
|
||||
* @param y the tile y-coordinate.
|
||||
*/
|
||||
protected void removeObjectShadow (int x, int y)
|
||||
{
|
||||
setObjectTileFootprint(x, y, _deftile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Place the given tile in the footprint of the object tile at the
|
||||
* given coordinates in the scene.
|
||||
@@ -359,30 +152,23 @@ public class MisoSceneImpl implements EditableMisoScene
|
||||
*/
|
||||
protected void setObjectTileFootprint (int x, int y, MisoTile stamp)
|
||||
{
|
||||
ObjectTile tile = objectTiles[x][y];
|
||||
|
||||
int endx = Math.max(0, (x - tile.baseWidth + 1));
|
||||
int endy = Math.max(0, (y - tile.baseHeight + 1));
|
||||
ObjectTile tile = _object.getTile(y, x);
|
||||
int endx = Math.max(0, (x - tile.getBaseWidth() + 1));
|
||||
int endy = Math.max(0, (y - tile.getBaseHeight() + 1));
|
||||
|
||||
for (int xx = x; xx >= endx; xx--) {
|
||||
for (int yy = y; yy >= endy; yy--) {
|
||||
baseTiles[xx][yy] = stamp;
|
||||
_base.setTile(yy, xx, stamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The default scene name. */
|
||||
protected static final String DEF_SCENE_NAME = "Untitled Scene";
|
||||
/** The base layer of tiles. */
|
||||
protected MisoTileLayer _base;
|
||||
|
||||
/** The unique scene id. */
|
||||
protected int _sid = SID_INVALID;
|
||||
/** The fringe layer of tiles. */
|
||||
protected TileLayer _fringe;
|
||||
|
||||
/** The scene version. */
|
||||
protected int _version;
|
||||
|
||||
/** The default tile for the base layer in the scene. */
|
||||
protected MisoTile _deftile;
|
||||
|
||||
/** The iso scene view data model. */
|
||||
protected IsoSceneViewModel _model;
|
||||
/** The object layer of tiles. */
|
||||
protected ObjectTileLayer _object;
|
||||
}
|
||||
|
||||
@@ -1,24 +1,40 @@
|
||||
//
|
||||
// $Id: IsoSceneView.java,v 1.71 2001/10/27 01:37:37 shaper Exp $
|
||||
// $Id: IsoSceneView.java,v 1.72 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Point;
|
||||
import java.awt.Font;
|
||||
import java.awt.BasicStroke;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import com.samskivert.util.HashIntMap;
|
||||
|
||||
import com.threerings.media.sprite.*;
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.media.sprite.DirtyRectList;
|
||||
import com.threerings.media.sprite.Path;
|
||||
import com.threerings.media.sprite.SpriteManager;
|
||||
|
||||
import com.threerings.media.tile.ObjectTile;
|
||||
import com.threerings.media.tile.ObjectTileLayer;
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.media.tile.TileLayer;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.scene.DirtyItemList.DirtyItem;
|
||||
import com.threerings.miso.scene.util.*;
|
||||
import com.threerings.miso.scene.util.AStarPathUtil;
|
||||
import com.threerings.miso.scene.util.IsoUtil;
|
||||
import com.threerings.miso.tile.MisoTileLayer;
|
||||
|
||||
/**
|
||||
* The iso scene view provides an isometric view of a particular
|
||||
@@ -54,7 +70,7 @@ public class IsoSceneView implements SceneView
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void setScene (MisoScene scene)
|
||||
public void setScene (DisplayMisoScene scene)
|
||||
{
|
||||
_scene = scene;
|
||||
|
||||
@@ -106,11 +122,6 @@ public class IsoSceneView implements SceneView
|
||||
_spritemgr.renderSpritePaths(gfx);
|
||||
}
|
||||
|
||||
// draw marks at each location
|
||||
if (_model.showLocs) {
|
||||
paintLocations(gfx);
|
||||
}
|
||||
|
||||
// paint any extra goodies
|
||||
paintExtras(gfx);
|
||||
|
||||
@@ -145,8 +156,7 @@ public class IsoSceneView implements SceneView
|
||||
{
|
||||
_dirtyRects.clear();
|
||||
_dirtyItems.clear();
|
||||
|
||||
_numDirty = 0;
|
||||
_numDirty = 0;
|
||||
for (int xx = 0; xx < _model.scenewid; xx++) {
|
||||
for (int yy = 0; yy < _model.scenehei; yy++) {
|
||||
_dirty[xx][yy] = false;
|
||||
@@ -207,25 +217,23 @@ public class IsoSceneView implements SceneView
|
||||
*/
|
||||
protected void renderTiles (Graphics2D gfx)
|
||||
{
|
||||
Tile[][][] tiles = _scene.getTiles();
|
||||
MisoTileLayer base = _scene.getBaseLayer();
|
||||
TileLayer fringe = _scene.getFringeLayer();
|
||||
|
||||
// render the base and fringe layers
|
||||
for (int yy = 0; yy < _model.scenehei; yy++) {
|
||||
for (int xx = 0; xx < _model.scenewid; xx++) {
|
||||
if (_dirty[xx][yy]) {
|
||||
|
||||
// draw both layers at this tile position
|
||||
for (int kk = MisoScene.LAYER_BASE;
|
||||
kk <= MisoScene.LAYER_FRINGE; kk++) {
|
||||
|
||||
// get the tile at these coordinates and layer
|
||||
Tile tile = tiles[kk][xx][yy];
|
||||
if (tile != null) {
|
||||
// draw the tile image
|
||||
tile.paint(gfx, _polys[xx][yy]);
|
||||
}
|
||||
}
|
||||
for (int yy = 0; yy < base.getHeight(); yy++) {
|
||||
for (int xx = 0; xx < base.getWidth(); xx++) {
|
||||
if (!_dirty[xx][yy]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// draw the base and fringe tile images
|
||||
Tile tile;
|
||||
if ((tile = base.getTile(yy, xx)) != null) {
|
||||
tile.paint(gfx, _polys[xx][yy]);
|
||||
}
|
||||
if ((tile = fringe.getTile(yy, xx)) != null) {
|
||||
tile.paint(gfx, _polys[xx][yy]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -251,8 +259,8 @@ public class IsoSceneView implements SceneView
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates and stores bounding polygons for all object tiles in
|
||||
* the scene for later use while rendering.
|
||||
* Generates and stores bounding polygons for all object tiles in the
|
||||
* scene for later use while rendering.
|
||||
*/
|
||||
protected void initAllObjectBounds ()
|
||||
{
|
||||
@@ -260,10 +268,10 @@ public class IsoSceneView implements SceneView
|
||||
_objpolys.clear();
|
||||
|
||||
// generate bounding polygons for all objects
|
||||
ObjectTile[][] tiles = _scene.getObjectLayer();
|
||||
for (int xx = 0; xx < _model.scenewid; xx++) {
|
||||
for (int yy = 0; yy < _model.scenehei; yy++) {
|
||||
ObjectTile tile = tiles[xx][yy];
|
||||
ObjectTileLayer tiles = _scene.getObjectLayer();
|
||||
for (int yy = 0; yy < tiles.getHeight(); yy++) {
|
||||
for (int xx = 0; xx < tiles.getWidth(); xx++) {
|
||||
ObjectTile tile = tiles.getTile(yy, xx);
|
||||
if (tile != null) {
|
||||
generateObjectBounds(tile, xx, yy);
|
||||
}
|
||||
@@ -343,47 +351,47 @@ public class IsoSceneView implements SceneView
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint demarcations at all locations in the scene, with each
|
||||
* location's cluster index, if any, along the right side of its
|
||||
* rectangle.
|
||||
*
|
||||
* @param gfx the graphics context.
|
||||
*/
|
||||
protected void paintLocations (Graphics2D gfx)
|
||||
{
|
||||
List locations = _scene.getLocations();
|
||||
int size = locations.size();
|
||||
// /**
|
||||
// * Paint demarcations at all locations in the scene, with each
|
||||
// * location's cluster index, if any, along the right side of its
|
||||
// * rectangle.
|
||||
// *
|
||||
// * @param gfx the graphics context.
|
||||
// */
|
||||
// protected void paintLocations (Graphics2D gfx)
|
||||
// {
|
||||
// List locations = _scene.getLocations();
|
||||
// int size = locations.size();
|
||||
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
// retrieve the location
|
||||
Location loc = (Location)locations.get(ii);
|
||||
// for (int ii = 0; ii < size; ii++) {
|
||||
// // retrieve the location
|
||||
// Location loc = (Location)locations.get(ii);
|
||||
|
||||
// get the cluster index this location is in, if any
|
||||
int clusteridx = MisoSceneUtil.getClusterIndex(_scene, loc);
|
||||
// // get the cluster index this location is in, if any
|
||||
// int clusteridx = MisoSceneUtil.getClusterIndex(_scene, loc);
|
||||
|
||||
// get the location's center coordinate
|
||||
Point spos = new Point();
|
||||
IsoUtil.fullToScreen(_model, loc.x, loc.y, spos);
|
||||
int cx = spos.x, cy = spos.y;
|
||||
// // get the location's center coordinate
|
||||
// Point spos = new Point();
|
||||
// IsoUtil.fullToScreen(_model, loc.x, loc.y, spos);
|
||||
// int cx = spos.x, cy = spos.y;
|
||||
|
||||
// paint the location
|
||||
loc.paint(gfx, cx, cy);
|
||||
// // paint the location
|
||||
// loc.paint(gfx, cx, cy);
|
||||
|
||||
if (clusteridx != -1) {
|
||||
// draw the cluster index number on the right side
|
||||
gfx.setFont(_font);
|
||||
gfx.setColor(Color.white);
|
||||
gfx.drawString(String.valueOf(clusteridx), cx + 5, cy + 3);
|
||||
}
|
||||
// if (clusteridx != -1) {
|
||||
// // draw the cluster index number on the right side
|
||||
// gfx.setFont(_font);
|
||||
// gfx.setColor(Color.white);
|
||||
// gfx.drawString(String.valueOf(clusteridx), cx + 5, cy + 3);
|
||||
// }
|
||||
|
||||
// highlight the location if it's the default entrance
|
||||
if (_scene.getEntrance() == loc) {
|
||||
gfx.setColor(Color.cyan);
|
||||
gfx.drawRect(spos.x - 5, spos.y - 5, 10, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
// // highlight the location if it's the default entrance
|
||||
// if (_scene.getEntrance() == loc) {
|
||||
// gfx.setColor(Color.cyan);
|
||||
// gfx.drawRect(spos.x - 5, spos.y - 5, 10, 10);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// documentation inherited
|
||||
public void invalidateRects (DirtyRectList rects)
|
||||
@@ -555,7 +563,7 @@ public class IsoSceneView implements SceneView
|
||||
}
|
||||
|
||||
// add any objects impacted by the dirty rectangle
|
||||
ObjectTile tiles[][] = _scene.getObjectLayer();
|
||||
ObjectTileLayer tiles = _scene.getObjectLayer();
|
||||
Iterator iter = _objpolys.keys();
|
||||
while (iter.hasNext()) {
|
||||
// get the object's coordinates and bounding polygon
|
||||
@@ -563,13 +571,11 @@ public class IsoSceneView implements SceneView
|
||||
Polygon poly = (Polygon)_objpolys.get(coord);
|
||||
|
||||
if (poly.intersects(r)) {
|
||||
|
||||
// get the dirty portion of the object
|
||||
Rectangle drect = poly.getBounds().intersection(r);
|
||||
|
||||
int tx = coord >> 16, ty = coord & 0x0000FFFF;
|
||||
_dirtyItems.appendDirtyObject(
|
||||
tiles[tx][ty], poly, tx, ty, drect);
|
||||
tiles.getTile(ty, tx), poly, tx, ty, drect);
|
||||
// Log.info("Dirtied item: Object(" + tx + ", " +
|
||||
// ty + ")");
|
||||
}
|
||||
@@ -628,8 +634,8 @@ public class IsoSceneView implements SceneView
|
||||
/** The scene view model data. */
|
||||
protected IsoSceneViewModel _model;
|
||||
|
||||
/** The scene object to be displayed. */
|
||||
protected MisoScene _scene;
|
||||
/** The scene to be displayed. */
|
||||
protected DisplayMisoScene _scene;
|
||||
|
||||
/** The sprite manager. */
|
||||
protected SpriteManager _spritemgr;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
//
|
||||
// $Id: IsoSceneViewModel.java,v 1.17 2001/10/22 23:55:14 mdb Exp $
|
||||
// $Id: IsoSceneViewModel.java,v 1.18 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.util.Config;
|
||||
@@ -14,9 +14,8 @@ import com.threerings.miso.scene.util.IsoUtil;
|
||||
import com.threerings.miso.util.MisoUtil;
|
||||
|
||||
/**
|
||||
* The iso scene view model provides a holding place for the myriad
|
||||
* parameters and bits of data that describe the details of an isometric
|
||||
* view of a scene.
|
||||
* Provides a holding place for the myriad parameters and bits of data
|
||||
* that describe the details of an isometric view of a scene.
|
||||
*
|
||||
* <p> The member data are public to facilitate speedy referencing by the
|
||||
* {@link IsoSceneView} class. The model should only be modified through
|
||||
@@ -56,7 +55,7 @@ public class IsoSceneViewModel
|
||||
public float slopeX, slopeY;
|
||||
|
||||
/** The x-axis line. */
|
||||
public Point lineX[];
|
||||
public Point[] lineX;
|
||||
|
||||
/** The length between fine coordinates in pixels. */
|
||||
public float finelen;
|
||||
@@ -70,9 +69,6 @@ public class IsoSceneViewModel
|
||||
/** Whether tile coordinates should be drawn. */
|
||||
public boolean showCoords;
|
||||
|
||||
/** Whether locations in the scene should be drawn. */
|
||||
public boolean showLocs;
|
||||
|
||||
/** Whether sprite paths should be drawn. */
|
||||
public boolean showPaths;
|
||||
|
||||
@@ -106,7 +102,6 @@ public class IsoSceneViewModel
|
||||
|
||||
// set our various flags
|
||||
showCoords = config.getValue(SHOW_COORDS_KEY, DEF_SHOW_COORDS);
|
||||
showLocs = config.getValue(SHOW_COORDS_KEY, DEF_SHOW_COORDS);
|
||||
showPaths = config.getValue(SHOW_PATHS_KEY, DEF_SHOW_PATHS);
|
||||
}
|
||||
|
||||
@@ -158,15 +153,6 @@ public class IsoSceneViewModel
|
||||
fy >= 0 && fy < finegran);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle whether locations in the scene should be drawn.
|
||||
*/
|
||||
public void toggleShowLocations ()
|
||||
{
|
||||
showLocs = !showLocs;
|
||||
notifyListeners(IsoSceneViewModelListener.SHOW_LOCATIONS_CHANGED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle whether coordinates should be drawn for each tile.
|
||||
*/
|
||||
@@ -275,10 +261,6 @@ public class IsoSceneViewModel
|
||||
protected static final String SHOW_COORDS_KEY =
|
||||
MisoUtil.CONFIG_KEY + ".show_coords";
|
||||
|
||||
/** The config key for whether to show locations. */
|
||||
protected static final String SHOW_LOCS_KEY =
|
||||
MisoUtil.CONFIG_KEY + ".show_locs";
|
||||
|
||||
/** The config key for whether to show sprite paths. */
|
||||
protected static final String SHOW_PATHS_KEY =
|
||||
MisoUtil.CONFIG_KEY + ".show_paths";
|
||||
@@ -293,7 +275,6 @@ public class IsoSceneViewModel
|
||||
protected static final int DEF_SCENE_HEIGHT = 22;
|
||||
protected static final int DEF_OFFSET_Y = -5;
|
||||
protected static final boolean DEF_SHOW_COORDS = false;
|
||||
protected static final boolean DEF_SHOW_LOCS = false;
|
||||
protected static final boolean DEF_SHOW_PATHS = false;
|
||||
|
||||
/** The model listeners. */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: IsoSceneViewModelListener.java,v 1.2 2001/10/26 01:40:22 mdb Exp $
|
||||
// $Id: IsoSceneViewModelListener.java,v 1.3 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -12,13 +12,13 @@ package com.threerings.miso.scene;
|
||||
*/
|
||||
public interface IsoSceneViewModelListener
|
||||
{
|
||||
/** Notification event constant indicating that the "show coordinates"
|
||||
* configuration has changed.. */
|
||||
public static final int SHOW_COORDINATES_CHANGED = 0;
|
||||
|
||||
/**
|
||||
* Called by the {@link com.threerings.miso.scene.IsoSceneView} when
|
||||
* the model is changed.
|
||||
*/
|
||||
public void viewChanged (int event);
|
||||
|
||||
/** Notification event constants. */
|
||||
public static final int SHOW_LOCATIONS_CHANGED = 0;
|
||||
public static final int SHOW_COORDINATES_CHANGED = 1;
|
||||
}
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
//
|
||||
// $Id: Location.java,v 1.8 2001/10/25 16:36:42 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
|
||||
import com.threerings.media.sprite.Sprite;
|
||||
|
||||
/**
|
||||
* A location object represents a unique well-defined location within
|
||||
* the scene at the lowest level of granularity available within the
|
||||
* scene coordinate system. Locations reside at a full coordinate
|
||||
* (comprised of tile coordinates and fine coordinates within the
|
||||
* tile), and only one location may reside at each full coordinate in
|
||||
* the scene.
|
||||
*/
|
||||
public class Location
|
||||
{
|
||||
/** The unique identifier for this location. */
|
||||
public int id = -1;
|
||||
|
||||
/** The location position in full coordinates. */
|
||||
public int x, y;
|
||||
|
||||
/** The location orientation. */
|
||||
public int orient;
|
||||
|
||||
/**
|
||||
* Constructs a location object.
|
||||
*
|
||||
* @param x the x-position full coordinate.
|
||||
* @param y the y-position full coordinate.
|
||||
* @param orient the location orientation.
|
||||
*/
|
||||
public Location (int x, int y, int orient)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.orient = orient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a location object with a default orientation.
|
||||
*
|
||||
* @param x the x-position full coordinate.
|
||||
* @param y the y-position full coordinate.
|
||||
*/
|
||||
public Location (int x, int y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.orient = Sprite.DIR_SOUTHWEST;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the location centered at the given coordinates to the
|
||||
* given graphics context.
|
||||
*
|
||||
* @param gfx the graphics context.
|
||||
* @param cx the center x-coordinate.
|
||||
* @param cy the center y-coordinate.
|
||||
*/
|
||||
public void paint (Graphics2D gfx, int cx, int cy)
|
||||
{
|
||||
// translate the origin to center on the location
|
||||
gfx.translate(cx, cy);
|
||||
|
||||
// rotate to reflect the location orientation
|
||||
double rot = (Math.PI / 4.0f) * orient;
|
||||
gfx.rotate(rot);
|
||||
|
||||
// draw the triangle
|
||||
gfx.setColor(getColor());
|
||||
gfx.fill(_tri);
|
||||
|
||||
// outline the triangle in black
|
||||
gfx.setColor(Color.black);
|
||||
gfx.draw(_tri);
|
||||
|
||||
// draw the rectangle
|
||||
gfx.setColor(Color.red);
|
||||
gfx.fillRect(-1, 2, 3, 3);
|
||||
|
||||
// restore the original transform
|
||||
gfx.rotate(-rot);
|
||||
gfx.translate(-cx, -cy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the location.
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("[");
|
||||
toString(buf);
|
||||
return buf.append("]").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overridden by derived classes (which should be sure
|
||||
* to call <code>super.toString()</code>) to append the derived class
|
||||
* specific event information to the string buffer.
|
||||
*/
|
||||
protected void toString (StringBuffer buf)
|
||||
{
|
||||
buf.append("id=").append(id);
|
||||
buf.append(", x=").append(x);
|
||||
buf.append(", y=").append(y);
|
||||
buf.append(", orient=").append(orient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color to paint the inside of the location.
|
||||
*/
|
||||
protected Color getColor ()
|
||||
{
|
||||
return Color.yellow;
|
||||
}
|
||||
|
||||
/** The triangle used to render a location on-screen. */
|
||||
protected static Polygon _tri;
|
||||
|
||||
static {
|
||||
_tri = new Polygon();
|
||||
_tri.addPoint(-3, -3);
|
||||
_tri.addPoint(3, -3);
|
||||
_tri.addPoint(0, 3);
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: MisoCharacterSprite.java,v 1.1 2001/10/26 01:17:21 shaper Exp $
|
||||
// $Id: MisoCharacterSprite.java,v 1.2 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class MisoCharacterSprite
|
||||
public boolean canTraverse (MisoTile tile)
|
||||
{
|
||||
// by default, passability is solely the province of the tile
|
||||
return tile.passable;
|
||||
return tile.isPassable();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
//
|
||||
// $Id: MisoScene.java,v 1.6 2001/10/17 22:21:22 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;
|
||||
|
||||
/**
|
||||
* A scene object represents the data model corresponding to a single
|
||||
* screen for game play. For instance, one scene might display a portion
|
||||
* of a street with several buildings scattered about on the periphery.
|
||||
*/
|
||||
public interface MisoScene
|
||||
{
|
||||
/** Scene id to denote an unset or otherwise invalid scene id. */
|
||||
public static final int SID_INVALID = -1;
|
||||
|
||||
/** The total number of layers. */
|
||||
public static final int NUM_LAYERS = 3;
|
||||
|
||||
/** The base layer id. */
|
||||
public static final int LAYER_BASE = 0;
|
||||
|
||||
/** The fringe layer id. */
|
||||
public static final int LAYER_FRINGE = 1;
|
||||
|
||||
/** The object layer id. */
|
||||
public static final int LAYER_OBJECT = 2;
|
||||
|
||||
/**
|
||||
* Returns the scene's unique identifier.
|
||||
*/
|
||||
public int getId ();
|
||||
|
||||
/**
|
||||
* Returns the scene's name. Every scene has a descriptive name.
|
||||
*/
|
||||
public String getName ();
|
||||
|
||||
/**
|
||||
* Returns an array of the tile layers that comprise the scene.
|
||||
* The array returned by this method should <em>not</em> be
|
||||
* modified.
|
||||
*/
|
||||
public Tile[][][] getTiles ();
|
||||
|
||||
/**
|
||||
* Returns the tile layer for the specified layer index. The
|
||||
* array returned by this method should <em>not</em> be modified.
|
||||
*/
|
||||
public Tile[][] getTiles (int lnum);
|
||||
|
||||
/**
|
||||
* Returns the tiles that comprise the base layer of this scene.
|
||||
* The array returned by this method should <em>not</em> be
|
||||
* modified.
|
||||
*/
|
||||
public MisoTile[][] getBaseLayer ();
|
||||
|
||||
/**
|
||||
* Returns the tiles that comprise the fringe layer of this scene.
|
||||
* The array returned by this method should <em>not</em> be
|
||||
* modified.
|
||||
*/
|
||||
public Tile[][] getFringeLayer ();
|
||||
|
||||
/**
|
||||
* Returns the tiles that comprise the object layer of this scene.
|
||||
* The array returned by this method should <em>not</em> be
|
||||
* modified.
|
||||
*/
|
||||
public ObjectTile[][] getObjectLayer ();
|
||||
|
||||
/**
|
||||
* Returns the default tile for the base layer of the scene.
|
||||
*/
|
||||
public MisoTile getDefaultTile ();
|
||||
|
||||
/**
|
||||
* 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 ();
|
||||
|
||||
/**
|
||||
* 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 ();
|
||||
|
||||
/**
|
||||
* 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 ();
|
||||
|
||||
/**
|
||||
* Returns the portal that is the default entrance to this scene.
|
||||
*/
|
||||
public Portal getEntrance ();
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
//
|
||||
// $Id: Portal.java,v 1.4 2001/10/25 16:36:43 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
/**
|
||||
* The portal class represents a {@link Location} in a scene that both
|
||||
* leads to a different scene and serves as a potential entrance into
|
||||
* its containing scene.
|
||||
*/
|
||||
public class Portal extends Location
|
||||
{
|
||||
/** The portal name used for binding the portal to another scene. */
|
||||
public String name;
|
||||
|
||||
/** The destination scene id. */
|
||||
public int sid;
|
||||
|
||||
/** The destination portal within the destination scene. */
|
||||
public Portal dest;
|
||||
|
||||
/**
|
||||
* Construct a portal object.
|
||||
*
|
||||
* @param loc the location associated with the portal.
|
||||
* @param name the portal name.
|
||||
*/
|
||||
public Portal (Location loc, String name)
|
||||
{
|
||||
super(loc.x, loc.y, loc.orient);
|
||||
this.name = name;
|
||||
sid = MisoScene.SID_INVALID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the destination information for this portal.
|
||||
*
|
||||
* @param sid the scene id.
|
||||
* @param dest the destination portal.
|
||||
*/
|
||||
public void setDestination (int sid, Portal dest)
|
||||
{
|
||||
this.sid = sid;
|
||||
this.dest = dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this portal has a valid destination scene and
|
||||
* portal.
|
||||
*/
|
||||
public boolean hasDestination ()
|
||||
{
|
||||
return (sid != MisoScene.SID_INVALID && dest != null);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void toString (StringBuffer buf)
|
||||
{
|
||||
super.toString(buf);
|
||||
buf.append(", name=").append(name);
|
||||
buf.append(", sid=").append(sid);
|
||||
buf.append(", dest=").append(dest);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected Color getColor ()
|
||||
{
|
||||
return Color.green;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SceneView.java,v 1.18 2001/10/26 01:17:21 shaper Exp $
|
||||
// $Id: SceneView.java,v 1.19 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -36,7 +36,7 @@ public interface SceneView
|
||||
*
|
||||
* @param scene the scene to render in the view.
|
||||
*/
|
||||
public void setScene (MisoScene scene);
|
||||
public void setScene (DisplayMisoScene scene);
|
||||
|
||||
/**
|
||||
* Returns a {@link Path} object detailing a valid path for the
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SceneViewPanel.java,v 1.19 2001/10/22 18:21:41 shaper Exp $
|
||||
// $Id: SceneViewPanel.java,v 1.20 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class SceneViewPanel extends AnimatedPanel
|
||||
/**
|
||||
* Sets the scene managed by the panel.
|
||||
*/
|
||||
public void setScene (MisoScene scene)
|
||||
public void setScene (DisplayMisoScene scene)
|
||||
{
|
||||
_view.setScene(scene);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: AStarPathUtil.java,v 1.7 2001/10/22 21:32:13 shaper Exp $
|
||||
// $Id: AStarPathUtil.java,v 1.8 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene.util;
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.threerings.media.util.MathUtil;
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.scene.Traverser;
|
||||
import com.threerings.miso.tile.MisoTile;
|
||||
import com.threerings.miso.tile.MisoTileLayer;
|
||||
|
||||
/**
|
||||
* The <code>AStarPathUtil</code> class provides a facility for
|
||||
@@ -43,7 +44,7 @@ public class AStarPathUtil
|
||||
* @return the list of points in the path.
|
||||
*/
|
||||
public static List getPath (
|
||||
MisoTile tiles[][], int tilewid, int tilehei, Traverser trav,
|
||||
MisoTileLayer 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);
|
||||
@@ -202,7 +203,7 @@ public class AStarPathUtil
|
||||
protected static boolean isTraversable (AStarInfo info, int x, int y)
|
||||
{
|
||||
return (isCoordinateValid(info, x, y) &&
|
||||
info.trav.canTraverse(info.tiles[x][y]));
|
||||
info.trav.canTraverse(info.tiles.getTile(y, x)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,8 +253,8 @@ public class AStarPathUtil
|
||||
*/
|
||||
class AStarInfo
|
||||
{
|
||||
/** The array of tiles being traversed. */
|
||||
public MisoTile tiles[][];
|
||||
/** The tile layer being traversed. */
|
||||
public MisoTileLayer tiles;
|
||||
|
||||
/** The tile array dimensions. */
|
||||
public int tilewid, tilehei;
|
||||
@@ -274,7 +275,7 @@ class AStarInfo
|
||||
public int destx, desty;
|
||||
|
||||
public AStarInfo (
|
||||
MisoTile tiles[][], int tilewid, int tilehei, Traverser trav,
|
||||
MisoTileLayer tiles, int tilewid, int tilehei, Traverser trav,
|
||||
int destx, int desty)
|
||||
{
|
||||
// save off references
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
//
|
||||
// $Id: ClusterUtil.java,v 1.3 2001/09/28 01:31:32 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.scene.*;
|
||||
|
||||
/**
|
||||
* The <code>ClusterUtil</code> class provides utility routines for
|
||||
* working with a list of <code>Cluster</code> objects associated with
|
||||
* a scene.
|
||||
*/
|
||||
public class ClusterUtil
|
||||
{
|
||||
/**
|
||||
* Return the cluster index number the given location is in, or -1
|
||||
* if the location is not in any cluster.
|
||||
*
|
||||
* @param clusters the cluster list.
|
||||
* @param loc the location.
|
||||
*/
|
||||
public static int getClusterIndex (List clusters, Location loc)
|
||||
{
|
||||
int size = clusters.size();
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
Cluster cluster = (Cluster)clusters.get(ii);
|
||||
if (cluster.contains(loc)) {
|
||||
return ii;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given location from its cluster, if any.
|
||||
*
|
||||
* @param clusters the cluster array.
|
||||
* @param loc the location.
|
||||
*/
|
||||
public static void remove (List clusters, Location loc)
|
||||
{
|
||||
int size = clusters.size();
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
Cluster cluster = (Cluster)clusters.get(ii);
|
||||
|
||||
if (cluster.contains(loc)) {
|
||||
cluster.remove(loc);
|
||||
|
||||
// remove the cluster itself if it contains no more locations
|
||||
if (cluster.size() == 0) {
|
||||
clusters.remove(cluster);
|
||||
}
|
||||
|
||||
// we know the location can only reside in at most one cluster
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-group the given location to be placed within the given cluster
|
||||
* index.
|
||||
*
|
||||
* <p> If the cluster index is -1, the location is simply removed
|
||||
* from any cluster it may reside in. Otherwise, the location is
|
||||
* removed from any location it may already be in, and placed in
|
||||
* the cluster corresponding to the requested cluster index.
|
||||
*
|
||||
* <p> The cluster index may be equal to the current number of clusters
|
||||
* in the group, in which case a new cluster object will be created
|
||||
* that initially contains only the given location.
|
||||
*
|
||||
* @param clusters the cluster list.
|
||||
* @param loc the location.
|
||||
* @param clusteridx the cluster index, or -1 to remove the location
|
||||
* from any cluster.
|
||||
*/
|
||||
public static void regroup (List clusters, Location loc, int clusteridx)
|
||||
{
|
||||
// just remove the location if clusteridx is -1
|
||||
if (clusteridx == -1) {
|
||||
remove(clusters, loc);
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure we're okay with the requested cluster index
|
||||
int size = clusters.size();
|
||||
if (clusteridx > size) {
|
||||
Log.warning("Attempt to regroup location to a non-contiguous " +
|
||||
"cluster index [loc=" + loc + ", clusteridx=" +
|
||||
clusteridx + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// get the cluster object the location's to be placed in
|
||||
Cluster cluster = null;
|
||||
if (clusteridx == size) {
|
||||
// the location's being added to a new cluster, so create it
|
||||
clusters.add(cluster = new Cluster());
|
||||
|
||||
} else {
|
||||
// retrieve the cluster we're planning to place the location in
|
||||
cluster = (Cluster)clusters.get(clusteridx);
|
||||
|
||||
// this should never happen, but sanity-check anyway
|
||||
if (cluster == null) {
|
||||
Log.warning("Failed to retrieve cluster [clusteridx=" +
|
||||
clusteridx + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// bail if the cluster already contains the location
|
||||
if (cluster.contains(loc)) return;
|
||||
}
|
||||
|
||||
// remove the location from any other cluster it may already be in
|
||||
remove(clusters, loc);
|
||||
|
||||
// add the location to the cluster
|
||||
cluster.add(loc);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: IsoUtil.java,v 1.14 2001/10/26 01:17:21 shaper Exp $
|
||||
// $Id: IsoUtil.java,v 1.15 2001/11/18 04:09:22 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene.util;
|
||||
|
||||
@@ -54,15 +54,15 @@ public class IsoUtil
|
||||
IsoSceneViewModel model, Polygon root, ObjectTile tile)
|
||||
{
|
||||
Rectangle bounds = root.getBounds();
|
||||
int sx = bounds.x - ((tile.baseWidth - 1) * model.tilehwid);
|
||||
int sy = bounds.y - tile.height + model.tilehei;
|
||||
int sx = bounds.x - ((tile.getBaseWidth() - 1) * model.tilehwid);
|
||||
int sy = bounds.y - tile.getHeight() + model.tilehei;
|
||||
|
||||
Polygon boundsPoly = new Polygon();
|
||||
int rx = sx, ry = sy;
|
||||
|
||||
// right point
|
||||
rx = sx + tile.width;
|
||||
ry = bounds.y - ((tile.baseHeight - 2) * model.tilehhei);
|
||||
rx = sx + tile.getWidth();
|
||||
ry = bounds.y - ((tile.getBaseHeight() - 2) * model.tilehhei);
|
||||
boundsPoly.addPoint(rx, ry);
|
||||
|
||||
// bottom-middle point
|
||||
@@ -72,17 +72,17 @@ public class IsoUtil
|
||||
|
||||
// left point
|
||||
rx = sx;
|
||||
ry = bounds.y - ((tile.baseWidth - 2) * model.tilehhei);
|
||||
ry = bounds.y - ((tile.getBaseWidth() - 2) * model.tilehhei);
|
||||
boundsPoly.addPoint(rx, ry);
|
||||
|
||||
// top-middle point
|
||||
rx += (tile.baseHeight * model.tilehwid);
|
||||
ry -= (tile.baseHeight * model.tilehhei);
|
||||
rx += (tile.getBaseHeight() * model.tilehwid);
|
||||
ry -= (tile.getBaseHeight() * model.tilehhei);
|
||||
boundsPoly.addPoint(rx, ry);
|
||||
|
||||
// right point
|
||||
rx = sx + tile.width;
|
||||
ry = bounds.y - ((tile.baseHeight - 2) * model.tilehhei);
|
||||
rx = sx + tile.getWidth();
|
||||
ry = bounds.y - ((tile.getBaseHeight() - 2) * model.tilehhei);
|
||||
boundsPoly.addPoint(rx, ry);
|
||||
|
||||
return boundsPoly;
|
||||
@@ -104,8 +104,8 @@ public class IsoUtil
|
||||
IsoSceneViewModel model, Polygon root, ObjectTile tile)
|
||||
{
|
||||
Rectangle bounds = root.getBounds();
|
||||
int sx = bounds.x - ((tile.baseWidth - 1) * model.tilehwid);
|
||||
int sy = bounds.y - tile.height + model.tilehei;
|
||||
int sx = bounds.x - ((tile.getBaseWidth() - 1) * model.tilehwid);
|
||||
int sy = bounds.y - tile.getHeight() + model.tilehei;
|
||||
|
||||
Polygon boundsPoly = new Polygon();
|
||||
int rx = sx, ry = sy;
|
||||
@@ -114,11 +114,11 @@ public class IsoUtil
|
||||
boundsPoly.addPoint(rx, ry);
|
||||
|
||||
// top-right point
|
||||
rx = sx + tile.width;
|
||||
rx = sx + tile.getWidth();
|
||||
boundsPoly.addPoint(rx, ry);
|
||||
|
||||
// bottom-right point
|
||||
ry = bounds.y - ((tile.baseHeight - 2) * model.tilehhei);
|
||||
ry = bounds.y - ((tile.getBaseHeight() - 2) * model.tilehhei);
|
||||
boundsPoly.addPoint(rx, ry);
|
||||
|
||||
// bottom-middle point
|
||||
@@ -128,7 +128,7 @@ public class IsoUtil
|
||||
|
||||
// bottom-left point
|
||||
rx = sx;
|
||||
ry = bounds.y - ((tile.baseWidth - 2) * model.tilehhei);
|
||||
ry = bounds.y - ((tile.getBaseWidth() - 2) * model.tilehhei);
|
||||
boundsPoly.addPoint(rx, ry);
|
||||
|
||||
// top-left point
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
//
|
||||
// $Id: MisoSceneUtil.java,v 1.4 2001/10/15 23:53:43 shaper Exp $
|
||||
|
||||
package com.threerings.miso.scene.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.threerings.miso.scene.*;
|
||||
|
||||
/**
|
||||
* Miso scene related utility functions and information.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param scene the scene whose locations should be searched.
|
||||
* @param x the full x-position coordinate.
|
||||
* @param y the full y-position coordinate.
|
||||
*
|
||||
* @return the location object.
|
||||
*/
|
||||
public static Location getLocation (MisoScene scene, int x, int y)
|
||||
{
|
||||
List locs = scene.getLocations();
|
||||
int size = locs.size();
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
Location loc = (Location)locs.get(ii);
|
||||
if (loc.x == x && loc.y == y) {
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the portal with the given name, or null if the portal isn't
|
||||
* found in the portal list.
|
||||
*
|
||||
* @param scene the scene whose portals should be searched.
|
||||
* @param name the portal name.
|
||||
*
|
||||
* @return the portal object.
|
||||
*/
|
||||
public static Portal getPortal (MisoScene scene, String name)
|
||||
{
|
||||
List portals = scene.getPortals();
|
||||
int size = portals.size();
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
Portal portal = (Portal)portals.get(ii);
|
||||
if (portal.name.equals(name)) {
|
||||
return portal;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cluster index number the given location is in, or -1
|
||||
* if the location is not in any cluster.
|
||||
*
|
||||
* @param scene the containing scene.
|
||||
* @param loc the location.
|
||||
*
|
||||
* @return the cluster index or -1 if the location is not in any
|
||||
* cluster.
|
||||
*/
|
||||
public static int getClusterIndex (MisoScene scene, Location loc)
|
||||
{
|
||||
return ClusterUtil.getClusterIndex(scene.getClusters(), loc);
|
||||
}
|
||||
|
||||
/** The default layer index for an unknown named layer. */
|
||||
protected static final int DEF_LAYER = -1;
|
||||
}
|
||||
Reference in New Issue
Block a user