Step 9
Time, Delta Time, and Integration: The Heartbeat of Simulation
Temporal Discretization, Timestep Strategy, and Numerical Integration in Real-Time Simulation Engines
Abstract

Real-time simulation requires the continuous evolution of physical systems to be approximated through discrete computational updates, making the treatment of time a fundamental concern in simulation engine design. This article examines temporal discretization through the concepts of delta time, timestep selection, and numerical integration, with particular attention to their implications for stability, determinism, accuracy, and implementation complexity. It first analyzes the role of delta time as the interface between continuous dynamics and frame-based execution, then compares variable and fixed timestep strategies as design alternatives for interactive simulation systems. The article subsequently evaluates Euler integration and fourth-order Runge–Kutta integration as representative numerical methods for advancing simulation state, highlighting the trade-off between computational efficiency and approximation quality. By synthesizing theoretical principles with implementation-oriented examples, the article demonstrates that timestep policy and integrator choice are not merely technical details but central determinants of simulation robustness, reproducibility, and behavioral fidelity.

Why Time Matters in Simulation

Physical time is continuous; simulation time is discrete.

Each frame supplies a delta time value, which the engine uses to advance the simulated world. Managing this conversion from continuous motion to discrete updates is the core timing problem in real-time simulation.

A robust time system must answer three questions:

  • Step size: how large should each update be?
  • Integration: how should physics advance during each step?
  • Stability: how can results remain predictable?

These questions frame the physics topics developed in the following sections.

Delta Time: The Fundamental Unit
Definition

Delta time is essential for ensuring consistent simulation behavior regardless of frame rate. By multiplying velocities, forces, and other time-dependent quantities by dt, the simulation can advance correctly even if the frame rate fluctuates.

Delta time (dt) is the elapsed time between two simulation updates. In C++ frameworks, it is commonly measured with a high-resolution clock:

auto now = std::chrono::high_resolution_clock::now();
auto dt = std::chrono::duration<float>(now - last).count();
last = now;
How dt drives motion

The simulation uses dt to scale physical changes over time:

Velocity updates position.

\(x_{t+dt}=x_{t}+v\cdot dt\)

Acceleration updates velocity.

\(v_{t+dt}=v_{t}+a\cdot dt\)

Why it matters

Because dt can vary from frame to frame, it directly affects stability and predictability. This leads to the choice between variable and fixed timestep strategies.

Variable vs Fixed Timestep
Variable Timestep

The simplest approach: use whatever \(dt\) the system gives you.

Pros

Cons

Variable timestep is fine for simple demos, but not for robust simulation.

Fixed Timestep

You choose a constant dt (e.g., 1/60 s), and the simulation updates in fixed increments.

Pros

Cons

The classic fixed timestep loop:

const double dt = 1.0 / 60.0;
double accumulator = 0.0;

while (running) {
    double frameTime = computeFrameTime();
    accumulator += frameTime;

    while (accumulator >= dt) {
        simulate(dt);
        accumulator -= dt;
    }

    render();
}

This pattern is the backbone of modern engines.

Integration: Moving Quantities Through Time

Integration is the numerical process of updating physical quantities across dt.

We’ll examine two methods:

  • Euler Integration — simple, fast, but unstable
  • Runge–Kutta (RK4) — accurate, stable, but more expensive
Euler Integration

Euler is the simplest numerical integrator.

Euler Velocity Update: \(v_{t+dt}=v_{t}+a\cdot dt\)

Euler Position Update: \(x_{t+dt}=x_{t}+v\cdot dt\)

C++ Implementation

v += a * dt;
x += v * dt;

Pros

  • Extremely simple
  • Very fast
  • Good for prototyping

Cons

  • Accumulates error quickly
  • Unstable for stiff systems
  • Sensitive to dt fluctuations

Euler is often “good enough” for arcade physics, but not for realistic simulation.

Runge–Kutta (RK4) Integration

RK4 is a higher order integrator that samples the derivative multiple times within the timestep.

It approximates the true continuous solution far better than Euler.

RK4 Concept

RK4 computes four estimates:

  • \(k_{1}\): derivative at start
  • \(k_{2}\): derivative at midpoint
  • \(k_{3}\): another midpoint sample
  • \(k_{4}\): derivative at end

Then combines them:

\(x_{t+dt}=x_{t}+\frac{1}{6}\left(k_{1}+2k_{2}+2k_{3}+k_{4}\right)\)

C++ Sketch

vector3 k1 = dt * f(x, v);
vector3 k2 = dt * f(x + 0.5 * k1, v);
vector3 k3 = dt * f(x + 0.5 * k2, v);
vector3 k4 = dt * f(x + k3, v);
x += (k1 + 2*k2 + 2*k3 + k4) / 6;

Pros

  • Very accurate
  • Much more stable
  • Handles stiff systems better

Cons

  • More expensive
  • Requires structured state representation
  • Overkill for simple games

RK4 is ideal for educational engines, simulations, and systems where accuracy matters.

Euler vs RK4 — A Practical Comparison
FeatureEulerRK4
ComplexityVery lowHigh
PerformanceVery fastSlower
AccuracyLowVery high
StabilityPoorExcellent
Best UseSimple arcade physicsRealistic or educational simulation
Key Insight

Euler is a first order method. RK4 is a fourth order method.

This means RK4’s error decreases dramatically as dt shrinks, while Euler’s error decreases slowly.

Choosing the Right Method for Your Engine

Your choice depends on your goals:

  • Educational engine (BeforeTheMesh) RK4 is perfect — it teaches real numerical methods and produces stable results.
  • High performance game engine Euler or semi implicit Euler is often used for speed.
  • Physics heavy simulation RK4 or even more advanced integrators (Verlet, symplectic methods).

For BeforeTheMesh, we will implement both — Euler for conceptual clarity, RK4 for accuracy.

How This Connects to Future Tutorials

This tutorial sets the stage for:

  • Forces and acceleration
  • Collision detection
  • Spatial partitioning
  • Debug visualization
  • Full engine architecture

Time and integration are the heartbeat of everything that follows.

Summary
  • Delta time is the fundamental unit of simulation.
  • Fixed timestep ensures stability and determinism.
  • Euler integration is simple but inaccurate.
  • RK4 integration is accurate but more expensive.
  • Your choice of integrator shapes the behavior of your engine.

This is the mathematical and conceptual foundation of BeforeTheMesh’s simulation arc.

Next Step

Next, we will dive into implementing these concepts in code, starting with the core simulation loop and integration methods.

Step 10: Building the Simulation Subsystem,