Skip to content

Sandbox pack: nav footprints, bounded stores, scripts, persistence, scene components, scenes in code - #1066

Merged
nicolas-maman merged 16 commits into
mainfrom
feat/sandbox-pack
Nov 24, 2026
Merged

nicolas-maman merged 16 commits into
mainfrom
feat/sandbox-pack

Conversation

@nicolas-maman

@nicolas-maman nicolas-maman commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

A pack of issues for building a sandbox game on ae3d. It is separate from the motion work (#939): none of it touches motion. It was checked to merge cleanly beside #939 either way round (a three-way merge of each file onto #939's head, done locally and not pushed). Each change has its changes/ entry and its docs page.

Closes #817, closes #819, closes #899, closes #508, closes #507, closes #895, closes #275. Part of #510: checkpoint and rollback agent ops.

What's in it

  • Nav: footprints, dear cells, clearance (ae3d.nav: flow_block_model blocks a model's bounding-sphere square, so a long wall or fence closes everything round it #817, ae3d.nav: a flow field's cells are only open or blocked, so keeping a body off a wall closes doorways and strands whoever stands in the margin #819). nav.flow_block_mesh blocks what a placed model really covers, instanced ones included. flow_open, flow_cost_rect and flow_price handle teardown and terrain prices. flow_clearance keeps walkers off walls without closing doorways. Building the field records each cell's way during the flood: 16.2 → 12.1 ms for 1M cells (benchmarks/bench_nav.ae). docs/crowds.md.

  • Geometry: bounded stores (geometry: growth doubles an int without a bound; a memset can be sized negative #899). Meshes and instance stores grow to a bound where every index still fits an int. Byte sizes are longs, so they no longer wrap past 59M vertices or 33M instances. inst_remove now moves phases and points along with the rest.

  • Scripts (Scripts attached to objects: one state per attachment, every phase, fields in the inspector, hot reload, an ABI check #508):

    • The struct is the declaration: @derive(schema) gives the fields, defaults, ranges and flags.
    • Every Unity phase, including on_enable/on_disable, collision and trigger enter/stay/exit, and on_net_spawn.
    • Triggers on every convex collider. Characters walk through them.
    • Each script library carries a layout hash, and the loader refuses a library built against another engine, naming both.
    • tools/new_game scaffolds a game repository.
    • Docs: docs/scripting.md.
  • Persistence (Persistence: an integrated save framework -- declared fields, stable ids, save slots, versioned migrations, off the frame #507):

    • Providers let a system save its own state (bodies' motion included).
    • save_async saves off the frame, with a picture.
    • Checkpoints and rollback, also as agent ops.
    • Captures 2,000 objects in 0.38 ms (was 8.1) and loads them in 4.9 ms (was 8.0), per benchmarks/bench_persist.ae.
    • Docs: docs/persistence.md.
  • What a scene is set to, as its root's components (Scene files: retire the view writer for components (a camera component first) #895). The camera, environment, rendering, culling and weather are written and read as components; no view is written any more, and older files still load.

  • Scenes in code (A scene DSL: nesting is the hierarchy, attachments are in scope #275). ae3d.scenedsl: nesting is the hierarchy, and what a model carries goes in its block. Its records (body, water, voxel world, figure, motion, a marker's light) are read by the scene file's own reader. The editor's Save also writes the scene as the code that builds it. examples/spinning_cube.ae is rewritten in it. Docs: docs/scenes-in-code.md.

  • Vulkan streams that grow, and freed buffers. An instance stream's ring now doubles when it grows. An outgrown ring and a freed mesh's buffers are retired until every frame in flight has passed its fence, instead of waiting for the whole device. 200 small emitters each growing a particle a frame: 20.3–20.6 → 3.10–3.13 ms a frame on an M1 Pro (benchmarks/bench_streams.ae, test_vk_rings).

  • The frame's stage report. The opaque draws were reported as camdepth, and the transparent ones as occlusion. On MoltenVK the stamps are now written at the scene pass's edges, the only place Metal samples them (test_vk_stages, docs/performance.md).

  • Lamp shadows and instancing. An instance stream that stands still is a static caster, drawn once into the lamps' faces instead of every frame. 40 instanced props among ten lamps: 1,047 → 125 draws a frame (benchmarks/bench_lamp_instances.ae). New calls: core.light_set_shadows(l, false) (saved in the scene file) and engine.engine_set_lamp_shadow_limit(e, n).

  • perf transparent_cover: names what the transparent pass shades, by covered screen area, since that pass's cost goes with area and not draws.

  • Vulkan opaque depth prepass. Each opaque pixel is now lit once: the lit shader can discard, which costs a tiled GPU its hidden-surface removal. 120 opaque layers at 640×360 went 20.3 → 2.48 ms on an M1 Pro, and the picture is the same to the channel (test_vk_prepass). AE3D_PREPASS=0 turns it off.

  • Hidden windows draw at the size asked (AE3D_PIXEL_SCALE=1 does the same for a shown window), on OpenGL and Vulkan.

Bugs found and fixed on the way

  • Picking on a Retina Mac read the wrong pixel: engine_pick now takes window points. On OpenGL a view left its viewport for the next frame, which was drawn at the view's size.
  • A held frame (frame.pause) showed no HUD, so the agent's snapshot of a paused scene had none.
  • test_agent_pick and the editor drive's divider check failed on main on a Retina Mac; both now compute in the frame's units.
  • Loading a scene with textures after engine_new waited forever. worker.wait() waits for detached jobs too, and the job pool's threads never end. The decodes now run on the engine's pool.
  • The editor dropped a body's trigger on save and on load. The Physics Body component now shows it.
  • A material's cutout, fire and soft were never written to the scene file. Its numbers are now one table that the writer, the reader and the DSL all use.
  • Characters met trigger shapes as walls. Contact impulses were the last sub-step's quarter of the step's.

Verified

  • Every affected suite passes, and each new suite is listed in its change file:
    • test_scenedsl 177
    • test_components 140
    • test_persist 42
    • test_contacts 22
    • test_scene_settings 15
    • test_net_spawn 10
    • test_agent_checkpoint 12
    • test_persist_bodies 8
  • 0 leaks under leaks for the headless suites. Windowed programs show the system baseline.
  • Editor drive on Vulkan: 208 checks, among them a new one: Save writes the scene's code beside its file.
  • Not regressions, and failing on main too: stale Blender exports (Blender 5.3 here) and test_physanim's wall-clock check under load.

Upstream Aether findings are drafted, not filed.

…cene components, scenes in code

- Nav (#817, #819): flow_block_mesh blocks what a placed model covers,
  flow_open / flow_cost_rect / flow_price / flow_clearance; ways recorded
  during the flood (16.2 -> 12.1 ms per 1M cells).
- Geometry (#899): mesh and instance stores bounded where every index fits
  an int, byte sizes in longs; inst_remove moves phases and points.
- Scripts (#508): @derive(schema) structs as kinds, every Unity phase
  (enable/disable, collisions, triggers, net spawn), triggers on every
  convex collider, a layout hash the loader checks, tools/new_game.
- Persistence (#507): providers, async saves with a picture, checkpoints
  and rollback (also agent ops); capture 21x faster.
- Scene settings as root components (#895): camera, environment,
  rendering, culling and weather; no view written, older files load.
- Scenes in code (#275): ae3d.scenedsl, nesting as the hierarchy, records
  read by the scene file's own reader; the editor writes each saved scene
  as code; spinning_cube rewritten in it.
- Fixed on the way: a textured scene loaded after engine_new waited for
  ever (worker.wait joins detached jobs); the editor dropped a body's
  trigger; material cutout/fire/soft never saved; characters met triggers
  as walls; contact impulse was one sub-step's.

Every change has its changes/ entry, docs and tests.
…r; frame stages charged with their own work

- An instance stream's ring at least doubles when it grows, and what it
  outgrew, the first upload's buffer and a freed mesh's buffers are
  retired: destroyed once every frame that could have drawn them has
  passed its fence (vkmesh.frame_begun), instead of behind
  vkDeviceWaitIdle. 200 streams growing a particle a frame: 20.3-20.6 ->
  3.10-3.13 ms a frame on an M1 Pro (benchmarks/bench_streams.ae).
- The stage report: the opaque draws were reported as camdepth and the
  transparent ones as occlusion (stamps written beside the next ones).
  On a Metal-layered device (vkdevice.portable) the marks inside the
  scene pass are written at its edges, where its timestamps land.
- test_vk_rings and test_vk_stages, new; docs/performance.md.
…mp limit; AE3D_PERF names what the transparent pass shades

- An instance stream counts as moving for a lamp's faces only in the frames
  its instances change (Model.instances_changed, both renderers); standing
  still it is the static layer's, drawn once. 40 instanced props among ten
  lamps: 1,047 -> 125 draws a frame, 11.5 -> 10.6 ms
  (benchmarks/bench_lamp_instances.ae, M1 Pro, Vulkan).
- core.light_set_shadows(l, false), kept in the scene file as
  "shadows": false; engine.engine_set_lamp_shadow_limit(e, n).
- perf transparent_cover: the five blended models covering the most screen
  a frame (engine.transparent_share).
- test_lamp_shadows (27), test_transparent_cover (4, new), test_scene_io;
  docs/rendering.md, docs/performance.md.
… view; hidden windows at the asked size; a held frame keeps its HUD

- Opaque depth prepass (Vulkan): depth first through the casters' depth
  shaders, then the lit draws test against it without writing, so each
  pixel is lit once. The lit shader can discard, which cost tiled GPUs
  their hidden-surface removal: 120 opaque layers at 640x360 went
  20.3 -> 2.48 ms on an M1 Pro. The same picture, to the channel
  (test_vk_prepass). AE3D_PREPASS=0 turns it off.
- engine_pick/_ask/_read take window points (the cursor's space). On a
  Retina Mac every pick read a spot halfway to the corner. OpenGL maps a
  pick from the frame's size, and a GL view no longer leaves its viewport
  for the next frame, which was drawn at the view's size.
- A hidden window, or any with AE3D_PIXEL_SCALE=1, draws at the size asked,
  on OpenGL and Vulkan (test_hidden_size).
- A held frame (frame.pause) keeps what its scripts drew on the HUD, so the
  agent's snapshot of a paused scene shows it (test_hud_hold).
- Particle emitters are named "particles". test_agent_pick and the editor
  drive's divider check now compute in the frame's units.
… cover after the behaviours

- The opaque prepass draws depth with no pixel shader, the device's fast
  depth path: one that could discard cost the prepass what it saves, and on
  a light scene (campfire) the frame was slower with it. Cut, wounded and
  damaged models stay out of it. Campfire now runs the same either way
  (112-120 fps); the 60-layer stack 4.3 -> 0.3 ms.
- test_scenedsl compares the written code to the golden with its numbers to
  twelve significant digits: a cone's cosine rounds differently with #939
  merged. It still fails on a changed name or a sixth-digit number.
- test_vk_prepass times each side as its best of eight frames.
- say_cover runs at the end of say_perf, clear of #939's say_behaviours, so
  the two branches merge without a conflict.
…nsparent cover leaves out the unseen

- menu.set_theme(stack, Theme) and set_menu_theme(menu, Theme): a game's
  menus in its own colours; theme_default() is the look menus had
  (test_menu, 40 checks).
- engine_pick_ready(e, k) / core.backend_pick_ready: read a pick once its
  frame is done on the device instead of waiting for it. Vulkan answers two
  frames later (vkframe.frame_serial), OpenGL the next. A read of a done
  answer no longer waits on the frame slot, which a newer frame may hold.
  A light scene: 2.8-3.0 ms a frame reading at once, 1.73-1.77 when ready,
  1.70-1.77 with no pick.
- The pick pass is scissored to the box round the asked pixels on both
  renderers.
- perf transparent_cover counts nothing for a model off the view or an
  emitter with no live particle; the frustum is made once a frame.
A menu that does not fit the screen (eight rows and a button in a window
900 tall: its button cut in half off the bottom) is scaled about its middle,
panel and widgets together, until it fits the screen less 12 points, and
moved inside it. widget_rect and panel_rect do it, so drawing and the hit
test agree. A menu that fits is drawn as placed. test_menu: 43 checks.
- core.model_set_emissive(m, r, g, b, strength) and model_set_emissive_map:
  light a surface gives the eye whatever lights it (a lit window, a lamp's
  pane), its map saying where. Added after the surface's shading and before
  the fog, so the bloom picks it up. Vulkan binds the map at (0, 10),
  OpenGL on unit 5; the lit shaders regenerated (glslang 16.6.0, 2,463
  offsets checked).
- glTF: emissiveFactor x KHR_materials_emissive_strength x emissiveTexture.
- Scene file "emissive"/"emissive_path" when set; scene DSL emissive() and
  emissive_map(), written back by the writer.
- test_emissive (new, both renderers in the dark, within 1 of 255),
  test_gltf, test_scene_io, test_scenedsl. test_vk_stages runs without the
  prepass, whose cheap opaque stage let noise flip it.
A light reaches where its fall-off drops to a 64th: a light_point made with
a range of 4 m reaches 28 m, listed in every cluster within and shaded by
every pixel there. light_set_reach(l, metres) ends it sooner with the same
fade; 0 keeps the fall-off's reach, so scenes light as they did. Kept in
the scene file as "reach". test_light_reach: 26 cells where it was in 802.
ae3d.scatter places a district's props from rules: a height field sampled
from the ground's models, tagged areas with a wealth, roads, exclusions,
and palettes (density, spacing, slope, height, tags, wealth, alignment,
scale, weighted props). The same seed places the same props on every
machine (integer random numbers, directions by rejection, its own cosine
series, no fused multiply-adds), and build_models makes one instanced
model per prop. load reads the rules from a JSON scatter file.

test_scatter checks every placement against every rule, holds the
fingerprint to one value, matches the file to the code and every
instance to its placement; 0 leaks. bench_scatter: 9,216 props over a
512 m square placed in 4 ms. docs/scatter.md.
…ng tests

A renderer holds a material's textures while any model it draws uses that
material (Material.renderer_users) and lets them go with the last. OpenGL
let a texture go once a model, deleting a shared one under the next and
leaving a model put back a dead id; Vulkan never let one go. A group with
no material holds the model's; a reupload keeps its texture; an id set
with no path (a view's picture) is left alone. test_texture_release holds
it on both renderers.

CI on this branch:
- Windows: @c_callback functions are weak definitions, which GNU ld does
  not export from a DLL, so every script was refused for not saying its
  layout. build_script.sh builds them strong there (-DAETHER_WEAK_DEF=).
- test_gpu_lit, test_gpu_lit_rq: the emissive map lit_pixel gained; the
  GL fixtures carry its uniform and sampler.
- test_vk_prepass on llvmpipe: the prepass now defaults off on a CPU
  rasterizer, where it cost more than it saved (152.6 ms against 144.2).
  The test measures off and on in turns and takes medians; back to back,
  the best of eight kept 13 us readings for 120 full-screen layers.
- test_vk_stages: each stage's median over 16 frames, not a sum.
- The branch's drawing suites listed in GPU_SUITES, so GPU-less runners
  skip them.
ae3d.cellfile: a cell's models in one file a worker decodes whole (its
meshes as the renderer takes them, materials, instances, transforms and
flags), touching nothing the loop thread does. ae3d.worldbake: a scene cut
into cells by where each model stands, each with a stand-in (merged,
simplified to its cluster graph's coarsest cut, each texture's mean colour
baked in, no texture held), and world.json. ae3d.stream: cells loaded on
workers around any number of foci, attached within a per-frame byte
budget nearest first, kept to a margin past the radius, stand-ins drawn
where a cell is not resident; events for what arrives and leaves; bytes
held and peak; the stream.cells op on the agent channel.

test_stream: a 512 m world of 256 cells driven across at 30 m/s in real
time. No cell within 64 m of the focus is ever missing, what is held stays
under the stated ceiling, a stand-in shows exactly where its cell is not,
every cell behind is let go, pacing a border loads its cell once (six
times with no margin), the cell file round-trips, 0 leaks.
An instanced model was never culled: a prop kind laid over a whole map
drew every copy every frame. A still, opaque stream of at least 128 copies
is now cut into clusters of about 32 nearby copies (a grid in Morton
order, a bounding sphere each) and sent once in that order; the camera's
opaque pass and prepass draw only the runs of clusters the frustum
reaches, joined across the smallest gaps past 16 runs (Vulkan from a first
instance, GL 4.1 by pointing the copy attributes at each run). A stream
that changes is drawn whole until it is still again; clustering again is
one pass, 46 us for 2,401 copies. Copies keep their indices: a pick's
place in cluster order is turned back into the copy.

bench_instance_cull, 600 tiles of 16 m with five instanced kinds:
13.92M triangles and 28.5-29.7 ms of scene pass drawn whole, 2.32M and
12.1-12.3 ms culled. test_instance_cull: the partition, the spheres, no
visible copy missed, the same picture with and without on both
renderers, picks naming the copy.
stream.set_physics: a cell's FLAG_COLLIDER models become static
colliders, their collision meshes built on the worker with the decode,
each model a game object with a mesh collider from the moment it is
attached, destroyed as the cell leaves. stream.set_nav: a resident cell's
FLAG_NAV models block the walkers' field as it arrives and unblock as it
leaves.

ae3d.nav counts what blocks a cell: flow_unblock_mesh and flow_unblock
take one blocker off each cell of a footprint, so a neighbour's walls and
a game's own block stay. A grown footprint changes each cell once (a
stamped one's cells listed as first reached): the 7,200-triangle fence
costs 0.43 ms where it cost 0.42.

test_stream_drive: a ball at 30 m/s on streamed ground in a running
engine never falls through (it does without the streamed colliders); p99
frame 9.41 ms streamed against 9.61 ms with everything loaded.
test_stream: crates block the field exactly where their cell is resident,
and the field is open once every cell is let go. test_nav: unblocking.
…s at 10

On Vulkan the draw set's emissive map moves from binding 10 to 11: the
motion branch (#939, #855) reads skin rows at 10, and both live in one draw
set once the branches meet. Shaders regenerated; test_emissive,
test_backend_parity and test_gpu_lit pass. The Windows define for scripts'
weak symbols sits in its own block in build_script.sh, apart from the
runtime-library line the motion branch rewrote.
CI caps every suite's engine at a few frames (AE3D_FRAMES), which stopped
both drives before they began: the loaded one drew 0 frames and the
streamed one 14. The drive sets its own bound, as the engine-view tests
do, and a p99 over no frames is 0 rather than whatever the buffer held.
@nicolas-maman
nicolas-maman merged commit ee7eca1 into main Nov 24, 2026
10 checks passed
nicolas-maman added a commit that referenced this pull request Nov 24, 2026
Conflicts resolved keeping both sides:
- the draw set holds the skin rows at binding 10 (storage buffer, both
  stages) and main's emissive map at 11 (fragment): BINDINGS 7, the pool
  5 images and 1 storage buffer a set, the emissive write at index 6;
- shaders.lit: the draw block keeps the skin base words and main's
  emissive and emissive_map (DRAW_COUNT 94), images skin_rows and
  emissive_map (IMAGE_COUNT 14);
- vulkan: a removed model lets go of its materials and its ray skin;
- build_script.sh: ae_cflags --cc (#1072) with main's NATIVE_DIR.
vkscene, vkspirv, vkmsl and the quoted Metal are regenerated by
tools/generate_shaders with glslang 16.6.0, not hand-merged; --check:
134 generated files current, 72 shaders, 1051188 B of SPIR-V,
1349 offsets verified against glslang.

The generator runs glslang as glslangValidator or as glslang, 16.6.0
either way, and scripts/glslang.sh fetches Khronos' Windows x86_64 build
(sha256 checked) as well as Linux's. Part of #1076.

AETHER_REF v0.941.0: an account trip marked on every account from the
one in use up to the one that ran out; nothing ae3d calls.

Checks (Windows, Aether 0.941.0): natives build; 379 programs under
tests, examples and tools through aetherc, 0 failed, 0 warning[;
test_motion, test_physanim, test_character, test_anim_pipeline,
test_determinism, test_net_anim, test_animator_back pass; test_gpu,
test_gpu_lit, test_gpu_layouts, test_emissive, test_skinned_render,
test_vk_rings pass, test_vk_msl skips (macOS only) as on main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment