ref: ccbf3ca6f1950fb1e39df40b2d44fe99ab9de0d1
parent: 2d1d54b96ba5b7edf4765230ddf00436eb924a52
author: Simon Tatham <anakin@pobox.com>
date: Mon May 3 05:43:08 EDT 2004
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]
--- a/cube.c
+++ b/cube.c
@@ -160,7 +160,7 @@
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) )
--- a/fifteen.c
+++ b/fifteen.c
@@ -19,8 +19,8 @@
#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 )
--- 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 @@
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 @@
{
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 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;
}
--- a/net.c
+++ b/net.c
@@ -56,8 +56,8 @@
#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,
--- a/sixteen.c
+++ b/sixteen.c
@@ -21,8 +21,8 @@
#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 )
--- a/windows.c
+++ b/windows.c
@@ -88,6 +88,7 @@
HPEN *pens;
HRGN clip;
UINT timer;
+ DWORD timer_last_tickcount;
int npresets;
game_params **presets;
struct font *fonts;
@@ -302,7 +303,10 @@
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 @@
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;
}