Added the ability to specify one portal in a scene as the "default

entrance."  The default entrance is specially highlighted in the scene
and can be read from and written to XML scene description files.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@558 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-10-25 16:36:43 +00:00
parent 63a822862d
commit 4b58a696ca
6 changed files with 139 additions and 60 deletions
@@ -1,5 +1,5 @@
// //
// $Id: DisplayMisoSceneImpl.java,v 1.41 2001/10/17 22:21:22 shaper Exp $ // $Id: DisplayMisoSceneImpl.java,v 1.42 2001/10/25 16:36:42 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -37,6 +37,9 @@ public class MisoSceneImpl implements EditableMisoScene
/** The portals to different scenes. */ /** The portals to different scenes. */
public ArrayList portals = new ArrayList(); public ArrayList portals = new ArrayList();
/** The default entrance portal. */
public Portal entrance;
/** The base tiles in the scene. */ /** The base tiles in the scene. */
public MisoTile[][] baseTiles; public MisoTile[][] baseTiles;
@@ -186,7 +189,7 @@ public class MisoSceneImpl implements EditableMisoScene
// documentation inherited // documentation inherited
public Portal getEntrance () public Portal getEntrance ()
{ {
return _entrance; return entrance;
} }
// documentation inherited // documentation inherited
@@ -210,7 +213,7 @@ public class MisoSceneImpl implements EditableMisoScene
// documentation inherited // documentation inherited
public void setEntrance (Portal entrance) public void setEntrance (Portal entrance)
{ {
_entrance = entrance; this.entrance = entrance;
} }
/** /**
@@ -378,9 +381,6 @@ public class MisoSceneImpl implements EditableMisoScene
/** The scene version. */ /** The scene version. */
protected int _version; protected int _version;
/** The default entrance portal. */
protected Portal _entrance;
/** The default tile for the base layer in the scene. */ /** The default tile for the base layer in the scene. */
protected MisoTile _deftile; protected MisoTile _deftile;
@@ -1,5 +1,5 @@
// //
// $Id: IsoSceneView.java,v 1.68 2001/10/24 01:33:47 shaper Exp $ // $Id: IsoSceneView.java,v 1.69 2001/10/25 16:36:42 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
@@ -196,6 +196,7 @@ public class IsoSceneView implements SceneView
*/ */
protected void renderScene (Graphics2D gfx) protected void renderScene (Graphics2D gfx)
{ {
// Log.info("renderScene");
renderTiles(gfx); renderTiles(gfx);
renderDirtyItems(gfx); renderDirtyItems(gfx);
} }
@@ -236,7 +237,8 @@ public class IsoSceneView implements SceneView
*/ */
protected void renderDirtyItems (Graphics2D gfx) protected void renderDirtyItems (Graphics2D gfx)
{ {
// Log.info("renderDirtyItems"); // Log.info("renderDirtyItems [rects=" + _dirtyRects.size() +
// ", items=" + _dirtyItems.size() + "].");
// sort the dirty sprites and objects visually back-to-front // sort the dirty sprites and objects visually back-to-front
DirtyItem items[] = _dirtyItems.sort(); DirtyItem items[] = _dirtyItems.sort();
@@ -244,6 +246,7 @@ public class IsoSceneView implements SceneView
// render each item clipping to its dirty rectangle // render each item clipping to its dirty rectangle
for (int ii = 0; ii < items.length; ii++) { for (int ii = 0; ii < items.length; ii++) {
items[ii].paint(gfx, items[ii].dirtyRect); items[ii].paint(gfx, items[ii].dirtyRect);
// Log.info("Painting item [item=" + items[ii] + "].");
} }
} }
@@ -352,56 +355,34 @@ public class IsoSceneView implements SceneView
List locations = _scene.getLocations(); List locations = _scene.getLocations();
int size = locations.size(); int size = locations.size();
// create the location triangle
Polygon tri = new Polygon();
tri.addPoint(-3, -3);
tri.addPoint(3, -3);
tri.addPoint(0, 3);
for (int ii = 0; ii < size; ii++) { for (int ii = 0; ii < size; ii++) {
// retrieve the location // retrieve the location
Location loc = (Location)locations.get(ii); Location loc = (Location)locations.get(ii);
// get the cluster index this location is in, if any // get the cluster index this location is in, if any
int clusteridx = MisoSceneUtil.getClusterIndex(_scene, loc); int clusteridx = MisoSceneUtil.getClusterIndex(_scene, loc);
// get the location's center coordinate
Point spos = new Point(); Point spos = new Point();
IsoUtil.fullToScreen(_model, loc.x, loc.y, spos); IsoUtil.fullToScreen(_model, loc.x, loc.y, spos);
int cx = spos.x, cy = spos.y; int cx = spos.x, cy = spos.y;
// translate the origin to center on the location // paint the location
gfx.translate(cx, cy); loc.paint(gfx, cx, cy);
// rotate to reflect the location orientation
double rot = (Math.PI / 4.0f) * loc.orient;
gfx.rotate(rot);
// draw the triangle
Color fcol = (loc instanceof Portal) ? Color.green : Color.yellow;
gfx.setColor(fcol);
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);
if (clusteridx != -1) { if (clusteridx != -1) {
// draw the cluster index number on the right side // draw the cluster index number on the right side
gfx.setFont(_font); gfx.setFont(_font);
gfx.setColor(Color.white); gfx.setColor(Color.white);
gfx.drawString("" + clusteridx, cx + 5, cy + 3); 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);
}
}
} }
// documentation inherited // documentation inherited
@@ -1,17 +1,21 @@
// //
// $Id: Location.java,v 1.7 2001/09/28 01:25:26 mdb Exp $ // $Id: Location.java,v 1.8 2001/10/25 16:36:42 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;
import com.threerings.media.sprite.Sprite; import com.threerings.media.sprite.Sprite;
/** /**
* The <code>Location</code> class represents a unique well-defined * A location object represents a unique well-defined location within
* location within the scene at the lowest level of granularity * the scene at the lowest level of granularity available within the
* available within the scene coordinate system. Locations reside at * scene coordinate system. Locations reside at a full coordinate
* a full coordinate (comprised of tile coordinates and fine * (comprised of tile coordinates and fine coordinates within the
* coordinates within the tile), and only one location may reside at * tile), and only one location may reside at each full coordinate in
* each full coordinate in the scene. * the scene.
*/ */
public class Location public class Location
{ {
@@ -25,7 +29,7 @@ public class Location
public int orient; public int orient;
/** /**
* Construct a <code>Location</code> object. * Constructs a location object.
* *
* @param x the x-position full coordinate. * @param x the x-position full coordinate.
* @param y the y-position full coordinate. * @param y the y-position full coordinate.
@@ -39,7 +43,7 @@ public class Location
} }
/** /**
* Construct a <code>Location</code> object with a default orientation. * Constructs a location object with a default orientation.
* *
* @param x the x-position full coordinate. * @param x the x-position full coordinate.
* @param y the y-position full coordinate. * @param y the y-position full coordinate.
@@ -52,7 +56,41 @@ public class Location
} }
/** /**
* Return a String representation of this object. * 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 () public String toString ()
{ {
@@ -74,4 +112,22 @@ public class Location
buf.append(", y=").append(y); buf.append(", y=").append(y);
buf.append(", orient=").append(orient); 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,8 +1,10 @@
// //
// $Id: Portal.java,v 1.3 2001/08/21 01:15:16 shaper Exp $ // $Id: Portal.java,v 1.4 2001/10/25 16:36:43 shaper Exp $
package com.threerings.miso.scene; package com.threerings.miso.scene;
import java.awt.Color;
/** /**
* The portal class represents a {@link Location} in a scene that both * The portal class represents a {@link Location} in a scene that both
* leads to a different scene and serves as a potential entrance into * leads to a different scene and serves as a potential entrance into
@@ -53,9 +55,7 @@ public class Portal extends Location
return (sid != MisoScene.SID_INVALID && dest != null); return (sid != MisoScene.SID_INVALID && dest != null);
} }
/** // documentation inherited
* Return a String representation of this object.
*/
protected void toString (StringBuffer buf) protected void toString (StringBuffer buf)
{ {
super.toString(buf); super.toString(buf);
@@ -63,4 +63,10 @@ public class Portal extends Location
buf.append(", sid=").append(sid); buf.append(", sid=").append(sid);
buf.append(", dest=").append(dest); buf.append(", dest=").append(dest);
} }
// documentation inherited
protected Color getColor ()
{
return Color.green;
}
} }
@@ -1,5 +1,5 @@
// //
// $Id: XMLSceneParser.java,v 1.22 2001/10/22 18:21:41 shaper Exp $ // $Id: XMLSceneParser.java,v 1.23 2001/10/25 16:36:43 shaper Exp $
package com.threerings.miso.scene.xml; package com.threerings.miso.scene.xml;
@@ -74,6 +74,9 @@ public class XMLSceneParser extends SimpleParser
String vals[] = StringUtil.parseStringArray(data); String vals[] = StringUtil.parseStringArray(data);
addPortals(_info.scene.portals, _info.scene.locations, vals); addPortals(_info.scene.portals, _info.scene.locations, vals);
} else if (qName.equals("entrance")) {
_info.scene.entrance = getEntrancePortal(data);
} else if (qName.equals("row")) { } else if (qName.equals("row")) {
addTileRow(_info, data); addTileRow(_info, data);
@@ -244,6 +247,23 @@ public class XMLSceneParser extends SimpleParser
} }
} }
/**
* Returns the default entrance portal for the scene, or
* <code>null</code> if an error occurs.
*/
protected Portal getEntrancePortal (String data)
{
ArrayList locs = _info.scene.locations;
int size = locs.size();
int pidx = parseInt(data);
if (size == 0 || pidx < 0 || pidx > size - 1) {
return null;
}
return (Portal)locs.get(pidx);
}
/** /**
* Parse the specified XML file and return a miso scene object with * Parse the specified XML file and return a miso scene object with
* the data contained therein. * the data contained therein.
@@ -271,9 +291,6 @@ public class XMLSceneParser extends SimpleParser
/** Temporary storage of scene info while parsing. */ /** Temporary storage of scene info while parsing. */
protected SceneInfo _info; protected SceneInfo _info;
// TODO: allow specifying the entrance location for a scene in the
// editor, read/write to XML scene description files.
/** /**
* A class to hold the information gathered while parsing. * A class to hold the information gathered while parsing.
*/ */
@@ -1,5 +1,5 @@
// //
// $Id: XMLSceneWriter.java,v 1.17 2001/10/22 18:21:42 shaper Exp $ // $Id: XMLSceneWriter.java,v 1.18 2001/10/25 16:36:43 shaper Exp $
package com.threerings.miso.scene.xml; package com.threerings.miso.scene.xml;
@@ -62,6 +62,8 @@ public class XMLSceneWriter extends DataWriter
dataElement("portals", getPortalData(scene)); dataElement("portals", getPortalData(scene));
dataElement("entrance", getEntranceData(scene));
startElement("tiles"); startElement("tiles");
for (int lnum = 0; lnum < MisoScene.NUM_LAYERS; lnum++) { for (int lnum = 0; lnum < MisoScene.NUM_LAYERS; lnum++) {
writeLayer(scene, lnum); writeLayer(scene, lnum);
@@ -189,6 +191,23 @@ public class XMLSceneWriter extends DataWriter
return buf.toString(); return buf.toString();
} }
/**
* Returns a string detailing the location index of the default
* entrance portal for the scene, or <code>"-1"</code> if no
* default portal is specified or an error occurs.
*/
protected String getEntranceData (MisoScene scene)
{
List locs = scene.getLocations();
Portal entrance = scene.getEntrance();
if (locs.size() == 0 || entrance == null) {
return "-1";
}
return String.valueOf(locs.indexOf(entrance));
}
/** /**
* Return a string representation of the tiles at the specified * Return a string representation of the tiles at the specified
* row and layer in the given scene. Only <code>len</code> tiles * row and layer in the given scene. Only <code>len</code> tiles