优化寻路速度

This commit is contained in:
yhh
2020-09-14 17:54:17 +08:00
parent 700d0194be
commit 24a463b85b
7 changed files with 46 additions and 32 deletions

View File

@@ -24,7 +24,10 @@ module es {
while (frontier.count > 0) {
let current = frontier.dequeue();
if (JSON.stringify(current.data) == JSON.stringify(goal)) {
if (current.data instanceof Vector2 && goal instanceof Vector2 && current.data.equals(goal)) {
foundPath = true;
break;
} else if (current.data == goal){
foundPath = true;
break;
}
@@ -68,7 +71,9 @@ module es {
let iterator = map.keys();
let r: IteratorResult<T>;
while (r = iterator.next() , !r.done) {
if (JSON.stringify(r.value) == JSON.stringify(compareKey))
if (r.value instanceof Vector2 && compareKey instanceof Vector2 && r.value.equals(compareKey))
return true;
else if (r.value == compareKey)
return true;
}
@@ -81,7 +86,9 @@ module es {
let r: IteratorResult<T>;
let v: IteratorResult<T>;
while (r = iterator.next(), v = valueIterator.next(), !r.done) {
if (JSON.stringify(r.value) == JSON.stringify(compareKey))
if (r.value instanceof Vector2 && compareKey instanceof Vector2 && r.value.equals(compareKey))
return v.value;
else if (r.value == compareKey)
return v.value;
}