diff --git a/docs/box3d-parity.md b/docs/box3d-parity.md index 990f992..32ed026 100644 --- a/docs/box3d-parity.md +++ b/docs/box3d-parity.md @@ -6,14 +6,17 @@ Box3D v0.1.0 is Ymir's physics implementation and executable semantics oracle. The production native session ABI and snapshot lowering are live; explicit retained-world ownership is still being connected. The exact upstream source is pinned as the `extern/box3d` submodule at the GameCult fork's commit -`fb719c4` (substep callback; `https://eureka.gamecult.org/forge/GameCult/box3d`, branch `gamecult/step-normal-impulse`). -The fork is upstream `8441b4a06d6d09dcfb0b0f704df4d847d1437b92` plus three commits: an observed field, +`c790839` (`https://eureka.gamecult.org/forge/GameCult/box3d`, branch `gamecult/destroy-enlarged-proxy`). +The fork is upstream `8441b4a06d6d09dcfb0b0f704df4d847d1437b92` plus these commits: an observed field, `b3ManifoldPoint.stepNormalImpulse`, the normal impulse each contact point applied over the whole step; a static assert that `RELAX_ITERATIONS` is 1, the one setting under which that sum is exact; and a substep callback (`b3World_SetSubStepCallback`, with `b3Body_GetSubStepState` and `b3Body_ApplySubStepImpulse`, valid only inside it) that the particle phase runs in, after the biased solve and before positions integrate. The first two change no solver arithmetic and a world with no callback registered runs exactly as before, so dynamics are bit-identical to upstream -(the six ABI 8 hashes pin it). To rebase it onto a newer Box3D, re-apply those commits, re-run the Soa impulse and +(the six ABI 8 hashes pin it). Then the contact friction hook (`ebe346a`, see `soa-world.md`), and a broad-phase +fix: a proxy destroyed after its step enlarged it, while it was the only buffered move, left its tree ancestors flagged +enlarged and the empty move buffer skipped the rebuild that clears them, so Debug validation aborted the next step; +the empty-buffer path now rebuilds (a root walk on a clean tree; the fork's `DestroyEnlargedProxyTest`). To rebase it onto a newer Box3D, re-apply those commits, re-run the Soa impulse and particle tests and compare a pile's state hash against the upstream build. Box3D does not own GameCult entity ids, gameplay policy, persistence, or result diff --git a/extern/box3d b/extern/box3d index ebe346a..c790839 160000 --- a/extern/box3d +++ b/extern/box3d @@ -1 +1 @@ -Subproject commit ebe346a92506c64b770b9b5e1b038871c3477445 +Subproject commit c7908394eb3ec3aa0f54bf26a98a683c1950ac15 diff --git a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaRemoveTests.cs b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaRemoveTests.cs index 8cf614c..8fe958c 100644 --- a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaRemoveTests.cs +++ b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaRemoveTests.cs @@ -299,6 +299,44 @@ public sealed class Box3DSoaRemoveTests _ = c; } + /// Random add/remove churn of falling spheres on a floor. Run it in Debug too: Box3D validates its broad-phase there, and a + /// body removed while its proxy was the only one moving left the dynamic tree flagged enlarged (fixed in box3d c790839). + [Fact] + public void Add_and_remove_churn_keeps_the_world_valid() + { + for (var seed = 1; seed <= 12; seed++) + { + using var world = World(bodies: 6, joints: 0); + world.AddStaticBox(1, (0f, -0.5f, 0f), (4f, 0.5f, 4f)); + var rng = new Random(seed); + var live = new List(); + var next = 2ul; + var removals = 0; + for (var step = 0; step < 120; step++) + { + if (rng.Next(3) == 0) + { + if (live.Count > 0 && (world.FreeBodySlots == 0 || rng.Next(2) == 0)) + { + var k = rng.Next(live.Count); + world.RemoveBody(live[k]); + live.RemoveAt(k); + removals++; + } + else if (world.FreeBodySlots > 0) + { + live.Add(world.AddSphere(next++, (4f * rng.NextSingle() - 2f, 0.2f + 2f * rng.NextSingle(), 4f * rng.NextSingle() - 2f), 0.1f, 1000f)); + } + } + world.Step(Dt); + } + Assert.True(removals >= 5, $"seed {seed}: {removals} removals"); + var view = world.View; + Assert.All(live, h => Assert.Equal((uint)Box3DSoaKind.Sphere, view.Kind[h])); + Assert.All(live, h => Assert.InRange(view.PositionY[h], 0f, 2.5f)); // on or above the floor, none lost through it + } + } + private static byte[] Replay() { using var world = World(bodies: 8, joints: 4);