hmm
This commit is contained in:
parent
d5c661bc22
commit
9ef1b8dbb1
23 changed files with 329 additions and 96 deletions
|
|
@ -3,6 +3,32 @@
|
|||
(function (global) {
|
||||
const World = global.World;
|
||||
if (!World) throw new Error("World is not available for mixin: world_update.js");
|
||||
function markSpatialDirtyIfMoved(worldRef, list, reason = "moved", threshold = 0.35) {
|
||||
if (!worldRef || !Array.isArray(list) || !list.length) return false;
|
||||
const thresholdSq = threshold * threshold;
|
||||
let moved = false;
|
||||
for (const entity of list) {
|
||||
if (!entity || entity.dead) continue;
|
||||
const x = Number.isFinite(entity.x) ? entity.x : 0;
|
||||
const y = Number.isFinite(entity.y) ? entity.y : 0;
|
||||
const oldX = entity._spatialTrackX;
|
||||
const oldY = entity._spatialTrackY;
|
||||
if (!Number.isFinite(oldX) || !Number.isFinite(oldY)) {
|
||||
entity._spatialTrackX = x;
|
||||
entity._spatialTrackY = y;
|
||||
moved = true;
|
||||
continue;
|
||||
}
|
||||
const dx = x - oldX;
|
||||
const dy = y - oldY;
|
||||
if (dx * dx + dy * dy <= thresholdSq) continue;
|
||||
entity._spatialTrackX = x;
|
||||
entity._spatialTrackY = y;
|
||||
moved = true;
|
||||
}
|
||||
if (moved) worldRef.markSpatialDirty?.(reason);
|
||||
return moved;
|
||||
}
|
||||
Object.defineProperties(World.prototype, Object.getOwnPropertyDescriptors({
|
||||
environmentScores() {
|
||||
const alive = this.tarinai || [];
|
||||
|
|
@ -227,29 +253,47 @@
|
|||
this.spatialDirtyMarksThisFrame = 0;
|
||||
this.ensureSpatial?.("update-start");
|
||||
|
||||
const perf = this.performanceLevel();
|
||||
const quality = this.performanceQuality?.() || {};
|
||||
const perf = Number(quality.level ?? this.performanceLevel?.() ?? 0) || 0;
|
||||
this.beginFramePerformanceBudgets?.(quality);
|
||||
const itemCountBefore = this.items.length;
|
||||
for (const it of this.items) it.update(dt, this);
|
||||
if (this.items.length) this.markSpatialDirty?.("items-updated");
|
||||
const itemsMoved = markSpatialDirtyIfMoved(this, this.items, "items-moved", 0.25);
|
||||
if (this.itemCounts?.ball) {
|
||||
this.ensureSpatial?.("ball-ball-collisions");
|
||||
this.resolveBallBallCollisions(dt);
|
||||
this.markSpatialDirty?.("ball-ball-collisions");
|
||||
}
|
||||
this.updateAnts?.(dt);
|
||||
if ((this.ants || []).length) this.markSpatialDirty?.("ants-updated");
|
||||
const antsMoved = markSpatialDirtyIfMoved(this, this.ants || [], "ants-moved", 0.25);
|
||||
if (itemsMoved || antsMoved || this.spatialDirty) this.ensureSpatial?.("post-mobile-item-update");
|
||||
|
||||
for (const ef of this.effects) ef.update(dt);
|
||||
|
||||
for (const t of this.tarinai) {
|
||||
t.update(dt);
|
||||
}
|
||||
this.resolveOwnedBedSleepConflicts?.();
|
||||
if (this.tarinai.length) this.markSpatialDirty?.("tarinai-updated");
|
||||
const now = this.time || 0;
|
||||
const bedConflictInterval = Number(quality.bedConflictInterval || 0.12) || 0.12;
|
||||
if (now >= (this.nextBedConflictCheckAt || 0)) {
|
||||
this.nextBedConflictCheckAt = now + bedConflictInterval;
|
||||
this.workStats && (this.workStats.bedConflictRuns = (this.workStats.bedConflictRuns || 0) + 1);
|
||||
this.resolveOwnedBedSleepConflicts?.();
|
||||
} else {
|
||||
this.workStats && (this.workStats.bedConflictSkips = (this.workStats.bedConflictSkips || 0) + 1);
|
||||
}
|
||||
markSpatialDirtyIfMoved(this, this.tarinai, "tarinai-moved", 0.25);
|
||||
this.ensureSpatial?.("post-tarinai-update");
|
||||
this.limitBallChasers();
|
||||
this.resolveBallInteractions(dt);
|
||||
this.resolveTarinaiHighSpeedCollisions(dt);
|
||||
const collisionInterval = Number(quality.collisionInterval || 0.04) || 0.04;
|
||||
if (now >= (this.nextTarinaiCollisionCheckAt || 0)) {
|
||||
this.nextTarinaiCollisionCheckAt = now + collisionInterval;
|
||||
this.workStats && (this.workStats.collisionRuns = (this.workStats.collisionRuns || 0) + 1);
|
||||
this.resolveTarinaiHighSpeedCollisions(dt);
|
||||
} else {
|
||||
this.workStats && (this.workStats.collisionSkips = (this.workStats.collisionSkips || 0) + 1);
|
||||
}
|
||||
|
||||
this.compactTimer += dt;
|
||||
const compactInterval = perf >= 2 ? 0.95 : 0.58;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue