Projects

Physics Engine

2026

  • C
  • Physics
  • Simulation
  • 3D

Description

A work-in-progress physics engine targeting deterministic rigidbody simulation for Gildenkrieg, designed to support large-scale, networked worlds with strict consistency between server and client.

The engine is built around a data-oriented architecture, leveraging Structure-of-Arrays (SoA) layouts and cache-friendly memory organization to efficiently simulate tens to hundreds of thousands of rigid bodies. It uses pooled memory, handle-based resource management (index + generation), and minimal allocation strategies to ensure predictable performance and avoid fragmentation under heavy load.

Determinism is a core design goal. All simulation steps are structured to produce identical results across platforms given the same inputs, enabling authoritative server simulation with client-side prediction and reconciliation. Floating-point behavior, update ordering, and constraint solving are carefully controlled to minimize divergence.

The simulation pipeline follows a structured update model:

  • Force accumulation and integration (semi-implicit Euler)
  • Broadphase collision detection (Sweep-and-Prune with axis optimization and support for sleeping/static bodies)
  • Narrowphase collision detection (AABB, sphere, and extensible convex support)
  • Contact generation and caching
  • Iterative constraint solving using sequential impulses with warm starting
  • Position correction and stabilization
  • Sleeping and island management for performance optimization

The engine includes a dynamic broadphase system optimized for large worlds, with support for incremental updates and efficient handling of both active and inactive bodies. Sleeping and island partitioning reduce unnecessary computation by grouping interacting bodies and disabling simulation for stable regions.

Collision resolution is handled via a sequential impulse solver, supporting normal and friction constraints using a Coulomb friction model. Warm starting is used to improve convergence across frames, and the solver is designed to remain stable under stacking and high-contact scenarios.

To support scalability, the engine separates active, sleeping, and unused bodies into contiguous regions, enabling fast iteration and minimizing branch divergence. Future extensions include spatial partitioning structures (e.g., BVH or grid acceleration) and parallel solver stages.

The engine is designed to integrate tightly with Gildenkrieg’s server architecture:

  • Deterministic stepping aligned with the server tick loop
  • Clear separation between simulation and networking layers
  • Efficient state extraction for snapshotting and replication
  • Compatibility with rollback, replay, and debugging systems

Additional goals and planned features include:

  • Continuous collision detection (CCD) for fast-moving objects
  • Constraint types beyond contacts (joints, springs, motors)
  • Hybrid broadphase systems for planetary-scale environments
  • SIMD acceleration and potential GPU-assisted workflows
  • Tooling for debugging, visualization, and profiling

This engine prioritizes correctness, determinism, and scalability over general-purpose flexibility, making it well-suited for authoritative multiplayer simulations and large, procedurally generated worlds.