优化寻路速度
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ module es {
|
||||
* @param node
|
||||
*/
|
||||
public isNodePassable(node: Vector2): boolean {
|
||||
return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node));
|
||||
return !this.walls.firstOrDefault(wall => wall.equals(node));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ module es {
|
||||
}
|
||||
|
||||
public cost(from: Vector2, to: Vector2): number {
|
||||
return this.weightedNodes.find((p) => JSON.stringify(p) == JSON.stringify(to)) ? this.weightedNodeWeight : this.defaultWeight;
|
||||
return this.weightedNodes.find((p) => p.equals(to)) ? this.weightedNodeWeight : this.defaultWeight;
|
||||
}
|
||||
|
||||
public heuristic(node: Vector2, goal: Vector2) {
|
||||
|
||||
Reference in New Issue
Block a user