Repository navigation
physics: cvc::physics facade with null and Jolt backends; state-tree binding (vehicle physics P1) - #641
Merged
Conversation
…binding (vehicle physics P1)
An engine-agnostic rigid-body world for the nav vehicle-physics work
(docs/roadmap/NAV-VEHICLE-PHYSICS-ROADMAP.md, docs/PHYSICS_API.md).
- inc/cvc/physics (std-only headers, no engine named anywhere):
- value types and materials;
- shapes: sphere, box, convex hull, static triangle mesh, and a height field
with per-cell materials;
- bodies; backends with capability bits; the world.
- world:
- steps in fixed quanta, or follows a world_clock;
- reports contacts sorted so worker threads never reorder them;
- raycasts;
- saves, restores and hashes its whole state;
- keeps a double-precision floating origin with rebase;
- reconfigure() for the runtime settings and set_material() for live
material changes.
- Behaviour:
- It refuses a determinism mode the build cannot deliver.
- It is thread-safe: every call locks the world, and step() holds the lock
for the engine step.
- null backend: bookkeeping without physics, for builds without an engine.
- Jolt backend (src/cvc/physics/jolt), built as its own target, cvc_physics_jolt:
- Jolt::Jolt is linked PRIVATE, so JPH_* definitions reach that one TU.
- CVC_WITH_JOLT is a private define, set from find_package(Jolt CONFIG).
- The target is a static archive in a shared cvc, or an OBJECT library in a
static cvc (where Jolt joins CVC_PRIVATE_LINK_PACKAGES).
- Z up: the height field's body is turned by the exact quaternion
(0.5, 0.5, 0.5, 0.5). Every height sample is checked against max_error
after Jolt compresses it.
- Friction and restitution come from cvc materials, with a choice of combine
rules.
- Nothing throws across a Jolt callback.
- Saved state uses a recorder whose bytes live in this TU, not Jolt's
stringstream recorder, so there is no C++ runtime layout dependency on
libJolt.
- Jolt's process globals are reference-counted by the worlds using them.
There is no singleton, and an application's own Jolt setup is respected.
- world_binding: configuration and materials from the app's state tree under
"physics.*" (knob seeding, invalid values ignored), runtime keys applied on
pull(), telemetry published on push(), and restart_required set when a
build-time key changes. One per app and world; thread-safe.
- The libcvc recipe declares joltphysics for the platforms it is published on.
Tests: physics_world_test, 30 tests (2 skip by design in a Jolt build). They
include the P1 gates:
1. a box rests on rolling terrain at the sampled height +-1 cm;
2. contacts report the cell's material and mu, and mu decides stick (0.9) or
slide (0.2) on a 20-degree slope;
3. the same trace twice gives the same hash;
4. 1 thread and 3 give the same hash;
5. save, restore and re-run give the same hash, in the same world and in a
fresh one.
Also tested: concurrent calls from four threads, the floating origin at UTM
scale, and tree-driven gravity and materials. Busy-scene hash after 300 steps
on Windows/MSVC: d3ebde22539c1c2f.
Linux and macOS failed to link: "undefined reference to typeinfo for JPH::PhysicsMaterial". - Cause: Jolt is built with -fno-rtti, and the backend subclasses Jolt's polymorphic classes (PhysicsMaterial, ContactListener, the layer filters, StateRecorder). With RTTI on, the subclasses' typeinfo references base typeinfo that libJolt never emitted. MSVC places its RTTI records in the referencing TU, so Windows linked. - Fix: compile cvc_physics_jolt with -fno-rtti, matching Jolt. Exceptions still work without RTTI. - Also: give world_backend an out-of-line destructor in world.cpp, so the interface's vtable and typeinfo are emitted in an RTTI TU and never in the backend's.
Building the whole Jolt backend with -fno-rtti made GCC/Clang emit weak copies of the typeinfo for every std exception it throws (invalid_argument, runtime_error, length_error, bad_alloc). On macOS those copies bind every reference inside libcvc.dylib, so exceptions thrown by libcvc stopped matching catch clauses in the tests and boost::any casts failed: 1029 of 3888 tests on package-macos. Only cvc_material needs it: JPH::PhysicsMaterial's key function is in libJolt (built without RTTI), so a cvc_material vtable emitted with RTTI references a typeinfo that exists nowhere. cvc_material now has an out-of-line destructor in jolt_material.cpp, the one file built with -fno-rtti; it throws and catches nothing. jolt_backend.cpp is back on RTTI. Jolt's other bases here have only inline virtuals.
transfix
added a commit
that referenced
this pull request
Oct 17, 2026
Minor release. It carries: - the world clock: lockstep and batch, followers, the sim.* binding, and nav on the clock (#629, #630, #631, #640); - the units registry with SI <-> normalized-frame conversions (#632); - cvc::physics with the Jolt backend (#641); - the material trainer on the kinematic bicycle and its pycvc bindings (#642). Bumps project(VERSION) 3.5.1 -> 3.6.0 and every cvcpkg recipe's upstream_version to match. cvc_revision stays 1, per the recipe-version gate.
transfix
added a commit
that referenced
this pull request
Nov 27, 2026
libcvc builds on Haiku with what the catalog has there: no gRPC chain (abseil, protobuf, re2, grpc), so build.sh turns both conference transports off on Haiku (the WebSocket one needs protobuf's wire too); no openblas, so no levmar; and no fontconfig, tvision or openmp. Its other runtime deps now cover haiku (boost, imagemagick, libigl, libiimod and joltphysics through cy-pca/cvcpkg#644, libsodium through #641). ari gets a haiku row; arisrv does not, since it needs gRPC.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 1 of
docs/roadmap/NAV-VEHICLE-PHYSICS-ROADMAP.md: an engine-agnostic rigid-body world with a Jolt backend. The API reference isdocs/PHYSICS_API.md.What
cvc::physics::world(inc/cvc/physics/, std-only headers, no engine named in any of them)step()/follow(world_clock). Contact events are sorted, so worker threads never reorder them. Raycasts.save()/restore()/state_hash()over the whole simulation state. A determinism mode the build cannot deliver is refused.rebase()moves it. City-scale coordinates keep sub-mm resolution.reconfigure()changes runtime settings, and refuses build-time ones by name.set_material()makes live material changes, e.g. rain.step()holds the lock for the engine step.Backends
null: bookkeeping only, for builds without an engine.jolt: its own target,cvc_physics_jolt, withJolt::Joltlinked PRIVATE, soJPH_*definitions reach one TU.CVC_PRIVATE_LINK_PACKAGES. This is the same shape ascvc_igl.CVC_WITH_JOLTis private and set fromfind_package(Jolt CONFIG).max_error.world_binding— configuration from the state treephysics.*, and unset keys are seeded with the defaults:fixed_dt, threads, determinism, buffer sizes, origin;materials.<name>.*.pull()applies runtime keys and materials; a changed build-time key setsrestart_required.push()publishes telemetry: tick, time,step_ms, bodies, contacts, version, and optionallystate_hash.Also
joltphysicsfor the platforms it is published on.cvc::physics_error.The P1 gates (
physics_world_test)Plus:
Verification (Windows, MSVC 2022, Jolt 5.6.0+cvc.5 from the local cvcpkg prefix)
physics_world_test: 30/30 pass. Two skip by design in a Jolt build: "refused when not built" and "refused when not cross-platform deterministic". It passed 3 repeated runs.d3ebde22539c1c2f. Printed, not yet asserted. A cross-platform golden can be added once CI shows the same value on Linux and macOS.system_macro_headers_test,world_units_testandworld_clock_testpass.-j 12and pass alone.Related: #640 makes
world_clock_bindingthread-safe. It is independent of this PR.Not in this PR: the vehicle (P2), the energy ledger (P3), the nav plant seam (P4) and the pycvc wrappers (P6).