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,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