GTK and Windows appear to handle timers very differently:
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 3 May 2004 09:43:08 +0000 (09:43 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 3 May 2004 09:43:08 +0000 (09:43 +0000)
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.

git-svn-id: svn://svn.tartarus.org/sgt/puzzles@4189 cda61777-01e9-0310-a592-d414129be87e

cube.c
fifteen.c
gtk.c
net.c
sixteen.c
windows.c

diff --git a/cube.c b/cube.c
index ccc8689..5e0b449 100644 (file)
--- a/cube.c
+++ b/cube.c
@@ -160,7 +160,7 @@ enum {
 enum { LEFT, RIGHT, UP, DOWN, UP_LEFT, UP_RIGHT, DOWN_LEFT, DOWN_RIGHT };
 
 #define GRID_SCALE 48.0F
-#define ROLLTIME 0.1F
+#define ROLLTIME 0.13F
 
 #define SQ(x) ( (x) * (x) )
 
index 3965844..de5a340 100644 (file)
--- a/fifteen.c
+++ b/fifteen.c
@@ -19,8 +19,8 @@ const int game_can_configure = TRUE;
 #define COORD(x)  ( (x) * TILE_SIZE + BORDER )
 #define FROMCOORD(x)  ( ((x) - BORDER + TILE_SIZE) / TILE_SIZE - 1 )
 
-#define ANIM_TIME 0.1F
-#define FLASH_FRAME 0.1F
+#define ANIM_TIME 0.13F
+#define FLASH_FRAME 0.13F
 
 #define X(state, i) ( (i) % (state)->w )
 #define Y(state, i) ( (i) / (state)->w )
diff --git a/gtk.c b/gtk.c
index ff6c3f7..1703001 100644 (file)
--- 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;
 }
 
diff --git a/net.c b/net.c
index 8b74e7b..b3b0a39 100644 (file)
--- a/net.c
+++ b/net.c
@@ -56,8 +56,8 @@ const int game_can_configure = TRUE;
 #define TILE_BORDER 1
 #define WINDOW_OFFSET 16
 
-#define ROTATE_TIME 0.1F
-#define FLASH_FRAME 0.05F
+#define ROTATE_TIME 0.13F
+#define FLASH_FRAME 0.07F
 
 enum {
     COL_BACKGROUND,
index f0acff5..02d24e4 100644 (file)
--- a/sixteen.c
+++ b/sixteen.c
@@ -21,8 +21,8 @@ const int game_can_configure = TRUE;
 #define COORD(x)  ( (x) * TILE_SIZE + BORDER )
 #define FROMCOORD(x)  ( ((x) - BORDER + 2*TILE_SIZE) / TILE_SIZE - 2 )
 
-#define ANIM_TIME 0.1F
-#define FLASH_FRAME 0.1F
+#define ANIM_TIME 0.13F
+#define FLASH_FRAME 0.13F
 
 #define X(state, i) ( (i) % (state)->w )
 #define Y(state, i) ( (i) / (state)->w )
index 87f4284..90d96d2 100644 (file)
--- a/windows.c
+++ b/windows.c
@@ -88,6 +88,7 @@ struct frontend {
     HPEN *pens;
     HRGN clip;
     UINT timer;
+    DWORD timer_last_tickcount;
     int npresets;
     game_params **presets;
     struct font *fonts;
@@ -302,7 +303,10 @@ void deactivate_timer(frontend *fe)
 
 void activate_timer(frontend *fe)
 {
-    fe->timer = SetTimer(fe->hwnd, fe->timer, 20, NULL);
+    if (!fe->timer) {
+       fe->timer = SetTimer(fe->hwnd, fe->timer, 20, NULL);
+       fe->timer_last_tickcount = GetTickCount();
+    }
 }
 
 static frontend *new_window(HINSTANCE inst)
@@ -942,8 +946,12 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
            PostQuitMessage(0);
        return 0;
       case WM_TIMER:
-       if (fe->timer)
-           midend_timer(fe->me, (float)0.02);
+       if (fe->timer) {
+           DWORD now = GetTickCount();
+           float elapsed = (float) (now - fe->timer_last_tickcount) * 0.001F;
+           midend_timer(fe->me, elapsed);
+           fe->timer_last_tickcount = now;
+       }
        return 0;
     }