Optimize mover rendering and segment plan pipeline

This commit is contained in:
scamiv
2026-02-27 15:06:48 +01:00
parent 9703fecab8
commit 2cda35fb40
17 changed files with 924 additions and 354 deletions
+20 -17
View File
@@ -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),
};
}
}
+22 -36
View File
@@ -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),
};
}
}