mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-16 13:14:56 +00:00
Remove path cache (#257)
This commit is contained in:
@@ -12,8 +12,6 @@ export class PathFinder {
|
|||||||
private aStar: AStar;
|
private aStar: AStar;
|
||||||
private computeFinished = true;
|
private computeFinished = true;
|
||||||
|
|
||||||
private pathCache: Map<number, TileRef[]> = new Map();
|
|
||||||
|
|
||||||
private constructor(
|
private constructor(
|
||||||
private game: Game,
|
private game: Game,
|
||||||
private newAStar: (curr: TileRef, dst: TileRef) => AStar,
|
private newAStar: (curr: TileRef, dst: TileRef) => AStar,
|
||||||
@@ -57,15 +55,6 @@ export class PathFinder {
|
|||||||
return { type: PathFindResultType.Completed, tile: curr };
|
return { type: PathFindResultType.Completed, tile: curr };
|
||||||
}
|
}
|
||||||
|
|
||||||
// make key the same between port a -> b and b -> a
|
|
||||||
const key = curr < dst ? curr * 1_000_000 + dst : dst * 1_000_000 + curr;
|
|
||||||
|
|
||||||
// get the cached path
|
|
||||||
if (this.pathCache.has(key)) {
|
|
||||||
this.path = this.pathCache.get(key)!;
|
|
||||||
return { type: PathFindResultType.NextTile, tile: this.path.shift() };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.computeFinished) {
|
if (this.computeFinished) {
|
||||||
if (this.shouldRecompute(curr, dst)) {
|
if (this.shouldRecompute(curr, dst)) {
|
||||||
this.curr = curr;
|
this.curr = curr;
|
||||||
@@ -86,8 +75,6 @@ export class PathFinder {
|
|||||||
// Remove the start tile
|
// Remove the start tile
|
||||||
this.path.shift();
|
this.path.shift();
|
||||||
|
|
||||||
// save the path in the cache
|
|
||||||
this.pathCache.set(key, [...this.path]);
|
|
||||||
return this.nextTile(curr, dst);
|
return this.nextTile(curr, dst);
|
||||||
case PathFindResultType.Pending:
|
case PathFindResultType.Pending:
|
||||||
return { type: PathFindResultType.Pending };
|
return { type: PathFindResultType.Pending };
|
||||||
|
|||||||
Reference in New Issue
Block a user