mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-29 03:34:19 +00:00
Big Water-Nukes Performance Improvements 💧 (#3668)
## Description: ### 1. Water Magnitude Calculation Optimization (WaterManager.ts) * Boxed BFS Approach: Refactored the water magnitude recomputation to use "Dirty" and "Seed" boxes. Instead of a global update, the system now only recalculates magnitudes within a specific radius of the affected area, significantly reducing CPU load after water-nuke-explosions * Shoreline Bit Optimization: Narrowed the scope for updating shoreline bits to a 2-ring neighborhood around converted tiles, avoiding unnecessary checks across the entire map. Performance test on the world map: - AtomBomb (r=30): 24ms (was 344ms with global BFS), 2,993 changed tiles (was 630k) - Massive (r=200): 178ms (was 378ms), 130k changed tiles (was 654k) ### 2. Pathfinding Rebuild Staggering (PathFinder.ts, TradeShipExecution.ts, TransportShipExecution.ts) * Distributed Rebuilds: Introduced a staggering mechanism in WaterPathFinder. Ship pathfinders now wait a randomized/distributed number of ticks (0 - 5 seconds) before rebuilding after a water graph change. * CPU Spike Mitigation: By spreading out these expensive A* rebuilds over time, we prevent lag when hundreds of ships attempt to re-path simultaneously * Like Mole said it: "Pretty realistic I;d say the capitan needs a second to realize the big nuke on the left opened a new path" From a performance test on the big new Luna map: Graph rebuild: 256.4ms Pathfinder-Rebuild of 329 ships (Including other Executions): 1564.4ms (No longer noticeable, spread over 5s) ### 3. Performance Refinements * Simplified deep ocean magnitude logic within the optimized BFS flow. * Improved memory efficiency by utilizing clipped BFS wavefronts. ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: FloPinguin
This commit is contained in:
@@ -22,6 +22,8 @@ export class TradeShipExecution implements Execution {
|
||||
private motionPlanId = 1;
|
||||
private motionPlanDst: TileRef | null = null;
|
||||
|
||||
private static _staggerCounter = 0;
|
||||
|
||||
constructor(
|
||||
private origOwner: Player,
|
||||
private srcPort: Unit,
|
||||
@@ -30,7 +32,9 @@ export class TradeShipExecution implements Execution {
|
||||
|
||||
init(mg: Game, ticks: number): void {
|
||||
this.mg = mg;
|
||||
this.pathFinder = new WaterPathFinder(mg);
|
||||
const stagger =
|
||||
TradeShipExecution._staggerCounter++ % WaterPathFinder.STAGGER_SPREAD;
|
||||
this.pathFinder = new WaterPathFinder(mg, stagger);
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
|
||||
@@ -29,6 +29,8 @@ export class TransportShipExecution implements Execution {
|
||||
private target: Player | TerraNullius;
|
||||
private pathFinder: WaterPathFinder;
|
||||
|
||||
private static _staggerCounter = 0;
|
||||
|
||||
private dst: TileRef | null;
|
||||
private src: TileRef | null;
|
||||
private retreatDst: TileRef | false | null = null;
|
||||
@@ -60,7 +62,9 @@ export class TransportShipExecution implements Execution {
|
||||
this.lastMove = ticks;
|
||||
this.mg = mg;
|
||||
this.target = mg.owner(this.ref);
|
||||
this.pathFinder = new WaterPathFinder(mg);
|
||||
const stagger =
|
||||
TransportShipExecution._staggerCounter++ % WaterPathFinder.STAGGER_SPREAD;
|
||||
this.pathFinder = new WaterPathFinder(mg, stagger);
|
||||
|
||||
if (
|
||||
this.attacker.unitCount(UnitType.TransportShip) >=
|
||||
|
||||
Reference in New Issue
Block a user