lag r
This commit is contained in:
parent
d875df8600
commit
2741b93dea
31 changed files with 751 additions and 546 deletions
|
|
@ -6,35 +6,40 @@
|
|||
Object.defineProperties(World.prototype, Object.getOwnPropertyDescriptors({
|
||||
updateAnts(dt) {
|
||||
if (!this.ants) this.ants = [];
|
||||
const nests = this.itemsOfType?.("ant_nest") || (this.items || []).filter(it => it && !it.dead && it.type === "ant_nest");
|
||||
for (const nest of nests) {
|
||||
if (typeof ensureAntNestWorkerPool === "function") ensureAntNestWorkerPool(nest);
|
||||
if (!Number.isFinite(nest.antCount)) nest.antCount = ANT_NEST_START_COUNT || 6;
|
||||
if (typeof syncAntNestCount === "function") syncAntNestCount(this, nest);
|
||||
nest.antSpawnTimer = Math.max(0, (nest.antSpawnTimer || 0) - dt);
|
||||
const outside = this.ants.filter(a => a && !a.dead && a.kind === "worker" && a.homeId === nest.id).length;
|
||||
const available = Array.isArray(nest.antWorkers) ? nest.antWorkers.length : Math.max(0, (nest.antCount || 0) - outside);
|
||||
const maxOutside = Math.min(ANT_NEST_MAX_OUTSIDE || 3, nest.antCount || 0);
|
||||
if (available > 0 && outside < maxOutside && (nest.antSpawnTimer || 0) <= 0 && (this.tarinai || []).some(t => t && !t.dead && !t.insideNestBoxId)) {
|
||||
const hp = Array.isArray(nest.antWorkers) && nest.antWorkers.length ? clamp(nest.antWorkers.pop(), 0, ANT_WORKER_HP || 32) : (ANT_WORKER_HP || 32);
|
||||
const a = new AntActor(this, {
|
||||
kind: "worker",
|
||||
homeId: nest.id,
|
||||
x: nest.x + rand(-nest.r * 0.18, nest.r * 0.18),
|
||||
y: nest.y - nest.r * 1.00 + rand(-3, 3),
|
||||
hp,
|
||||
maxHp: ANT_WORKER_HP || 32,
|
||||
});
|
||||
this.ants.push(a);
|
||||
this.emit?.("ant:spawned", { ant: a, nest });
|
||||
this.antNestUpdateAccum = (this.antNestUpdateAccum || 0) + dt;
|
||||
if (this.antNestUpdateAccum >= 3.0) {
|
||||
const nestDt = this.antNestUpdateAccum;
|
||||
this.antNestUpdateAccum = 0;
|
||||
const nests = this.itemsOfType?.("ant_nest") || (this.items || []).filter(it => it && !it.dead && it.type === "ant_nest");
|
||||
for (const nest of nests) {
|
||||
if (typeof ensureAntNestWorkerPool === "function") ensureAntNestWorkerPool(nest);
|
||||
if (!Number.isFinite(nest.antCount)) nest.antCount = ANT_NEST_START_COUNT || 6;
|
||||
if (typeof syncAntNestCount === "function") syncAntNestCount(this, nest);
|
||||
nest.antSpawnTimer = rand(1.6, 3.8) + outside * 0.45;
|
||||
this.drawListDirty = true;
|
||||
nest.antSpawnTimer = Math.max(0, (nest.antSpawnTimer || 0) - nestDt);
|
||||
let outside = 0;
|
||||
for (const a of this.ants) if (a && !a.dead && a.kind === "worker" && a.homeId === nest.id) outside += 1;
|
||||
const available = Array.isArray(nest.antWorkers) ? nest.antWorkers.length : Math.max(0, (nest.antCount || 0) - outside);
|
||||
const maxOutside = Math.min(ANT_NEST_MAX_OUTSIDE || 3, nest.antCount || 0);
|
||||
if (available > 0 && outside < maxOutside && (nest.antSpawnTimer || 0) <= 0 && (this.tarinai || []).some(t => t && !t.dead && !t.insideNestBoxId)) {
|
||||
const hp = Array.isArray(nest.antWorkers) && nest.antWorkers.length ? clamp(nest.antWorkers.pop(), 0, ANT_WORKER_HP || 32) : (ANT_WORKER_HP || 32);
|
||||
const a = new AntActor(this, {
|
||||
kind: "worker",
|
||||
homeId: nest.id,
|
||||
x: nest.x + rand(-nest.r * 0.18, nest.r * 0.18),
|
||||
y: nest.y - nest.r * 1.00 + rand(-3, 3),
|
||||
hp,
|
||||
maxHp: ANT_WORKER_HP || 32,
|
||||
});
|
||||
this.ants.push(a);
|
||||
this.emit?.("ant:spawned", { ant: a, nest });
|
||||
if (typeof syncAntNestCount === "function") syncAntNestCount(this, nest);
|
||||
nest.antSpawnTimer = rand(2.5, 5.5) + outside * 0.65;
|
||||
this.drawListDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
const aliveAntCount = (this.ants || []).reduce((n, a) => n + (a && !a.dead ? 1 : 0), 0);
|
||||
const q = this.performanceQuality ? this.performanceQuality() : null;
|
||||
const stride = Math.max(1, Math.min(3, q?.antStride || (aliveAntCount >= 70 ? 3 : aliveAntCount >= 28 ? 2 : 1)));
|
||||
const stride = aliveAntCount >= 28 ? 3 : 2;
|
||||
this.antUpdatePhase = ((this.antUpdatePhase || 0) + 1) % stride;
|
||||
for (let i = 0; i < this.ants.length; i++) {
|
||||
const a = this.ants[i];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue