--- ray/src/util/rad.c 1993/03/12 13:37:03 2.4 +++ ray/src/util/rad.c 1993/06/14 10:49:08 2.11 @@ -94,10 +94,18 @@ int (*setqopts[3])() = {lowqopts, medqopts, hiqopts}; #define renderopts (*setqopts[vscale(QUALITY)]) + /* overture calculation file */ +#ifdef NIX +char overfile[] = "overture.raw"; +#else +char overfile[] = "/dev/null"; +#endif + extern long fdate(), time(); long scenedate; /* date of latest scene or object file */ long octreedate; /* date of octree */ +long matdate; /* date of latest material file */ int explicate = 0; /* explicate variables */ int silent = 0; /* do work silently */ @@ -159,8 +167,11 @@ char *argv[]; /* print all values if requested */ if (explicate) printvals(); - /* run simulation */ + /* build octree */ oconv(); + /* check date on ambient file */ + checkambfile(); + /* run simulation */ renderopts(ropts); xferopts(ropts); if (rvdevice != NULL) @@ -413,6 +424,9 @@ checkfiles() /* check for existence and modified tim vnam(OCTREE), vnam(SCENE)); exit(1); } + matdate = -1; + if (vdef(MATERIAL)) + matdate = checklast(vval(MATERIAL)); } @@ -547,6 +561,19 @@ register char *oo; } +checkambfile() /* check date on ambient file */ +{ + long afdate; + + if (!vdef(AMBFILE)) + return; + if ((afdate = fdate(vval(AMBFILE))) < 0) + return; + if (octreedate > afdate | matdate > afdate) + rmfile(vval(AMBFILE)); +} + + double ambval() /* compute ambient value */ { @@ -664,8 +691,10 @@ register char *op; else op = addarg(op, "-ds .3"); op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15"); - sprintf(op, " -ab %d", overture=vint(INDIRECT)); - op += strlen(op); + if (overture = vint(INDIRECT)) { + sprintf(op, " -ab %d", overture); + op += strlen(op); + } if (vdef(AMBFILE)) { sprintf(op, " -af %s", vval(AMBFILE)); op += strlen(op); @@ -760,31 +789,26 @@ xferopts(ro) /* transfer options if indicated */ char *ro; { int fd, n; + register char *cp; n = strlen(ro); if (n < 2) return; if (vdef(OPTFILE)) { - if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) + for (cp = ro; cp[1]; cp++) + if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3])) + *cp = '\n'; + else + *cp = cp[1]; + *cp = '\n'; + fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666); + if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0) syserr(vval(OPTFILE)); - if (write(fd, ro+1, n-1) != n-1) - syserr(vval(OPTFILE)); - write(fd, "\n", 1); - close(fd); sprintf(ro, " \"^%s\"", vval(OPTFILE)); } #ifdef MSDOS else if (n > 50) { - register char *evp = bmalloc(n+6); - if (evp == NULL) - syserr(progname); - strcpy(evp, "ROPT="); - strcat(evp, ro); - if (putenv(evp) != 0) { - fprintf(stderr, "%s: out of environment space\n", - progname); - exit(1); - } + setenv("ROPT", ro+1); strcpy(ro, " $ROPT"); } #endif @@ -924,8 +948,13 @@ register char *vs; cp += strlen(cp); } } - /* append any additional options */ - strcpy(cp, vs); + strcpy(cp, vs); /* append any additional options */ +#ifdef MSDOS + if (strlen(viewopts) > 40) { + setenv("VIEW", viewopts); + return("$VIEW"); + } +#endif return(viewopts); } @@ -933,11 +962,11 @@ register char *vs; char * getview(n, vn) /* get view n, or NULL if none */ int n; -char *vn; +char *vn; /* returned view name */ { - register char *mv; + register char *mv = NULL; - if (viewselect != NULL) { + if (viewselect != NULL) { /* command-line selected */ if (n) /* only do one */ return(NULL); if (viewselect[0] == '-') { /* already specified */ @@ -956,13 +985,14 @@ char *vn; return(specview(mv)); return(specview(viewselect)); /* standard view? */ } - if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) { + mv = nvalue(vv+VIEW, n); /* use view n */ + if (vn != NULL & mv != NULL) { if (*mv != '-') while (*mv && !isspace(*mv)) *vn++ = *mv++; *vn = '\0'; } - return(specview(nvalue(vv+VIEW, n))); /* use view n */ + return(specview(mv)); } @@ -1020,12 +1050,6 @@ char *opts; else badvalue(REPORT); } - /* check date on ambient file */ - if (vdef(AMBFILE)) { - long afdate = fdate(vval(AMBFILE)); - if (afdate >= 0 & octreedate > afdate) - rmfile(vval(AMBFILE)); - } /* do each view */ vn = 0; while ((vw = getview(vn++, vs)) != NULL) { @@ -1033,11 +1057,11 @@ char *opts; sprintf(vs, "%d", vn); sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs); /* check date on picture */ - if (fdate(picfile) > octreedate) + if (fdate(picfile) >= octreedate) continue; /* build rpict command */ sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs); - if (fdate(rawfile) > octreedate) /* recover */ + if (fdate(rawfile) >= octreedate) /* recover */ sprintf(combuf, "rpict%s%s -ro %s %s", rep, opts, rawfile, vval(OCTREE)); else { @@ -1045,14 +1069,16 @@ char *opts; sprintf(combuf, "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s", rep, vw, opts, - vval(OCTREE), rawfile); + vval(OCTREE), overfile); if (runcom(combuf)) { fprintf(stderr, - "%s: error in overture for view %s\n\t%s removed\n", - progname, vs, rawfile); - unlink(rawfile); + "%s: error in overture for view %s\n", + progname, vs); exit(1); } +#ifdef NIX + rmfile(overfile); +#endif } sprintf(combuf, "rpict%s %s %s%s %s > %s", rep, vw, res, opts, @@ -1108,6 +1134,26 @@ char *fn; return(0); return(unlink(fn)); } + + +#ifdef MSDOS +setenv(vname, value) /* set an environment variable */ +char *vname, *value; +{ + register char *evp; + + evp = bmalloc(strlen(vname)+strlen(value)+2); + if (evp == NULL) + syserr(progname); + sprintf(evp, "%s=%s", vname, value); + if (putenv(evp) != 0) { + fprintf(stderr, "%s: out of environment space\n", progname); + exit(1); + } + if (!silent) + printf("set %s\n", evp); +} +#endif badvalue(vc) /* report bad variable value and exit */