Skip to content

FrameTimer ​

Frame-oriented timer for computing clamped delta time.

The frame timer 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).

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

Construction ​

Constructors ​


FrameTimer() ​

Constructs a frame timer.

cpp
FrameTimer::FrameTimer(bool auto_start);
ParameterDescription
auto_startStarts timer immediately upon construction.

Functions ​

Start() void ​

Starts the internal timer.

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

cpp
void FrameTimer::Start();

Tick() float ​

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.

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

Released under the MIT License.