aboutsummaryrefslogtreecommitdiff
path: root/gtk.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2004-05-03 09:43:08 +0000
committerSimon Tatham <anakin@pobox.com>2004-05-03 09:43:08 +0000
commitccbf3ca6f1950fb1e39df40b2d44fe99ab9de0d1 (patch)
treecb04a0da087247f6e7d846c15c8157a9c012e192 /gtk.c
parent2d1d54b96ba5b7edf4765230ddf00436eb924a52 (diff)
downloadpuzzles-ccbf3ca6f1950fb1e39df40b2d44fe99ab9de0d1.zip
puzzles-ccbf3ca6f1950fb1e39df40b2d44fe99ab9de0d1.tar.gz
puzzles-ccbf3ca6f1950fb1e39df40b2d44fe99ab9de0d1.tar.bz2
puzzles-ccbf3ca6f1950fb1e39df40b2d44fe99ab9de0d1.tar.xz
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]
Diffstat (limited to 'gtk.c')
-rw-r--r--gtk.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/gtk.c b/gtk.c
index ff6c3f7..1703001 100644
--- a/gtk.c
+++ b/gtk.c
@@ -9,6 +9,8 @@
#include <stdarg.h>
#include <string.h>
+#include <sys/time.h>
+
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
@@ -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;
}