From ccbf3ca6f1950fb1e39df40b2d44fe99ab9de0d1 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 3 May 2004 09:43:08 +0000 Subject: GTK and Windows appear to handle timers very differently: specifically, the elapsed time between calls varies much more with GTK than it does under Windows. Therefore, I now take my own time readings on every timer call, and this appears to have made the animations run at closer to the same speed between platforms. Having done that, I decided some of them were at the _wrong_ speed, and fiddled with each game's timings as well. [originally from svn r4189] --- gtk.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'gtk.c') diff --git a/gtk.c b/gtk.c index ff6c3f7..1703001 100644 --- a/gtk.c +++ b/gtk.c @@ -9,6 +9,8 @@ #include #include +#include + #include #include @@ -63,6 +65,7 @@ struct frontend { GdkGC *gc; int bbox_l, bbox_r, bbox_u, bbox_d; int timer_active, timer_id; + struct timeval last_time; struct font *fonts; int nfonts, fontsize; config_item *cfg; @@ -354,8 +357,15 @@ static gint timer_func(gpointer data) { frontend *fe = (frontend *)data; - if (fe->timer_active) - midend_timer(fe->me, 0.02); /* may clear timer_active */ + if (fe->timer_active) { + struct timeval now; + float elapsed; + gettimeofday(&now, NULL); + elapsed = ((now.tv_usec - fe->last_time.tv_usec) * 0.000001F + + (now.tv_sec - fe->last_time.tv_sec)); + midend_timer(fe->me, elapsed); /* may clear timer_active */ + fe->last_time = now; + } return fe->timer_active; } @@ -369,8 +379,10 @@ void deactivate_timer(frontend *fe) void activate_timer(frontend *fe) { - if (!fe->timer_active) + if (!fe->timer_active) { fe->timer_id = gtk_timeout_add(20, timer_func, fe); + gettimeofday(&fe->last_time, NULL); + } fe->timer_active = TRUE; } -- cgit v1.1