void update_evolve() { static clock_t lastP = 0; static WINDOWPLACEMENT p; // start timer timer_mark(); if (!lastP || clock() - lastP > 1000) { GetWindowPlacement(g_hWnd, &p); lastP = clock(); } evolve_win_tick(); if (p.showCmd != SW_SHOWMINIMIZED && (g_EvolveState.step % 2 == 0)) evolve_win_draw(g_hWnd); // Clamp it when viewing creatures so it doesnt evolve so fast you can't see whats going on float dur = (float) timer_mark(); float stepCnt = (float)(g_EvolveState.parms.popCols * g_EvolveState.parms.popRows * 2); float genPerSec = 3; float minMs = (1.0f / genPerSec) / stepCnt; if (g_Stats != 2 && dur < minMs) Sleep( max( 1, (DWORD) (minMs - dur) ) ); }
GLvoid update_world() { u_int dt; u_int i; if (++mutex_frames > 1) { --mutex_frames; printf("update already occuring\n"); return; } mutex_frames = 1; dt = timer_mark(timer_frames); gv = gv * GR + GQ * (float) dt; // printf("target: %d / elapsed: %d [avg: %0.3f] / CI: %d\n", TI, dt, gv, CI); CI += TI - ((int) gv); if (CI <= 0) CI = 1000; if (! state_paused) { for (i = 0; i < SPF; i++) { sample_world(); } } draw_gl(); glutTimerFunc(CI/1000, update_world, 0); mutex_frames = 0; }