check bi-directional paths in graph building
This commit is contained in:
+15
-10
@@ -88,20 +88,21 @@ export default class Entity {
|
||||
|
||||
async takeStep(distanceTraveled = 0) {
|
||||
const speed = (this.speed / (this.game?.tickBudget ?? 1000)) - distanceTraveled
|
||||
const collidables = this.collidables()
|
||||
if (this.#dest != null) {
|
||||
const fixedDest = SATX.clamp(SATX.fixCollisions(this.#dest, this.collidables(), this.radius), this.game?.width, this.game?.height, this.radius)
|
||||
const fixedDest = SATX.clamp(SATX.fixCollisions(this.#dest, collidables, this.radius), this.game?.width, this.game?.height, this.radius)
|
||||
|
||||
if (this.#path.length < 1 || !this.#path.at(-1).equals(this.#dest)) {
|
||||
if (this.#path.length < 1 || !this.#path.at(-1).equals(fixedDest)) {
|
||||
console.time('pathfinding')
|
||||
console.time('waypoints')
|
||||
const waypoints = (this.game?.unadjustedWaypoints.map(([unadjusted, direction]) => unadjusted.clone().add(direction.clone().multiplyScalar(this.radius))) ?? []).concat([this.position, fixedDest])
|
||||
console.timeEnd('waypoints')
|
||||
console.time('graph')
|
||||
const graph = Pathfind.buildGraph(waypoints, this.collidables(), this.radius)
|
||||
console.timeEnd('graph')
|
||||
console.time('path')
|
||||
// console.time('waypoints')
|
||||
const waypoints = this.waypoints().concat([this.position, fixedDest])
|
||||
// console.timeEnd('waypoints')
|
||||
// console.time('graph')
|
||||
const graph = Pathfind.buildGraph(waypoints, collidables, this.radius)
|
||||
// console.timeEnd('graph')
|
||||
// console.time('path')
|
||||
this.#path = Pathfind.shortestPath(graph, this.position, fixedDest)
|
||||
console.timeEnd('path')
|
||||
// console.timeEnd('path')
|
||||
console.timeEnd('pathfinding')
|
||||
}
|
||||
|
||||
@@ -137,4 +138,8 @@ export default class Entity {
|
||||
this.takeStep(),
|
||||
])
|
||||
}
|
||||
|
||||
waypoints() {
|
||||
return this.game?.unadjustedWaypoints.map(([waypoint, direction]) => waypoint.clone().add(direction.clone().multiplyScalar(this.radius))) ?? []
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user