--- ray/src/hd/rholo.c 1997/11/20 11:39:24 3.12 +++ ray/src/hd/rholo.c 1997/12/12 11:13:16 3.20 @@ -9,6 +9,7 @@ static char SCCSid[] = "$SunId$ SGI"; */ #include "rholo.h" +#include "random.h" #include "paths.h" #include #include @@ -25,12 +26,14 @@ char froot[MAXPATH]; /* root file name */ int nowarn = 0; /* turn warnings off? */ -double expval = 1.; /* global exposure value */ - int ncprocs = 0; /* desired number of compute processes */ char *outdev = NULL; /* output device name */ +int readinp = 0; /* read commands from stdin */ + +int force = 0; /* allow overwrite of holodeck */ + time_t starttime; /* time we got started */ time_t endtime; /* time we should end by */ time_t reporttime; /* time for next report */ @@ -58,9 +61,9 @@ char *argv[]; { HDGRID hdg; int i; - int force = 0; /* mark start time */ starttime = time(NULL); + initurand(16384); /* initialize urand */ progname = argv[0]; /* get arguments */ for (i = 1; i < argc && argv[i][0] == '-'; i++) switch (argv[i][1]) { @@ -70,6 +73,9 @@ char *argv[]; case 'f': /* force overwrite */ force++; break; + case 'i': /* read input from stdin */ + readinp++; + break; case 'n': /* compute processes */ if (i >= argc-2) goto userr; @@ -113,12 +119,17 @@ char *argv[]; creatholo(&hdg); } else { /* else load holodeck */ loadholo(); - if (vdef(RIF)) /* load RIF if any */ + /* check settings */ + checkvalues(); + /* load RIF if any */ + if (vdef(RIF)) getradfile(vval(RIF)); + /* set defaults */ + setdefaults(NULL); } /* initialize */ initrholo(); - /* run */ + /* main loop */ while (rholo()) ; /* done */ @@ -182,6 +193,8 @@ initrholo() /* get our holodeck running */ { extern int global_packet(); register int i; + /* close holodeck on exec() */ + fcntl(hdlist[0]->fd, F_SETFD, FD_CLOEXEC); if (outdev != NULL) /* open output device */ disp_open(outdev); @@ -212,7 +225,7 @@ initrholo() /* get our holodeck running */ if (ncprocs > 0) { i = start_rtrace(); if (i < 1) - error(USER, "cannot start rtrace process"); + error(USER, "cannot start rtrace process(es)"); if (vdef(REPORT)) { /* make first report */ printargs(rtargc, rtargv, stderr); report(0); @@ -267,7 +280,7 @@ rholo() /* holodeck main loop */ if (!disp_check(idle)) return(0); /* display only? */ - if (ncprocs <= 0) + if (nprocs <= 0) return(1); /* check file size */ if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { @@ -333,32 +346,6 @@ register HDGRID *gp; sprintf(errmsg, "ignoring all but first %s", vnam(SECTION)); error(WARNING, errmsg); } - if (sscanf(vval(SECTION), - "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", - &gp->orig[0], &gp->orig[1], &gp->orig[2], - &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], - &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], - &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2]) != 12) - badvalue(SECTION); - maxlen = 0.; - for (i = 0; i < 3; i++) - if ((len[i] = VLEN(gp->xv[i])) > maxlen) - maxlen = len[i]; - if (!vdef(GRID)) { - sprintf(buf, "%.4f", maxlen/8.); - vval(GRID) = savqstr(buf); - vdef(GRID)++; - } - if ((d = vflt(GRID)) <= FTINY) - badvalue(GRID); - for (i = 0; i < 3; i++) - gp->grid[i] = len[i]/d + (1.-FTINY); - if (!vdef(EXPOSURE)) { - sprintf(errmsg, "%s must be defined", vnam(EXPOSURE)); - error(USER, errmsg); - } - expval = vval(EXPOSURE)[0] == '-' || vval(EXPOSURE)[0] == '+' ? - pow(2., vflt(EXPOSURE)) : vflt(EXPOSURE); if (!vdef(OCTREE)) { if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL) error(SYSTEM, "out of memory"); @@ -369,6 +356,10 @@ register HDGRID *gp; vval(OBSTRUCTIONS) = "T"; vdef(OBSTRUCTIONS)++; } + if (!vdef(VDIST)) { + vval(VDIST) = "F"; + vdef(VDIST)++; + } if (!vdef(OCCUPANCY)) { vval(OCCUPANCY) = "U"; vdef(OCCUPANCY)++; @@ -376,6 +367,33 @@ register HDGRID *gp; /* append rendering options */ if (vdef(RENDER)) rtargc += wordstring(rtargv+rtargc, vval(RENDER)); + + if (gp == NULL) /* already initialized? */ + return; + /* set grid parameters */ + gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; + if (sscanf(vval(SECTION), + "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd", + &gp->orig[0], &gp->orig[1], &gp->orig[2], + &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], + &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], + &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], + &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) + badvalue(SECTION); + maxlen = 0.; + for (i = 0; i < 3; i++) + if ((len[i] = VLEN(gp->xv[i])) > maxlen) + maxlen = len[i]; + if (!vdef(GRID)) { + sprintf(buf, "%.4f", maxlen/8.); + vval(GRID) = savqstr(buf); + vdef(GRID)++; + } + if ((d = vflt(GRID)) <= FTINY) + badvalue(GRID); + for (i = 0; i < 3; i++) + if (gp->grid[i] <= 0) + gp->grid[i] = len[i]/d + (1.-FTINY); } @@ -463,7 +481,7 @@ loadholo() /* start loading a holodeck from fname */ done_packets(pl) /* handle finished packets */ PACKET *pl; { - static int nunflushed = 0; + static int n2flush = 0; register PACKET *p; while (pl != NULL) { @@ -474,8 +492,8 @@ PACKET *pl; p->nr*sizeof(RAYVAL)); if (outdev != NULL) /* display it */ disp_packet((PACKHEAD *)p); - else - nunflushed += p->nr; + if (hdcachesize <= 0) /* manual flushing */ + n2flush += p->nr; nraysdone += p->nr; npacksdone++; } @@ -483,17 +501,29 @@ PACKET *pl; p->next = freepacks; freepacks = p; } - if (nunflushed >= 256*RPACKSIZ) { + if (n2flush > 512*RPACKSIZ*nprocs) { hdflush(NULL); /* flush holodeck buffers */ - nunflushed = 0; + n2flush = 0; } } +checkrad() /* check to make sure octree is up to date */ +{ + char combuf[128]; + + if (!vdef(RIF)) + return; + sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF)); + if (system(combuf)) + error(WARNING, "error running rad"); +} + + getradfile(rfargs) /* run rad and get needed variables */ char *rfargs; { - static short mvar[] = {OCTREE,EXPOSURE,-1}; + static short mvar[] = {OCTREE,-1}; static char tf1[] = TEMPLATE; char tf2[64]; char combuf[256]; @@ -523,10 +553,9 @@ char *rfargs; else sprintf(cp, ")[ \t]*=' > %s", tf2); if (system(combuf)) { - error(SYSTEM, "cannot execute rad command"); unlink(tf2); /* clean up */ unlink(tf1); - quit(1); + error(SYSTEM, "cannot execute rad command"); } if (pippt == NULL) { loadvars(tf2); /* load variables */ @@ -593,22 +622,21 @@ int ec; int status = 0; if (hdlist[0] != NULL) { /* flush holodeck */ - if (ncprocs > 0) { + if (nprocs > 0) { done_packets(flush_queue()); status = end_rtrace(); /* close rtrace */ - hdflush(NULL); - if (vdef(REPORT)) { - long fsiz, fuse; - report(0); - fsiz = hdfilen(hdlist[0]->fd); - fuse = hdfiluse(hdlist[0]->fd, 1); - fprintf(stderr, + } + hdflush(NULL); + if (ncprocs > 0 && vdef(REPORT)) { + long fsiz, fuse; + report(0); + fsiz = hdfilen(hdlist[0]->fd); + fuse = hdfiluse(hdlist[0]->fd, 1); + fprintf(stderr, "%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n", - hdkfile, fsiz/(1024.*1024.), - 100.*(fsiz-fuse)/fsiz); - } - } else - hdflush(NULL); + hdkfile, fsiz/(1024.*1024.), + 100.*(fsiz-fuse)/fsiz); + } } if (orig_mode >= 0) /* reset holodeck access mode */ fchmod(hdlist[0]->fd, orig_mode);