M4: engine.physics — Box3D, over a narrow, verified P/Invoke shim
native/physics-native/lingua_physics.c wraps Box3D at a specific pinned commit (47d7f7c — Box3D has no 1.0 release yet, and its only tag, v0.1.0, already diverges from this API, confirmed by diffing headers rather than assuming). The wrapper is deliberately narrow: Box3D's own b3WorldDef/ b3BodyDef/b3ShapeDef are large structs with function pointers, and b3BoxHull's own doc comment says it "has data hanging off the end and cannot be directly copied" — none of that crosses the P/Invoke boundary. Every exported Lingua_* function takes and returns only plain int32/float/ bool scalars, and handles are this shim's own array-index handles, not Box3D's id structs. C# binds them with classic DllImport rather than the newer LibraryImport specifically because LibraryImport's generated marshalling needs AllowUnsafeBlocks even for an all-scalar signature like every one of these — DllImport needs none, keeping this plugin inside the kernel's "no unsafe in the v1 hot path" rule with no exception required. engine.physics adds Rigidbody/BoxCollider/SphereCollider components and PhysicsWorld, which diffs Query<Rigidbody>() against its own tracked set every Stage.FixedUpdate (there's no destruction event to hook) to create and destroy native bodies, steps Box3D once per invocation — Engine.Host's accumulator decides how many times that runs per frame, not this plugin — and writes each body's resulting transform back to GameObject.Transform. IPhysicsService exposes ApplyLinearImpulse/Get/SetLinearVelocity for gameplay code. Verified twice: a standalone C smoke test against the native shim alone (a box dropped from y=5 onto a static ground settles at y≈1.0, exactly where the two half-heights sum to), and the full pipeline through Engine. Host — a headless run with a real scene, --dump showing the same box settling at y=0.9999 after physics, scene load, and Stage.FixedUpdate all went through the real kernel. 5 new automated tests in Engine.Physics. Tests cover the same settling behavior for both shapes, a missing-collider warning that fires once and doesn't throw, cleanup after a GameObject is destroyed mid-simulation, and that an applied impulse actually changes velocity — all passed on the first run. Physics-enabled GameObjects must be root-level for now: PhysicsWorld writes Box3D's world-space transform straight into LocalPosition/ LocalRotation, correct only when local and world space are the same thing. A parented rigidbody needs the same parent-WorldMatrix-inverse handling GizmoMath.WorldToLocalPosition already does for the gizmo — real, not-yet-done work, not silently wrong. Full suite: 81 tests. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N1qPfzq8TDCUMFMV3UwV5N
This commit is contained in:
@@ -57,6 +57,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Editor", "plugins\en
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Editor.Tests", "tests\Engine.Editor.Tests\Engine.Editor.Tests.csproj", "{7F1CF468-6717-4152-BA95-2DA1E011B6CB}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "engine.physics", "engine.physics", "{5BFA9F87-CB7C-360F-A763-812D3AAB4167}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Physics.Contracts", "plugins\engine.physics\Engine.Physics.Contracts\Engine.Physics.Contracts.csproj", "{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Physics", "plugins\engine.physics\Engine.Physics\Engine.Physics.csproj", "{A9205D28-762B-49C0-8CFF-8D59BA330786}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Physics.Tests", "tests\Engine.Physics.Tests\Engine.Physics.Tests.csproj", "{70245995-311C-4CBE-A433-F4035303BEDB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -283,6 +291,42 @@ Global
|
||||
{7F1CF468-6717-4152-BA95-2DA1E011B6CB}.Release|x64.Build.0 = Release|Any CPU
|
||||
{7F1CF468-6717-4152-BA95-2DA1E011B6CB}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{7F1CF468-6717-4152-BA95-2DA1E011B6CB}.Release|x86.Build.0 = Release|Any CPU
|
||||
{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D}.Release|x64.Build.0 = Release|Any CPU
|
||||
{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D}.Release|x86.Build.0 = Release|Any CPU
|
||||
{A9205D28-762B-49C0-8CFF-8D59BA330786}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A9205D28-762B-49C0-8CFF-8D59BA330786}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A9205D28-762B-49C0-8CFF-8D59BA330786}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{A9205D28-762B-49C0-8CFF-8D59BA330786}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{A9205D28-762B-49C0-8CFF-8D59BA330786}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{A9205D28-762B-49C0-8CFF-8D59BA330786}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{A9205D28-762B-49C0-8CFF-8D59BA330786}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A9205D28-762B-49C0-8CFF-8D59BA330786}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A9205D28-762B-49C0-8CFF-8D59BA330786}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{A9205D28-762B-49C0-8CFF-8D59BA330786}.Release|x64.Build.0 = Release|Any CPU
|
||||
{A9205D28-762B-49C0-8CFF-8D59BA330786}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{A9205D28-762B-49C0-8CFF-8D59BA330786}.Release|x86.Build.0 = Release|Any CPU
|
||||
{70245995-311C-4CBE-A433-F4035303BEDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{70245995-311C-4CBE-A433-F4035303BEDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{70245995-311C-4CBE-A433-F4035303BEDB}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{70245995-311C-4CBE-A433-F4035303BEDB}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{70245995-311C-4CBE-A433-F4035303BEDB}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{70245995-311C-4CBE-A433-F4035303BEDB}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{70245995-311C-4CBE-A433-F4035303BEDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{70245995-311C-4CBE-A433-F4035303BEDB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{70245995-311C-4CBE-A433-F4035303BEDB}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{70245995-311C-4CBE-A433-F4035303BEDB}.Release|x64.Build.0 = Release|Any CPU
|
||||
{70245995-311C-4CBE-A433-F4035303BEDB}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{70245995-311C-4CBE-A433-F4035303BEDB}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -312,5 +356,9 @@ Global
|
||||
{6A2943F1-1984-470D-BD74-C6E16BB77241} = {8067C66D-9D49-192B-E4C1-1C024401ACE3}
|
||||
{B60A3933-923C-4339-98D1-E4C87A76E80B} = {8067C66D-9D49-192B-E4C1-1C024401ACE3}
|
||||
{7F1CF468-6717-4152-BA95-2DA1E011B6CB} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
|
||||
{5BFA9F87-CB7C-360F-A763-812D3AAB4167} = {07D57EEB-2F50-60C4-C011-FE4FA775C9A8}
|
||||
{70BE8EA7-0EF5-4AA1-A6CD-79B7ED4C207D} = {5BFA9F87-CB7C-360F-A763-812D3AAB4167}
|
||||
{A9205D28-762B-49C0-8CFF-8D59BA330786} = {5BFA9F87-CB7C-360F-A763-812D3AAB4167}
|
||||
{70245995-311C-4CBE-A433-F4035303BEDB} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Reference in New Issue
Block a user