Removed vestigal code, generally cleaned up.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2579 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
//
|
//
|
||||||
// $Id: TilePath.java,v 1.15 2003/04/27 03:53:41 mdb Exp $
|
// $Id: TilePath.java,v 1.16 2003/05/16 00:22:22 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.miso.client;
|
package com.threerings.miso.client;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.Point;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.threerings.util.DirectionCodes;
|
import com.threerings.util.DirectionCodes;
|
||||||
@@ -11,8 +11,6 @@ import com.threerings.util.DirectionCodes;
|
|||||||
import com.threerings.media.sprite.Sprite;
|
import com.threerings.media.sprite.Sprite;
|
||||||
import com.threerings.media.util.LineSegmentPath;
|
import com.threerings.media.util.LineSegmentPath;
|
||||||
import com.threerings.media.util.MathUtil;
|
import com.threerings.media.util.MathUtil;
|
||||||
import com.threerings.media.util.PathNode;
|
|
||||||
import com.threerings.media.util.Pathable;
|
|
||||||
|
|
||||||
import com.threerings.miso.Log;
|
import com.threerings.miso.Log;
|
||||||
import com.threerings.miso.util.MisoSceneMetrics;
|
import com.threerings.miso.util.MisoSceneMetrics;
|
||||||
@@ -41,85 +39,19 @@ public class TilePath extends LineSegmentPath
|
|||||||
*/
|
*/
|
||||||
public TilePath (MisoSceneMetrics metrics, Sprite sprite,
|
public TilePath (MisoSceneMetrics metrics, Sprite sprite,
|
||||||
List tiles, int destx, int desty)
|
List tiles, int destx, int desty)
|
||||||
{
|
|
||||||
_metrics = metrics;
|
|
||||||
|
|
||||||
// set up the path nodes
|
|
||||||
createPath(sprite, tiles, destx, desty);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the estimated number of millis that we'll be traveling
|
|
||||||
* along this path.
|
|
||||||
*/
|
|
||||||
public long getEstimTravelTime ()
|
|
||||||
{
|
|
||||||
return (long)(_estimPixels / _vel);
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
|
||||||
public boolean tick (Pathable pable, long timestamp)
|
|
||||||
{
|
|
||||||
boolean moved = super.tick(pable, timestamp);
|
|
||||||
|
|
||||||
if (moved) {
|
|
||||||
Sprite mcs = (Sprite)pable;
|
|
||||||
int sx = mcs.getX(), sy = mcs.getY();
|
|
||||||
Point pos = new Point();
|
|
||||||
|
|
||||||
// check whether we've arrived at the destination tile
|
|
||||||
if (!_arrived) {
|
|
||||||
// get the sprite's latest tile coordinates
|
|
||||||
MisoUtil.screenToTile(_metrics, sx, sy, pos);
|
|
||||||
|
|
||||||
// if the sprite has reached the destination tile,
|
|
||||||
// update the sprite's tile location and remember
|
|
||||||
// we've arrived
|
|
||||||
int dtx = _dest.getTileX(), dty = _dest.getTileY();
|
|
||||||
if (pos.x == dtx && pos.y == dty) {
|
|
||||||
// Log.info("Sprite arrived [dtx=" + dtx +
|
|
||||||
// ", dty=" + dty + "].");
|
|
||||||
_arrived = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log.info("Sprite moved [s=" + mcs + "].");
|
|
||||||
}
|
|
||||||
|
|
||||||
return moved;
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
|
||||||
protected PathNode getNextNode ()
|
|
||||||
{
|
|
||||||
// upgrade the path node to a tile path node
|
|
||||||
_dest = (TilePathNode)super.getNextNode();
|
|
||||||
|
|
||||||
// note that we've not yet arrived at the destination tile
|
|
||||||
_arrived = false;
|
|
||||||
|
|
||||||
return _dest;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Populate the path with the tile path nodes that lead the sprite
|
|
||||||
* from its starting position to the given destination coordinates
|
|
||||||
* following the given list of tile coordinates.
|
|
||||||
*/
|
|
||||||
protected void createPath (Sprite sprite, List tiles, int destx, int desty)
|
|
||||||
{
|
{
|
||||||
// constrain destination pixels to fine coordinates
|
// constrain destination pixels to fine coordinates
|
||||||
Point fpos = new Point();
|
Point fpos = new Point();
|
||||||
MisoUtil.screenToFull(_metrics, destx, desty, fpos);
|
MisoUtil.screenToFull(metrics, destx, desty, fpos);
|
||||||
|
|
||||||
// add the starting path node
|
// add the starting path node
|
||||||
Point ipos = new Point();
|
Point ipos = new Point();
|
||||||
int sx = sprite.getX(), sy = sprite.getY();
|
int sx = sprite.getX(), sy = sprite.getY();
|
||||||
MisoUtil.screenToTile(_metrics, sx, sy, ipos);
|
MisoUtil.screenToTile(metrics, sx, sy, ipos);
|
||||||
addNode(ipos.x, ipos.y, sx, sy, NORTH);
|
addNode(ipos.x, ipos.y, sx, sy, NORTH);
|
||||||
|
|
||||||
// TODO: make more visually appealing path segments from start
|
// TODO: make more visually appealing path segments from start to
|
||||||
// to second tile, and penultimate to ultimate tile.
|
// second tile, and penultimate to ultimate tile
|
||||||
|
|
||||||
// add all remaining path nodes excepting the last one
|
// add all remaining path nodes excepting the last one
|
||||||
Point prev = new Point(ipos.x, ipos.y);
|
Point prev = new Point(ipos.x, ipos.y);
|
||||||
@@ -132,12 +64,12 @@ public class TilePath extends LineSegmentPath
|
|||||||
int dir = MisoUtil.getIsoDirection(prev.x, prev.y, next.x, next.y);
|
int dir = MisoUtil.getIsoDirection(prev.x, prev.y, next.x, next.y);
|
||||||
|
|
||||||
// determine the node's position in screen pixel coordinates
|
// determine the node's position in screen pixel coordinates
|
||||||
MisoUtil.tileToScreen(_metrics, next.x, next.y, spos);
|
MisoUtil.tileToScreen(metrics, next.x, next.y, spos);
|
||||||
|
|
||||||
// add the node to the path, wandering through the middle
|
// add the node to the path, wandering through the middle
|
||||||
// of each tile in the path for now
|
// of each tile in the path for now
|
||||||
int dsx = spos.x + _metrics.tilehwid;
|
int dsx = spos.x + metrics.tilehwid;
|
||||||
int dsy = spos.y + _metrics.tilehhei;
|
int dsy = spos.y + metrics.tilehhei;
|
||||||
addNode(next.x, next.y, dsx, dsy, dir);
|
addNode(next.x, next.y, dsx, dsy, dir);
|
||||||
|
|
||||||
prev = next;
|
prev = next;
|
||||||
@@ -145,7 +77,7 @@ public class TilePath extends LineSegmentPath
|
|||||||
|
|
||||||
// get the final destination point's screen coordinates
|
// get the final destination point's screen coordinates
|
||||||
// constrained to the closest full coordinate
|
// constrained to the closest full coordinate
|
||||||
MisoUtil.fullToScreen(_metrics, fpos.x, fpos.y, spos);
|
MisoUtil.fullToScreen(metrics, fpos.x, fpos.y, spos);
|
||||||
|
|
||||||
// get the tile coordinates for the final destination tile
|
// get the tile coordinates for the final destination tile
|
||||||
int tdestx = MisoUtil.fullToTile(fpos.x);
|
int tdestx = MisoUtil.fullToTile(fpos.x);
|
||||||
@@ -156,7 +88,7 @@ public class TilePath extends LineSegmentPath
|
|||||||
if (prev.x == ipos.x && prev.y == ipos.y) {
|
if (prev.x == ipos.x && prev.y == ipos.y) {
|
||||||
// if destination is within starting tile, direction is
|
// if destination is within starting tile, direction is
|
||||||
// determined by studying the fine coordinates
|
// determined by studying the fine coordinates
|
||||||
dir = MisoUtil.getDirection(_metrics, sx, sy, spos.x, spos.y);
|
dir = MisoUtil.getDirection(metrics, sx, sy, spos.x, spos.y);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// else it's based on the last tile we traversed
|
// else it's based on the last tile we traversed
|
||||||
@@ -167,6 +99,15 @@ public class TilePath extends LineSegmentPath
|
|||||||
addNode(tdestx, tdesty, spos.x, spos.y, dir);
|
addNode(tdestx, tdesty, spos.x, spos.y, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the estimated number of millis that we'll be traveling
|
||||||
|
* along this path.
|
||||||
|
*/
|
||||||
|
public long getEstimTravelTime ()
|
||||||
|
{
|
||||||
|
return (long)(_estimPixels / _vel);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a node to the path with the specified destination
|
* Add a node to the path with the specified destination
|
||||||
* coordinates and facing direction.
|
* coordinates and facing direction.
|
||||||
@@ -188,18 +129,9 @@ public class TilePath extends LineSegmentPath
|
|||||||
_nodes.add(new TilePathNode(tx, ty, x, y, dir));
|
_nodes.add(new TilePathNode(tx, ty, x, y, dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether the sprite has arrived at the current destination tile. */
|
|
||||||
protected boolean _arrived;
|
|
||||||
|
|
||||||
/** The destination tile path node. */
|
|
||||||
protected TilePathNode _dest;
|
|
||||||
|
|
||||||
/** Used to compute estimated travel time. */
|
/** Used to compute estimated travel time. */
|
||||||
protected Point _last;
|
protected Point _last;
|
||||||
|
|
||||||
/** Estimated pixels traveled. */
|
/** Estimated pixels traveled. */
|
||||||
protected int _estimPixels;
|
protected int _estimPixels;
|
||||||
|
|
||||||
/** The scene metrics. */
|
|
||||||
protected MisoSceneMetrics _metrics;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user