Repository navigation
Jolt Physics Integration
Audience: Programmers | Mixed
Thread Context: Physics runs on the main thread by default; Jolt's
JobSystemThreadPooldispatches the broad-phase/narrow-phase work across worker threads. The contact listener and body-activation listener are invoked on Jolt's internal threads, so pending-contact and surface-velocity state are mutex-protected.Platform/Backend Scope: Cross-platform. Jolt is the sole physics backend. Builds without Jolt fall back to
PhysicsSystemStub.cpp.
SparkEngine uses Jolt Physics for 3D rigid-body, character, vehicle, ragdoll, and soft-body simulation. The engine migrated from Bullet Physics to Jolt across roughly seven commits (~6,500 lines). The integration is wrapped behind the engine's own PhysicsSystem API rather than exposing Jolt types directly, and a no-Jolt stub (PhysicsSystemStub.cpp) keeps the engine buildable without the dependency.
All physics source lives under SparkEngine/Source/Physics/.
PhysicsSystem.h/.cpp, PhysicsSystemQueries.cpp, PhysicsShapeFactory.cpp, PhysicsSpatialQueries.cpp, PhysicsConstraints.cpp, PhysicsMotorControl.cpp:
- Full Jolt
PhysicsSystemlifecycle (Init / Update / Shutdown) - Multi-threaded job system (
JobSystemThreadPool) - Broad-phase layers (NON_MOVING, MOVING, TRIGGER)
- Contact listener with surface-velocity support (conveyor belts)
- Body-activation listener
- Shape cache (hash-based deduplication)
- Fixed-timestep accumulator with interpolation
- Deterministic mode (
PhysicsSettings::mDeterministicSimulationtoggle) - Binary state serialization (body positions/velocities save/load)
15 types in the CollisionShapeType enum: Box, Sphere, Capsule, Cylinder, Cone (convex hull), Mesh, ConvexHull, Heightfield, Compound (static), TaperedCapsule, TaperedCylinder, Plane, Scaled, OffsetCenterOfMass, MutableCompound, Empty.
12 types plus motors: Point2Point, Hinge, Slider, ConeTwist (SwingTwist), 6DOF, Fixed, Distance, Cone, Gear, RackAndPinion, Pulley, Path (Hermite spline). Motors: Hinge velocity/position, Slider velocity/position, Disable.
-
CharacterController (
CharacterController.h/.cpp) — JoltCharacterVirtual(slopes, stairs, ground state, moving platforms) -
VehiclePhysics (
VehiclePhysics.h/.cpp) — wheeled, tracked, motorcycle with engine/transmission/differential -
RagdollSystem (
RagdollSystem.h/.cpp) — 3 modes (Physics, Kinematic, Blended), per-part constraints -
SoftBodyPhysics (
SoftBodyPhysics.h/.cpp) — XPBD cloth/deformable, skinned constraints (cloth-to-skeleton), wind -
ClothSimulation (
ClothSimulation.h/.cpp) — standalone cloth, separate from Jolt soft body - GroupFilterTable — sub-group collision pairs
- MutableCompoundShape — runtime add/remove of sub-shapes
-
Buoyancy —
ApplyBuoyancyImpulsewith a water plane -
Debug renderer (
PhysicsDebugRenderer.h/.cpp) — debug-draw data collector
-
SPARK_DOUBLE_PRECISION_PHYSICSCMake option (OFF by default;CMakeLists.txt:140) maps toJPH_DOUBLE_PRECISIONfor large worlds -
PhysicsSystemStub.cppprovides a no-Jolt fallback; all constraint stubs return ashared_ptrwith a null Jolt backend, so calls are safe - All enum-to-string conversions cover every enum value
-
PhysicsComponents.hprovidesRigidBodyComponentandColliderComponent - The physics update system in the ECS syncs
Transform↔ physics -
PhysicsHandleis an opaque handle linking ECS entities toPhysicsBodyinstances - Editor panels:
Physics2DPanelandPhysics3DPanelboth exist underSparkEditor/Source/Panels/
- The
g_physicsSystemaccessor inPhysicsSystemQueries.cppletsPhysicsBodymethods call back into the system (e.g.SetPositionroutes throughBodyInterface). - The contact listener runs on Jolt's internal threads — it uses a mutex for pending contacts.
- The surface-velocity map is also mutex-protected for contact-listener thread safety.
-
IPhysicsBackend.his a forward-looking abstraction.PhysicsSystemdoes not currently inherit it — engine code still usesPhysicsSystemdirectly. (See the deferred Phase 8C item in Reflection & Polymorphism Refactoring Plan.)
| Feature | Priority | Notes |
|---|---|---|
Full JPH::DebugRenderer subclass |
Medium | Current data collector works; full impl needs graphics-engine wiring |
Per-triangle PhysicsMaterial
|
Low | Jolt supports it on MeshShape but we don't expose it |
| Hair simulation (GPU strands) | Low | 3 Jolt files, very specialized |
Jolt native StateRecorder
|
Low | Our binary format covers the common case |
| Constraint breaking | Low |
SetBreakingThreshold stubbed; Jolt has no direct API, needs force monitoring |
IPhysicsBackend inheritance |
Low | Reflection plan Phase 8C — deferred (ID-vs-pointer API mismatch) |
-
Original entry date: 2026-03-22 (
jolt-physics-integration.md, type: Observation) - Verified against codebase 2026-06-08.
- Status bullets:
-
Still accurate. All listed core systems, shapes (15), constraints (12 + motors), and subsystems are present under
SparkEngine/Source/Physics/. - Jolt is referenced ~45 times in
PhysicsSystem.cpp;PhysicsSystemStub.cppconfirms the no-Jolt fallback. -
SPARK_DOUBLE_PRECISION_PHYSICSconfirmed atCMakeLists.txt:140(OFF by default). - Both
Physics2DPanelandPhysics3DPanelconfirmed present in the editor. - The original file's "future work" items remain open;
IPhysicsBackendis present butPhysicsSystemstill does not inherit it (confirmed inIPhysicsBackend.hheader doc).
-
Still accurate. All listed core systems, shapes (15), constraints (12 + motors), and subsystems are present under
- Reflection & Polymorphism Refactoring Plan — Phase 8C (physics backend integration)
- GPU/CPU Separation Plan
Published from 2b03dc797148. Edit the canonical source in wiki/.
- Documentation
- Docs route
- Wiki index
- Guides
- Tutorials
- Samples
- Examples
- API Reference
- API route
- Reference
- Build Guide
- Dependencies
- FAQ
- Changelog
- Roadmap
- Contributing
- Code of Conduct
- Home
- FAQ
- Getting Started
- Quick-Start Tutorial
- Making Your First Game
- Making Your First Multiplayer Game
- Artist Workflow Guide
- Editor Walkthrough
- Migration Guide
- How SparkEngine Works
- Architecture Overview
- Engine Architecture Flowchart
- Creating a Game Module
- Game Modules (catalog)
- Entity Component System
- Rendering and Graphics
- Physics
- Cloth Simulation
- Audio
- Input System
- Camera System
- Scripting with AngelScript
- Visual Scripting
- AI and Navigation
- Animation
- 2D Systems
- Networking
- Dedicated Server
- Multiplayer Quick Start
- Area Server Architecture
- Scene Management
- Large World Support
- Collaborative Editing
- Coroutine System
- Event System
- Event Response System
- Job System
- UI System
- UI Layout Extensions
- Localization
- Dialogue System
- Destruction System
- Replay System
- Achievement System
- Loading System
- Mod System
- Content Delivery
- Tween System
- Memory Integrity
- Gameplay Systems
- Terrain and Procedural Generation
- Save System
- Persistence System
- Day Night Cycle and Weather
- Cinematic Sequencer
- Runtime Prefabs
- SparkEditor
- Editor Tutorials
- SparkConsole
- SparkDaemon
- Shader Pipeline
- Asset Pipeline
- Asset Validation
- Asset Migration
- Game Packaging
- Online Services
- DataTable System
- Loot and Crafting System
- CSG System
- Font System
- Timer Manager
- Movie Render Pipeline
- HLOD and World Partition
- Remote Debug System
- Selection Manager
- Asset Dependency Graph
- Editor Automation
- File Watcher
- Project Templates
- System Requirements
- VR Support
- Mobile Platform
- Accessibility
- Platform Input
- Platform Certification
- Cross-Compilation: Wine Testing
- RHI Abstraction Layer
- D3D11 Backend
- D3D12 Backend
- Vulkan Backend
- OpenGL Backend
- Metal Backend
- DXR Raytracing
- Hybrid Ray Tracing
- Upscaling (DLSS/FSR)
- Render Graph
- Shader Graph
- GPU Particles
- GPU-Driven Rendering
- Volumetric Fog
- Volumetric Clouds
- Global Illumination
- Virtual Texturing
- Water Rendering
- Clustered Lighting
- Material System
- Post-Processing
- Shadow System
- Particle System
- Decal System
- Sky and Atmosphere
- Foliage System
- Mesh Shaders
- Neural Rendering
- Configuration Reference
- Performance Tips
- Benchmark Framework
- Threading Model
- Fuzz Policy and Parser Security
- Memory Safety
- Memory Management Patterns
- Build System and CMake Modules
- Profiler and Debugging
- Performance Profiling Guide
- Telemetry System
- Crash Reporting
- Golden Image Testing
- Utilities
- Testing
- Fuzz Policy and Parser Security
- Codebase Statistics
- Codebase Health
- Error Handling Patterns
- Hot Reload Overview
- Troubleshooting
- Contributing
- Workflow Patterns
- Build Optimizations
- CI Reproducible Builds
- GitHub API and PR Checks
- Git Rebase Conflicts
- Clang-Format
- Code Quality Violations
- AI Bloat Pattern
- MinGW + Wine Cross-Compilation
- Live Editor Testing
- Engine & Renderer Landscape
- DuetOS Portability Catalog
- Five-Engine Analysis
- Eleven-Engine Analysis
- ThorVG / Unity Graphics Analysis
- Advanced Techniques Catalog
- Third-Party Library Evaluation
- Engine Viability Evaluation
- Engine Feature Recommendations
- Project Recommendations
- Mac Compatibility Analysis
- Codebase Observations
- Codebase Bloat Audit
- Test Suite Audit
- Documentation Coverage Audit
- ThirdParty Dependencies Audit
- Load Test Baseline
- Gameplay Systems Status
- SparkGame Module Status
- Stub and Abandoned Features
- Memory Integrity System
- Memory Safety Evaluation
- Hardware Acceleration Systems
- Jolt Physics Integration
- GPU/CPU Separation Plan
- Daemon Services Architecture
- Reflection & Polymorphism Refactoring Plan
- SparkBuild In-Tree
- Wine No-JobSystem Breakthrough
- Wine Role and Fallback Tiers