Cross-platform C SDK logo

Cross-platform C SDK

Clocks

❮ Back
Next ❯
This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.

Time control.


Functions

Clock*clock_create (...)
voidclock_destroy (...)
bool_tclock_frame (...)
voidclock_reset (...)
real64_tclock_elapsed (...)

Simple objects that allow us, in a comfortable way, to measure the time span between two instants. They are also useful for launching events at regular time intervals (Listing 1).

Listing 1: 25fps animation.
1
2
3
4
5
6
7
8
9
Clock *clock = clock_create(.04);
for (;;)
{
    ...
    if (clock_frame(clock) == TRUE)
        listener_event(transition, ekGUI_EVENT_ANIMATION, NULL, params, NULL, void, EvTransition, void);
    ...
}
clock_destroy(&clock);

clock_create ()

Create a clock.

Clock*
clock_create(const real64_t interval);
interval

Time interval for animation control (in seconds).

Return

The new clock.


clock_destroy ()

Destroy the clock.

void
clock_destroy(Clock **clk);
clk

Clock. Will be set to NULL after destruction.


clock_frame ()

Detect if a new sequence in an animation has expired.

bool_t
clock_frame(Clock *clk,
            real64_t *prev_frame,
            real64_t *curr_frame);
clk

Clock.

prev_frame

Time mark of the previous instant. Only relevant if returns TRUE.

curr_frame

Time mark of the current instant. Only relevant if returns TRUE.

Return

TRUE if the time has come to launch a new sequence. FALSE if we have to wait.


clock_reset ()

Set the clock to 0.0.

void
clock_reset(Clock *clk);
clk

Clock.


clock_elapsed ()

Gets the time elapsed since the object was created or since the last call to clock_reset.

real64_t
clock_elapsed(Clock *clk);
clk

Clock.

Return

The number of seconds (with precision of micro-seconds 0.000001).

❮ Back
Next ❯