Docs: soa-world ABI 16, joint stress, body removal, removal facts
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
99d0d26656
commit
2cb5b588bc
1 changed files with 33 additions and 12 deletions
|
|
@ -8,13 +8,13 @@ Box3D decides every physical outcome; Ymir creates bodies, steps the world and e
|
|||
`ymir_box3d_session_*` (`ymir_box3d.c`) is the planar Aetheria session: gravity is zero, Y is locked,
|
||||
only yaw rotates (`motionLocks.linearY/angularX/angularZ`), and state leaves by `copy_bodies` into an
|
||||
array of structs. A body cannot fall or tumble there, and every read is a copy. The SoA world is a
|
||||
separate native object (`ymir_box3d_soa.c`, ABI 15) so the Aetheria session's contract is untouched.
|
||||
separate native object (`ymir_box3d_soa.c`, ABI 16) so the Aetheria session's contract is untouched.
|
||||
|
||||
## Contract
|
||||
|
||||
- Native (ABI 15): `ymir_box3d_soa_create(capacity, joint_capacity, gravity, fact_capacity, hit_threshold, particle_capacities*) /
|
||||
- Native (ABI 16): `ymir_box3d_soa_create(capacity, joint_capacity, gravity, fact_capacity, hit_threshold, particle_capacities*) /
|
||||
create_particles / destroy_particles / create_distances / create_bends / create_sensors / attach / remove / set_material / free_slots /
|
||||
add_body / add_joint / step / get_view / get_facts / set_anchor_target / destroy_joint / free_joint_slots / apply_impulse / cast_ray_closest / destroy`. `add_body` takes one descriptor (sphere, capsule, box, static box, anchor; position,
|
||||
add_body / add_joint / step / get_view / get_facts / set_anchor_target / destroy_joint / set_joint_thresholds / remove_body / free_joint_slots / free_body_slots / apply_impulse / cast_ray_closest / destroy`. `add_body` takes one descriptor (sphere, capsule, box, static box, anchor; position,
|
||||
rotation, velocity, size, density, friction, restitution, rolling resistance, material id, parent, limb). Capacities are fixed at creation,
|
||||
so lane pointers never move.
|
||||
- Body lanes (`ymir_box3d_soa_view`): `stable_id`, `kind`, `parent` and `limb` (set at creation, not read by
|
||||
|
|
@ -33,6 +33,11 @@ separate native object (`ymir_box3d_soa.c`, ABI 15) so the Aetheria session's co
|
|||
(world orientation of frame A, quaternion), `joint_origin` (world position of frame A's origin, the anchor), `joint_rotation` (frame B relative to frame A, quaternion,
|
||||
w >= 0) and `joint_angular_velocity` (B minus A, in frame A). A consumer can compute a joint torque from
|
||||
these and write it as equal and opposite torques on the two body lanes.
|
||||
- Joint stress: `joint_constraint_force_xyz` (N) and `joint_constraint_torque_xyz` (N m) are Box3D's constraint solution for the joint at the end of the last step
|
||||
(`b3Joint_GetConstraintForce/Torque`, world frame; a hung mass at rest reads m g within 2%; a removed lane reads 0). The joint desc's `force_threshold` and
|
||||
`torque_threshold` (+inf, the default, is never; NaN or a negative value is refused; `set_joint_thresholds(joint, generation, force, torque)` changes a live joint's)
|
||||
make Box3D report the joint in a step where its load reaches one: an Overload fact `{joint_lane, joint_generation, force xyz, torque xyz}` (the load read after the step), at most once per
|
||||
joint per step. The threshold is a sensor: Ymir never removes a joint on it, the caller decides with `destroy_joint`. Joint user data is lane + 1.
|
||||
- Contact lanes (read-only, rewritten by every `step`): `contact_impulse` (N s: the normal impulse the
|
||||
body's touching contacts delivered to it over the whole step, the sum of Box3D's `stepNormalImpulse` over
|
||||
its manifold points; 0 for a body touching nothing; exact, so a jointed limb's reading is what the contacts
|
||||
|
|
@ -54,6 +59,11 @@ separate native object (`ymir_box3d_soa.c`, ABI 15) so the Aetheria session's co
|
|||
rewrites them. `*_dropped` counts the facts a step could not keep past `fact_capacity`. The lane in a fact
|
||||
is the body's user data (lane + 1) and the stable id is the shape's user data. The facts report; they
|
||||
decide nothing.
|
||||
- Overload and removal facts (buffers fixed at create like the rest): `overload` (above), `body_removed` `{lane, generation (the dead handle's), stable_id, wet_patches, wet_volume}`
|
||||
and `joint_removed` `{lane, generation, body_a, body_b, with_body}` (1 when a removed body took the joint, 0 for `destroy_joint`). `remove_body` and `destroy_joint` write them
|
||||
into pending arrays and the next `step` publishes them in removal order (a lane is removed at most once between steps, so they never overflow), with the End touch facts the
|
||||
removal caused: a removed body's shape is no longer valid, so its End facts are attributed from the retired shape table `{shape, lane, stable_id}`, cleared once the step has
|
||||
collected them. Every removal path (a grab release, a cut, a gib, a level unload) appears in these facts. A step refused for a non-finite write lane publishes nothing and keeps them.
|
||||
- Grab and poke input (immediate commands; Ymir decides nothing about grabbing, so a player grab, a scripted
|
||||
hook and a cursor tool are all the same three calls):
|
||||
- Anchor (body kind 4): a kinematic body with no shape. It never collides or is hit, its size lanes are 0 and
|
||||
|
|
@ -68,21 +78,32 @@ separate native object (`ymir_box3d_soa.c`, ABI 15) so the Aetheria session's co
|
|||
linear spring pulls body B's anchor point onto A's (A an anchor, B the body to grab). `max_force` and
|
||||
`max_torque` bound the pull: with a max force below the weight the body hangs below the target. `joint_angle`
|
||||
reads 0.
|
||||
- Release: the cursor's anchor is long-lived (a client creates one per cursor and keeps it; bodies are never
|
||||
removed here). `destroy_joint(joint, generation)` releases a grab by destroying the motor joint only; the anchor and the
|
||||
grabbed body stay. Only motor joints can be destroyed (general joint and body removal belongs to
|
||||
`ymir-break-and-remove`); anything else is refused. The joint's lane becomes a tombstone: `joint_kind` 4
|
||||
(Removed), `joint_body_a/b` -1 and every joint lane 0. `joint_count` counts slots ever used, tombstones included.
|
||||
- Release: the cursor's anchor is long-lived (a client creates one per cursor and keeps it, or removes it with `remove_body`).
|
||||
`destroy_joint(joint, generation)` releases a joint of any kind (a grab, a cut, a tear) through the one joint-ending path, `ymir_soa_retire_joint`,
|
||||
the only `b3DestroyJoint`; the bodies stay. The joint's lane becomes a tombstone: `joint_kind` 4
|
||||
(Removed), `joint_body_a/b` -1, every joint lane 0 (the constraint lanes included), generation + 1; no last state is kept, a caller that wants it reads before
|
||||
removing. `joint_count` counts slots ever used, tombstones included.
|
||||
`add_joint` reuses the lowest tombstone only after a step has completed since the destroy, so lanes read within a
|
||||
step stay valid; until then the slot is not free. `free_joint_slots` (managed `FreeJointSlots`) is what
|
||||
`add_joint` could create right now: check it, and `FreeBodySlots`, before adding an anchor for a grab, so a full
|
||||
world leaves no orphan anchor. Repeated grab and release on one slot do not grow the world.
|
||||
A joint's handle is its lane and the slot's generation (`joint_generation` lane, counts destroys of the slot;
|
||||
managed `Box3DSoaJointHandle`, returned by `AddJoint` and `AddMotorJoint`, converts to the lane). `destroy_joint`
|
||||
refuses a generation that is not the slot's, so a second release click with an old handle never destroys a later
|
||||
refuses a generation that is not the slot's, a removed lane and an out-of-range lane, so a second release click with an old handle never destroys a later
|
||||
grab that reused the slot. Anchor creation must be followed by a joint that validates (its spring fields are
|
||||
checked there), or the anchor is left behind: with one long-lived anchor per cursor that is accepted, and an atomic
|
||||
`AddGrab` is a follow-up only if cursors become dynamic.
|
||||
- Body removal: `remove_body(lane, generation)` (managed `RemoveBody(Box3DSoaBodyHandle)`) is the one body-ending path. A body's handle is its lane
|
||||
and the lane's generation (`body_generation` lane; managed `Box3DSoaBodyHandle`, returned by every `Add*` body helper, converts to the lane, so lane arrays and `int`
|
||||
parameters take it unchanged). It is refused whole, changing nothing, for a lane that is not a live body, a stale generation, and with status REFERENCED (6; managed: it
|
||||
throws) while a live body attachment or liquid sensor names the body: the caller removes those first (an anchor is a body and gets no rule of its own: its attachments
|
||||
and sensors count the same). Otherwise, in order: the body's wet patches are removed (`ymir_particles_release_body`, no Box3D call), every joint naming the body is
|
||||
retired (ascending lane, so a removed anchor ends its grabs and their handles go stale), the body's shape is entered in the retired table, Box3D destroys the body and the lane
|
||||
becomes a tombstone: `kind` 5 (Removed), every other lane 0 (stable id 0, parent -1, limb 0), generation + 1. Lane order never changes (no swap-remove; `count` is the
|
||||
high-water mark of lanes ever used). `add_body` takes the lowest Removed lane whose step has completed, else appends, else FULL; a lane is never reused before the step
|
||||
whose facts name it dead, and the removed stable id may be reused. `free_body_slots` (managed `FreeBodySlots`) counts them. `attach`, `create_sensors`, `add_joint` and a
|
||||
new body's `parent` refuse a Removed lane; a live child's `parent` may still name one (the consumer owns its tree). `particle_support_body` is a last-step fact and may name a
|
||||
removed lane until the next substep; a drop cannot settle on it (its proxy reads no shape). Box3D's own joint cascade in `b3DestroyBody` never runs: the joints are retired first.
|
||||
- `apply_impulse(lane, impulse, point)`: a one-shot world impulse (N s) at a world point; off the centre of mass it
|
||||
also spins the body. Dynamic bodies only (a static body or anchor is refused), non-finite input refused.
|
||||
- `cast_ray_closest(origin, translation)` fills a `ymir_box3d_soa_ray_hit` {hit, lane, stable_id, point, normal,
|
||||
|
|
@ -280,7 +301,7 @@ of sqrt(2gh), point and normal), lifting gives one end, dropped counters resetti
|
|||
hits, facts lasting one step, overflow counted, per-step byte determinism of facts and contact lanes, and
|
||||
no allocation across 100 steps with fact reads. `Box3DSoaImpulseTests`: `contact_impulse` and the hit `impulse` equal the momentum change of the bodies the contact acted on, plus their weight, within 1e-4 of the peak at every step: a 5 kg ball and a 0.3 g BB at 100 m/s onto a jointed forearm (the BB reads 0.030 N s, the ball over 400 times more), the arm falling forearm-first onto a slab, a sphere dropped 1.4 m at 60 and 240 Hz, 1 and 4 sub-steps, restitution 0 and 0.5, two free bodies at restitution 0 and 0.5; a swung arm into a slab, a big sphere with 60 small ones converging (more contacts than graph colours, so the scalar overflow solver runs: the big lane is the sum of the small lanes, each equal to its own momentum change), and at rest `contact_impulse / dt` is the weight (0.1%, a lone sphere) while a body touching nothing reads 0.
|
||||
|
||||
`Box3DSoaParticleTests`: the ABI 8 scene's six checkpoint hashes with no particle capacity (pinned from 5104b17); a 48-particle rope (a builder in the tests: distances and soft bends) hanging from a tethered static point under 1% stretch for 4 s; a 70 kg sphere held by the same rope (from 1 s to 5 s speed under 0.001 m/s, stretch under 0.1%, the impulse per tick within 0.5% of m g dt); an anchor dragging a 5 kg box along the floor (`particle_impulse` reads it); a sphere, capsule, box and static box each pushed into a lying rope's end (no particle over 10% of its radius inside); a 16 x 16 sheet from the same two commands hung by two corners (after 5 s the corners carry the weight within 1% and no edge is past 5%), and by two corners of two pins each (after 8 s, same bounds: it still rings at 5 s); edge tension, the edge at 0, 10 and 46 and both attachment forces read the load at 1, 5, 20 and 70 kg; a cut (remove an edge of a hung 40-rope: the bends over it die, tethers 39 -> 19, the component splits, the head holds and the tail falls); overload (300 kg) removes nothing; destroying a mid-rope particle removes its constraints and releases a held body; a 24-particle cantilever at 32 substeps under a 30 and a 10 degree hard limit and a stiff and a floppy soft pass, and a limit-only bend bit-identical to no bend inside its cone; momentum of a rope, a sheet and a blob thrown into each other with no gravity within 5e-4 and energy never rising; phase rules (groups, `SELF_COLLIDE`, `SELF_FILTER`, a folded rope); an off-centre attachment spinning a free box by I^-1 (r x J) within 2%; lanes reused after a step lowest first, stale generations refused, a derivation that does not fit refused with no lane changed, bad input refused; a pile of four ropes and a sheet on two bodies byte-equal across two runs at six checkpoints (pinned), a one-ulp difference diverging, and eight concurrent worlds giving the serial bytes; no allocation across 100 steps and across a cut, a destroy and a create, and none for a 300-distance batch created and removed; gravity along each axis; a spinning box carrying its attachment point and two ends on one light box settling (the proxy's rotation); one group's `SELF_COLLIDE` needing both particles and `SELF_FILTER` either; a slack pair tether leaving its body alone; a refused `attach` leaving no lane and no tether; each particle on the nearest point of its two nearest islands (a 5-rope held at both ends, a star whose centre keeps the two nearer arms, a 9-rope with two touching points counting as one island) and no pair between two static points; every tether's parent present after each of 20 attaches on a 32 x 32 sheet (float ties at rank 2 gated); a particle held by two bodies touching neither. `Box3DSoaParticleSourceTests` reads the C source: no Box3D call in `ymir_particles.*`, no allocation outside create and free, no threads or atomics, no rope, sheet, cloth or chain identifier in the solver or the binding, the tether and component lanes written only by the derivation, every topology command ending in it, `begin` and `end` called once (in the step), `substep` once (in the callback), the callback the only user of the fork's two accessors, no topology change in the phases, and the retired names absent.
|
||||
`Box3DSoaRemoveTests`: removing a body retires its joints and zeroes its lane (old handles stale, others untouched, facts one step), is refused while an attachment or a liquid sensor names it (nothing changed; after the caller removes them it succeeds; attach, sensors, add_joint and a parent then refuse the lane), takes its wet patches with it (count and summed volume on the fact, another body's patches untouched), ends a grab when the anchor goes, ends a touch by name, leaves a drop unable to settle, keeps the other lanes' state, reuses a lane one step later with a new generation, repeats bit for bit with removals and thresholds over 300 steps and allocates nothing managed. `Box3DSoaJointTests`: the constraint lanes read m g, an overload is reported once its load reaches the threshold and the joint stays, thresholds are refused when NaN or negative. `Box3DSoaGrabTests`: every joint kind destroys through one path. `Box3DSoaParticleTests`: the ABI 8 scene's six checkpoint hashes with no particle capacity (pinned from 5104b17); a 48-particle rope (a builder in the tests: distances and soft bends) hanging from a tethered static point under 1% stretch for 4 s; a 70 kg sphere held by the same rope (from 1 s to 5 s speed under 0.001 m/s, stretch under 0.1%, the impulse per tick within 0.5% of m g dt); an anchor dragging a 5 kg box along the floor (`particle_impulse` reads it); a sphere, capsule, box and static box each pushed into a lying rope's end (no particle over 10% of its radius inside); a 16 x 16 sheet from the same two commands hung by two corners (after 5 s the corners carry the weight within 1% and no edge is past 5%), and by two corners of two pins each (after 8 s, same bounds: it still rings at 5 s); edge tension, the edge at 0, 10 and 46 and both attachment forces read the load at 1, 5, 20 and 70 kg; a cut (remove an edge of a hung 40-rope: the bends over it die, tethers 39 -> 19, the component splits, the head holds and the tail falls); overload (300 kg) removes nothing; destroying a mid-rope particle removes its constraints and releases a held body; a 24-particle cantilever at 32 substeps under a 30 and a 10 degree hard limit and a stiff and a floppy soft pass, and a limit-only bend bit-identical to no bend inside its cone; momentum of a rope, a sheet and a blob thrown into each other with no gravity within 5e-4 and energy never rising; phase rules (groups, `SELF_COLLIDE`, `SELF_FILTER`, a folded rope); an off-centre attachment spinning a free box by I^-1 (r x J) within 2%; lanes reused after a step lowest first, stale generations refused, a derivation that does not fit refused with no lane changed, bad input refused; a pile of four ropes and a sheet on two bodies byte-equal across two runs at six checkpoints (pinned), a one-ulp difference diverging, and eight concurrent worlds giving the serial bytes; no allocation across 100 steps and across a cut, a destroy and a create, and none for a 300-distance batch created and removed; gravity along each axis; a spinning box carrying its attachment point and two ends on one light box settling (the proxy's rotation); one group's `SELF_COLLIDE` needing both particles and `SELF_FILTER` either; a slack pair tether leaving its body alone; a refused `attach` leaving no lane and no tether; each particle on the nearest point of its two nearest islands (a 5-rope held at both ends, a star whose centre keeps the two nearer arms, a 9-rope with two touching points counting as one island) and no pair between two static points; every tether's parent present after each of 20 attaches on a 32 x 32 sheet (float ties at rank 2 gated); a particle held by two bodies touching neither. `Box3DSoaParticleSourceTests` reads the C source: no Box3D call in `ymir_particles.*`, no allocation outside create and free, no threads or atomics, no rope, sheet, cloth or chain identifier in the solver or the binding, the tether and component lanes written only by the derivation, every topology command ending in it, `begin` and `end` called once (in the step), `substep` once (in the callback), the callback the only user of the fork's two accessors, no topology change in the phases, and the retired names absent.
|
||||
|
||||
`Box3DSoaCouplingTests`: a sphere thrown at 5 m/s with a 48 x 20 g rope from rest keeps x momentum within 0.1% and gains no energy, at 5 and 70 kg; thrown up it reaches the apex momentum allows; 5 kg snapping a taut rope at 6 m/s keeps at most 5% of its energy and 70 kg is still within a tick; a 45 degree pendulum for 12 s gains no energy and loses at most 1.25 times a heavy-particle control, and a hung body keeps its spin about the vertical; removing the body attachment or destroying the rope's particles frees a held 70 kg body in the step after, with no upward impulse; `particle_impulse` equals M dv minus M g dt every tick, hung and thrown; material friction 0.6 holds a rope on a 20 degree slope and friction 0 does not; no particle is farther from a tethered point than its rest path; an attached end stays on its body point; a world whose only body is static still steps the particles (a dropped rope falls g t^2 / 2 within 2%) and rests; and a cost line with 16 ropes x 48 and one 16 x 16 sheet at 4 substeps, one body and forty (printed, not asserted).
|
||||
|
||||
|
|
@ -288,8 +309,8 @@ no allocation across 100 steps with fact reads. `Box3DSoaImpulseTests`: `contact
|
|||
|
||||
`Box3DSoaFluidTests`: the refusals (a distance or attachment naming fluid, a viscosity below 0 or not finite; a batch of fluid past the fluid capacity, refused whole); 64 fluid particles created and destroyed a tick on the 20-pin sheet leaving every tether lane byte-equal; an 8 x 8 x 16 column in a box well (max density, mean density, nothing outside); fluid thrown into a free sheet and rope at fluid : solid mass 64 : 20, 1 : 30, 30 : 1 and 100 : 1 (momentum drift, energy on every row); a 343-particle fluid block dropped 15 cm onto a floor of immovable solid particles at 4 substeps (penetration, nothing through the floor's interior bar the one particle over a lattice hole); probe scene 3, the 343-particle pour on a tilted sheet and a sloped rope at 4 substeps, printed as readings with the same block flagged solid as the control, asserting nothing; fluid pushing a free box with the impulse lane equal to its M dv; a 3 r lattice not clumping; XSPH damping a shear field; the kernel reaching a larger solid beyond two contact radii; the pour's six checkpoint hashes (two runs, a one-ulp nudge, eight concurrent worlds). Each bound states its readings and the mutant it separates from. `Fluid_cost_line` prints 512 and 2000 fluid particles on the sheet scene at viscosity 0 and 0.01. Overflow is asserted 0 in the column, the floor and the pour.
|
||||
|
||||
Body removal with a stable ordering rule, compound bodies
|
||||
and per-shape material, and motor joints with a velocity target or per-joint force readback (the motor joint here is a position spring only; Lodur drives limbs from torque lanes).
|
||||
Compound bodies
|
||||
and per-shape material, and motor joints with a velocity target (the motor joint here is a position spring only; Lodur drives limbs from torque lanes). A one-call cascading `remove_body` that also removes the attachments and sensors naming the body is not built: the caller removes them first.
|
||||
`Ymir.Core` has no session-level surface over the SoA world yet; consumers use `Ymir.Box3D` directly.
|
||||
Unity consumption is unrun; cross-platform bit-identity is unclaimed.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue