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)
Parameter | Description |
---|---|
auto_start | If 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)
Parameter | Description |
---|---|
max_delta | Maximum allowed delta in seconds (default: 0.1s). |