Re: cannot use clock() for realtime graphical simulations



Hi

>From the Glib docs: "Note that timeout functions may be delayed, due to
the processing of other event sources. Thus they should not be relied on
for precise timing. After each call to the timeout function, the time of
the next timeout is recalculated based on the current time and the given
interval (it does not try to 'catch up' time lost in delays)."

What I'm doing to draw a timed animation (I use it in an other way to a
have a constant framerate, but the idea is just adapted to your problem):

g_thread_create(my_thread_function, ...)

gpointer my_thread_function( gpointer data )
{
	g_timer_new

	while(not thread quit)
	{
		g_timer_start ()

		// do none gtk calculation

		sleep = 50 - g_timer_elapsed()
		if( sleep > 0 )
			g_usleep( sleep )

		GDK_THREADS_ENTER();

		// do your gtk / gdk stuff

		GDK_THREADS_LEAVE();
	}
}

Since you must get the GDK lock, there may still be a lag, when you have
complex Gtk callbacks.

You also try to g_timeout_add_full(G_PRIORITY_HIGH_IDLE, ...) and break
complex Gtk callbacks via

while (gtk_events_pending ())
	gtk_main_iteration ();

HTH

Jan-Marek



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