T-011: Environment fields
Goal
The world outside the organisms: terrain and the fields stored on a coarse 3D grid. See
docs/DESIGN.md section 3.
Scope
- Terrain: a seeded height field with rocky and sandy areas and a few vents.
- Light: fades with depth and is blocked by opaque cells above (coarse column shading). Day and night, and seasons, from a world clock.
- Dissolved nutrients: diffuse, drift with the current, are taken up and released. Total matter must be conserved exactly by the field code.
- Vent chemicals: released at vents, diffuse, decay.
- Temperature: warmer near the surface and near vents.
- Current: a slowly changing flow field.
- Background colour: water colour by depth, terrain colour by place.
- Sampling functions for other modules: value and gradient at a point.
- Fields update on a slower cadence than physics. Everything in
Params.
Done when
- ☐ Tests: nutrient total is constant under diffusion and drift. Light under an opaque slab is dimmer than beside it. Fields are identical for the same seed.
- ☐ Field update cost measured and logged.
- ☐ A debug dump (image slices of each field) saved under
docs/media/T-011/.
Result
Done on branch t-011-environment-fields. All of it lives in crates/sim/src/fields/, plus
one line in world.rs so a new world has its terrain from the start.
What exists now
- Terrain: a seeded height field (1-unit samples) with rolling hills, rocky patches that
stand higher and rougher than sand (40% rock by default), ground colour (sand, rock,
mineral crust at vents) and 3 vents on mounds.
floor_heightandcurrentkeep their signatures for physics;floor_normalandfloor_roughnessare new. - Grid: 4-unit voxels filling the box, each water or ground.
- Light: falls down each column, dimmed by water and shaded by every cell by its own
opacity and size. Day and night, seasons.
light(p)for brightness;light_per_cross_section(p),light_budget(voxel)andlight_shade(voxel)for income, conserved by construction. - Nutrients, vent chemicals, vent heat: whole quanta per voxel. Diffuse and drift with
the current with the total exactly constant.
take(fair shares when overdrawn) andgivefor uptake and release;add_by_handfor god mode, recorded inby_hand. - Temperature: warm surface with a thermocline, seasonal and daily swing, warm water around vents.
- Current: incompressible eddies and gyres from the curl of a random potential, weaker at depth, zero through walls and ground, blending to a new pattern every 120 s.
- Sampling: value and gradient for light, nutrient, chemical and temperature at any point, callable inside parallel loops. Water colour by depth, ground colour by place.
- Cadence: transport every 8 steps, light every 4. Everything tunable is in
[fields](55 parameters, each with meaning, unit and range).
Done when
- ☑ Tests:
crates/sim/tests/fields.rs. Nutrient total constant under diffusion and drift (four regimes including currents too fast for one step). Light under an opaque slab dimmer than beside it, and no shadow from a clear slab. Fields identical for the same seed, and on 1 and 4 threads. Plus random-world shading, light conservation per column and per voxel, fairtake, terrain, current, vents, day and night, grid rebuilds. - ☑ Field update cost measured:
docs/perf/LOG.md(bench entries and the note after them),crates/sim/examples/fields_bench.rs. About 11 ns per voxel per update; 0.025 ms per step for the default world. - ☑ Debug images:
docs/media/T-011/, explained in itsREADME.md.
Design notes, including what the grid can and cannot resolve about one body, are in
docs/ARCHITECTURE.md section 16.