Skip to content

FrameTimer

Frame-oriented helper for computing clamped delta time.

FrameTimer builds on top of Timer to provide a simple, per-frame timestep suitable for driving simulations and animations. Each call to Tick returns the elapsed time since the previous call, clamped by max_delta to guard against stalls (e.g., window drags, breakpoints).

Typical usage:

cpp
vglx::FrameTimer clock(true); // auto-start
while (running) {
  const float dt = clock.Tick(); // seconds (float), clamped
  scene.Advance(dt);
  renderer.Render(&scene, &camera);
}

Construction

Constructors


FrameTimer()

cpp
vglx::FrameTimer::FrameTimer(bool auto_start)
ParameterDescription
auto_startIf true, timer starts immediately upon construction.

Constructs a FrameTimer object.

Functions

Start() void

cpp
void vglx::FrameTimer::Start()

Starts the internal timer. Also initializes the internal reference time so the next call to Tick returns the true frame delta.

Tick() float

cpp
float vglx::FrameTimer::Tick(double max_delta=0.1)
ParameterDescription
max_deltaMaximum allowed delta in seconds (default: 0.1s).

Returns the clamped time delta since the previous tick. Computes the elapsed seconds since the previous Tick (or since Start if this is the first tick) and clamps it to max_delta.

Released under the MIT License.