Fixed up path-finding, path-following, and tile coordinate drawing.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@260 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-08-15 22:06:21 +00:00
parent 9f620978e5
commit affc3e82b7
7 changed files with 123 additions and 51 deletions
@@ -1,5 +1,5 @@
//
// $Id: IsoSceneView.java,v 1.46 2001/08/15 03:13:06 shaper Exp $
// $Id: IsoSceneView.java,v 1.47 2001/08/15 22:06:21 shaper Exp $
package com.threerings.miso.scene;
@@ -87,6 +87,11 @@ public class IsoSceneView implements EditableSceneView
clearDirtyRegions();
}
// draw sprite paths
if (_model.showPaths) {
_spritemgr.renderSpritePaths(gfx);
}
// draw marks at each location
if (_model.showLocs) {
paintLocations(gfx);
@@ -170,7 +175,8 @@ public class IsoSceneView implements EditableSceneView
// paint the tile coordinate if desired
if (_model.showCoords) {
paintCoords(gfx, xx, yy, poly.xpoints[0], poly.ypoints[0]);
paintCoords(gfx, xx, yy, poly.xpoints[0],
poly.ypoints[0] - _model.tilehhei);
}
// bail early if we know we've drawn all dirty tiles
@@ -567,6 +573,9 @@ public class IsoSceneView implements EditableSceneView
return null;
}
// TODO: make more visually appealing path segments from start
// to second tile, and penultimate to ultimate tile.
// construct path with starting screen position
Path path = new Path(sprite.x, sprite.y);
@@ -589,9 +598,6 @@ public class IsoSceneView implements EditableSceneView
path.addNode(nspos.x + _model.tilehwid,
nspos.y + _model.tilehhei, dir);
// Log.info("Adding node [tx=" + n.x + ", ty=" + n.y +
// ", dir=" + dir + "].");
prev = n;
}
@@ -1,5 +1,5 @@
//
// $Id: IsoSceneViewModel.java,v 1.7 2001/08/15 01:08:49 mdb Exp $
// $Id: IsoSceneViewModel.java,v 1.8 2001/08/15 22:06:21 shaper Exp $
package com.threerings.miso.scene;
@@ -65,6 +65,9 @@ public class IsoSceneModel
/** Whether locations in the scene should be drawn. */
public boolean showLocs;
/** Whether sprite paths should be drawn. */
public boolean showPaths;
/**
* Construct an IsoSceneModel with reasonable default values.
*/
@@ -126,6 +129,16 @@ public class IsoSceneModel
showCoords = show;
}
/**
* Set whether sprite paths should be drawn.
*
* @param show whether to show paths.
*/
public void setShowSpritePaths (boolean show)
{
showPaths = show;
}
/**
* Set the dimensions of the tiles that comprise the base layer of
* the isometric view and therefore drive the view geometry as a
@@ -1,5 +1,5 @@
//
// $Id: AStarPathUtil.java,v 1.1 2001/08/15 02:30:27 shaper Exp $
// $Id: AStarPathUtil.java,v 1.2 2001/08/15 22:06:21 shaper Exp $
package com.threerings.miso.scene.util;
@@ -109,22 +109,27 @@ public class AStarPathUtil
// skip node if it's impassable
// TODO: fix hard-coded consideration of only the base layer
if (!info.trav.canTraverse(info.tiles[x][y][0])) return;
if (!info.trav.canTraverse(info.tiles[x][y][0])) {
return;
}
// calculate the new cost for this node
int newg = n.g + 1; // getCost() is always 1?
int newg = n.g + 1; // cost to go node-to-node is always 1 for now
// retrieve the node corresponding to this location
AStarNode np = getNode(info, x, y);
// skip if it's already in the open or closed list or if its
// actual cost is less than the just-calculated cost
// TODO: shouldn't <= below be >=?
if ((info.open.contains(np) || info.closed.contains(np)) &&
np.g <= newg) {
return;
}
// remove the node from the open list since we're about to
// modify its score which determines its placement in the list
info.open.remove(np);
// update the node's information
np.parent = n;
np.g = newg;
@@ -134,7 +139,7 @@ public class AStarPathUtil
// remove it from the closed list if it's present
info.closed.remove(np);
// add it to the open list in case it's not already there
// add it to the open list for further consideration
info.open.add(np);
}
@@ -181,7 +186,7 @@ public class AStarPathUtil
*/
protected static int getDistanceEstimate (int ax, int ay, int bx, int by)
{
return (int)MathUtil.distance(ax, ay, bx, by);
return Math.max(Math.abs(bx - ax), Math.abs(by - ay));
}
}
@@ -264,14 +269,16 @@ class AStarNode implements Comparable
{
int bf = ((AStarNode)o).f;
if (f == bf){
return 0;
}
// since the set contract is fulfilled using the equality
// results returned here, and we'd like to allow multiple
// nodes with equivalent scores in our set, we explicitly
// define object equivalence as the result of object.equals(),
// else we use the object hashcode since it will return a
// consistent, though arbitrary, ordering for the objects.
if (f == bf) {
return (this == o) ? 0 : (hashCode() - o.hashCode());
}
if (f < bf) {
return -1;
}
return 1;
return f - bf;
}
}