The OpenD Programming Language

MMClock

A clock you can use for multimedia applications. It compares time elapsed against a position variable you pass in to figure out how long to wait to get to that point. Very similar to Phobos' StopWatch but with built-in wait capabilities.

More...

Members

Functions

currentPosition
Duration currentPosition()

Returns the current time on the clock since the last call to restart, excluding times when the clock was paused.

pause
void pause()

Pauses the clock.

restart
void restart()

Restarts the clock from position zero.

timeUntil
Duration timeUntil(Duration position)
waitUntil
bool waitUntil(Duration position)

Goes to sleep until the real clock catches up to the given position.

Variables

speed
int speed;

1000 = 1.0, 2000 = 2.0, 500 = 0.5, etc.

Detailed Description

For example, suppose you want something to happen 60 frames per second:

MMClock clock;
Duration frame;
clock.restart();
while(running) {
	frame += 1.seconds / 60;
	bool onSchedule = clock.waitUntil(frame);

	do_essential_frame_work();

	if(onSchedule) {
		// if we're on time, do other work too.
		// but if we weren't on time, skipping this
		// might help catch back up to where we're
		// supposed to be.

		do_would_be_nice_frame_work();
	}
}

Meta