diff options
| -rw-r--r-- | cube.c | 2 | ||||
| -rw-r--r-- | fifteen.c | 4 | ||||
| -rw-r--r-- | gtk.c | 18 | ||||
| -rw-r--r-- | net.c | 4 | ||||
| -rw-r--r-- | sixteen.c | 4 | ||||
| -rw-r--r-- | windows.c | 14 |
6 files changed, 33 insertions, 13 deletions
@@ -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) ) @@ -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 ) @@ -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; } @@ -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, @@ -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 ) @@ -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; } |