Shift Engine Docs

These docs follow the main branch and can describe changes newer than v0.3.2. Release archives and checksums are published on GitHub Releases.

Vehicle physics, tyres, damage & AI

Shift Engine's vehicle model lives in libs/drive (namespace drive) — a standalone, deterministic, double-precision C++20 library with zero graphics or OS dependencies. Every car runs as a 6-DOF rigid body in a right-handed Y-up frame (+X right, +Y up, +Z forward; wheels 0=LF, 1=RF, 2=LR, 3=RR) stepped at a fixed 120 Hz outer rate split into 3 × 360 Hz internal substeps.

Vehicle::step() → 120 Hz Fixed Outer Step (3 × 360 Hz Substeps) dt_sub = 1 / 360 s (double) INPUTS shape_input() [Catmull-Rom speed steer / 900° wheel] · update_gearbox() · drive::MeshGround (BVH4 / BVH8 AVX2 & NEON) 1. SUSPENSION & GROUND • Ackermann steer + 5-pass raycast • 9 Bumpiness noises + 3-tap Springiness • Preload + bump/rebound + bumpstops • Anti-roll bars + airborne gravity scale 2. REV LIMIT, BRAKES, ABS & STM • 40 ms rev-cut (preserves boost BOV) • Per-car 6-pass brake bias & decel table • Asymmetric outside-wheel STM braking • Steer-dependent ABS + 40 ms recovery 3. COMBINED-SLIP TYRES • Two-load blend (10 ↔ 1020 kgf curves) • Normalized circle s = hypot(sx, sy) • Off-road peak SA + rear-grip fix • Finite-diff slope dFx/dω → implicit J_eff 4. 4×4 IMPLICIT DRIVELINE & LSD • 2-stage TCS + 15 Hz turbo/SC boost • Locked vs. slipping clutch capacity • Coupled 4×4 active-set F/R/C LSD solve • Wheel ω_new + idle stall clamp 5. BODY FORCES, YAW & 3D AERO • Re-evaluate tyres at ω_new + VelDepDrag • FrictionTorqueMod yaw-torque shaping • Surface linear/angular mud/water drag • 3D drag + pitch AoA downforce + draft 6. EULER, CONTACTS & DAMAGE • Semi-implicit Euler + gyroscopic ω×(Iω) • Body collision spheres + push-out • GimbalLock tilt spring & rollover guard • Quaternion pose + 10³ voxel damage
The 6-stage 360 Hz substep loop inside libs/drive/src/vehicle.cpp. Every car's parameters come from gamedb.slt + physics.zip via from_physics.h (or synthetic defaults in unit tests).
Vehicle::step() 120 Hz Fixed Outer Step -> 3 x 360 Hz Substeps (double precision, +X right, +Y up, +Z forward):


Pre-substep inputs:
- shape_input(): 31-sample Catmull-Rom speed-sensitive steering curve (bypassed in 900-deg Separate Wheel linear mode).
- update_gearbox(): automatic / manual / manual+clutch state machine.
- Ground queries: drive::MeshGround using 4-wide BVH4 (128 B nodes) and 8-wide BVH8 (256 B nodes) with x86-64 AVX2+FMA+BMI1 (bvh8_avx2.asm) and ARM64 NEON (bvh8_neon.S) kernels.


Substep Stage 1 — Suspension & Ground Contact:
- Ackermann front steering; 5-pass raycast rejecting near-vertical faces (dot(n, up) < 0.17) and steps > 0.30 m.
- 9 procedural SurfaceTypes.xml Bumpiness noise types (HeightGrid, Simplex, Ridges, RidgesAndBumps, Simplex4/Power/Abs, Simplex3Multiplied, SinWave) with 25 ms low-pass height filter and analytical normal gradients.
- Soft-ground Springiness: slew-clamped deflection smoothed by 3-sample moving-average ring buffer.
- Static corner preloads, asymmetric bump/rebound dampers, progressive bumpstops damped by closing speed along ground normal, anti-roll bars, airborne gravity scaling (1.05 per lifted tyre, 1.15 all-off).


Substep Stage 2 — Rev Limiter, Brakes, ABS & STM:
- 40 ms rev-limiter throttle cut without opening turbo BOV.
- Per-car brake calibration (6 fixed-point longitudinal load-transfer iterations at 50/80/200 mph + 10-sample Catmull-Rom decel table).
- Stability Management (STM): asymmetric outside-wheel braking (+amt outside, -0.5*amt inside), capped near -0.9 slip when ABS is off.
- ABS / No-ABS slip ring buffer (up to 8 substeps), steering-dependent release thresholds, smooth 40 ms pressure recovery.


Substep Stage 3 — Combined-Slip Tyres & Linearized Spin:
- Two-load blended friction curves (light ~10.2 kgf to heavy ~1019.7 kgf, clamped 5000 kgf).
- Normalized combined slip: sigma = (omega*r - vx)/v_min, alpha = atan2(vy, v_min)*180/pi, sx = sigma/sig_pk, sy = alpha/alpha_norm, s = max(hypot(sx, sy), 1e-4).
- Fx = mu_x(s*sig_pk) * (sx/s) * N * kx, Fy = -mu_y(s*alpha_pk) * (sy/s) * N * ky.
- Finite-difference longitudinal slope dFx/domega folded into J_eff[i] = J_wheel + reflected*weight + dt*r*slope.


Substep Stage 4 — Coupled 4x4 Implicit Driveline, Clutch, TCS & LSD:
- 2-stage TCS (15 ms attack / 45 ms recovery torque cut + launch wheel-speed trim).
- 15 Hz turbo/supercharger boost pressure filter.
- Coupled 4x4 active-set linear solve (solve_4x4) across front, rear, and center LSDs simultaneously with clutch capacity solve.


Substep Stage 5 — Body Forces, Yaw Shaping & 3D Aerodynamics:
- Re-evaluate tyre forces at omega_new + slew-clamped VelDepFriction surface drag.
- FrictionTorqueMod yaw-torque shaping (steering mode, drivetrain, off-road weight, mass, cos_yaw, 8..15 m/s blend).
- Per-surface LinearDrag/AngularDrag + 3D quadratic drag, axle lateral drag, pitch AoA front/rear downforce, and drafting.


Substep Stage 6 — Integration, Body Contacts & Voxel Damage:
- Semi-implicit Euler linear velocity + gyroscopic angular velocity (tl - wl x (I*wl)).
- Body collision spheres (restitution + speed-blended 10..40 mph friction + push-out) + GimbalLock rollover guard (cos0=0.87, cos1=0.82).
- Quaternion pose integration + 10x10x10 (32 KB) trilinear VoxelDamageGrid with exact algebraic rewind inverse and 21 mechanical channels.

Tyres, coupled 4×4 driveline & damage#

Two-Load Combined-Slip Tyre Model List_TireFrictionMultiCurve · s = hypot(sx, sy) Normalized slip s μ (grip) s = 1.0 (peak) light (10 kgf) heavy (1020 kgf) +Fx (drive) -Fx (brake) Fy (sx,sy) Fx = μx(s·σ_pk) · (sx / s) · N · kx Fy = -μy(s·α_pk) · (sy / s) · N · ky Linearized implicit spin: J_eff = J_w + J_ref + dt · r · (dFx/dω) Off-road surfaces blend α_norm toward off_road_peak_sa Coupled 4×4 Implicit Driveline & Voxel Damage Simultaneous active-set solve_4x4() · 0 oscillation ENGINE 15 Hz Turbo/SC CLUTCH lock / slip cap CENTER LSD (AWD) r_f/r_r radius-matched Front LSD (k_f / ±T_max) LF (ω0) RF (ω1) Rear LSD (k_r / ±T_max) LR (ω2) RR (ω3) 10×10×10 Voxel Damage Grid & 21 Mechanical Channels • 1,000 cells × 8 corners (32 KB lazy), Schlick falloff + exact rewind inverse • 7 car-local falloff boxes → engine, gearbox, steering, aero, 4×(tyre/brake/susp)
Left: two-load blended combined-slip friction curves and normalized slip circle with linearized implicit wheel spin inertia. Right: simultaneous 4×4 active-set LSD/AWD solver and 10×10×10 voxel damage grid.
Two-Load Combined-Slip Tyre Model & Coupled 4x4 Implicit Driveline / Voxel Damage:


Tyre Model:
- Blends light-load (~10.2 kgf) and heavy-load (~1019.7 kgf, clamped 5000 kgf) friction curves linearly by corner load N/9.80665.
- Evaluates combined normalized slip s = max(hypot(sx, sy), 1e-4) where sx = sigma / sig_pk and sy = alpha / alpha_norm.
- Off-road surfaces shift alpha_norm toward off_road_peak_sa by surf.off_roadness.
- Forces: Fx = mu_x(s * sig_pk) * (sx / s) * N * kx; Fy = -mu_y(s * alpha_pk) * (sy / s) * N * ky.
- Linearized implicit wheel spin inertia: J_eff[i] = wheel_inertia + reflected * weight[i] + dt * r[i] * dFx/domega.


Coupled 4x4 Driveline & LSD Active-Set Solver:
- Engine (15 Hz turbo/supercharger boost, 40 ms rev limiter) -> Clutch (locked vs. slipping at ClutchMaxTorque) -> Center LSD (AWD, rolling-radius matched r_front/r_rear) -> Front LSD (LF/RF) & Rear LSD (LR/RR).
- Solves all 4 wheel angular velocities (omega0..omega3) simultaneously in a 4x4 linear system (solve_4x4) with active-set saturation transitions at +-RelVelClamp (up to 4 inner active-set iterations x 2 outer clutch passes).


Voxel Damage Grid & Mechanical Channels:
- 10x10x10 car-space grid (1,000 cells x 8 corner floats = 32,000 bytes, lazily allocated on first impact), Schlick impact falloff (max 0.95), exact algebraic rewind inverse (rewind_corner_damage), glass break threshold 0.005.
- 7 car-local 3D mechanical falloff boxes map impacts into 21 rewind-serialized channels (9 vehicle-wide + 4 wheels x 3).

Subsystem breakdown#

Suspension & procedural surfaces

Preloaded raycast corners with 5-pass wall/curb filtering, asymmetric bump/rebound dampers, closing-speed bumpstops, anti-roll bars, 9 procedural SurfaceTypes.xml Bumpiness noise modes, and 3-tap soft-ground Springiness.

Two-load combined-slip tyres

Blends light (~10.2 kgf) and heavy (~1019.7 kgf) friction curves by corner load, evaluates normalized combined slip s = hypot(sx, sy) with off-road peak slip shift, and folds dFx/dω into implicit wheel inertia J_eff.

Coupled 4×4 implicit LSD & boost

Solves all 4 wheel speeds simultaneously in solve_4x4() with active-set lockup across front, rear, and radius-matched AWD center LSDs — eliminating multi-diff oscillation — alongside a 15 Hz turbo/SC boost filter and 40 ms rev cut.

Brakes, ABS, TCS, STM & yaw shaping

6-pass per-car brake calibration, steering-dependent ABS with 40 ms recovery, 2-stage TCS, asymmetric outside-wheel STM, Catmull-Rom speed-sensitive steering, and FrictionTorqueMod yaw-torque shaping.

SIMD BVH8 collision & 3D aero

MeshGround packs 4-wide BVH4 (128 B) and 8-wide BVH8 (256 B) SoA trees with hand-written AVX2+FMA+BMI1 (bvh8_avx2.asm) and ARM64 NEON (bvh8_neon.S) kernels, body spheres + GimbalLock, and pitch-AoA 3D downforce/drafting.

10×10×10 voxel damage & rewind

Lazily allocated 32 KB trilinear voxel deformation grid with Schlick falloff and an exact algebraic rewind inverse, plus 7 car-local falloff boxes driving 21 rewind-serialized mechanical damage channels.

AI drivers, wheels & UDP telemetry#

ModuleHeaderKey capabilities
AI speed & steering plannerdrive/ai_driver.hData-oriented SoA O(1) updates; 40-bin AiCapacity fixed-point tables from each car's actual physics; 20-bin empirical AiYawGain; 3D curvature/bank/grade friction-circle braking planner; live AI Rubberbanding toggle & strength/catchup/slowdown (0%–150%).
Separate USB wheels & FFBdrive/wheel_ffb.hMulti-USB wheel base + separate pedals + H-shifter (1–7+R) + analog handbrake, 270°–1080° linear mode, physics-driven DirectInput FFB (inertia, friction, damper, aligning torque, road/engine rumble split), and ffb-trace.csv recorder.
Forza UDP Telemetry Outdrive/telemetry_udp.hStreams FM7 Data Out Dash (311 B) or FH4/5 Horizon (324 B) little-endian UDP packets (default 127.0.0.1:5300) for SimHub & motion rigs, with 0.5 s pause auto-muting (IsRaceOn = 0).
Rewind & replaysdrive/rewind.h, drive/replay.hRolling ring-buffer snapshots preserving pose, wheel spin/compression, boost/clutch, all 21 damage channels, and voxel impact history.
Exact physics equations & constants in libs/drive: - Coordinate frame: +X right, +Y up, +Z forward. .carbin visual meshes use -Z forward and are mirrored on GPU upload. - Outer step: kStep = 1/120 s (120 Hz); substeps_for(dt, hz) = max(1, ceil(min(dt, 0.1) * hz - 1e-9)) -> 3 substeps at 360 Hz. - Suspension: probe_height = 1.0 m; 5-pass raycast rejects dot(normal, up) < 0.17 (kWheelMinNormalUp) and step penetration > 0.30 m (kWheelMaxStepInto, kTyreMaxCompression = 0.06 m). Bumpiness 9 noise types (1 HeightGrid, 2 Simplex, 3 Ridges, 4 RidgesAndBumps, 5 Simplex4, 6 Simplex4Power, 7 Simplex4Abs, 8 Simplex3Multiplied, 9 SinWave) low-pass filtered tau = 25 ms. Springiness uses 3-sample moving-average ring buffer gated by spring_norm_y_cutoff (0.707) and spring_speed_cutoff (4.0 m/s). Bumpstop max force capped at 2.5*m*g, damped by closing speed along ground normal. Airborne gravity: per_tyre_off_gravity_scale = 1.05, airborne_gravity_scale = 1.15. Surface caps slew tau = 80 ms, airborne hold 0.25 s. - Tyre law: sigma = (omega * r - vx) / max(|vx|, slip_speed_floor); alpha = atan2(vy, max(|vx|, slip_speed_floor)) * 180/pi; sig_pk = longitudinal.peak_slip(kgf, stretch); alpha_pk = clamp(lateral.peak_slip(kgf, stretch), 4, 18); alpha_norm = lerp(alpha_pk, off_road_peak_sa, off_roadness); sx = sigma/sig_pk; sy = alpha/alpha_norm; s = max(hypot(sx, sy), 1e-4); Fx = mu_x(s*sig_pk)*(sx/s)*N*kx; Fy = -mu_y(s*alpha_pk)*(sy/s)*N*ky. Implicit wheel inertia: J_eff[i] = wheel_inertia + reflected * weight[i] + dt * r[i] * max(0, dFx/domega). - Driveline & engine: closed-throttle engine braking ramps -1.0x at max(800, idle_rpm) to -2.63x at redline_rpm. Rev limiter cuts throttle for 40 ms without opening turbo BOV. Turbo/supercharger boost uses 15 Hz pressure filter. AWD open torque weights: 0.5 * (1 - rear_split) * R_rear / (rear_split * R_front + (1 - rear_split) * R_rear) front and symmetric rear. Coupled 4x4 active-set solve_4x4() across front, rear, and center LSDs (up to 4 inner active-set iterations x 2 outer clutch passes, RelVelClamp in rpm * pi/30). - Steering & brakes: init_steer_curve() precomputes 31 samples up to 150 mph via 6 fixed-point lateral load-transfer passes, evaluated by 4-point Catmull-Rom cubic spline. init_brakes() runs 6 fixed-point longitudinal load-transfer passes at 50/80/200 mph plus 10-sample Catmull-Rom decel table. ABS uses up to 8-sample slip ring buffer and 40 ms recovery. TCS stage 1 rate-limits cut (15 ms attack / 45 ms recovery) with YawMinAngleForTCS..YawMaxAngleForTCS fade; stage 2 trims wheel omega during GearState::kLaunch. STM applies +amt outside / -0.5*amt inside above StabilityManageSpeed, capped near -0.9 slip when ABS is off. FrictionTorqueMod blends over speed^2 in [64, 225] (8..15 m/s). - Aero: 3D quadratic drag (body + front/rear part + drafting + damage + high-speed ramp + surface AeroDragScale), axle lateral drag, vertical drag, front/rear downforce with pitch AoA falloff max(0, 1 - |atan2(vy, vz)| / aero_zero_df_rad) applied at axle lever arms z_f, z_r. - Collision: MeshGround Bvh4Node (128 B) + TriPacket4 (176 B) serialized via serialize_bvh4()/deserialize_bvh4(); Bvh8Node (256 B) + TriPacket8 (352 B) via bvh8_avx2.asm (x86-64 AVX2+FMA+BMI1) and bvh8_neon.S (ARM64 NEON). Body spheres resolve restitution + speed-blended friction (10..40 mph) + push-out + world_torque_scale (0.55, 0.65, 0.55); GimbalLock activates past cos0=0.87 / cos1=0.82. - Damage: EDamageDifficulty {Cosmetic=0, Limited=1 (0.5 ModFullDamage), Simulation=2 (over-rev +150 RPM at 0.3/s, sputter >0.3)}. 11 List_DamageModDef rows (MPH * 0.44704 -> m/s), 7 car-local falloff boxes (BodyCenter, Front, Rear, WheelFL/FR/RR/RL), 21 rewind-serialized channels. VoxelDamageGrid: 10x10x10 (1000 cells x 8 floats = 32,000 bytes), Schlick falloff max 0.95, exact rewind_corner_damage inverse, kGlassBreakThreshold = 0.005. - AI: AiCapacity 40 bins at 2.5 m/s (floor(0.4*v)), AiYawGain 20 bins at 5 m/s, slope_curvature = 0.75, friction-circle braking full * sqrt(1 - min(v_lim^2 / v_c^2, 1)). CLI flags: --ai-mode stock|fair|hard, --no-rubberband, --rubberband-strength 0..150, --rubberband-catchup 0..150, --rubberband-slowdown 0..150. - UDP Telemetry: kFm7DashSize = 311 bytes, kFh4HorizonSize = 324 bytes (232 B Sled + 12 B Horizon gap + Dash), default target 127.0.0.1:5300.