Allow whirled.spot.data.Location to be extended so that games
with 3d coordinate systems (or that track additional location information besides orientation) can just drop in their new Location class. Refactored Portal to contain a Location object rather than duplicate the fields, so that Portals can work unchanged with a 3d coordinate system. Note: I haven't yet updated SpotSceneRuleSet. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4072 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -163,9 +163,9 @@ public class StageScenePanel extends MisoScenePanel
|
||||
_portobjs.clear();
|
||||
for (Iterator iter = _scene.getPortals(); iter.hasNext(); ) {
|
||||
Portal portal = (Portal) iter.next();
|
||||
Point p = getScreenCoords(portal.x, portal.y);
|
||||
int tx = MisoUtil.fullToTile(portal.x);
|
||||
int ty = MisoUtil.fullToTile(portal.y);
|
||||
Point p = getScreenCoords(portal.loc.x, portal.loc.y);
|
||||
int tx = MisoUtil.fullToTile(portal.loc.x);
|
||||
int ty = MisoUtil.fullToTile(portal.loc.y);
|
||||
Point ts = MisoUtil.tileToScreen(_metrics, tx, ty, new Point());
|
||||
|
||||
// Log.info("Added portal " + portal +
|
||||
@@ -180,7 +180,7 @@ public class StageScenePanel extends MisoScenePanel
|
||||
ObjectTile tile = new PortalObjectTile(
|
||||
ts.x + _metrics.tilehwid - p.x + (PORTAL_ICON_WIDTH / 2),
|
||||
ts.y + _metrics.tilehei - p.y + (PORTAL_ICON_HEIGHT / 2));
|
||||
tile.setImage(ots.getTileMirage(portal.orient));
|
||||
tile.setImage(ots.getTileMirage(portal.loc.orient));
|
||||
|
||||
_portobjs.add(new SceneObject(this, info, tile) {
|
||||
public boolean setHovered (boolean hovered) {
|
||||
@@ -482,7 +482,7 @@ public class StageScenePanel extends MisoScenePanel
|
||||
Iterator iter = _scene.getPortals();
|
||||
while (iter.hasNext()) {
|
||||
Portal portal = (Portal)iter.next();
|
||||
if (portal.x == fullX && portal.y == fullY) {
|
||||
if (portal.loc.x == fullX && portal.loc.y == fullY) {
|
||||
return portal;
|
||||
}
|
||||
}
|
||||
@@ -554,7 +554,7 @@ public class StageScenePanel extends MisoScenePanel
|
||||
Iterator iter = _scene.getPortals();
|
||||
while (iter.hasNext()) {
|
||||
Portal p = (Portal)iter.next();
|
||||
if (p.x == loc.x && p.y == loc.y) {
|
||||
if (loc.equals(p.loc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,8 +307,8 @@ public class StageSceneManager extends SpotSceneManager
|
||||
_plocs.clear();
|
||||
for (Iterator iter = _sscene.getPortals(); iter.hasNext(); ) {
|
||||
Portal port = (Portal)iter.next();
|
||||
_plocs.add(new Point(MisoUtil.fullToTile(port.x),
|
||||
MisoUtil.fullToTile(port.y)));
|
||||
_plocs.add(new Point(MisoUtil.fullToTile(port.loc.x),
|
||||
MisoUtil.fullToTile(port.loc.y)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -889,14 +889,14 @@ public class EditorScenePanel extends StageScenePanel
|
||||
{
|
||||
// get the portal's center coordinate
|
||||
Point spos = new Point();
|
||||
MisoUtil.fullToScreen(_metrics, port.x, port.y, spos);
|
||||
MisoUtil.fullToScreen(_metrics, port.loc.x, port.loc.y, spos);
|
||||
int cx = spos.x, cy = spos.y;
|
||||
|
||||
// translate the origin to center on the portal
|
||||
gfx.translate(cx, cy);
|
||||
|
||||
// rotate to reflect the portal orientation
|
||||
double rot = (Math.PI / 4.0f) * port.orient;
|
||||
double rot = (Math.PI / 4.0f) * port.loc.orient;
|
||||
gfx.rotate(rot);
|
||||
|
||||
// draw the triangle
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.threerings.miso.util.MisoUtil;
|
||||
import com.threerings.util.DirectionCodes;
|
||||
import com.threerings.util.DirectionUtil;
|
||||
|
||||
import com.threerings.whirled.spot.data.Location;
|
||||
import com.threerings.whirled.spot.tools.EditablePortal;
|
||||
|
||||
import com.threerings.stage.data.StageScene;
|
||||
@@ -36,8 +37,7 @@ public class PortalTool extends MouseInputAdapter
|
||||
|
||||
// configure the portal with these full coordinates
|
||||
_portal = new EditablePortal();
|
||||
_portal.x = p.x;
|
||||
_portal.y = p.y;
|
||||
_portal.loc = new Location(p.x, p.y, (byte)DirectionCodes.NORTH);
|
||||
|
||||
// we want to listen to drags and clicks
|
||||
_panel.addMouseListener(this);
|
||||
@@ -99,8 +99,8 @@ public class PortalTool extends MouseInputAdapter
|
||||
}
|
||||
|
||||
// if our orientation changed, repaint
|
||||
if (norient != _portal.orient) {
|
||||
_portal.orient = (byte)norient;
|
||||
if (norient != _portal.loc.orient) {
|
||||
_portal.loc.orient = (byte)norient;
|
||||
_panel.repaint();
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,8 @@ public class PortalTool extends MouseInputAdapter
|
||||
protected void savePortal ()
|
||||
{
|
||||
// try to come up with a reasonable name
|
||||
String dirname = DirectionUtil.toString(_portal.orient).toLowerCase();
|
||||
String dirname =
|
||||
DirectionUtil.toString(_portal.loc.orient).toLowerCase();
|
||||
String name = dirname;
|
||||
for (int ii=1; portalNameExists(name); ii++) {
|
||||
name = dirname + ii;
|
||||
|
||||
@@ -39,14 +39,10 @@ public class Portal extends SimpleStreamableObject
|
||||
/** This portal's unique identifier. */
|
||||
public short portalId;
|
||||
|
||||
/** This portal's x coordinate (interpreted by the display system). */
|
||||
public int x;
|
||||
|
||||
/** This portal's y coordinate (interpreted by the display system). */
|
||||
public int y;
|
||||
|
||||
/** This portal's y orientation (interpreted by the display system). */
|
||||
public byte orient;
|
||||
/** The location of the portal. Typically this is a base Location (2d)
|
||||
* class, but different games could use a different subclass of
|
||||
* Location. */
|
||||
public Location loc;
|
||||
|
||||
/** The scene identifier of the scene to which a body will exit when
|
||||
* they "use" this portal. */
|
||||
@@ -62,7 +58,7 @@ public class Portal extends SimpleStreamableObject
|
||||
*/
|
||||
public Location getLocation ()
|
||||
{
|
||||
return new Location(x, y, orient);
|
||||
return (Location) loc.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +70,9 @@ public class Portal extends SimpleStreamableObject
|
||||
*/
|
||||
public Location getOppLocation ()
|
||||
{
|
||||
return new Location(x, y, (byte)DirectionUtil.getOpposite(orient));
|
||||
Location oppLoc = getLocation();
|
||||
oppLoc.orient = (byte) DirectionUtil.getOpposite(oppLoc.orient);
|
||||
return oppLoc;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,12 +110,6 @@ public class Portal extends SimpleStreamableObject
|
||||
}
|
||||
}
|
||||
|
||||
/** {@link #toString} helper function. */
|
||||
public String orientToString ()
|
||||
{
|
||||
return DirectionUtil.toShortString(orient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a reasonable hashcode for portal instances.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SpotSceneWriter.java,v 1.9 2004/08/27 02:20:48 mdb Exp $
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -27,6 +27,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||
import com.megginson.sax.DataWriter;
|
||||
import com.threerings.tools.xml.NestableWriter;
|
||||
|
||||
import com.threerings.whirled.spot.data.Location;
|
||||
import com.threerings.whirled.spot.data.SpotSceneModel;
|
||||
import com.threerings.whirled.spot.tools.EditablePortal;
|
||||
|
||||
@@ -56,7 +57,7 @@ public class SpotSceneWriter
|
||||
{
|
||||
if (model.defaultEntranceId != -1) {
|
||||
attrs.addAttribute("", "defaultEntranceId", "", "",
|
||||
Integer.toString(model.defaultEntranceId));
|
||||
String.valueOf(model.defaultEntranceId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,11 +69,8 @@ public class SpotSceneWriter
|
||||
EditablePortal port = (EditablePortal)model.portals[ii];
|
||||
AttributesImpl attrs = new AttributesImpl();
|
||||
attrs.addAttribute("", "portalId", "", "",
|
||||
Integer.toString(port.portalId));
|
||||
attrs.addAttribute("", "x", "", "", Integer.toString(port.x));
|
||||
attrs.addAttribute("", "y", "", "", Integer.toString(port.y));
|
||||
attrs.addAttribute("", "orient", "", "",
|
||||
Integer.toString(port.orient));
|
||||
String.valueOf(port.portalId));
|
||||
addPortalLocationAttributes(port.loc, attrs);
|
||||
maybeAddAttr(attrs, "name", port.name);
|
||||
maybeAddAttr(attrs, "targetSceneName", port.targetSceneName);
|
||||
maybeAddAttr(attrs, "targetPortalName", port.targetPortalName);
|
||||
@@ -80,6 +78,17 @@ public class SpotSceneWriter
|
||||
}
|
||||
}
|
||||
|
||||
protected void addPortalLocationAttributes (
|
||||
Location portalLoc, AttributesImpl attrs)
|
||||
{
|
||||
// we assume here that the Location is purely 2d. Subclasses
|
||||
// may write out more information
|
||||
attrs.addAttribute("", "x", "", "", String.valueOf(portalLoc.x));
|
||||
attrs.addAttribute("", "y", "", "", String.valueOf(portalLoc.y));
|
||||
attrs.addAttribute("", "orient", "", "",
|
||||
String.valueOf(portalLoc.orient));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the supplied attribute to the attributes object iff the value
|
||||
* is non-null.
|
||||
|
||||
Reference in New Issue
Block a user