Magnum::Timeline class

Timeline.

Keeps track of time delta between frames. Can be used as source for animation speed computations.

Basic usage

Construct the timeline on initialization so the instance is available for whole lifetime of the application. Call start() before first draw event is performed, after everything is properly initialized.

In your draw event implementation don't forget to call nextFrame() after buffer swap. You can use previousFrameDuration() to compute animation speed. To limit application framerate you can use Platform::*Application::setSwapInterval() or Platform::*Application::setMinimalLoopPeriod(). Note that on Emscripten the framerate is governed by browser and you can't do anything about it.

Example usage:

MyApplication::MyApplication(const Arguments& arguments): Platform::Application{arguments} {
    // Initialization ...

    // Enable VSync or set minimal loop period for the application, if
    // needed/applicable ...

    timeline.start();
}

void MyApplication::drawEvent() {
    // Distance of object travelling at speed of 15 units per second
    Float distance = 15.0f*timeline.previousFrameDuration();

    // Move object, draw ...

    swapBuffers();
    redraw();
    timeline.nextFrame();
}

Constructors, destructors, conversion operators

Timeline() explicit
Constructor.

Public functions

void start()
Start timeline.
void stop()
Stop timeline.
void nextFrame()
Advance to next frame.
auto previousFrameTime() const -> Float
Time at previous frame (in seconds)
auto previousFrameDuration() const -> Float
Duration of previous frame (in seconds)

Function documentation

Magnum::Timeline::Timeline() explicit

Constructor.

Creates stopped timeline.

void Magnum::Timeline::start()

Start timeline.

Sets previous frame time and duration to 0.

void Magnum::Timeline::stop()

Stop timeline.

void Magnum::Timeline::nextFrame()

Advance to next frame.

Float Magnum::Timeline::previousFrameTime() const

Time at previous frame (in seconds)

Returns time elapsed since start() was called. If the timeline is stopped, the function returns 0.0f.

Float Magnum::Timeline::previousFrameDuration() const

Duration of previous frame (in seconds)

If the timeline is stopped, the function returns 0.0f.