void speed_test (fractal_context * c, struct image *img) { //unsigned int sum; tl_timer *t; int time; unsigned int i; set_fractalc (c, img); t = tl_create_timer (); cfractalc.maxiter = 100; #ifdef SLOWFUNCPTR i = calculateswitch (0.0, 0.0, 0.0, 0.0, 0); #else (void) cfractalc.currentformula->calculate (0.0, 0.0, 0.0, 0.0); if (cfractalc.currentformula->calculate_periodicity != NULL) (void) cfractalc.currentformula->calculate_periodicity (0.0, 0.0, 0.0, 0.0); if (cfractalc.currentformula->smooth_calculate != NULL) (void) cfractalc.currentformula->smooth_calculate (0.0, 0.0, 0.0, 0.0); if (cfractalc.currentformula->smooth_calculate_periodicity != NULL) (void) cfractalc.currentformula->smooth_calculate_periodicity (0.0, 0.0, 0.0, 0.0); #endif cfractalc.maxiter = 20000000; tl_update_time (); tl_reset_timer (t); /*sum = rdtsc (); */ #ifdef SLOWFUNCPTR i = calculateswitch (0.0, 0.0, 0.0, 0.0, 0); #else i = cfractalc.currentformula->calculate (0.0, 0.0, 0.0, 0.0); #endif /*sum -= rdtsc (); printf ("%f\n", (double) (-sum) / cfractalc.maxiter); */ tl_update_time (); time = tl_lookup_timer (t); x_message ("Result:%i Formulaname:%s Time:%i Mloops per sec:%.2f", (int) i, cfractalc.currentformula->name[0], time, cfractalc.maxiter / (double) time); #ifndef SLOWFUNCPTR if (cfractalc.currentformula->smooth_calculate != NULL) { tl_update_time (); tl_reset_timer (t); i = cfractalc.currentformula->smooth_calculate (0.0, 0.0, 0.0, 0.0); tl_update_time (); time = tl_lookup_timer (t); x_message ("Result:%i Formulaname:%s Time:%i Mloops per sec:%.2f", (int) i, cfractalc.currentformula->name[0], time, cfractalc.maxiter / (double) time); } #endif tl_free_timer (t); }
int tl_process_group(tl_group * group) { int again = 1; tl_timer *timer; int minwait = INT_MAX; tl_update_time(); while (again) { again = 0; minwait = INT_MAX; timer = group->next; while (timer != NULL) { if (timer->handler && timer->interval > 0) { int time = timer->wait - tl_lookup_timer(timer); if (time < 500) { again = 1; tl_reset_timer(timer); if (time < -200 * 1000000) time = 0; /*underflow? */ timer->wait = timer->interval + time; time = timer->wait; timer->handler(); tl_update_time(); } if (time < minwait) minwait = time; } else if (timer->multihandler && timer->interval > 0) { int time = timer->wait - tl_lookup_timer(timer); if (time < 500) { int n; tl_reset_timer(timer); if (time < -200 * 1000000) time = 0; /*underflow? */ n = -(time + 500) / timer->interval + 1; timer->wait = timer->interval * n + time; time = timer->wait; timer->multihandler(n); tl_update_time(); } if (time < minwait) minwait = time; } timer = timer->next; } } if (minwait != INT_MAX) { if (minwait < 0) return (0); return (minwait); } return (-1); }
static void ui_do_fractal(int mode) { int time, time1; if (mode < fastmode + 1) interruptiblemode = 1; else interruptiblemode = 0; if (tbreak) tl_reset_timer(maintimer); incalculation = 1; starttime1 = 0; endtime1 = 0; set_view(zcontext, &zcontext->s); waitcount = tl_lookup_timer(maintimer) / WAITTIME + 2; waitcount1 = tl_lookup_timer(maintimer) / WAITTIME1 + 1; do_fractal(zcontext, interruptiblemode); bbupdate(); if (interruptiblemode) { bbupdate(); time1 = time = tl_lookup_timer(maintimer); time -= endtime1 - starttime1; maxtime = time * 5; if (maxtime > 1000000 / 10) maxtime = time * 3; if (maxtime < 1000000 / 30) maxtime = 1000000 / 30; maxtime -= time1 - endtime1; } updatestatus(); }
void tl_set_interval(tl_timer * timer, int interval) { if (timer->interval <= 0) { tl_reset_timer(timer); } timer->interval = interval; if (timer->group == asyncgroup) update_async(); }
static void start_save(struct uih_context *uih, const char *name) { if (!changed && !uih->savec->firsttime) { char s[256]; sprintf(s, "\n(usleep %i)\n", tl_lookup_timer(uih->savec->timer)); myputs(s); tl_reset_timer(uih->savec->timer); } changed = 1; myputc('('); myputs(name); first = 0; }
static void updatestatus(void) { double times = (zcontext->currentformula->v.mc - zcontext->currentformula->v.nc) / (zcontext->s.mc - zcontext->s.nc); ui_display(); sprintf(zoomed, "%.2f", times); tl_process_group(syncgroup, NULL); bbupdate(); drawingtime = tl_lookup_timer(maintimer); tl_reset_timer(maintimer); if (drawingtime > 200000) drawingtime = 200000; mul = (double) drawingtime / FRAMETIME; incalculation = 0; }
tl_group *tl_create_group(void) { tl_group *timer; timer = (tl_group *) malloc(sizeof(tl_group)); if (timer == NULL) return NULL; timer->interval = -1; timer->handler = NULL; timer->multihandler = NULL; timer->next = NULL; timer->previous = NULL; timer->group = timer; tl_reset_timer(timer); return (timer); }
void timestuff(int rate, void (*control) (int), void (*draw) (void), int maxtime) { int waitmode = 0, t; tl_timer *timer; bbupdate(); /*starttime = TIME; */ endtime = starttime + maxtime; timer = tl_create_timer(); if (control == NULL) { rate = -40; } if (rate < 0) { waitmode = 1, rate = -rate; control1 = control; tl_set_multihandler(timer, mycontrol); } else tl_set_multihandler(timer, control); tl_set_interval(timer, 1000000 / rate); tl_add_timer(syncgroup, timer); tl_reset_timer(timer); if (control != NULL) control(1); while (!finish_stuff && TIME < endtime) { called = 0; t = tl_process_group(syncgroup); bbupdate(); if (TIME > endtime) break; #ifdef __DJGPP__ if (0) #else if (!called && waitmode) #endif tl_sleep(t); else { if (draw != NULL) draw(); } } starttime = endtime; tl_free_timer(timer); }
static int uih_message1 (uih_context * c, CONST char *message, int type) { static int pid; int i; for (i = 0; i < NMESSAGES && c->messg.message[i] != NULL; i++); if (i == NMESSAGES) uih_scrollup (c), i--; c->messg.message[i] = mystrdup (message); c->messg.messagetype[i] = type; c->messg.messagetimer[i] = tl_create_timer (); tl_reset_timer (c->messg.messagetimer[i]); tl_set_interval (c->messg.messagetimer[i], 1);; tl_slowdown_timer (c->messg.messagetimer[i], EXPIRETIME);; tl_set_handler (c->messg.messagetimer[i], (void (*)(void *)) uih_scrollup, c); tl_add_timer (syncgroup, c->messg.messagetimer[i]); /*tl_remove_timer (c->messg.messagetimer[i]); */ c->messg.pid[i] = ++pid; c->display = 1; return (pid); }
tl_timer *tl_create_timer(void) { tl_timer *timer; timer = (tl_timer *) calloc(1, sizeof(tl_timer)); if (timer == NULL) return NULL; timer->interval = -1; timer->handler = NULL; timer->multihandler = NULL; timer->userdata = NULL; timer->next = NULL; timer->previous = NULL; timer->group = NULL; timer->stopped = 0; timer->stoppedtime = 0; timer->slowdown = 0; timer->emulator = NULL; tl_reset_timer(timer); #ifdef _WIN32 QueryPerformanceFrequency(&frequency); #endif return (timer); }
void scene6(void) { int width, height, scanline; int i, formula = 0; char *buffer1, *buffer2; displayed = 0; incalculation = 0; fastmode = 2; interruptiblemode = 0; autopilot = 0; maxstep = MAXSTEP; speedup = STEP; step = 0; tbreak = 0; maintimer = tl_create_timer(); signal(SIGFPE, SIG_IGN); width = aa_imgwidth(context); height = aa_imgheight(context); scanline = width; buffer1 = context->imagebuffer; buffer2 = malloc(width * height); endtime = starttime + ETIME1; params->bright = -255; zcontext = make_context(width, height, scanline, 0, 1, flip_buffers, ui_waitfunc, buffer1, buffer2, get_pixelwidth(width), get_pixelheight(height)); if (!zcontext) { exit(-1); } set_formula(zcontext, formula); for (i = 0; i < 255; i++) { /*zcontext->colors[i] = (i * 15) % 255 + 1; */ zcontext->colors[i] = (i * 8) % 255 + 1; } zcontext->colors[0] = 0; zcontext->num_colors = 255; tbreak = 2; zcontext->maxiter = 150; fastmode--; zcontext->range = 8; zcontext->incoloringmode = 0; zcontext->coloringmode = 0; zcontext->plane = 0; ui_do_fractal(NEW_IMAGE); ui_autopilot(); speedup = 1 * STEP; maxstep *= 5; step = -maxstep; tl_process_group(syncgroup, NULL); bbupdate(); tl_reset_timer(maintimer); main_loop(); starttime = endtime; context->imagebuffer = buffer1; free(buffer2); tl_free_timer(maintimer); params->bright = 0; params->randomval = 0; initlepic(); drawptr = mydraw1; timestuff(-60, ctrllepic, draw, 2000000); drawptr = mydraw; /*timestuff(60, NULL, draw, 4 * 1000000); */ /*timestuff(20, blur, draw, 4 * 1000000); */ timestuff(60, NULL, draw, 3 * 1000000); }
int tl_process_group(tl_group * group, int *activated) { int again = 1; tl_timer *timer, *timer1; int minwait = INT_MAX; tl_update_time(); if (activated != NULL) *activated = 0; while (again) { group->slowdown = 0; again = 0; minwait = INT_MAX; timer = group->next; while (timer != NULL) { timer1 = timer->next; if (timer->handler && timer->interval >= 0) { int time = timer->interval - tl_lookup_timer(timer); if (time < 500) { if (activated != NULL) (*activated)++; again = 1; tl_reset_timer(timer); if (time < -200 * 1000000) time = 0; /*underflow? */ tl_slowdown_timer(timer, time); time = timer->interval + time; timer->handler(timer->userdata); tl_update_time(); } if (time < minwait) minwait = time; } else if (timer->multihandler && timer->interval > 0) { int time = timer->interval - tl_lookup_timer(timer); if (time < 500) { int n; if (activated != NULL) (*activated)++; tl_reset_timer(timer); if (time < -200 * 1000000) time = 0; /*underflow? */ n = -(time + 500) / timer->interval + 1; time = timer->interval * n + time; tl_slowdown_timer(timer, time - timer->interval + n * timer->interval); timer->multihandler(timer->userdata, n); tl_update_time(); } if (time < minwait) minwait = time; } if (group->slowdown) { again = 1; break; } timer = timer1; } } if (minwait != INT_MAX) { if (minwait < 0) return (0); return (minwait); } return (-1); }
int uih_save_enable(struct uih_context *uih, xio_file f, int mode) { struct uih_savedcontext *s; int i; last = 0; if (uih->save) { uih_error(uih, "Recording is already enabled"); return 0; } s = (struct uih_savedcontext *) calloc(1, sizeof(*s)); if (f == NULL || s == NULL) { uih_error(uih, "File could not be opended or out of memory"); return 0; } uih->savec = s; s->fcontext = make_fractalc(1, uih->image->pixelwidth * uih->image->width, uih->image->pixelheight * uih->image->height); if (s->fcontext == NULL) { uih_error(uih, "File could not be opended or out of memory"); return 0; } s->mode = mode; /*Invalidate context to force save everything first */ s->speedup = STEP; s->maxstep = MAXSTEP; s->xcenter = INT_MAX; s->fastmode = 2; s->juliamode = 0; s->cycling = 0; for (i = 0; i < uih_nfilters; i++) s->filter[i] = 0; s->pressed = 0; s->firsttime = 1; uih->palettechanged = 1; s->cyclingspeed = 30; s->fcontext->pre = s->fcontext->pim = 0; s->fcontext->bre = s->fcontext->bim = 0; s->fcontext->currentformula = NULL; s->fcontext->periodicity = 1; s->fcontext->maxiter = 170; s->fcontext->bailout = 4; s->fcontext->coloringmode = 0; s->fcontext->incoloringmode = 0; s->fcontext->outtcolor = 0; s->fcontext->intcolor = 0; s->fcontext->mandelbrot = 1; s->fcontext->plane = 0; s->fcontext->range = 3; s->fcontext->angle = 0; s->rotatepressed = 0; s->autorotate = 0; s->fastrotate = 0; s->rotationspeed = 10; s->clearscreen = 0; s->color = 0; s->xtextpos = 1; s->ytextpos = 1; s->file = f; s->timer = tl_create_timer(); s->synctimer = tl_create_timer(); uih->viewchanged = 1; uih->palettechanged = 1; uih->save = 1; uih_emulatetimers(uih); tl_reset_timer(s->timer); uih->moved = 0; #ifndef _plan9_ if (mode == UIH_SAVEANIMATION) myputs(";Animation file automatically generated by XaoS " XaoS_VERSION "\n" "; - a realtime interactive fractal zoomer\n" ";Use xaos -play <filename> to replay it\n"); else if (mode == UIH_SAVEPOS) myputs(";Position file automatically generated by XaoS " XaoS_VERSION "\n" "; - a realtime interactive fractal zoomer\n" ";Use xaos -load <filename> to display it\n"); #endif uih_saveframe(uih); uih_updatemenus(uih, "save"); xio_putc('\n', f); return 1; }
void uih_saveframe(struct uih_context *uih) { struct uih_savedcontext *s = uih->savec; int i; int resetsync = 0; if (uih->save) { changed = 0; if (s->firsttime) save_noparam(uih, "initstate"); if (s->nonfractalscreen && !uih->nonfractalscreen) save_noparam(uih, "display"), s->nonfractalscreen = 0; for (i = uih_nfilters; i >= 0; i--) { if (uih->filter[i] != NULL) { if (s->filter[i] != 1) { start_save(uih, "filter"); save_keystring(uih, uih->filter[i]->action->shortname); save_onoff(uih, 1); s->filter[i] = 1; stop_save(uih); } } else if (s->filter[i] != 0) { s->filter[i] = 0; start_save(uih, "filter"); save_keystring(uih, uih_filters[i]->shortname); save_onoff(uih, 0); stop_save(uih); } } if (uih->palettechanged) { switch (uih->palettetype) { case 0: save_intc(uih, "defaultpalette", uih->paletteshift); break; default: start_save(uih, "palette"); save_int(uih, uih->palettetype); save_int(uih, uih->paletteseed); save_int(uih, uih->paletteshift); stop_save(uih); break; } uih->palettechanged = 0; s->manualpaletteshift = 0; } if (s->manualpaletteshift != uih->manualpaletteshift) save_intc(uih, "shiftpalette", uih->manualpaletteshift - s->manualpaletteshift), s->manualpaletteshift = uih->manualpaletteshift; if (s->fcontext->currentformula != uih->fcontext->currentformula) { save_keystringc(uih, "formula", uih->fcontext->currentformula->shortname), s->fcontext->currentformula = uih->fcontext->currentformula; #ifdef SFFE_USING /*SFFE : malczak */ if ((int) (uih->fcontext->currentformula - formulas) == 24) //user formula { save_stringc(uih, "usrform", uih->parser->expression); if (uih->pinit) save_stringc(uih, "usrformInit", uih->pinit->expression); else save_stringc(uih, "usrformInit", ""); }; /*SFFE : malczak */ #endif set_formula(s->fcontext, (int) (uih->fcontext->currentformula - formulas)); } if (s->mode >= UIH_SAVEALL) save_intc(uih, "letterspersec", uih->letterspersec); if (s->mode > UIH_SAVEPOS) { if (s->speedup != uih->speedup) save_floatc(uih, "speedup", uih->speedup), s->speedup = uih->speedup; if (s->maxstep != uih->maxstep) save_floatc(uih, "maxstep", uih->maxstep), s->maxstep = uih->maxstep; if (s->fastmode != uih->fastmode) save_nstringc(uih, "fastmode", uih->fastmode, save_fastmode), s->fastmode = uih->fastmode; } if (s->juliamode != uih->juliamode) save_onoffc(uih, "fastjulia", uih->juliamode), s->juliamode = uih->juliamode; if (s->cycling != uih->cycling) save_onoffc(uih, "cycling", uih->cycling), s->cycling = uih->cycling; if (s->mode >= UIH_SAVEPOS && s->fcontext->periodicity != uih->fcontext->periodicity) save_onoffc(uih, "periodicity", uih->fcontext->periodicity), s->fcontext->periodicity = uih->fcontext->periodicity; if ((uih->cycling || s->mode >= UIH_SAVEALL) && (s->cyclingspeed != uih->cyclingspeed || s->direction != uih->direction * uih->cyclingdirection)) save_intc(uih, "cyclingspeed", uih->cyclingspeed * uih->direction * uih->cyclingdirection), s->cyclingspeed = uih->cyclingspeed, s->direction = uih->direction * uih->cyclingdirection; if ((s->mode > UIH_SAVEPOS && (uih->step || uih->zoomactive)) && (s->xcenter != uih->xcenter || s->ycenter != uih->ycenter)) save_coordc(uih, "zoomcenter", uih->xcenter, uih->ycenter), s->xcenter = uih->xcenter, s->ycenter = uih->ycenter; if ((!uih->fcontext->mandelbrot || uih->juliamode) && (s->fcontext->pre != uih->fcontext->pre || s->fcontext->pim != uih->fcontext->pim)) { if (uih->juliamode && uih->pressed) save_coordc(uih, "morphjulia", uih->fcontext->pre, uih->fcontext->pim), s->fcontext->pre = uih->fcontext->pre, s->fcontext->pim = uih->fcontext->pim; else save_coordc(uih, "juliaseed", uih->fcontext->pre, uih->fcontext->pim), s->fcontext->pre = uih->fcontext->pre, s->fcontext->pim = uih->fcontext->pim; } if (uih->fcontext->bre != s->fcontext->bre || uih->fcontext->bim != s->fcontext->bim) { save_coordc(uih, "perturbation", uih->fcontext->bre, uih->fcontext->bim), s->fcontext->bre = uih->fcontext->bre, s->fcontext->bim = uih->fcontext->bim; } if (uih->fastrotate != s->fastrotate && s->mode > UIH_SAVEPOS) { save_onoffc(uih, "fastrotate", uih->fastrotate); s->fastrotate = uih->fastrotate; } if (uih->fcontext->angle != s->fcontext->angle && s->autorotate != 1) { if (s->rotatepressed && s->mode == UIH_SAVEANIMATION) save_float2c(uih, "morphangle", uih->fcontext->angle, 5); else save_float2c(uih, "angle", uih->fcontext->angle, 5); s->rotatepressed = uih->rotatepressed; s->fcontext->angle = uih->fcontext->angle; } if (uih->rotationspeed != s->rotationspeed && ((s->mode > UIH_SAVEPOS && uih->rotatemode == ROTATE_CONTINUOUS) || s->mode >= UIH_SAVEALL)) { save_float2c(uih, "rotationspeed", uih->rotationspeed, 6); s->rotationspeed = uih->rotationspeed; } if (s->autorotate != (uih->rotatemode == ROTATE_CONTINUOUS)) { s->autorotate = (uih->rotatemode == ROTATE_CONTINUOUS); save_onoffc(uih, "autorotate", s->autorotate); } if (s->fcontext->maxiter != uih->fcontext->maxiter) save_intc(uih, "maxiter", uih->fcontext->maxiter), s->fcontext->maxiter = uih->fcontext->maxiter; if (s->fcontext->bailout != uih->fcontext->bailout) save_floatc(uih, "bailout", uih->fcontext->bailout), s->fcontext->bailout = uih->fcontext->bailout; if (s->fcontext->coloringmode != uih->fcontext->coloringmode) save_intc(uih, "outcoloring", uih->fcontext->coloringmode), s->fcontext->coloringmode = uih->fcontext->coloringmode; if (s->fcontext->incoloringmode != uih->fcontext->incoloringmode) save_intc(uih, "incoloring", uih->fcontext->incoloringmode), s->fcontext->incoloringmode = uih->fcontext->incoloringmode; if (s->fcontext->incoloringmode != uih->fcontext->incoloringmode) save_intc(uih, "incoloring", uih->fcontext->incoloringmode), s->fcontext->incoloringmode = uih->fcontext->incoloringmode; if ((s->fcontext->incoloringmode == 10 || s->mode >= UIH_SAVEALL) && s->fcontext->intcolor != uih->fcontext->intcolor) save_intc(uih, "intcoloring", uih->fcontext->intcolor), s->fcontext->intcolor = uih->fcontext->intcolor; if ((s->fcontext->coloringmode == 10 || s->mode >= UIH_SAVEALL) && s->fcontext->outtcolor != uih->fcontext->outtcolor) save_intc(uih, "outtcoloring", uih->fcontext->outtcolor), s->fcontext->outtcolor = uih->fcontext->outtcolor; if (s->fcontext->mandelbrot != uih->fcontext->mandelbrot) save_onoffc(uih, "julia", !uih->fcontext->mandelbrot), s->fcontext->mandelbrot = uih->fcontext->mandelbrot; if (s->mode > UIH_SAVEPOS && s->fcontext->range != uih->fcontext->range) save_intc(uih, "range", uih->fcontext->range), s->fcontext->range = uih->fcontext->range; if (s->fcontext->plane != uih->fcontext->plane) save_intc(uih, "plane", uih->fcontext->plane), s->fcontext->plane = uih->fcontext->plane; if (s->zoomactive != uih->zoomactive && s->mode > UIH_SAVEPOS) { switch (uih->zoomactive) { case -1: save_noparam(uih, "unzoom"); break; case 1: save_noparam(uih, "zoom"); break; default: save_noparam(uih, "stop"); break; } s->zoomactive = uih->zoomactive; } if ((s->mode >= UIH_SAVEPOS || uih->displaytext) && s->color != uih->color) { start_save(uih, "color"); save_nstring(uih, uih->color, uih_colornames); stop_save(uih); s->color = uih->color; } if (s->clearscreen) { save_noparam(uih, "clearscreen"); s->clearscreen = 0; s->nonfractalscreen = 1; } if (uih->displaytext) { for (i = 0; i < 3; i++) { if (uih->displaytext & (1 << i)) { if (s->ytextpos != i || s->xtextpos != uih->textpos[i]) { start_save(uih, "textpossition"); save_nstring(uih, uih->xtextpos, xtextposnames); save_nstring(uih, uih->ytextpos, ytextposnames); stop_save(uih); s->xtextpos = uih->xtextpos; s->ytextpos = uih->ytextpos; } save_stringc(uih, "text", uih->text[i]); s->nonfractalscreen = 1; } } save_noparam(uih, "textsleep"); uih->displaytext = 0; } if (s->autorotate && changed && tl_lookup_timer(uih->savec->synctimer) > 500000) save_float2c(uih, "angle", uih->fcontext->angle, 5), resetsync = 1; if (s->mode == UIH_SAVEPOS) savepos(uih); else { if (uih->viewchanged) savepos(uih), uih->viewchanged = 0; else if (uih->moved) savepos3(uih), uih->moved = 0; else if (((changed && uih->step) || last) && tl_lookup_timer(uih->savec->synctimer) > 500000) resetsync = 1, savepos2(uih); } if (uih->savec->firsttime) uih->savec->firsttime = 0; if (s->writefailed) uih_save_disable(uih); if (resetsync) tl_reset_timer(uih->savec->synctimer); } /*if uih->save */ }