From a54e01a0fd9293b46f7ebdb18a3a6c6cc0dbead3 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sun, 27 Apr 2003 03:53:41 +0000 Subject: [PATCH] Provide estimated travel time. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2473 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/miso/client/TilePath.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/miso/client/TilePath.java b/src/java/com/threerings/miso/client/TilePath.java index bc859c959..33d208684 100644 --- a/src/java/com/threerings/miso/client/TilePath.java +++ b/src/java/com/threerings/miso/client/TilePath.java @@ -1,5 +1,5 @@ // -// $Id: TilePath.java,v 1.14 2003/04/17 19:21:16 mdb Exp $ +// $Id: TilePath.java,v 1.15 2003/04/27 03:53:41 mdb Exp $ package com.threerings.miso.client; @@ -10,6 +10,7 @@ import com.threerings.util.DirectionCodes; import com.threerings.media.sprite.Sprite; import com.threerings.media.util.LineSegmentPath; +import com.threerings.media.util.MathUtil; import com.threerings.media.util.PathNode; import com.threerings.media.util.Pathable; @@ -47,6 +48,15 @@ public class TilePath extends LineSegmentPath 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) { @@ -169,6 +179,12 @@ public class TilePath extends LineSegmentPath */ protected void addNode (int tx, int ty, int x, int y, int dir) { + if (_last == null) { + _last = new Point(); + } else { + _estimPixels += MathUtil.distance(_last.x, _last.y, x, y); + } + _last.setLocation(x, y); _nodes.add(new TilePathNode(tx, ty, x, y, dir)); } @@ -178,6 +194,12 @@ public class TilePath extends LineSegmentPath /** The destination tile path node. */ protected TilePathNode _dest; + /** Used to compute estimated travel time. */ + protected Point _last; + + /** Estimated pixels traveled. */ + protected int _estimPixels; + /** The scene metrics. */ protected MisoSceneMetrics _metrics; }