优化寻路速度
This commit is contained in:
@@ -309,7 +309,11 @@ var es;
|
|||||||
costSoFar.set(start, 0);
|
costSoFar.set(start, 0);
|
||||||
var _loop_2 = function () {
|
var _loop_2 = function () {
|
||||||
var current = frontier.dequeue();
|
var current = frontier.dequeue();
|
||||||
if (JSON.stringify(current.data) == JSON.stringify(goal)) {
|
if (current.data instanceof es.Vector2 && goal instanceof es.Vector2 && current.data.equals(goal)) {
|
||||||
|
foundPath = true;
|
||||||
|
return "break";
|
||||||
|
}
|
||||||
|
else if (current.data == goal) {
|
||||||
foundPath = true;
|
foundPath = true;
|
||||||
return "break";
|
return "break";
|
||||||
}
|
}
|
||||||
@@ -345,7 +349,9 @@ var es;
|
|||||||
var iterator = map.keys();
|
var iterator = map.keys();
|
||||||
var r;
|
var r;
|
||||||
while (r = iterator.next(), !r.done) {
|
while (r = iterator.next(), !r.done) {
|
||||||
if (JSON.stringify(r.value) == JSON.stringify(compareKey))
|
if (r.value instanceof es.Vector2 && compareKey instanceof es.Vector2 && r.value.equals(compareKey))
|
||||||
|
return true;
|
||||||
|
else if (r.value == compareKey)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -356,7 +362,9 @@ var es;
|
|||||||
var r;
|
var r;
|
||||||
var v;
|
var v;
|
||||||
while (r = iterator.next(), v = valueIterator.next(), !r.done) {
|
while (r = iterator.next(), v = valueIterator.next(), !r.done) {
|
||||||
if (JSON.stringify(r.value) == JSON.stringify(compareKey))
|
if (r.value instanceof es.Vector2 && compareKey instanceof es.Vector2 && r.value.equals(compareKey))
|
||||||
|
return v.value;
|
||||||
|
else if (r.value == compareKey)
|
||||||
return v.value;
|
return v.value;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -397,7 +405,7 @@ var es;
|
|||||||
return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
|
return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
|
||||||
};
|
};
|
||||||
AstarGridGraph.prototype.isNodePassable = function (node) {
|
AstarGridGraph.prototype.isNodePassable = function (node) {
|
||||||
return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); });
|
return !this.walls.firstOrDefault(function (wall) { return wall.equals(node); });
|
||||||
};
|
};
|
||||||
AstarGridGraph.prototype.search = function (start, goal) {
|
AstarGridGraph.prototype.search = function (start, goal) {
|
||||||
return es.AStarPathfinder.search(this, start, goal);
|
return es.AStarPathfinder.search(this, start, goal);
|
||||||
@@ -413,7 +421,7 @@ var es;
|
|||||||
return this._neighbors;
|
return this._neighbors;
|
||||||
};
|
};
|
||||||
AstarGridGraph.prototype.cost = function (from, to) {
|
AstarGridGraph.prototype.cost = function (from, to) {
|
||||||
return this.weightedNodes.find(function (p) { return JSON.stringify(p) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight;
|
return this.weightedNodes.find(function (p) { return p.equals(to); }) ? this.weightedNodeWeight : this.defaultWeight;
|
||||||
};
|
};
|
||||||
AstarGridGraph.prototype.heuristic = function (node, goal) {
|
AstarGridGraph.prototype.heuristic = function (node, goal) {
|
||||||
return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y);
|
return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y);
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+6
-15
@@ -14,31 +14,22 @@
|
|||||||
"game": [
|
"game": [
|
||||||
"bin-debug/Fgui/common/commonBinder.js",
|
"bin-debug/Fgui/common/commonBinder.js",
|
||||||
"bin-debug/UI/mvc/BaseView.js",
|
"bin-debug/UI/mvc/BaseView.js",
|
||||||
"bin-debug/SampleHelpers/SampleScene.js",
|
|
||||||
"bin-debug/Scenes/Ninja Adventure/ProjectileHitDetector.js",
|
|
||||||
"bin-debug/UI/loading/LoadingView.js",
|
"bin-debug/UI/loading/LoadingView.js",
|
||||||
"bin-debug/Scenes/Ninja Adventure/CameraBounds.js",
|
"bin-debug/UI/PopManager.js",
|
||||||
|
"bin-debug/AssetAdapter.js",
|
||||||
|
"bin-debug/Fgui/common/UI_com_tips.js",
|
||||||
"bin-debug/Fgui/loading/loadingBinder.js",
|
"bin-debug/Fgui/loading/loadingBinder.js",
|
||||||
"bin-debug/Fgui/loading/UI_View_loading.js",
|
"bin-debug/Fgui/loading/UI_View_loading.js",
|
||||||
"bin-debug/Fgui/sc/scBinder.js",
|
"bin-debug/Fgui/sc/scBinder.js",
|
||||||
"bin-debug/Fgui/sc/UI_btn_sc.js",
|
"bin-debug/Fgui/sc/UI_btn_sc.js",
|
||||||
"bin-debug/Fgui/sc/UI_combo_sc_popup.js",
|
"bin-debug/Fgui/sc/UI_combo_sc_popup.js",
|
||||||
"bin-debug/Fgui/sc/UI_View_sc.js",
|
"bin-debug/Fgui/sc/UI_View_sc.js",
|
||||||
"bin-debug/Platform.js",
|
"bin-debug/SampleHelpers/SampleScene.js",
|
||||||
"bin-debug/Scenes/Animated Tiles/AnimatedTilesScene.js",
|
|
||||||
"bin-debug/Scenes/Empty Scene/BasicScene.js",
|
|
||||||
"bin-debug/Scenes/LineCasting/LineCaster.js",
|
|
||||||
"bin-debug/Scenes/LineCasting/LineCastingScene.js",
|
|
||||||
"bin-debug/Main.js",
|
"bin-debug/Main.js",
|
||||||
"bin-debug/Scenes/Ninja Adventure/FireballProjectileController.js",
|
|
||||||
"bin-debug/Scenes/Ninja Adventure/Ninja.js",
|
|
||||||
"bin-debug/Scenes/Ninja Adventure/NinjaAdventureScene.js",
|
|
||||||
"bin-debug/ThemeAdapter.js",
|
|
||||||
"bin-debug/UI/PopManager.js",
|
|
||||||
"bin-debug/UI/loading/LoadingControl.js",
|
"bin-debug/UI/loading/LoadingControl.js",
|
||||||
"bin-debug/UI/loading/LoadingEvents.js",
|
"bin-debug/UI/loading/LoadingEvents.js",
|
||||||
"bin-debug/AssetAdapter.js",
|
"bin-debug/Platform.js",
|
||||||
"bin-debug/Fgui/common/UI_com_tips.js",
|
"bin-debug/ThemeAdapter.js",
|
||||||
"bin-debug/UI/mvc/EventManager.js",
|
"bin-debug/UI/mvc/EventManager.js",
|
||||||
"bin-debug/UI/mvc/Extension.js",
|
"bin-debug/UI/mvc/Extension.js",
|
||||||
"bin-debug/UI/mvc/FguiUtils.js",
|
"bin-debug/UI/mvc/FguiUtils.js",
|
||||||
|
|||||||
+13
-5
@@ -309,7 +309,11 @@ var es;
|
|||||||
costSoFar.set(start, 0);
|
costSoFar.set(start, 0);
|
||||||
var _loop_2 = function () {
|
var _loop_2 = function () {
|
||||||
var current = frontier.dequeue();
|
var current = frontier.dequeue();
|
||||||
if (JSON.stringify(current.data) == JSON.stringify(goal)) {
|
if (current.data instanceof es.Vector2 && goal instanceof es.Vector2 && current.data.equals(goal)) {
|
||||||
|
foundPath = true;
|
||||||
|
return "break";
|
||||||
|
}
|
||||||
|
else if (current.data == goal) {
|
||||||
foundPath = true;
|
foundPath = true;
|
||||||
return "break";
|
return "break";
|
||||||
}
|
}
|
||||||
@@ -345,7 +349,9 @@ var es;
|
|||||||
var iterator = map.keys();
|
var iterator = map.keys();
|
||||||
var r;
|
var r;
|
||||||
while (r = iterator.next(), !r.done) {
|
while (r = iterator.next(), !r.done) {
|
||||||
if (JSON.stringify(r.value) == JSON.stringify(compareKey))
|
if (r.value instanceof es.Vector2 && compareKey instanceof es.Vector2 && r.value.equals(compareKey))
|
||||||
|
return true;
|
||||||
|
else if (r.value == compareKey)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -356,7 +362,9 @@ var es;
|
|||||||
var r;
|
var r;
|
||||||
var v;
|
var v;
|
||||||
while (r = iterator.next(), v = valueIterator.next(), !r.done) {
|
while (r = iterator.next(), v = valueIterator.next(), !r.done) {
|
||||||
if (JSON.stringify(r.value) == JSON.stringify(compareKey))
|
if (r.value instanceof es.Vector2 && compareKey instanceof es.Vector2 && r.value.equals(compareKey))
|
||||||
|
return v.value;
|
||||||
|
else if (r.value == compareKey)
|
||||||
return v.value;
|
return v.value;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -397,7 +405,7 @@ var es;
|
|||||||
return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
|
return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
|
||||||
};
|
};
|
||||||
AstarGridGraph.prototype.isNodePassable = function (node) {
|
AstarGridGraph.prototype.isNodePassable = function (node) {
|
||||||
return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); });
|
return !this.walls.firstOrDefault(function (wall) { return wall.equals(node); });
|
||||||
};
|
};
|
||||||
AstarGridGraph.prototype.search = function (start, goal) {
|
AstarGridGraph.prototype.search = function (start, goal) {
|
||||||
return es.AStarPathfinder.search(this, start, goal);
|
return es.AStarPathfinder.search(this, start, goal);
|
||||||
@@ -413,7 +421,7 @@ var es;
|
|||||||
return this._neighbors;
|
return this._neighbors;
|
||||||
};
|
};
|
||||||
AstarGridGraph.prototype.cost = function (from, to) {
|
AstarGridGraph.prototype.cost = function (from, to) {
|
||||||
return this.weightedNodes.find(function (p) { return JSON.stringify(p) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight;
|
return this.weightedNodes.find(function (p) { return p.equals(to); }) ? this.weightedNodeWeight : this.defaultWeight;
|
||||||
};
|
};
|
||||||
AstarGridGraph.prototype.heuristic = function (node, goal) {
|
AstarGridGraph.prototype.heuristic = function (node, goal) {
|
||||||
return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y);
|
return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y);
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -24,7 +24,10 @@ module es {
|
|||||||
while (frontier.count > 0) {
|
while (frontier.count > 0) {
|
||||||
let current = frontier.dequeue();
|
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;
|
foundPath = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -68,7 +71,9 @@ module es {
|
|||||||
let iterator = map.keys();
|
let iterator = map.keys();
|
||||||
let r: IteratorResult<T>;
|
let r: IteratorResult<T>;
|
||||||
while (r = iterator.next() , !r.done) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +86,9 @@ module es {
|
|||||||
let r: IteratorResult<T>;
|
let r: IteratorResult<T>;
|
||||||
let v: IteratorResult<T>;
|
let v: IteratorResult<T>;
|
||||||
while (r = iterator.next(), v = valueIterator.next(), !r.done) {
|
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;
|
return v.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ module es {
|
|||||||
* @param node
|
* @param node
|
||||||
*/
|
*/
|
||||||
public isNodePassable(node: Vector2): boolean {
|
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 {
|
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) {
|
public heuristic(node: Vector2, goal: Vector2) {
|
||||||
|
|||||||
Reference in New Issue
Block a user