Serious scene surgery.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@344 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DisplayMisoSceneImpl.java,v 1.34 2001/09/21 00:21:40 mdb Exp $
|
||||
// $Id: DisplayMisoSceneImpl.java,v 1.35 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -21,32 +21,8 @@ import com.threerings.miso.scene.util.ClusterUtil;
|
||||
* screen for game play. For instance, one scene might display a portion
|
||||
* of a street with several buildings scattered about on the periphery.
|
||||
*/
|
||||
public class MisoScene implements Scene
|
||||
public class MisoSceneImpl implements EditableMisoScene
|
||||
{
|
||||
/** 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;
|
||||
|
||||
/** The total number of layers. */
|
||||
public static final int NUM_LAYERS = 3;
|
||||
|
||||
/** The latest scene file format version. */
|
||||
public static final short VERSION = 1;
|
||||
|
||||
/** String translations of each tile layer name. */
|
||||
public static final String[] XLATE_LAYERS = { "Base", "Fringe", "Object" };
|
||||
|
||||
/** Scene id to denote an unset or otherwise invalid scene id. */
|
||||
public static final int SID_INVALID = -1;
|
||||
|
||||
/** The tiles comprising 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
|
||||
@@ -57,8 +33,8 @@ public class MisoScene implements Scene
|
||||
* @param deftsid the default tileset id.
|
||||
* @param deftid the default tile id.
|
||||
*/
|
||||
public MisoScene (IsoSceneViewModel model, TileManager tilemgr,
|
||||
int deftsid, int deftid)
|
||||
public MisoSceneImpl (IsoSceneViewModel model, TileManager tilemgr,
|
||||
int deftsid, int deftid)
|
||||
{
|
||||
_model = model;
|
||||
_tilemgr = tilemgr;
|
||||
@@ -70,13 +46,13 @@ public class MisoScene implements Scene
|
||||
_clusters = new ArrayList();
|
||||
_portals = new ArrayList();
|
||||
|
||||
tiles = new Tile[_model.scenewid][_model.scenehei][NUM_LAYERS];
|
||||
_tiles = new Tile[_model.scenewid][_model.scenehei][NUM_LAYERS];
|
||||
_deftile = _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;
|
||||
_tiles[xx][yy][ii] = _deftile;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,7 +60,7 @@ public class MisoScene implements Scene
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new miso scene object with the given values.
|
||||
* Construct a new Miso scene object with the given values.
|
||||
*
|
||||
* @param model the iso scene view model.
|
||||
* @param tilemgr the tile manager.
|
||||
@@ -93,10 +69,10 @@ public class MisoScene implements Scene
|
||||
* @param portals the portals.
|
||||
* @param tiles the tiles comprising the scene.
|
||||
*/
|
||||
public MisoScene (IsoSceneViewModel model, TileManager tilemgr,
|
||||
String name, ArrayList locations,
|
||||
ArrayList clusters, ArrayList portals,
|
||||
Tile tiles[][][])
|
||||
public MisoSceneImpl (IsoSceneViewModel model, TileManager tilemgr,
|
||||
String name, ArrayList locations,
|
||||
ArrayList clusters, ArrayList portals,
|
||||
Tile[][][] tiles)
|
||||
{
|
||||
_model = model;
|
||||
_tilemgr = tilemgr;
|
||||
@@ -105,7 +81,7 @@ public class MisoScene implements Scene
|
||||
_locations = locations;
|
||||
_clusters = clusters;
|
||||
_portals = portals;
|
||||
this.tiles = tiles;
|
||||
_tiles = tiles;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -133,89 +109,60 @@ public class MisoScene implements Scene
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default tile for the base layer of the scene.
|
||||
*/
|
||||
// documentation inherited
|
||||
public Tile[][][] getTiles ()
|
||||
{
|
||||
return _tiles;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Tile getDefaultTile ()
|
||||
{
|
||||
return _deftile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the scene locations list.
|
||||
*/
|
||||
public ArrayList getLocations ()
|
||||
// documentation inherited
|
||||
public Location[] getLocations ()
|
||||
{
|
||||
return _locations;
|
||||
Location[] locs = new Location[_locations.size()];
|
||||
_locations.toArray(locs);
|
||||
return locs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cluster list.
|
||||
*/
|
||||
public ArrayList getClusters ()
|
||||
// documentation inherited
|
||||
public Cluster[] getClusters ()
|
||||
{
|
||||
return _clusters;
|
||||
Cluster[] clusters = new Cluster[_clusters.size()];
|
||||
_clusters.toArray(clusters);
|
||||
return clusters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the scene portals list.
|
||||
*/
|
||||
public ArrayList getPortals ()
|
||||
// documentation inherited
|
||||
public Portal[] getPortals ()
|
||||
{
|
||||
return _portals;
|
||||
Portal[] portals = new Portal[_portals.size()];
|
||||
_portals.toArray(portals);
|
||||
return portals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default entrance portal for this scene.
|
||||
*
|
||||
* @param entrance the entrance portal.
|
||||
*/
|
||||
// documentation inherited
|
||||
public Portal getEntrance ()
|
||||
{
|
||||
return _entrance;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void setName (String name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void setEntrance (Portal entrance)
|
||||
{
|
||||
_entrance = entrance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of clusters in the scene.
|
||||
*/
|
||||
public int getNumClusters ()
|
||||
{
|
||||
return _clusters.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of actual (non-null) tiles present in the
|
||||
* specified tile layer for this scene.
|
||||
*/
|
||||
public int getNumLayerTiles (int lnum)
|
||||
{
|
||||
if (lnum == LAYER_BASE) {
|
||||
return _model.scenewid * _model.scenehei;
|
||||
}
|
||||
|
||||
int numTiles = 0;
|
||||
for (int xx = 0; xx < _model.scenewid; xx++) {
|
||||
for (int yy = 0; yy < _model.scenehei; yy++) {
|
||||
if (tiles[xx][yy] != null) {
|
||||
numTiles++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return numTiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cluster index number the given location is in, or -1
|
||||
* if the location is not in any cluster.
|
||||
*
|
||||
* @param loc the location.
|
||||
*/
|
||||
public int getClusterIndex (Location loc)
|
||||
{
|
||||
return ClusterUtil.getClusterIndex(_clusters, loc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified location in the scene. If the cluster
|
||||
* index number is -1, the location will be removed from any
|
||||
@@ -259,28 +206,9 @@ public class MisoScene implements Scene
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the location object at the given full coordinates, or
|
||||
* null if no location is currently present at that location.
|
||||
*
|
||||
* @param x the full x-position coordinate.
|
||||
* @param y the full y-position coordinate.
|
||||
*
|
||||
* @return the location object.
|
||||
*/
|
||||
public Location getLocation (int x, int y)
|
||||
{
|
||||
int size = _locations.size();
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
Location loc = (Location)_locations.get(ii);
|
||||
if (loc.x == x && loc.y == y) return loc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
@@ -301,25 +229,7 @@ public class MisoScene implements Scene
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the portal with the given name, or null if the portal
|
||||
* isn't found in the portal list.
|
||||
*
|
||||
* @param name the portal name.
|
||||
*
|
||||
* @return the portal object.
|
||||
*/
|
||||
public Portal getPortal (String name)
|
||||
{
|
||||
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 a string representation of this Scene object.
|
||||
* Return a string representation of this Miso scene object.
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
@@ -341,6 +251,9 @@ public class MisoScene implements Scene
|
||||
/** The unique scene id. */
|
||||
protected int _sid;
|
||||
|
||||
/** The tiles comprising the scene. */
|
||||
public Tile[][][] _tiles;
|
||||
|
||||
/** The default entrance portal. */
|
||||
protected Portal _entrance;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: IsoSceneView.java,v 1.54 2001/09/13 19:10:26 mdb Exp $
|
||||
// $Id: IsoSceneView.java,v 1.55 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -17,12 +17,13 @@ import com.threerings.media.tile.TileManager;
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.scene.util.AStarPathUtil;
|
||||
import com.threerings.miso.scene.util.IsoUtil;
|
||||
import com.threerings.miso.scene.util.MisoSceneUtil;
|
||||
|
||||
/**
|
||||
* The <code>IsoSceneView</code> provides an isometric view of a
|
||||
* particular scene.
|
||||
*/
|
||||
public class IsoSceneView implements EditableSceneView
|
||||
public class IsoSceneView implements SceneView
|
||||
{
|
||||
/**
|
||||
* Construct an <code>IsoSceneView</code> object.
|
||||
@@ -39,10 +40,6 @@ public class IsoSceneView implements EditableSceneView
|
||||
|
||||
setModel(model);
|
||||
|
||||
// initialize the highlighted objects
|
||||
_htile = new Point(-1, -1);
|
||||
_hfull = new Point(-1, -1);
|
||||
|
||||
// get the font used to render tile coordinates
|
||||
_font = new Font("Arial", Font.PLAIN, 7);
|
||||
|
||||
@@ -65,6 +62,12 @@ public class IsoSceneView implements EditableSceneView
|
||||
clearDirtyRegions();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void setScene (MisoScene scene)
|
||||
{
|
||||
_scene = scene;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint the scene view and any highlighted tiles to the given
|
||||
* graphics context.
|
||||
@@ -73,7 +76,9 @@ public class IsoSceneView implements EditableSceneView
|
||||
*/
|
||||
public void paint (Graphics g)
|
||||
{
|
||||
if (_scene == null) return;
|
||||
if (_scene == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics2D gfx = (Graphics2D)g;
|
||||
|
||||
@@ -107,13 +112,21 @@ public class IsoSceneView implements EditableSceneView
|
||||
paintLocations(gfx);
|
||||
}
|
||||
|
||||
// draw highlighted tiles and full coordinates
|
||||
paintHighlights(gfx);
|
||||
// paint any extra goodies
|
||||
paintExtras(gfx);
|
||||
|
||||
// restore the original clipping region
|
||||
gfx.setClip(oldclip);
|
||||
}
|
||||
|
||||
/**
|
||||
* A function where derived classes can paint extra stuff while we've
|
||||
* got the clipping region set up.
|
||||
*/
|
||||
protected void paintExtras (Graphics2D g)
|
||||
{
|
||||
}
|
||||
|
||||
protected void clearDirtyRegions ()
|
||||
{
|
||||
_dirtyRects.clear();
|
||||
@@ -155,6 +168,7 @@ public class IsoSceneView implements EditableSceneView
|
||||
protected void renderSceneInvalid (Graphics2D gfx)
|
||||
{
|
||||
int numDrawn = 0;
|
||||
Tile[][][] tiles = _scene.getTiles();
|
||||
|
||||
for (int yy = 0; yy < _model.scenehei; yy++) {
|
||||
for (int xx = 0; xx < _model.scenewid; xx++) {
|
||||
@@ -169,7 +183,7 @@ public class IsoSceneView implements EditableSceneView
|
||||
for (int kk = 0; kk < MisoScene.NUM_LAYERS; kk++) {
|
||||
|
||||
// get the tile at these coordinates and layer
|
||||
Tile tile = _scene.tiles[xx][yy][kk];
|
||||
Tile tile = tiles[xx][yy][kk];
|
||||
if (tile == null) continue;
|
||||
|
||||
// offset the image y-position by the tile-specific height
|
||||
@@ -202,6 +216,7 @@ public class IsoSceneView implements EditableSceneView
|
||||
*/
|
||||
protected void renderScene (Graphics2D gfx)
|
||||
{
|
||||
Tile[][][] tiles = _scene.getTiles();
|
||||
int mx = 1;
|
||||
int my = 0;
|
||||
|
||||
@@ -222,7 +237,7 @@ public class IsoSceneView implements EditableSceneView
|
||||
|
||||
for (int kk = 0; kk < MisoScene.NUM_LAYERS; kk++) {
|
||||
// grab the tile we're rendering
|
||||
Tile tile = _scene.tiles[tx][ty][kk];
|
||||
Tile tile = tiles[tx][ty][kk];
|
||||
if (tile == null) continue;
|
||||
|
||||
// determine screen y-position, accounting for
|
||||
@@ -290,45 +305,6 @@ public class IsoSceneView implements EditableSceneView
|
||||
gfx.drawString(str, sx + cx - (fm.stringWidth(str)/2), sy + cy + fhei);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint highlights around any highlighted tiles and fine coordinates.
|
||||
*
|
||||
* @param gfx the graphics context.
|
||||
*/
|
||||
protected void paintHighlights (Graphics2D gfx)
|
||||
{
|
||||
// paint the highlighted tile
|
||||
if (_htile.x != -1 && _htile.y != -1) {
|
||||
// set the desired stroke and color
|
||||
Stroke ostroke = gfx.getStroke();
|
||||
gfx.setStroke(_hstroke);
|
||||
gfx.setColor(Color.green);
|
||||
|
||||
// draw the tile outline
|
||||
gfx.draw(_polys[_htile.x][_htile.y]);
|
||||
|
||||
// restore the original stroke
|
||||
gfx.setStroke(ostroke);
|
||||
}
|
||||
|
||||
// paint the highlighted full coordinate
|
||||
if (_hfull.x != -1 && _hfull.y != -1) {
|
||||
Point spos = new Point();
|
||||
IsoUtil.fullToScreen(_model, _hfull.x, _hfull.y, spos);
|
||||
|
||||
// set the desired stroke and color
|
||||
Stroke ostroke = gfx.getStroke();
|
||||
gfx.setStroke(_hstroke);
|
||||
|
||||
// draw a red circle at the coordinate
|
||||
gfx.setColor(Color.red);
|
||||
gfx.draw(new Ellipse2D.Float(spos.x - 1, spos.y - 1, 3, 3));
|
||||
|
||||
// restore the original stroke
|
||||
gfx.setStroke(ostroke);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint demarcations at all locations in the scene, with each
|
||||
* location's cluster index, if any, along the right side of its
|
||||
@@ -338,8 +314,8 @@ public class IsoSceneView implements EditableSceneView
|
||||
*/
|
||||
protected void paintLocations (Graphics2D gfx)
|
||||
{
|
||||
ArrayList locations = _scene.getLocations();
|
||||
int size = locations.size();
|
||||
Location[] locations = _scene.getLocations();
|
||||
int size = locations.length;
|
||||
|
||||
// create the location triangle
|
||||
Polygon tri = new Polygon();
|
||||
@@ -350,10 +326,10 @@ public class IsoSceneView implements EditableSceneView
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
|
||||
// retrieve the location
|
||||
Location loc = (Location)locations.get(ii);
|
||||
Location loc = locations[ii];
|
||||
|
||||
// get the cluster index this location is in, if any
|
||||
int clusteridx = _scene.getClusterIndex(loc);
|
||||
int clusteridx = MisoSceneUtil.getClusterIndex(_scene, loc);
|
||||
|
||||
Point spos = new Point();
|
||||
IsoUtil.fullToScreen(_model, loc.x, loc.y, spos);
|
||||
@@ -393,26 +369,6 @@ public class IsoSceneView implements EditableSceneView
|
||||
}
|
||||
}
|
||||
|
||||
public void setHighlightedTile (int sx, int sy)
|
||||
{
|
||||
if (sx == -1 && sy == -1) {
|
||||
_htile.setLocation(-1, -1);
|
||||
return;
|
||||
}
|
||||
|
||||
IsoUtil.screenToTile(_model, sx, sy, _htile);
|
||||
}
|
||||
|
||||
public void setHighlightedFull (int x, int y)
|
||||
{
|
||||
if (x == -1 && y == -1) {
|
||||
_hfull.setLocation(-1, -1);
|
||||
return;
|
||||
}
|
||||
|
||||
IsoUtil.screenToFull(_model, x, y, _hfull);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate a list of rectangles in the view for later repainting.
|
||||
*
|
||||
@@ -560,27 +516,6 @@ public class IsoSceneView implements EditableSceneView
|
||||
_spritemgr.invalidateIntersectingSprites(rects, _polys[x][y]);
|
||||
}
|
||||
|
||||
public void setScene (MisoScene scene)
|
||||
{
|
||||
_scene = scene;
|
||||
}
|
||||
|
||||
public void setTile (int x, int y, int lnum, Tile tile)
|
||||
{
|
||||
Point tpos = new Point();
|
||||
IsoUtil.screenToTile(_model, x, y, tpos);
|
||||
_scene.tiles[tpos.x][tpos.y][lnum] = tile;
|
||||
}
|
||||
|
||||
public void deleteTile (int x, int y, int lnum)
|
||||
{
|
||||
Point tpos = new Point();
|
||||
IsoUtil.screenToTile(_model, x, y, tpos);
|
||||
|
||||
Tile tile = (lnum == 0) ? _scene.getDefaultTile() : null;
|
||||
_scene.tiles[tpos.x][tpos.y][lnum] = tile;
|
||||
}
|
||||
|
||||
public void setModel (IsoSceneViewModel model)
|
||||
{
|
||||
_model = model;
|
||||
@@ -608,7 +543,7 @@ public class IsoSceneView implements EditableSceneView
|
||||
// get a reasonable path from start to end
|
||||
List tilepath =
|
||||
AStarPathUtil.getPath(
|
||||
_scene.tiles, _model.scenewid, _model.scenehei,
|
||||
_scene.getTiles(), _model.scenewid, _model.scenehei,
|
||||
sprite, stpos.x, stpos.y, tbx, tby);
|
||||
if (tilepath == null) {
|
||||
return null;
|
||||
@@ -666,54 +601,6 @@ public class IsoSceneView implements EditableSceneView
|
||||
return path;
|
||||
}
|
||||
|
||||
public void updateLocation (Location loc, int clusteridx)
|
||||
{
|
||||
_scene.updateLocation(loc, clusteridx);
|
||||
}
|
||||
|
||||
public void addPortal (Portal portal)
|
||||
{
|
||||
_scene.addPortal(portal);
|
||||
}
|
||||
|
||||
public void removeLocation (Location loc)
|
||||
{
|
||||
_scene.removeLocation(loc);
|
||||
}
|
||||
|
||||
public Location createLocation (int sx, int sy)
|
||||
{
|
||||
Point fpos = new Point();
|
||||
IsoUtil.screenToFull(_model, sx, sy, fpos);
|
||||
return new Location(fpos.x, fpos.y);
|
||||
}
|
||||
|
||||
public Location getLocation (int sx, int sy)
|
||||
{
|
||||
Point fpos = new Point();
|
||||
IsoUtil.screenToFull(_model, sx, sy, fpos);
|
||||
return _scene.getLocation(fpos.x, fpos.y);
|
||||
}
|
||||
|
||||
public int getClusterIndex (Location loc)
|
||||
{
|
||||
return _scene.getClusterIndex(loc);
|
||||
}
|
||||
|
||||
public int getNumClusters ()
|
||||
{
|
||||
return (_scene == null) ? 0 : _scene.getNumClusters();
|
||||
}
|
||||
|
||||
/** The stroke object used to draw highlighted tiles and coordinates. */
|
||||
protected BasicStroke _hstroke = new BasicStroke(3);
|
||||
|
||||
/** The currently highlighted tile. */
|
||||
protected Point _htile;
|
||||
|
||||
/** The currently highlighted full coordinate. */
|
||||
protected Point _hfull;
|
||||
|
||||
/** The font to draw tile coordinates. */
|
||||
protected Font _font;
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// $Id: MisoScene.java,v 1.1 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import com.threerings.media.tile.Tile;
|
||||
import com.threerings.whirled.data.Scene;
|
||||
|
||||
/**
|
||||
* 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 extends Scene
|
||||
{
|
||||
/** 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;
|
||||
|
||||
/**
|
||||
* Return the tiles that comprise this scene.
|
||||
*/
|
||||
public Tile[][][] getTiles ();
|
||||
|
||||
/**
|
||||
* Return the default tile for the base layer of the scene.
|
||||
*/
|
||||
public Tile getDefaultTile ();
|
||||
|
||||
/**
|
||||
* Return the locations in this scene.
|
||||
*/
|
||||
public Location[] getLocations ();
|
||||
|
||||
/**
|
||||
* Return the clusters in this scene.
|
||||
*/
|
||||
public Cluster[] getClusters ();
|
||||
|
||||
/**
|
||||
* Return the portals associated with this scene.
|
||||
*/
|
||||
public Portal[] getPortals ();
|
||||
|
||||
/**
|
||||
* Return the portal that is the default entrance to this scene.
|
||||
*/
|
||||
public Portal getEntrance ();
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SceneViewPanel.java,v 1.13 2001/08/29 18:41:46 shaper Exp $
|
||||
// $Id: SceneViewPanel.java,v 1.14 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
@@ -30,13 +30,22 @@ public class SceneViewPanel
|
||||
_smodel = new IsoSceneViewModel(config);
|
||||
|
||||
// create the scene view
|
||||
_view = new IsoSceneView(tilemgr, spritemgr, _smodel);
|
||||
_view = newSceneView(tilemgr, spritemgr, _smodel);
|
||||
|
||||
// set our attributes for optimal display performance
|
||||
setDoubleBuffered(false);
|
||||
setOpaque(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the underlying scene view implementation.
|
||||
*/
|
||||
protected IsoSceneView newSceneView (
|
||||
TileManager tmgr, SpriteManager smgr, IsoSceneViewModel model)
|
||||
{
|
||||
return new IsoSceneView(tmgr, smgr, model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the scene managed by the panel.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ClusterUtil.java,v 1.1 2001/08/14 21:29:40 shaper Exp $
|
||||
// $Id: ClusterUtil.java,v 1.2 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene.util;
|
||||
|
||||
@@ -22,12 +22,14 @@ public class ClusterUtil
|
||||
* @param clusters the cluster list.
|
||||
* @param loc the location.
|
||||
*/
|
||||
public static int getClusterIndex (ArrayList clusters, Location loc)
|
||||
public static int getClusterIndex (Cluster[] clusters, Location loc)
|
||||
{
|
||||
int size = clusters.size();
|
||||
int size = clusters.length;
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
Cluster cluster = (Cluster)clusters.get(ii);
|
||||
if (cluster.contains(loc)) return ii;
|
||||
Cluster cluster = clusters[ii];
|
||||
if (cluster.contains(loc)) {
|
||||
return ii;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -35,7 +37,7 @@ public class ClusterUtil
|
||||
/**
|
||||
* Remove the given location from its cluster, if any.
|
||||
*
|
||||
* @param clusters the cluster list.
|
||||
* @param clusters the cluster array.
|
||||
* @param loc the location.
|
||||
*/
|
||||
public static void remove (ArrayList clusters, Location loc)
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// $Id: MisoSceneUtil.java,v 1.1 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene.util;
|
||||
|
||||
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" };
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
Location[] locs = scene.getLocations();
|
||||
int size = locs.length;
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
Location loc = locs[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)
|
||||
{
|
||||
Portal[] portals = scene.getPortals();
|
||||
int size = portals.length;
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
Portal portal = portals[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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// $Id: EditableMisoScene.java,v 1.1 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import com.threerings.whirled.data.EditableScene;
|
||||
|
||||
/**
|
||||
* The editable Miso scene interface provides the means for modifying a
|
||||
* Miso scene which is needed by things like the scene editor. This is
|
||||
* separated from the read-only interface to avoid implying to users of
|
||||
* the Miso scene interface that editing scenes is a safe thing to do. In
|
||||
* fact it should only be done under special circumstances.
|
||||
*/
|
||||
public interface EditableMisoScene
|
||||
extends EditableScene, MisoScene
|
||||
{
|
||||
/**
|
||||
* Set the default entrance portal for this scene.
|
||||
*
|
||||
* @param entrance the entrance portal.
|
||||
*/
|
||||
public void setEntrance (Portal 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 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: XMLSceneGroupParser.java,v 1.3 2001/08/21 01:15:16 shaper Exp $
|
||||
// $Id: XMLSceneGroupParser.java,v 1.4 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene.xml;
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.samskivert.util.*;
|
||||
import com.samskivert.xml.XMLUtil;
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.scene.*;
|
||||
import com.threerings.miso.scene.util.MisoSceneUtil;
|
||||
import com.threerings.whirled.data.Scene;
|
||||
|
||||
/**
|
||||
@@ -228,7 +229,7 @@ public class XMLSceneGroupParser extends DefaultHandler
|
||||
protected void resolvePortal (SceneInfo sinfo, PortalInfo pinfo)
|
||||
{
|
||||
// get the source portal object
|
||||
Portal src = sinfo.scene.getPortal(pinfo.src);
|
||||
Portal src = MisoSceneUtil.getPortal(sinfo.scene, pinfo.src);
|
||||
if (src == null) {
|
||||
Log.warning("Missing source portal [scene=" + sinfo.name +
|
||||
", pinfo=" + pinfo + "].");
|
||||
@@ -244,7 +245,7 @@ public class XMLSceneGroupParser extends DefaultHandler
|
||||
}
|
||||
|
||||
// get the destination portal object
|
||||
Portal dest = destScene.getPortal(pinfo.dest);
|
||||
Portal dest = MisoSceneUtil.getPortal(destScene, pinfo.dest);
|
||||
if (dest == null) {
|
||||
Log.warning("Missing destination portal [scene=" + sinfo.name +
|
||||
", pinfo=" + pinfo + "].");
|
||||
@@ -262,7 +263,8 @@ public class XMLSceneGroupParser extends DefaultHandler
|
||||
*/
|
||||
protected void resolveEntrance (SceneInfo sinfo)
|
||||
{
|
||||
Portal entrance = sinfo.scene.getPortal(sinfo.entrance);
|
||||
Portal entrance = MisoSceneUtil.getPortal(
|
||||
sinfo.scene, sinfo.entrance);
|
||||
if (entrance == null) {
|
||||
Log.warning( "Missing entrance portal [scene=" + sinfo.name +
|
||||
", entrance=" + sinfo.entrance + "].");
|
||||
@@ -289,12 +291,12 @@ public class XMLSceneGroupParser extends DefaultHandler
|
||||
SceneInfo sinfo = (SceneInfo)sceneinfo.get(ii);
|
||||
|
||||
// get the portals in the scene
|
||||
List portals = sinfo.scene.getPortals();
|
||||
Portal[] portals = sinfo.scene.getPortals();
|
||||
|
||||
// check each portal to make sure it has a valid destination
|
||||
int psize = portals.size();
|
||||
int psize = portals.length;
|
||||
for (int jj = 0; jj < size; jj++) {
|
||||
Portal portal = (Portal)portals.get(jj);
|
||||
Portal portal = portals[jj];
|
||||
if (!portal.hasDestination()) {
|
||||
Log.warning("Unbound portal [scene=" + sinfo.name +
|
||||
", portal=" + portal + "].");
|
||||
@@ -322,7 +324,7 @@ public class XMLSceneGroupParser extends DefaultHandler
|
||||
public ArrayList portals;
|
||||
|
||||
/** The scene object obtained from the scene repository. */
|
||||
public MisoScene scene;
|
||||
public MisoSceneImpl scene;
|
||||
|
||||
public SceneInfo (String src)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: XMLSceneParser.java,v 1.15 2001/08/29 19:50:46 shaper Exp $
|
||||
// $Id: XMLSceneParser.java,v 1.16 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene.xml;
|
||||
|
||||
@@ -60,12 +60,12 @@ public class XMLSceneParser extends DefaultHandler
|
||||
|
||||
} else if (qName.equals("version")) {
|
||||
int version = getInt(_chars.toString());
|
||||
if (version < 0 || version > MisoScene.VERSION) {
|
||||
if (version < 0 || version > XMLSceneVersion.VERSION) {
|
||||
Log.warning(
|
||||
"Unrecognized scene file format version, will attempt " +
|
||||
"to continue parsing file but your mileage may vary " +
|
||||
"[fname=" + _fname + ", version=" + version +
|
||||
", known_version=" + MisoScene.VERSION + "].");
|
||||
", known_version=" + XMLSceneVersion.VERSION + "].");
|
||||
}
|
||||
|
||||
} else if (qName.equals("locations")) {
|
||||
@@ -280,7 +280,7 @@ public class XMLSceneParser extends DefaultHandler
|
||||
*
|
||||
* @return the scene object, or null if an error occurred.
|
||||
*/
|
||||
public MisoScene loadScene (String fname) throws IOException
|
||||
public EditableMisoScene loadScene (String fname) throws IOException
|
||||
{
|
||||
_fname = fname;
|
||||
|
||||
@@ -354,7 +354,7 @@ public class XMLSceneParser extends DefaultHandler
|
||||
public int colstart;
|
||||
|
||||
/** The scene object constructed once all scene info is parsed. */
|
||||
public MisoScene scene;
|
||||
public EditableMisoScene scene;
|
||||
|
||||
public SceneInfo ()
|
||||
{
|
||||
@@ -365,7 +365,7 @@ public class XMLSceneParser extends DefaultHandler
|
||||
|
||||
public void constructScene (TileManager tilemgr)
|
||||
{
|
||||
scene = new MisoScene(
|
||||
scene = new MisoSceneImpl(
|
||||
_model, tilemgr, name, locations, clusters, portals, tiles);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: XMLSceneRepository.java,v 1.11 2001/08/29 19:50:46 shaper Exp $
|
||||
// $Id: XMLSceneRepository.java,v 1.12 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene.xml;
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.threerings.media.tile.TileManager;
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.scene.IsoSceneViewModel;
|
||||
import com.threerings.miso.scene.MisoScene;
|
||||
import com.threerings.miso.scene.EditableMisoScene;
|
||||
import com.threerings.miso.util.MisoUtil;
|
||||
|
||||
/**
|
||||
@@ -63,7 +64,7 @@ public class XMLFileSceneRepository
|
||||
* @param fname the full pathname to the file.
|
||||
* @return the scene object.
|
||||
*/
|
||||
public MisoScene loadScene (String fname) throws IOException
|
||||
public EditableMisoScene loadScene (String fname) throws IOException
|
||||
{
|
||||
String path = getScenePath() + fname;
|
||||
Log.info("Loading scene [path=" + path + "].");
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// $Id: XMLSceneVersion.java,v 1.1 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene.xml;
|
||||
|
||||
/**
|
||||
* This class tracks the version number of the XML scene file format. When
|
||||
* modifications are made to the file format, the version number in this
|
||||
* class should be increased.
|
||||
*/
|
||||
public class XMLSceneVersion
|
||||
{
|
||||
/** The latest scene file format version. */
|
||||
public static int VERSION = 1;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: XMLSceneWriter.java,v 1.12 2001/08/29 19:50:46 shaper Exp $
|
||||
// $Id: XMLSceneWriter.java,v 1.13 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.miso.scene.xml;
|
||||
|
||||
@@ -7,9 +7,10 @@ import java.awt.Point;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.util.ListUtil;
|
||||
|
||||
import org.xml.sax.*;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
import com.megginson.sax.DataWriter;
|
||||
|
||||
import com.threerings.media.tile.Tile;
|
||||
@@ -52,7 +53,7 @@ public class XMLSceneWriter extends DataWriter
|
||||
startElement("scene");
|
||||
|
||||
dataElement("name", scene.getName());
|
||||
dataElement("version", "" + MisoScene.VERSION);
|
||||
dataElement("version", "" + XMLSceneVersion.VERSION);
|
||||
dataElement("locations", getLocationData(scene));
|
||||
|
||||
startElement("clusters");
|
||||
@@ -86,21 +87,22 @@ public class XMLSceneWriter extends DataWriter
|
||||
*/
|
||||
protected void writeClusters (MisoScene scene) throws SAXException
|
||||
{
|
||||
ArrayList clusters = scene.getClusters();
|
||||
ArrayList locs = scene.getLocations();
|
||||
Cluster[] clusters = scene.getClusters();
|
||||
Location[] locs = scene.getLocations();
|
||||
|
||||
int size = clusters.size();
|
||||
int size = clusters.length;
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
Cluster cluster = (Cluster)clusters.get(ii);
|
||||
Cluster cluster = clusters[ii];
|
||||
ArrayList clusterlocs = cluster.getLocations();
|
||||
|
||||
StringBuffer buf = new StringBuffer();
|
||||
int clustersize = clusterlocs.size();
|
||||
for (int jj = 0; jj < clustersize; jj++) {
|
||||
buf.append(locs.indexOf(clusterlocs.get(jj)));
|
||||
if (jj < clustersize - 1) buf.append(",");
|
||||
Location cloc = (Location)clusterlocs.get(jj);
|
||||
buf.append(ListUtil.indexOfEqual(locs, cloc));
|
||||
if (jj < clustersize - 1) {
|
||||
buf.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
dataElement("cluster", buf.toString());
|
||||
@@ -144,16 +146,18 @@ public class XMLSceneWriter extends DataWriter
|
||||
*/
|
||||
protected String getPortalData (MisoScene scene)
|
||||
{
|
||||
ArrayList locs = scene.getLocations();
|
||||
ArrayList portals = scene.getPortals();
|
||||
Location[] locs = scene.getLocations();
|
||||
Portal[] portals = scene.getPortals();
|
||||
|
||||
StringBuffer buf = new StringBuffer();
|
||||
int size = portals.size();
|
||||
int size = portals.length;
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
Portal portal = (Portal)portals.get(ii);
|
||||
buf.append(locs.indexOf(portal)).append(",");
|
||||
Portal portal = portals[ii];
|
||||
buf.append(ListUtil.indexOfEqual(locs, portal)).append(",");
|
||||
buf.append(portal.name);
|
||||
if (ii < size - 1) buf.append(",");
|
||||
if (ii < size - 1) {
|
||||
buf.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
@@ -168,16 +172,18 @@ public class XMLSceneWriter extends DataWriter
|
||||
*/
|
||||
protected String getLocationData (MisoScene scene)
|
||||
{
|
||||
ArrayList locs = scene.getLocations();
|
||||
Location[] locs = scene.getLocations();
|
||||
|
||||
StringBuffer buf = new StringBuffer();
|
||||
int size = locs.size();
|
||||
int size = locs.length;
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
Location loc = (Location)locs.get(ii);
|
||||
Location loc = locs[ii];
|
||||
buf.append(loc.x).append(",");
|
||||
buf.append(loc.y).append(",");
|
||||
buf.append(loc.orient);
|
||||
if (ii < size - 1) buf.append(",");
|
||||
if (ii < size - 1) {
|
||||
buf.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
@@ -201,10 +207,11 @@ public class XMLSceneWriter extends DataWriter
|
||||
int colstart, int len)
|
||||
{
|
||||
StringBuffer buf = new StringBuffer();
|
||||
Tile[][][] tiles = scene.getTiles();
|
||||
|
||||
int numtiles = colstart + len;
|
||||
for (int ii = colstart; ii < numtiles; ii++) {
|
||||
Tile tile = scene.tiles[ii][rownum][lnum];
|
||||
Tile tile = tiles[ii][rownum][lnum];
|
||||
if (tile == null) {
|
||||
Log.warning("Null tile [x=" + ii + ", rownum=" + rownum +
|
||||
", lnum=" + lnum + "].");
|
||||
@@ -213,7 +220,9 @@ public class XMLSceneWriter extends DataWriter
|
||||
|
||||
buf.append(tile.tsid).append(",");
|
||||
buf.append(tile.tid);
|
||||
if (ii != numtiles - 1) buf.append(",");
|
||||
if (ii != numtiles - 1) {
|
||||
buf.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
@@ -265,15 +274,21 @@ public class XMLSceneWriter extends DataWriter
|
||||
protected boolean getSparseColumn (
|
||||
MisoScene scene, int rownum, int lnum, int info[])
|
||||
{
|
||||
Tile[][][] tiles = scene.getTiles();
|
||||
int start = -1, len = 0;
|
||||
for (int xx = info[0]; xx < _model.scenewid; xx++) {
|
||||
Tile tile = scene.tiles[xx][rownum][lnum];
|
||||
Tile tile = tiles[xx][rownum][lnum];
|
||||
if (tile == null) {
|
||||
if (start == -1) continue;
|
||||
else break;
|
||||
if (start == -1) {
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (start == -1) start = xx;
|
||||
if (start == -1) {
|
||||
start = xx;
|
||||
}
|
||||
len++;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// $Id: EditableScene.java,v 1.1 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.data;
|
||||
|
||||
/**
|
||||
* The editable scene interface. This separate interface allows the
|
||||
* ability to modify the scenes to be restricted only to code that needs
|
||||
* such an ability.
|
||||
*/
|
||||
public interface EditableScene extends Scene
|
||||
{
|
||||
/**
|
||||
* Updates the scene's name.
|
||||
*/
|
||||
public void setName (String name);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Scene.java,v 1.3 2001/09/21 00:21:40 mdb Exp $
|
||||
// $Id: Scene.java,v 1.4 2001/09/21 02:30:35 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.data;
|
||||
|
||||
@@ -9,6 +9,9 @@ package com.threerings.whirled.data;
|
||||
*/
|
||||
public interface Scene
|
||||
{
|
||||
/** Scene id to denote an unset or otherwise invalid scene id. */
|
||||
public static final int SID_INVALID = -1;
|
||||
|
||||
/**
|
||||
* Returns the scene's unique identifier.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user