Skip to content

feat: Integrate Jolt Physics as native host service in SpacetimeDB#1

Open
pbisogno wants to merge 4 commits intomasterfrom
feature/jolt-physics-integration
Open

feat: Integrate Jolt Physics as native host service in SpacetimeDB#1
pbisogno wants to merge 4 commits intomasterfrom
feature/jolt-physics-integration

Conversation

@pbisogno
Copy link
Owner

Add Jolt Physics 5.0.0 as a native C++ host service accessible from WASM modules via host functions. Includes:

  • JoltC C API: Vehicle system (WheeledVehicleController) with structs for vehicle params, wheel state, and full vehicle state
  • Rust physics service: PhysicsState singleton managing multiple physics worlds, body creation/destruction, vehicle support, and 2-layer broadphase
  • WASM host functions: 18 physics_* functions in spacetime_10.5 namespace bridging WASM memory to native Jolt calls
  • C# bindings: High-level Physics.cs wrapper with serialization for FFI
  • Test module: physics-test-cs with tables, reducers, and 30Hz physics tick

Description of Changes

API and ABI breaking changes

Expected complexity level and risk

Testing

pbisogno and others added 4 commits March 16, 2026 16:59
Add Jolt Physics 5.0.0 as a native C++ host service accessible from WASM modules
via host functions. Includes:

- JoltC C API: Vehicle system (WheeledVehicleController) with structs for
  vehicle params, wheel state, and full vehicle state
- Rust physics service: PhysicsState singleton managing multiple physics worlds,
  body creation/destruction, vehicle support, and 2-layer broadphase
- WASM host functions: 18 physics_* functions in spacetime_10.5 namespace
  bridging WASM memory to native Jolt calls
- C# bindings: High-level Physics.cs wrapper with serialization for FFI
- Test module: physics-test-cs with tables, reducers, and 30Hz physics tick

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the vendored joltc-sys-patched folder (~577 files, 11MB) with a
git dependency pointing to pbisogno/jolt-rust feature/spacetimedb branch.

The Jolt Physics code now lives in its own fork chain:
- pbisogno/jolt-rust (build.rs patches for Windows/SpacetimeDB)
- pbisogno/JoltC (Vehicle API additions)
- jrouwe/JoltPhysics (upstream, unchanged)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Each module now owns its own Arc<PhysicsState>, ensuring:
- Module A cannot access Module B's physics worlds
- Physics resources are automatically cleaned up when a module is dropped
- Multiple database instances can run independent physics simulations

The PhysicsState flows through: ModuleCommon -> InstanceEnv -> host functions.
Removed the global static PHYSICS singleton and physics() accessor.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace as_raw() with raw() to match current rolt/joltc-sys API
- Add ? operator for create_body return type (now returns Option)
- Fix borrow-then-move issue in v8/mod.rs by cloning physics Arc early
- Add build_check.ps1 with MSVC + Strawberry Perl + LLVM setup

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant