--- ray/src/hd/rholo.c 1997/12/08 20:27:34 3.18 +++ ray/src/hd/rholo.c 1997/12/15 20:43:01 3.28 @@ -10,7 +10,6 @@ static char SCCSid[] = "$SunId$ SGI"; #include "rholo.h" #include "random.h" -#include "paths.h" #include #include #include @@ -22,7 +21,7 @@ VARIABLE vv[] = RHVINIT; /* variable-value pairs */ char *progname; /* our program name */ char *hdkfile; /* holodeck file name */ -char froot[MAXPATH]; /* root file name */ +char froot[256]; /* root file name */ int nowarn = 0; /* turn warnings off? */ @@ -32,6 +31,8 @@ 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 */ @@ -59,7 +60,6 @@ char *argv[]; { HDGRID hdg; int i; - int force = 0; /* mark start time */ starttime = time(NULL); initurand(16384); /* initialize urand */ @@ -88,26 +88,27 @@ char *argv[]; default: goto userr; } - /* do we have a job? */ - if (outdev == NULL && ncprocs <= 0) - goto userr; /* get root file name */ rootname(froot, hdkfile=argv[i++]); - /* load... */ - if (i < argc) { /* variables */ - loadvars(argv[i++]); - /* cmdline settings */ - for ( ; i < argc; i++) - if (setvariable(argv[i], matchvar) < 0) { - sprintf(errmsg, "unknown variable: %s", - argv[i]); - error(USER, errmsg); - } - /* check settings */ - checkvalues(); - /* load RIF if any */ - if (vdef(RIF)) - getradfile(vval(RIF)); + /* load variables? */ + if (i < argc) + if (argv[i][0] != '-' && argv[i][0] != '+') + loadvars(argv[i]); /* load variables from file */ + + if (i >= argc || argv[i][0] == '+') + loadholo(); /* load existing holodeck */ + + while (++i < argc) /* get command line settings */ + if (setvariable(argv[i], matchvar) < 0) { + sprintf(errmsg, "unknown variable: %s", argv[i]); + error(USER, errmsg); + } + /* check settings */ + checkvalues(); + /* load RIF if any */ + getradfile(); + + if (hdlist[0] == NULL) { /* create new holodeck */ /* set defaults */ setdefaults(&hdg); /* holodeck exists? */ @@ -116,16 +117,8 @@ char *argv[]; "holodeck file exists -- use -f to overwrite"); /* create holodeck */ creatholo(&hdg); - } else { /* else load holodeck */ - loadholo(); - /* check settings */ - checkvalues(); - /* load RIF if any */ - if (vdef(RIF)) - getradfile(vval(RIF)); - /* set defaults */ + } else /* else just set defaults */ setdefaults(NULL); - } /* initialize */ initrholo(); /* main loop */ @@ -135,7 +128,7 @@ char *argv[]; quit(0); userr: fprintf(stderr, -"Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n", +"Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", progname); quit(1); } @@ -149,7 +142,7 @@ int signo; if (gotsig++) /* two signals and we're gone! */ _exit(signo); - alarm(30); /* allow 30 seconds to clean up */ + alarm(60); /* allow 60 seconds to clean up */ signal(SIGALRM, SIG_DFL); /* make certain we do die */ eputs("signal - "); eputs(sigerr[signo]); @@ -208,7 +201,7 @@ initrholo() /* get our holodeck running */ if (!vdef(TIME) || vflt(TIME) <= FTINY) endtime = 0; else - endtime = starttime + vflt(TIME)*3600.; + endtime = starttime + vflt(TIME)*3600. + .5; /* set up memory cache */ if (outdev == NULL) hdcachesize = 0; /* manual flushing */ @@ -224,7 +217,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); @@ -235,7 +228,7 @@ initrholo() /* get our holodeck running */ goto memerr; freepacks[--i].nr = 0; freepacks[i].next = NULL; - if (!vbool(OBSTRUCTIONS)) { + if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) { freepacks[i].offset = (float *)bmalloc( RPACKSIZ*sizeof(float)*(i+1) ); if (freepacks[i].offset == NULL) @@ -279,56 +272,44 @@ rholo() /* holodeck main loop */ if (!disp_check(idle)) return(0); /* display only? */ - if (ncprocs <= 0) - return(1); + if (nprocs <= 0) { + idle = 1; + return(outdev != NULL); + } /* check file size */ if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { error(WARNING, "file limit exceeded"); - return(0); + done_rtrace(); + return(1); /* comes back */ } /* check time */ if (endtime > 0 || reporttime > 0) t = time(NULL); if (endtime > 0 && t >= endtime) { error(WARNING, "time limit exceeded"); - return(0); + done_rtrace(); + return(1); /* comes back */ } if (reporttime > 0 && t >= reporttime) report(t); - /* get packets to process */ + idle = 0; /* get packets to process */ while (freepacks != NULL) { p = freepacks; freepacks = p->next; p->next = NULL; if (!next_packet(p)) { p->next = freepacks; freepacks = p; + idle = 1; break; } if (pl == NULL) pl = p; else plend->next = p; plend = p; } - idle = pl == NULL && freepacks != NULL; - /* are we out of stuff to do? */ - if (idle && outdev == NULL) - return(0); - /* else process packets */ + /* process packets */ done_packets(do_packets(pl)); return(1); /* and continue */ } -report(t) /* report progress so far */ -time_t t; -{ - if (t == 0) - t = time(NULL); - fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n", - progname, npacksdone, nraysdone, (t-starttime)/3600.); - fflush(stderr); - if (vdef(REPORT)) - reporttime = t + (time_t)(vflt(REPORT)*60.+.5); -} - - setdefaults(gp) /* set default values */ register HDGRID *gp; { @@ -351,18 +332,10 @@ register HDGRID *gp; sprintf(vval(OCTREE), "%s.oct", froot); vdef(OCTREE)++; } - if (!vdef(OBSTRUCTIONS)) { - vval(OBSTRUCTIONS) = "T"; - vdef(OBSTRUCTIONS)++; - } if (!vdef(VDIST)) { vval(VDIST) = "F"; vdef(VDIST)++; } - if (!vdef(OCCUPANCY)) { - vval(OCCUPANCY) = "U"; - vdef(OCCUPANCY)++; - } /* append rendering options */ if (vdef(RENDER)) rtargc += wordstring(rtargv+rtargc, vval(RENDER)); @@ -500,67 +473,20 @@ PACKET *pl; p->next = freepacks; freepacks = p; } - if (n2flush > 512*RPACKSIZ*ncprocs) { + if (n2flush > 512*RPACKSIZ*nprocs) { hdflush(NULL); /* flush holodeck buffers */ n2flush = 0; } } -getradfile(rfargs) /* run rad and get needed variables */ -char *rfargs; -{ - static short mvar[] = {OCTREE,-1}; - static char tf1[] = TEMPLATE; - char tf2[64]; - char combuf[256]; - char *pippt; - register int i; - register char *cp; - /* create rad command */ - mktemp(tf1); - sprintf(tf2, "%s.rif", tf1); - sprintf(combuf, - "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", - rfargs, tf1); - cp = combuf; - while (*cp){ - if (*cp == '|') pippt = cp; - cp++; - } /* match unset variables */ - for (i = 0; mvar[i] >= 0; i++) - if (!vdef(mvar[i])) { - *cp++ = '|'; - strcpy(cp, vnam(mvar[i])); - while (*cp) cp++; - pippt = NULL; - } - if (pippt != NULL) - strcpy(pippt, "> /dev/null"); /* nothing to match */ - else - sprintf(cp, ")[ \t]*=' > %s", tf2); - if (system(combuf)) { - error(SYSTEM, "cannot execute rad command"); - unlink(tf2); /* clean up */ - unlink(tf1); - quit(1); - } - if (pippt == NULL) { - loadvars(tf2); /* load variables */ - unlink(tf2); - } - rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ - unlink(tf1); /* clean up */ -} - - rootname(rn, fn) /* remove tail from end of fn */ register char *rn, *fn; { char *tp, *dp; for (tp = NULL, dp = rn; *rn = *fn++; rn++) - if (ISDIRSEP(*rn)) + if (*rn == '/') dp = rn; else if (*rn == '.') tp = rn; @@ -609,23 +535,18 @@ int ec; { int status = 0; - if (hdlist[0] != NULL) { /* flush holodeck */ - if (ncprocs > 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, + if (hdlist[0] != NULL) { /* close holodeck */ + if (nprocs > 0) + status = done_rtrace(); /* calls hdsync() */ + if (ncprocs > 0 && vdef(REPORT)) { + long fsiz, fuse; + 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);