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]
This commit is contained in:
Simon Tatham
2004-05-03 09:43:08 +00:00
parent 2d1d54b96b
commit ccbf3ca6f1
6 changed files with 33 additions and 13 deletions

2
cube.c
View File

@ -160,7 +160,7 @@ enum {
enum { LEFT, RIGHT, UP, DOWN, UP_LEFT, UP_RIGHT, DOWN_LEFT, DOWN_RIGHT }; enum { LEFT, RIGHT, UP, DOWN, UP_LEFT, UP_RIGHT, DOWN_LEFT, DOWN_RIGHT };
#define GRID_SCALE 48.0F #define GRID_SCALE 48.0F
#define ROLLTIME 0.1F #define ROLLTIME 0.13F
#define SQ(x) ( (x) * (x) ) #define SQ(x) ( (x) * (x) )

View File

@ -19,8 +19,8 @@ const int game_can_configure = TRUE;
#define COORD(x) ( (x) * TILE_SIZE + BORDER ) #define COORD(x) ( (x) * TILE_SIZE + BORDER )
#define FROMCOORD(x) ( ((x) - BORDER + TILE_SIZE) / TILE_SIZE - 1 ) #define FROMCOORD(x) ( ((x) - BORDER + TILE_SIZE) / TILE_SIZE - 1 )
#define ANIM_TIME 0.1F #define ANIM_TIME 0.13F
#define FLASH_FRAME 0.1F #define FLASH_FRAME 0.13F
#define X(state, i) ( (i) % (state)->w ) #define X(state, i) ( (i) % (state)->w )
#define Y(state, i) ( (i) / (state)->w ) #define Y(state, i) ( (i) / (state)->w )

18
gtk.c
View File

@ -9,6 +9,8 @@
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <sys/time.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
@ -63,6 +65,7 @@ struct frontend {
GdkGC *gc; GdkGC *gc;
int bbox_l, bbox_r, bbox_u, bbox_d; int bbox_l, bbox_r, bbox_u, bbox_d;
int timer_active, timer_id; int timer_active, timer_id;
struct timeval last_time;
struct font *fonts; struct font *fonts;
int nfonts, fontsize; int nfonts, fontsize;
config_item *cfg; config_item *cfg;
@ -354,8 +357,15 @@ static gint timer_func(gpointer data)
{ {
frontend *fe = (frontend *)data; frontend *fe = (frontend *)data;
if (fe->timer_active) if (fe->timer_active) {
midend_timer(fe->me, 0.02); /* may clear 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; return fe->timer_active;
} }
@ -369,8 +379,10 @@ void deactivate_timer(frontend *fe)
void activate_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); fe->timer_id = gtk_timeout_add(20, timer_func, fe);
gettimeofday(&fe->last_time, NULL);
}
fe->timer_active = TRUE; fe->timer_active = TRUE;
} }

4
net.c
View File

@ -56,8 +56,8 @@ const int game_can_configure = TRUE;
#define TILE_BORDER 1 #define TILE_BORDER 1
#define WINDOW_OFFSET 16 #define WINDOW_OFFSET 16
#define ROTATE_TIME 0.1F #define ROTATE_TIME 0.13F
#define FLASH_FRAME 0.05F #define FLASH_FRAME 0.07F
enum { enum {
COL_BACKGROUND, COL_BACKGROUND,

View File

@ -21,8 +21,8 @@ const int game_can_configure = TRUE;
#define COORD(x) ( (x) * TILE_SIZE + BORDER ) #define COORD(x) ( (x) * TILE_SIZE + BORDER )
#define FROMCOORD(x) ( ((x) - BORDER + 2*TILE_SIZE) / TILE_SIZE - 2 ) #define FROMCOORD(x) ( ((x) - BORDER + 2*TILE_SIZE) / TILE_SIZE - 2 )
#define ANIM_TIME 0.1F #define ANIM_TIME 0.13F
#define FLASH_FRAME 0.1F #define FLASH_FRAME 0.13F
#define X(state, i) ( (i) % (state)->w ) #define X(state, i) ( (i) % (state)->w )
#define Y(state, i) ( (i) / (state)->w ) #define Y(state, i) ( (i) / (state)->w )

View File

@ -88,6 +88,7 @@ struct frontend {
HPEN *pens; HPEN *pens;
HRGN clip; HRGN clip;
UINT timer; UINT timer;
DWORD timer_last_tickcount;
int npresets; int npresets;
game_params **presets; game_params **presets;
struct font *fonts; struct font *fonts;
@ -302,7 +303,10 @@ void deactivate_timer(frontend *fe)
void activate_timer(frontend *fe) void activate_timer(frontend *fe)
{ {
if (!fe->timer) {
fe->timer = SetTimer(fe->hwnd, fe->timer, 20, NULL); fe->timer = SetTimer(fe->hwnd, fe->timer, 20, NULL);
fe->timer_last_tickcount = GetTickCount();
}
} }
static frontend *new_window(HINSTANCE inst) static frontend *new_window(HINSTANCE inst)
@ -942,8 +946,12 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
PostQuitMessage(0); PostQuitMessage(0);
return 0; return 0;
case WM_TIMER: case WM_TIMER:
if (fe->timer) if (fe->timer) {
midend_timer(fe->me, (float)0.02); 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; return 0;
} }