stable
This commit is contained in:
parent
fbdac9ebf1
commit
86226ccc94
97 changed files with 5790 additions and 2307 deletions
71
js/simulation_environment_system.js
Normal file
71
js/simulation_environment_system.js
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
"use strict";
|
||||
|
||||
// Layer: simulation/system-environment
|
||||
// Owns frame time, world clock, frame signals, weather/terrain preparation,
|
||||
// phase-change notification, and diagnostics publication.
|
||||
(function (global) {
|
||||
function normalizeDelta(worldRef, dt) {
|
||||
if (!worldRef || worldRef.paused) return null;
|
||||
let frameDt = dt * worldRef.speed;
|
||||
frameDt = Math.min(frameDt, 0.12 * worldRef.speed);
|
||||
return frameDt;
|
||||
}
|
||||
|
||||
function updateClock(worldRef, dt) {
|
||||
const prevTime = worldRef.time;
|
||||
worldRef.time += dt;
|
||||
const previousDay = worldRef.day || 1;
|
||||
worldRef.day = Math.floor(worldRef.time / CONFIG.dayLength) + 1;
|
||||
const prevHour = worldRef.hourOfDay ? worldRef.hourOfDay(prevTime) : 0;
|
||||
const nowHour = worldRef.hourOfDay ? worldRef.hourOfDay(worldRef.time) : 0;
|
||||
const crossedColonyEvalHour = (worldRef.day !== previousDay) ? (nowHour >= 6) : (prevHour < 6 && nowHour >= 6);
|
||||
const pendingColonyMoodEvaluation = crossedColonyEvalHour && worldRef.lastColonyMoodDay !== worldRef.day;
|
||||
if (worldRef.day !== previousDay) {
|
||||
for (const t of worldRef.tarinai || []) if (t) t.personalityDaily = { day: worldRef.day, total: 0, byKey: {}, byCause: {} };
|
||||
}
|
||||
return { prevTime, previousDay, prevHour, nowHour, crossedColonyEvalHour, pendingColonyMoodEvaluation };
|
||||
}
|
||||
|
||||
function updateFrameSignals(worldRef, dt) {
|
||||
if (worldRef.pointer) worldRef.pointer.motion = Math.max(0, (worldRef.pointer.motion || 0) - dt * 2.4);
|
||||
worldRef.shakeTimer = Math.max(0, (worldRef.shakeTimer || 0) - dt);
|
||||
if ((worldRef.shakeTimer || 0) <= 0) { worldRef.shakeDuration = 0; worldRef.shakeStrength = 0; }
|
||||
}
|
||||
|
||||
function updateEnvironment(worldRef, dt) {
|
||||
worldRef.updateWeather(dt);
|
||||
worldRef.foodSpoilagePenalty = Math.max(0, (worldRef.foodSpoilagePenalty || 0) - dt * 0.010);
|
||||
worldRef.updateTerrainDirtyState?.(dt);
|
||||
}
|
||||
|
||||
function prepareSpatialFrame(worldRef) {
|
||||
worldRef.spatialRebuildsThisFrame = 0;
|
||||
worldRef.spatialDirtyMarksThisFrame = 0;
|
||||
worldRef.ensureSpatial?.("update-start");
|
||||
worldRef.beginFramePerformanceBudgets?.();
|
||||
}
|
||||
|
||||
function emitPhaseChange(worldRef) {
|
||||
const phase = worldRef.phaseName();
|
||||
if (phase !== worldRef.lastPhase) {
|
||||
worldRef.lastPhase = phase;
|
||||
worldRef.emit("world:phase", { world: worldRef, phase });
|
||||
}
|
||||
}
|
||||
|
||||
function finalizeDiagnostics(worldRef) {
|
||||
worldRef.lastRuntimeDiagnostics = worldRef.runtimeDiagnostics?.() || null;
|
||||
}
|
||||
|
||||
const phases = Object.freeze({
|
||||
normalizeDelta,
|
||||
updateClock,
|
||||
updateFrameSignals,
|
||||
updateEnvironment,
|
||||
prepareSpatialFrame,
|
||||
emitPhaseChange,
|
||||
finalizeDiagnostics,
|
||||
});
|
||||
|
||||
global.TarinaiEnvironmentSimulationSystem = Object.freeze({ phases });
|
||||
})(typeof window !== "undefined" ? window : globalThis);
|
||||
Loading…
Add table
Add a link
Reference in a new issue