Skip to content

Agent loop (#510): run to a moment, watch, physics and walks; shadow culling for clustered copies (#19) - #1084

Merged
nicolas-maman merged 10 commits into
mainfrom
feat/agent-loop
Nov 25, 2026
Merged

nicolas-maman merged 10 commits into
mainfrom
feat/agent-loop

Conversation

@nicolas-maman

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

Copy link
Copy Markdown
Collaborator

Follows #1066.

The agent's loop over a running game (#510)

  • ae3d.agentwatch: expressions over a game's objects, such as Player.Health.value < 50 and 'Enemy 2'.position.y < -10 || frame > 900. A path with nothing there is false, not 0. A malformed expression is refused, naming the column and what was expected.
  • object.find: by part of a name, a tag or a component kind.
  • frame.until: runs until the expression holds, then holds at that frame and answers it. At its timeout it answers with met false.
  • watch.add, watch.get, watch.list and watch.remove: a value read every frame, the last 4,096 frames kept, answered 1,024 at a time with more and next.
  • physics.bodies, physics.contacts and physics.ray, from ae3d.physics. Answers are bounded.
  • nav.flow_path: A* between any two places, using the flood's own rule and prices, with string-pulled corners. It leaves the walkers' target alone.
  • ae3d.navagent: puts a game's fields on the channel for nav.fields and nav.path.
  • log.tail and log.since: the program's console. stdout and stderr are kept while the channel is open, each line with its frame and the object whose script printed it, and passed through to the terminal unchanged. At exit the streams are drained and put back; a crash puts them back before its stack trace. AE3D_CONSOLE=0 turns this off.
  • script.list, script.reload name [source] and script.errors: a script is rebuilt and swapped under every object carrying it, with fields kept by name. A failed build is refused with the compiler's own words, and the old code keeps running. The rebuilt library is opened from a copy named for the process, because glibc's dlopen hands back a library it already has open for a path, and on Linux that kept the old code running.

#917, a world baked in batches

  • worldbake.begin, add, finish: a world too large to build whole is built and baked a part at a time. Models are bucketed by cell in one pass, and a texture's mean colour is read once per bake (96 cells: 65 s before, 2.6 s after).
  • The stream drops a cell's decoded textures from its count once the renderer holds them. Once settled, it holds exactly its cells' geometry, checked to the byte.
  • A batch with a model off the grid is refused whole. Before, the model was dropped from the world without a word.
  • examples/open_world: the street laid out as a city and streamed around a car. AE3D_CITY=16x12 is the README's city: 372 cells, 36,879 models, built and baked in 34 s at 274 MB peak.

#19, clustered copies in the shadows

  • Each sun cascade and each lamp face draws only the clusters of a still instance stream that it reaches. Before, it drew every copy on the map.
  • Clusters hold about 8 copies instead of 32.
  • bench_instance_cull (600 tiles, five kinds, cascades to 110 m):
Shadow pass Scene pass
Drawn whole 19.1–19.4 ms 29.6–30.7 ms
Culled 1.9–2.6 ms 7.4–7.8 ms

Checks

  • New: test_agent_script (10) and test_agent_console. test_stream (24) gains two-batch bakes, off-grid refusal and a held-bytes check.
  • New: test_agentwatch (19, headless), test_agent_until (11) and test_agent_world (11), the last two over a real socket. test_nav gains path checks; test_instance_cull (22) now has shadows, and with the cascades' runs cut, 4,108 channels differ.
  • The regression batch passes locally, including both editor drives (208 of 208 each). The new suites have no leaks beyond AppKit's own cycles.
  • gen_agent_docs --check is clean.

ae3d.agentwatch: expressions over a game's objects -- a component's field
by object name, quoted name or #id, kind and field (quoted where a name has
a space), positions and axes, numbers, true, false and frame, with
arithmetic, comparisons, && || ! and parentheses. A path with nothing there
is false, not 0; a malformed expression is refused naming where and what
was expected.

Agent ops: object.find (part of a name, tag, component kind); frame.until
(run until it holds, hold there and answer; met false at its timeout;
nothing after it answered before it); watch.add, watch.get (1,024 samples
an answer, more and next), watch.list, watch.remove (the last 4,096 frames
kept). test_agentwatch (19, headless) and test_agent_until (11, over a
socket: the run stops at the first frame its condition holds and holds
there, the watch reads every frame on the way). docs/agent.md.
A sun cascade draws only the clusters of a still instance stream over its
box, and a lamp's face only those it casts onto (core.instance_runs_by,
both renderers): every copy on the map was drawn into every cascade. The
tests are the ones that already culled whole casters, cluster by cluster.

Clusters hold about 8 copies, not 32: a 50-tile view of a 600-tile map
drew 1.35M triangles where it drew 2.32M, in the same five runs.

bench_instance_cull with the sun's cascades out to 110 m: shadow pass
19.1-19.4 ms drawn whole, 1.9-2.6 ms culled; scene pass 29.6-30.7 against
7.4-7.8. test_instance_cull turns shadows on over a ground: they fall, and
the culled picture is the whole draw's on both renderers (with the
cascades' runs cut, 4,108 channels differ).
physics.bodies (each body's object, kind, place, velocity, sleep, mass),
physics.contacts (each touching pair once: point, normal, depth, impulse)
and physics.ray (the first thing met, static too), from ae3d.physics, each
answer bounded with a count and more.

nav.flow_path: the walk between any two places by A*, the flood's own step
rule and prices, its corners string-pulled; it reads the field and leaves
the walkers' target and ways alone. ae3d.navagent puts a game's fields on
the channel (nav.fields, nav.path) without nav carrying the channel.

test_nav: a walk through a wall's gap, an open walk's octile cost, ends
blocked or walled in, the field's own costs untouched. test_agent_world
(11, over a socket): bodies and a region, the crate's contact once, rays
onto the crate and the ground, a ray refused, nav.fields and nav.path.
While the channel is open, stdout and stderr go through pipes, a reader
thread a stream passing every byte through to where it went and keeping
the last 4,096 lines, each with its frame (the engine's mark at a frame's
end) and, for a script's line, its object (the behaviours' marks around a
script phase that runs, buffered). At exit the streams are put back and
drained, so a program's last lines still reach the terminal; a crash puts
them back before its stack trace, with async-signal-safe calls only.
AE3D_CONSOLE=0 leaves the streams alone.

log.tail and log.since answer with the lines, 1,024 at most, with next,
more and oldest. test_agent_console (10, over a socket): a script's line
carries the frame it saw and its object, the program's none, stderr kept,
since and count, no mark in any line, the verdict after the engine
reaching stdout. Every agent suite and both editor drives pass under it.
ae3d.script keeps the scripts a program opens, by name: reload_named opens
one's library again and swaps it under every object carrying it, fields
kept by name; build_and_reload builds the source first, its stdout and
stderr both read back (stdout alone took a failed build, whose compiler
talks on stderr, for a clean one, and said it reloaded). A source whose
name is not the library's is refused. Agent ops script.list,
script.reload and script.errors.

test_agent_script (10, over a socket): rebuilt from changed source and
swapped while the game runs, the console hearing the new code and the
field the game set kept; a broken source refused with the compiler's
words, the running code left as it was.
worldbake bakes in batches (begin, add, finish), so a world too large to
build whole is built and baked a part at a time. Models are bucketed by
cell in one pass and a texture's mean colour is read once a bake. The
stream lets a cell's decoded textures go from its count once they are
the renderer's. examples/open_world lays the street out as a city, sized
by AE3D_CITY, and streams it.
worldbake.add left a model whose centre stood off the grid out of the
bake with nothing said. The batch is now refused whole, naming the model
and where it stands, before anything is written. An add to a bake begin
refused answers an error instead of reading through null.
test_stream settles a stream and checks it holds exactly its resident
cells' geometry and its stand-ins', with no texture counted once the
renderer has it; without the stream letting textures go it fails by
17,408 bytes. cellfile.data_image_bytes gives a decode's textures alone.
glibc's dlopen hands back the library it already has open for a path,
and the old library stays open until the states are swapped, so a reload
on Linux ran the old code on (test_agent_script on the Linux runner).
The rebuilt library is opened from a copy beside it, deleted once open,
or on Windows when the script is closed.
Two programs reloading one script in one directory staged to the same
file, which on Windows the first holds open; the copy now carries the
process id.
@nicolas-maman
nicolas-maman merged commit 5780e6b into main Nov 25, 2026
10 checks passed
nicolas-maman added a commit that referenced this pull request Nov 25, 2026
The only conflict was the Aether pin's changelog in ci.yml: both sides
pin v0.945.0; both notes are kept.
nicolas-maman added a commit that referenced this pull request Nov 25, 2026
…1087)

With the shadow cascades (#1084), a frame of 600 tiles on a CI runner's
llvmpipe takes seconds, and the timed sweep ran to the suite's 300 s
timeout. The warm-up's own scene pass now says what kind of renderer this
is: over 250 ms (bench_black_hole's guard) is software, and the sweep is
skipped with a note. The triangle counts, which check the culling, are
printed either way. On an RTX 4070 Ti the sweep runs as before: scene
pass 2.76 ms drawn whole, 0.70 ms culled.

Part of #1087
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant