makepad/libs/effect_sim
Admin 012e6f7df5 tools, libs and the rest
cargo-makepad, makepad-builder (with an Android step on every OS), CI tools
and tiles, and the remaining libraries.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 12:26:21 +02:00
..
src tools, libs and the rest 2026-10-13 12:26:21 +02:00
tests tools, libs and the rest 2026-10-13 12:26:21 +02:00
Cargo.toml effect-sim: physics as a VFX layer (KERNELS.md P7, §3.6) -- makepad-effect-sim, a deterministic stepper that hosts one box3d world and stateful kernel sims for a document on a fixed, exact time grid, seeded and seekable; same-machine reproducibility is the contract (export, seek and re-render agree on the machine that renders; nothing crosses machines, gameplay physics stays in Sandbox's sim). time.rs: sim time is whole ticks at 272 160 000/s (every common frame rate incl. the 1001 rates, the render graph's sub-frames up to 324 at 90/180/360 degree shutters and 1/n s steps land exactly; f64 seconds snap to the nearest tick), StepDt a rational step (1/240 default, refused off the grid or outside 1/10000..1/10 s), step(t) = floor(t/dt), alpha, spawn at ceil(t/dt) (a beat is exact to one step), negative time is the initial state. desc.rs: Physics / Body / Spawn / Sim as plain values with compiled kernels (shapes box, sphere, capsule, plane, hull, mesh, height field; fixed, dynamic, kinematic driven by the host's Drive at each step's time). layouts.rs: the Body (spawn), Rigid (a drawn body: pose, previous pose, scale, colour, seed, stable id, age, radius, speed, group), Contact and Event records kernels read and write; zero is every field's default, and every Body record is validated (finite, sizes, speeds, material values in range) before anything is made from it. stepper.rs: a step drives kinematic bodies, steps the world, keeps its hits and sleeps (box3d clears them every step) for retain seconds, expires bodies whose life ran out, runs due spawns (a kernel's output(Body) or emit_buffer(Body, n), or records in place; delay waits in the pending queue), runs due sim updates (prev -> next, physics inputs bound, emit_buffer(Body) spawns), records the step's poses. Checkpoints every 0.5 s of sim time are complete: the world's snapshot image and geometry registry (restored into a shell world as box3d's snapshot test does), step, spawn cursor and pending queue, contact and event history, sim states, the stable id table (box3d body index to document id -- a snapshot scrubs user data -- groups, render fields, expiry) and a version stamp (document hash, every kernel's program hash, input revisions, grid, seed, precision); a checkpoint with another stamp is never restored, a reload with another stamp discards them all; under the byte budget (64 MiB default) the ring thins to 2 s, then 5 s, then drops the oldest, never the initial state. seek(t) keeps steps step(t)-1 ..= step(t)+1 available (a view interpolates, slerp for rotations, and gives the pose one step earlier) and restores the newest valid checkpoint at or before step(t)-1 only when those frames are gone (or a checkpoint lies far ahead); advance_to(t, budget) is the realtime form (the last state stays up while behind, counted). View: bodies of a group interpolated, written in any reflected instance layout by field name, contacts and events in the retention window, sim states, a hash. bridge.rs: bodies published through a makepad-render-kernels OutputRing slot (publish_bodies), the physics kernel module (nearest, overlaps, raycast over Rigid records) and the Sim kernel sources. Checked: cargo test --release -p makepad-effect-sim (unit 5: tick grid, sub-frames, floor/ceil/alpha, layouts, record validation; tests/stepper.rs 12: seek == play at 20 random frame and sub-frame times of a 600-piece beat-timed confetti scene with a kinematic paddle, delayed and expiring bodies and a sparks sim reading contacts -- view hash and whole-state hash, cold on a fresh stepper and on one seeking back and forth through its own checkpoints (17 restores); a 1 MiB budget still seeks exactly; stale checkpoints (edited document) discarded 11/11, never restored, and the result equals a fresh stepper of the edit; spawns on the beat's step; delay/life across seeks; contacts readable for the whole window and bodies interpolated; bodies through a ring with fences two frames late; a sim spawning bodies and querying bodies; realtime catch-up equals locked time; an out-of-range record refused with its field; 2000 bodies: 0.72 ms per 1/120 s of sim incl. 0.04 ms pose extraction on one worker, budget 1 ms). 2026-09-30 13:31:41 +02:00