Skip to content

DayNightSystem

DayNightSystem

Phase · priority Environment · 5
Reads world_time (via ctx.WorldTime), temperature on Outdoor locations
Writes ambient_temperature on the World node; temperature on Outdoor locations
Settings BaseDayTemperature 15 °C, TemperatureAmplitude 10 °C, OutdoorEquilibrationPerHour 0.4
Status designed · Phase 1 (#34)
PLAN §11.4, §5.5
Player Time

Computes the ambient temperature from the clock and pulls outdoor places toward it. It does not advance time: the engine owns world_time (an earlier draft had this system write it, which stopped the clock whenever the sun was toggled off).

var minuteOfDay = ctx.WorldTime % 1440;
var ambient = baseTemp + amp * DeterministicMath.Sin(2 * MathF.PI * minuteOfDay / 1440f);   // never Math.Sin
yield return new SetAttributeIntent(world, "ambient_temperature", ambient);

foreach (var outdoor in view.NodesWithComponent("Outdoor"))
{
    var temp  = view.GetOrDefault(outdoor, "temperature", ambient);
    var delta = (ambient - temp) * s.OutdoorEquilibrationPerHour / ctx.Hours(1);
    if (Math.Abs(delta) > 0.1f) yield return new DeltaAttributeIntent(outdoor, "temperature", delta);
}

Midday ≈ 25 °C, midnight ≈ 5 °C at defaults. Buildings (no Outdoor) are left to HeatSystem's slower equilibration, which is why they buffer the night.

Hot-toggle: off, ambient_temperature stays at its last value and the day stops changing; time itself continues. Trace: one ambient_temperature set per tick; outdoor deltas carry no Inputs (the cause is the clock).

History

Phase Change
1 Introduced; no longer advances world_time; equilibration rate per hour; DeterministicMath.Sin.

See also: HeatSystem · Clock and simulation time