From f0ff20fd2373ef1905046c62f05d19f704a34d65 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 25 Mar 2011 03:19:51 +0000 Subject: [PATCH] Come to think of it, we don't need to maintain a list of closed nodes; we can just use a flag. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@1131 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../com/threerings/media/util/AStarPathUtil.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/threerings/media/util/AStarPathUtil.java b/src/main/java/com/threerings/media/util/AStarPathUtil.java index f166f4e9..65ad1fd2 100644 --- a/src/main/java/com/threerings/media/util/AStarPathUtil.java +++ b/src/main/java/com/threerings/media/util/AStarPathUtil.java @@ -23,14 +23,12 @@ package com.threerings.media.util; import java.util.ArrayList; import java.util.List; -import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.awt.Point; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import com.samskivert.util.HashIntMap; @@ -187,7 +185,7 @@ public class AStarPathUtil stepper.considerSteps(n.x, n.y); // push the node on the closed list - info.closed.add(n); + n.closed = true; } // return the best path we could find if we were asked to do so @@ -248,7 +246,7 @@ public class AStarPathUtil // skip if it's already in the open or closed list or if its // actual cost is less than the just-calculated cost - if ((info.open.contains(np) || info.closed.contains(np)) && np.g <= newg) { + if ((info.open.contains(np) || np.closed) && np.g <= newg) { return; } @@ -263,7 +261,7 @@ public class AStarPathUtil np.f = np.g + np.h; // remove it from the closed list if it's present - info.closed.remove(np); + np.closed = false; // add it to the open list for further consideration info.open.add(np); @@ -325,9 +323,6 @@ public class AStarPathUtil /** The set of open nodes being searched. */ public SortedSet open; - /** The set of closed nodes being searched. */ - public Set closed; - /** The destination coordinates in the tile array. */ public int destx, desty; @@ -346,7 +341,6 @@ public class AStarPathUtil // construct the open and closed lists open = new TreeSet(); - closed = Sets.newIdentityHashSet(); } /** @@ -422,6 +416,9 @@ public class AStarPathUtil /** The node's monotonically-increasing unique identifier. */ public int id; + /** Whether or not this node is on the closed list. */ + public boolean closed; + public Node (int x, int y) { this.x = x; this.y = y;