stable
This commit is contained in:
parent
fbdac9ebf1
commit
86226ccc94
97 changed files with 5790 additions and 2307 deletions
51
js/simulation_maintenance_system.js
Normal file
51
js/simulation_maintenance_system.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
"use strict";
|
||||
|
||||
// Layer: simulation/system-maintenance
|
||||
// Owns periodic compaction, counts refresh, grass limit enforcement,
|
||||
// out-of-bounds cleanup, and draw-list invalidation.
|
||||
(function (global) {
|
||||
function runMaintenance(worldRef, dt, itemCountBefore) {
|
||||
worldRef.compactTimer += dt;
|
||||
const compactInterval = 2.5;
|
||||
let itemsCompacted = false;
|
||||
if (worldRef.compactTimer >= compactInterval) {
|
||||
itemsCompacted = worldRef.compactItems();
|
||||
worldRef.compactEffects();
|
||||
worldRef.compactTarinai();
|
||||
worldRef.compactAnts?.();
|
||||
worldRef.compactTimer = 0;
|
||||
}
|
||||
|
||||
worldRef.countsTimer += dt;
|
||||
const countsInterval = 2.0;
|
||||
if (worldRef.countsTimer >= countsInterval || itemsCompacted || worldRef.items.length !== itemCountBefore) {
|
||||
worldRef.updateItemCounts();
|
||||
worldRef.updateEffectCounts();
|
||||
worldRef.countsTimer = 0;
|
||||
}
|
||||
if ((worldRef.time || 0) >= (worldRef.nextGrassLimitCheckAt || 0)) {
|
||||
worldRef.nextGrassLimitCheckAt = (worldRef.time || 0) + 3.0;
|
||||
const removedGrass = worldRef.enforceGrassLimit?.("periodic-grass-limit") || 0;
|
||||
if (removedGrass > 0) {
|
||||
worldRef.compactItems();
|
||||
worldRef.updateItemCounts();
|
||||
}
|
||||
}
|
||||
|
||||
if ((worldRef.outOfBoundsCheckAt || -999) + 5.0 <= worldRef.time) {
|
||||
worldRef.outOfBoundsCheckAt = worldRef.time;
|
||||
worldRef.sanitizeOutOfBounds();
|
||||
}
|
||||
|
||||
worldRef.drawSortTimer += dt;
|
||||
const sortInterval = 0.25;
|
||||
if (worldRef.drawSortTimer >= sortInterval) {
|
||||
worldRef.drawListDirty = true;
|
||||
worldRef.drawSortTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
global.TarinaiMaintenanceSimulationSystem = Object.freeze({
|
||||
phases: Object.freeze({ runMaintenance }),
|
||||
});
|
||||
})(typeof window !== "undefined" ? window : globalThis);
|
||||
Loading…
Add table
Add a link
Reference in a new issue