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:
@@ -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