71. Sky, weather and the time of day
Status: partly implemented. The bounded declared day/phase clock below is qualified on native and Wasm; the shared sky/weather renderer remains a design draft. Today each realm keeps its own clock of the day and its own sky: Everglade's 48-minute day and weather schedule, Fairy Forest's day and night in `metaverse/fairy-forest/night.coax`, Hecate's Cemetery's moon in `apps/openagents-web/villa.coax`, and the space realms' starfield in `metaverse/stars.coax`. This chapter plans one realm environment clock that drives the sky, the weather and chapter 13's lighting record. Shared sky and cloud rendering lives in
metaverse-engine/render/shade/sky.coax; this chapter's environment clock and unified weather schedule remain unbuilt.
The time of day and the weather change how every surface looks and some of how the world behaves: who is outdoors, how high the river runs, how far you can see. If each is a pure function of the realm's clock and seed, every visitor, a late joiner and a replay see the same sky with no extra messages.
What this chapter teaches
- How to declare a realm's day clock: real time, a cycle of fixed length, or a fixed time for goldens.
- How to compute the sun's elevation and the moon's phase from the clock.
- How to schedule weather from a climate, a seed and the world tick, with local overlays that never change the schedule.
- How to pin the sky for tests and goldens.
Outline
- The day clock. A realm declares its clock in
realms.jsonasreal(the visitor's local time),cycle(for example a 48-minute day,FFN_CYCLE_SECONDS2880) orfixed:T(0 midnight, 0.5 noon). A?clock=Tpage fact pins a shot. Goldens are always noon. The day clock reads chapter 1's simulation time; it never owns time. - Sun and moon. The sun's elevation runs from
sun_lowat midnight tosun_highat noon as0.5 (low + high) − 0.5 (high − low) cos(2π clock)(metaverse_style_sun_elevationin `metaverse/style-preset.coax`). The moon's phase is the age since the mean new moon of 6 January 2000 18:14 UTC over the mean synodic month, 29.530588853 days (villa_moon_phase); the lit share of the disc is(1 − cos 2π phase) / 2. Only one of them leads as the key light. - Palette through the day. Style keys at four clock keys (midnight, dawn, noon, dusk) mix by the clock. Dusk warms a palette and night takes it to a blue dusk (
metaverse_style_flat_timein `metaverse/style.coax`). - The sky. A painted sky and haze per style; for space, star layers in screen cells picked by a hash, with twinkle, and a Sun of disc, corona and halo (
metaverse_star_layer,metaverse_sun_disc,metaverse_sun_corona). - The weather schedule. Ten-minute blocks draw clear, overcast, fog, rain or storm from a climate's weights (
weather_temperate,weather_coastal), blend over 60 s, and vary rain and wind with seeded smooth noise (`metaverse-engine/world/water-weather.coax`). Strong wind starts at 9 m/s and disperses fog. - Weather on the ground. Wetness and puddles integrate over the last hour on a 30 s grid fixed to the tick. Water rises by the mean rain over the last 30 minutes times 0.15 m, and currents speed up by up to 1.6 (chapter 70).
- Local overlays. A
WeatherOverlay(a spell's rain, fog cloud or storm) is an area with a start tick and a duration. It changes what is drawn and felt inside its area and never changes the schedule. - Routines on the clock. People's days are rows of time of day, place and route, so where they are is a pure function of the clock (
everglade/legacy/v1/routines.coax). - Pinning.
?weather=clear|overcast|fog|rain|stormpins the weather; a still page keeps a calm sky unless pinned, so goldens don't change with the schedule.
What exists today
- metaverse/style-preset.coax and metaverse/style.coax: style keys per clock key, sun elevation, haze and light shafts.
- metaverse-engine/world/water-weather.coax: the weather schedule, SRD effects, overlays, ground wetness and rising water.
- metaverse/fairy-forest/night.coax: the three clock modes and resting to night or morning.
- apps/openagents-web/villa.coax: the moon's phase and its fixed direction, about 33 degrees up.
- metaverse/stars.coax: the starfield and the Sun for space backgrounds.
What it builds
metaverse-engine/world/day.coax: the day clock, its modes and pinning.metaverse-engine/world/sky.coax: sun elevation, moon phase and the sky inputs to the lighting record.metaverse-engine/world/weather.coax: the schedule, overlays and ground state.
Acceptance checks and oracles
The chapter is done when:
- Two clients and a late joiner at the same tick compute the same weather state and ground wetness, bit for bit.
- The moon's phase matches an independent ephemeris computation within a stated tolerance for a set of dates.
- At each clock key the key light and palette equal the preset's values, and the sun and moon never both lead.
- A weather overlay leaves the schedule unchanged before, during and after it.
- Goldens render with the pinned clock and weather and don't change when the schedule moves.
- Everglade in a storm stays inside its phone-tier GPU budget.
Dependencies
Chapters 1 (the clock), 5 (replay), 12 (materials) and 13 (the lighting record). Chapter 70 for rising water. From Coax: R13 typed clocks for civil and simulation time.
Declared-state adoption (#12991)
Declared-state profile 1 implements day plus phase from the existing paid clock, recorded jumps, day reset masks and a separate visual-only override. It does not implement the complete shared sky/weather renderer planned here; that broader design remains draft. See the runtime guide and qualification. This addition does not promote the chapter’s remaining teaching or qualification scope.
For the bounded profile, declare day_ticks on StateSchema, and set the NPC field’s reset mask to include STATE_DAY. At each step paid by FrameClock, prepare one command against the live revision. Normal commands advance phase by one; wrapping phase increments day and applies DAY defaults once. A recorded jump sets day and phase explicitly and uses that same reset batch. Duplicate operation IDs refuse before any reset. A visual override changes only drawing.
State Lab uses 512 ticks per day to make these transitions observable. The runtime conformance probe uses 16, all seven reset events, a day jump and natural midnights, under four native/Wasm frame schedules. These deliberately short days qualify lifecycle semantics, not astronomical time or weather rendering.