mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-01 22:23:28 +00:00
perf: PortExecution only check to spawn trade ships every 10 ticks.
This commit is contained in:
@@ -17,6 +17,7 @@ export class PortExecution implements Execution {
|
||||
private mg: Game;
|
||||
private port: Unit;
|
||||
private random: PseudoRandom;
|
||||
private checkOffset: number;
|
||||
|
||||
constructor(
|
||||
private _owner: PlayerID,
|
||||
@@ -31,6 +32,7 @@ export class PortExecution implements Execution {
|
||||
}
|
||||
this.mg = mg;
|
||||
this.random = new PseudoRandom(mg.ticks());
|
||||
this.checkOffset = mg.ticks() % 10;
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
@@ -55,6 +57,11 @@ export class PortExecution implements Execution {
|
||||
this._owner = this.port.owner().id();
|
||||
}
|
||||
|
||||
// Only check every 10 ticks for performance.
|
||||
if ((this.mg.ticks() + this.checkOffset) % 10 != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const totalNbOfPorts = this.mg.units(UnitType.Port).length;
|
||||
if (
|
||||
!this.random.chance(this.mg.config().tradeShipSpawnRate(totalNbOfPorts))
|
||||
|
||||
Reference in New Issue
Block a user