Re: About gtk_timeout_add



"Paul" <jarlongl ms21 hinet net> writes:

   i want to write an animation program with maximum frame rate 30. So i use

gtk_timeout_add(1000/30, (GtkFunction)animate, 0) to call animation function
every 1/30 second. But the animation function is called only about 17
times/second. For testing purpose, the animation function looks like the
following

static gint animate() {

cnt++;

return 1;

}

As i know, setitimer is very accurate.

Are there any other functions can be used to achieve an accurate timeout?


There are a couple possible sources of your problem:

 - limited system clock precision
 - you are taking too long to render each frame

The standard solution to the problem is to drop frames. That is, at
each timeout invocation, skip ahead to the frame that _should_ be
displayed at the current time instead of the next frame.

Assume your animation is 5 seconds long; then _always_ play it in 5
seconds. If you "fall behind," then skip frames until you are caught
up.

Even if you are playing slowly enough to "keep up" in general, you
really want to do this, as imprecision in the clock and random factors
such as the computer suddenly getting busy with other things can mess
up your timing.

Of course once you have frame-dropping working, you can try to
optimize the rendering of each frame, and you'll end up dropping fewer
of them.

Havoc




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]