"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);