X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/5928817c732d591bd446b6b048702a98f5ec1804..6beae1313e7dacce5c1ea85a47edd5f8c4df4ce1:/windows.c diff --git a/windows.c b/windows.c index 8fbcf8e..4213e4c 100644 --- 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) @@ -311,15 +315,22 @@ static frontend *new_window(HINSTANCE inst) int x, y; RECT r, sr; HDC hdc; + time_t t; fe = snew(frontend); - fe->me = midend_new(fe); + + time(&t); + fe->me = midend_new(fe, &t, sizeof(t)); + fe->inst = inst; midend_new_game(fe->me); midend_size(fe->me, &x, &y); fe->timer = 0; + fe->fonts = NULL; + fe->nfonts = fe->fontsize = 0; + { int i, ncolours; float *colours; @@ -676,6 +687,7 @@ static int get_config(frontend *fe, int which) mkctrl(fe, col1l, col2r, y, y+height, "BUTTON", BS_NOTIFY | BS_AUTOCHECKBOX | WS_TABSTOP, 0, i->name, (j->ctlid = id++)); + CheckDlgButton(fe->cfgbox, j->ctlid, (i->ival != 0)); y += height; break; @@ -938,8 +950,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; } @@ -950,8 +966,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { MSG msg; - srand(time(NULL)); - InitCommonControls(); if (!prev) {