76 lines
3.8 KiB
JavaScript
76 lines
3.8 KiB
JavaScript
"use strict";
|
|
|
|
// Layer: simulation/systems-facade
|
|
// Owns the concrete phase registry boundary. The actual phase implementations
|
|
// are split across simulation_*_system.js files; this facade preserves the
|
|
// public TarinaiSimulationSystems contract for system_order.js and legacy tests.
|
|
(function (global) {
|
|
function phaseFrom(moduleName, phaseName) {
|
|
const fn = global[moduleName]?.phases?.[phaseName];
|
|
if (typeof fn !== "function") throw new Error(`Tarinai simulation phase missing: ${moduleName}.${phaseName}`);
|
|
return fn;
|
|
}
|
|
|
|
function normalizeDelta(worldRef, dt) { return phaseFrom("TarinaiEnvironmentSimulationSystem", "normalizeDelta")(worldRef, dt); }
|
|
function updateClock(worldRef, dt) { return phaseFrom("TarinaiEnvironmentSimulationSystem", "updateClock")(worldRef, dt); }
|
|
function updateFrameSignals(worldRef, dt) { return phaseFrom("TarinaiEnvironmentSimulationSystem", "updateFrameSignals")(worldRef, dt); }
|
|
function updateEnvironment(worldRef, dt) { return phaseFrom("TarinaiEnvironmentSimulationSystem", "updateEnvironment")(worldRef, dt); }
|
|
function prepareSpatialFrame(worldRef) { return phaseFrom("TarinaiEnvironmentSimulationSystem", "prepareSpatialFrame")(worldRef); }
|
|
function updateItemsAndAnts(worldRef, dt) { return phaseFrom("TarinaiItemAntSimulationSystem", "updateItemsAndAnts")(worldRef, dt); }
|
|
function updateEffects(worldRef, dt) { return phaseFrom("TarinaiEffectsSimulationSystem", "updateEffects")(worldRef, dt); }
|
|
function updateCreatures(worldRef, dt) { return phaseFrom("TarinaiCreatureSimulationSystem", "updateCreatures")(worldRef, dt); }
|
|
function runMaintenance(worldRef, dt, itemCountBefore) { return phaseFrom("TarinaiMaintenanceSimulationSystem", "runMaintenance")(worldRef, dt, itemCountBefore); }
|
|
function emitPhaseChange(worldRef) { return phaseFrom("TarinaiEnvironmentSimulationSystem", "emitPhaseChange")(worldRef); }
|
|
function spawnAmbientTarinai(worldRef, dt) { return phaseFrom("TarinaiAmbientSimulationSystem", "spawnAmbientTarinai")(worldRef, dt); }
|
|
function spawnAmbientGrass(worldRef, dt) { return phaseFrom("TarinaiAmbientSimulationSystem", "spawnAmbientGrass")(worldRef, dt); }
|
|
function spawnRainWater(worldRef, dt) { return phaseFrom("TarinaiAmbientSimulationSystem", "spawnRainWater")(worldRef, dt); }
|
|
function finalizeDiagnostics(worldRef) { return phaseFrom("TarinaiEnvironmentSimulationSystem", "finalizeDiagnostics")(worldRef); }
|
|
// finalizeDiagnostics publishes worldRef.lastRuntimeDiagnostics.
|
|
|
|
function update(worldRef, dt) {
|
|
const frameDt = normalizeDelta(worldRef, dt);
|
|
if (frameDt === null) return;
|
|
updateClock(worldRef, frameDt);
|
|
updateFrameSignals(worldRef, frameDt);
|
|
updateEnvironment(worldRef, frameDt);
|
|
prepareSpatialFrame(worldRef);
|
|
const mobile = updateItemsAndAnts(worldRef, frameDt);
|
|
updateEffects(worldRef, frameDt);
|
|
updateCreatures(worldRef, frameDt);
|
|
runMaintenance(worldRef, frameDt, mobile.itemCountBefore);
|
|
emitPhaseChange(worldRef);
|
|
spawnAmbientTarinai(worldRef, frameDt);
|
|
spawnAmbientGrass(worldRef, frameDt);
|
|
spawnRainWater(worldRef, frameDt);
|
|
finalizeDiagnostics(worldRef);
|
|
}
|
|
|
|
const phases = Object.freeze({
|
|
normalizeDelta,
|
|
updateClock,
|
|
updateFrameSignals,
|
|
updateEnvironment,
|
|
prepareSpatialFrame,
|
|
updateItemsAndAnts,
|
|
updateEffects,
|
|
updateCreatures,
|
|
runMaintenance,
|
|
emitPhaseChange,
|
|
spawnAmbientTarinai,
|
|
spawnAmbientGrass,
|
|
spawnRainWater,
|
|
finalizeDiagnostics,
|
|
});
|
|
|
|
const helpers = Object.freeze({
|
|
...(global.TarinaiSimulationRuntime?.helpers || {}),
|
|
...(global.TarinaiItemAntSimulationSystem?.helpers || {}),
|
|
...(global.TarinaiCreatureSimulationSystem?.helpers || {}),
|
|
});
|
|
|
|
global.TarinaiSimulationSystems = Object.freeze({
|
|
update,
|
|
phases,
|
|
helpers,
|
|
});
|
|
})(typeof window !== "undefined" ? window : globalThis);
|