From 6913e5a127850e4a14828d8dacb857180c6051bb Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Fri, 21 Jul 2006 08:23:42 +0000 Subject: [PATCH] Created an ExtendedTraversalPred that can check if the movement from one tile to another is traversable instead of just the destination being a traversable tile git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@18 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../threerings/media/util/AStarPathUtil.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/java/com/threerings/media/util/AStarPathUtil.java b/src/java/com/threerings/media/util/AStarPathUtil.java index 4583fda0..9232f507 100644 --- a/src/java/com/threerings/media/util/AStarPathUtil.java +++ b/src/java/com/threerings/media/util/AStarPathUtil.java @@ -52,6 +52,21 @@ public class AStarPathUtil public boolean canTraverse (Object traverser, int x, int y); } + /** + * Provides extended traversibility information when computing paths. + */ + public static interface ExtendedTraversalPred extends TraversalPred + { + /** + * Requests to know if the specific traverser (which was provided + * in the call to {@link #getPath}) can traverse from the specified + * source tile coordinate to the specified destination tile + * coodinate. + */ + public boolean canTraverse ( + Object traverser, int sx, int sy, int dx, int dy); + } + /** * Considers all the possible steps the piece in question can take. */ @@ -338,8 +353,15 @@ public class AStarPathUtil protected boolean isStepValid (int sx, int sy, int dx, int dy) { // not traversable if the destination itself fails test - if (!isTraversable(dx, dy)) { - return false; + if (tpred instanceof ExtendedTraversalPred) { + if (!((ExtendedTraversalPred)tpred).canTraverse( + trav, sx, sy, dx, dy)) { + return false; + } + } else { + if (!isTraversable(dx, dy)) { + return false; + } } // if the step is diagonal, make sure the corners don't impede