mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-02 18:58:09 +00:00
Optimize mover rendering and segment plan pipeline
This commit is contained in:
@@ -8,7 +8,6 @@ import {
|
||||
UnitType,
|
||||
} from "../game/Game";
|
||||
import { TileRef } from "../game/GameMap";
|
||||
import { densePathToLosKeypointSegments } from "../game/MotionPlans";
|
||||
import { PathFinding } from "../pathfinding/PathFinder";
|
||||
import { PathStatus, SteppingPathFinder } from "../pathfinding/types";
|
||||
import { distSortUnit } from "../Util";
|
||||
@@ -115,22 +114,7 @@ export class TradeShipExecution implements Execution {
|
||||
if (dst !== this.motionPlanDst) {
|
||||
this.motionPlanId++;
|
||||
const from = result.node;
|
||||
const segPlan = this.pathFinder.planSegments?.(from, dst) ??
|
||||
(() => {
|
||||
const densePath = this.pathFinder.findPath(from, dst);
|
||||
return densePath
|
||||
? densePathToLosKeypointSegments(
|
||||
densePath,
|
||||
this.mg.map(),
|
||||
(t) =>
|
||||
this.mg.isWater(t) ||
|
||||
(this.mg.isLand(t) && this.mg.isShoreline(t)),
|
||||
)
|
||||
: null;
|
||||
})() ?? {
|
||||
points: Uint32Array.from([from]),
|
||||
segmentSteps: new Uint32Array(0),
|
||||
};
|
||||
const segPlan = this.safeSegmentPlan(from, dst);
|
||||
|
||||
this.mg.recordMotionPlan({
|
||||
kind: "grid_segments",
|
||||
@@ -226,4 +210,23 @@ export class TradeShipExecution implements Execution {
|
||||
dstPort(): TileRef {
|
||||
return this._dstPort.tile();
|
||||
}
|
||||
|
||||
private safeSegmentPlan(from: TileRef, to: TileRef): {
|
||||
points: Uint32Array;
|
||||
segmentSteps: Uint32Array;
|
||||
} {
|
||||
const segPlan = this.pathFinder.planSegments?.(from, to);
|
||||
if (segPlan) {
|
||||
return segPlan;
|
||||
}
|
||||
|
||||
const map = this.mg.map();
|
||||
console.warn(
|
||||
`TradeShipExecution: missing segment plan from (${map.x(from)},${map.y(from)}) to (${map.x(to)},${map.y(to)}); using defensive single-point fallback`,
|
||||
);
|
||||
return {
|
||||
points: Uint32Array.from([from]),
|
||||
segmentSteps: new Uint32Array(0),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,7 @@ import {
|
||||
UnitType,
|
||||
} from "../game/Game";
|
||||
import { TileRef } from "../game/GameMap";
|
||||
import {
|
||||
densePathToLosKeypointSegments,
|
||||
MotionPlanRecord,
|
||||
} from "../game/MotionPlans";
|
||||
import { MotionPlanRecord } from "../game/MotionPlans";
|
||||
import { targetTransportTile } from "../game/TransportShipUtils";
|
||||
import { PathFinding } from "../pathfinding/PathFinder";
|
||||
import { PathStatus, SteppingPathFinder } from "../pathfinding/types";
|
||||
@@ -116,22 +113,7 @@ export class TransportShipExecution implements Execution {
|
||||
targetTile: this.dst,
|
||||
});
|
||||
|
||||
const segPlan = this.pathFinder.planSegments?.(this.src, this.dst) ??
|
||||
(() => {
|
||||
const densePath = this.pathFinder.findPath(this.src, this.dst);
|
||||
return densePath
|
||||
? densePathToLosKeypointSegments(
|
||||
densePath,
|
||||
this.mg.map(),
|
||||
(t) =>
|
||||
this.mg.isWater(t) ||
|
||||
(this.mg.isLand(t) && this.mg.isShoreline(t)),
|
||||
)
|
||||
: null;
|
||||
})() ?? {
|
||||
points: Uint32Array.from([this.src]),
|
||||
segmentSteps: new Uint32Array(0),
|
||||
};
|
||||
const segPlan = this.safeSegmentPlan(this.src, this.dst);
|
||||
|
||||
const motionPlan: MotionPlanRecord = {
|
||||
kind: "grid_segments",
|
||||
@@ -281,22 +263,7 @@ export class TransportShipExecution implements Execution {
|
||||
if (this.dst !== null && this.dst !== this.motionPlanDst) {
|
||||
this.motionPlanId++;
|
||||
const from = this.boat.tile();
|
||||
const segPlan = this.pathFinder.planSegments?.(from, this.dst) ??
|
||||
(() => {
|
||||
const densePath = this.pathFinder.findPath(from, this.dst);
|
||||
return densePath
|
||||
? densePathToLosKeypointSegments(
|
||||
densePath,
|
||||
this.mg.map(),
|
||||
(t) =>
|
||||
this.mg.isWater(t) ||
|
||||
(this.mg.isLand(t) && this.mg.isShoreline(t)),
|
||||
)
|
||||
: null;
|
||||
})() ?? {
|
||||
points: Uint32Array.from([from]),
|
||||
segmentSteps: new Uint32Array(0),
|
||||
};
|
||||
const segPlan = this.safeSegmentPlan(from, this.dst);
|
||||
|
||||
this.mg.recordMotionPlan({
|
||||
kind: "grid_segments",
|
||||
@@ -318,4 +285,23 @@ export class TransportShipExecution implements Execution {
|
||||
isActive(): boolean {
|
||||
return this.active;
|
||||
}
|
||||
|
||||
private safeSegmentPlan(from: TileRef, to: TileRef): {
|
||||
points: Uint32Array;
|
||||
segmentSteps: Uint32Array;
|
||||
} {
|
||||
const segPlan = this.pathFinder.planSegments?.(from, to);
|
||||
if (segPlan) {
|
||||
return segPlan;
|
||||
}
|
||||
|
||||
const map = this.mg.map();
|
||||
console.warn(
|
||||
`TransportShipExecution: missing segment plan from (${map.x(from)},${map.y(from)}) to (${map.x(to)},${map.y(to)}); using defensive single-point fallback`,
|
||||
);
|
||||
return {
|
||||
points: Uint32Array.from([from]),
|
||||
segmentSteps: new Uint32Array(0),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user