ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo.c
(Generate patch)

Comparing ray/src/hd/rholo.c (file contents):
Revision 3.21 by gregl, Fri Dec 12 18:12:40 1997 UTC vs.
Revision 3.28 by gregl, Mon Dec 15 20:43:01 1997 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ SGI";
10  
11   #include "rholo.h"
12   #include "random.h"
13 #include "paths.h"
13   #include <signal.h>
14   #include <sys/types.h>
15   #include <sys/stat.h>
# Line 22 | Line 21 | VARIABLE       vv[] = RHVINIT;         /* variable-value pairs */
21  
22   char    *progname;              /* our program name */
23   char    *hdkfile;               /* holodeck file name */
24 < char    froot[MAXPATH];         /* root file name */
24 > char    froot[256];             /* root file name */
25  
26   int     nowarn = 0;             /* turn warnings off? */
27  
# Line 89 | Line 88 | char   *argv[];
88                  default:
89                          goto userr;
90                  }
92                                                /* do we have a job? */
93        if (outdev == NULL && ncprocs <= 0)
94                goto userr;
91                                                  /* get root file name */
92          rootname(froot, hdkfile=argv[i++]);
93 <                                                /* load... */
94 <        if (i < argc) {                         /* variables */
95 <                loadvars(argv[i++]);
96 <                                                        /* cmdline settings */
97 <                for ( ; i < argc; i++)
98 <                        if (setvariable(argv[i], matchvar) < 0) {
99 <                                sprintf(errmsg, "unknown variable: %s",
100 <                                                argv[i]);
101 <                                error(USER, errmsg);
102 <                        }
103 <                                                        /* check settings */
104 <                checkvalues();
105 <                                                        /* load RIF if any */
106 <                if (vdef(RIF))
107 <                        getradfile(vval(RIF));
93 >                                                /* load variables? */
94 >        if (i < argc)
95 >                if (argv[i][0] != '-' && argv[i][0] != '+')
96 >                        loadvars(argv[i]);      /* load variables from file */
97 >
98 >        if (i >= argc || argv[i][0] == '+')
99 >                loadholo();                     /* load existing holodeck */
100 >
101 >        while (++i < argc)                      /* get command line settings */
102 >                if (setvariable(argv[i], matchvar) < 0) {
103 >                        sprintf(errmsg, "unknown variable: %s", argv[i]);
104 >                        error(USER, errmsg);
105 >                }
106 >                                                /* check settings */
107 >        checkvalues();
108 >                                                /* load RIF if any */
109 >        getradfile();
110 >
111 >        if (hdlist[0] == NULL) {                /* create new holodeck */
112                                                          /* set defaults */
113                  setdefaults(&hdg);
114                                                          /* holodeck exists? */
# Line 117 | Line 117 | char   *argv[];
117                                  "holodeck file exists -- use -f to overwrite");
118                                                          /* create holodeck */
119                  creatholo(&hdg);
120 <        } else {                                /* else load holodeck */
121 <                loadholo();
122 <                                                        /* check settings */
123 <                checkvalues();
124 <                                                        /* load RIF if any */
125 <                if (vdef(RIF))
126 <                        getradfile(vval(RIF));
127 <                                                        /* set defaults */
120 >        } else                                  /* else just set defaults */
121                  setdefaults(NULL);
129        }
122                                                  /* initialize */
123          initrholo();
124                                                  /* main loop */
# Line 136 | Line 128 | char   *argv[];
128          quit(0);
129   userr:
130          fprintf(stderr,
131 < "Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n",
131 > "Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n",
132                          progname);
133          quit(1);
134   }
# Line 150 | Line 142 | int  signo;
142          if (gotsig++)                   /* two signals and we're gone! */
143                  _exit(signo);
144  
145 <        alarm(30);                      /* allow 30 seconds to clean up */
145 >        alarm(60);                      /* allow 60 seconds to clean up */
146          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
147          eputs("signal - ");
148          eputs(sigerr[signo]);
# Line 209 | Line 201 | initrholo()                    /* get our holodeck running */
201          if (!vdef(TIME) || vflt(TIME) <= FTINY)
202                  endtime = 0;
203          else
204 <                endtime = starttime + vflt(TIME)*3600.;
204 >                endtime = starttime + vflt(TIME)*3600. + .5;
205                                                  /* set up memory cache */
206          if (outdev == NULL)
207                  hdcachesize = 0;        /* manual flushing */
# Line 236 | Line 228 | initrholo()                    /* get our holodeck running */
228                          goto memerr;
229                  freepacks[--i].nr = 0;
230                  freepacks[i].next = NULL;
231 <                if (!vbool(OBSTRUCTIONS)) {
231 >                if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) {
232                          freepacks[i].offset = (float *)bmalloc(
233                                          RPACKSIZ*sizeof(float)*(i+1) );
234                          if (freepacks[i].offset == NULL)
# Line 280 | Line 272 | rholo()                                /* holodeck main loop */
272                  if (!disp_check(idle))
273                          return(0);
274                                          /* display only? */
275 <        if (nprocs <= 0)
275 >        if (nprocs <= 0) {
276 >                idle = 1;
277                  return(outdev != NULL);
278 +        }
279                                          /* check file size */
280          if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
281                  error(WARNING, "file limit exceeded");
282                  done_rtrace();
289                idle = 1;
283                  return(1);      /* comes back */
284          }
285                                          /* check time */
# Line 295 | Line 288 | rholo()                                /* holodeck main loop */
288          if (endtime > 0 && t >= endtime) {
289                  error(WARNING, "time limit exceeded");
290                  done_rtrace();
298                idle = 1;
291                  return(1);      /* comes back */
292          }
293          if (reporttime > 0 && t >= reporttime)
294                  report(t);
295 <                                        /* get packets to process */
295 >        idle = 0;                       /* get packets to process */
296          while (freepacks != NULL) {
297                  p = freepacks; freepacks = p->next; p->next = NULL;
298                  if (!next_packet(p)) {
# Line 318 | Line 310 | rholo()                                /* holodeck main loop */
310   }
311  
312  
321 report(t)                       /* report progress so far */
322 time_t  t;
323 {
324        static time_t   seconds2go = 1000000;
325
326        if (t == 0L)
327                t = time(NULL);
328        sprintf(errmsg, "%ld packets (%ld rays) done after %.2f hours\n",
329                        npacksdone, nraysdone, (t-starttime)/3600.);
330        eputs(errmsg);
331        if (seconds2go == 1000000)
332                seconds2go = vdef(REPORT) ? (long)(vflt(REPORT)*60. + .5) : 0L;
333        if (seconds2go)
334                reporttime = t + seconds2go;
335 }
336
337
313   setdefaults(gp)                 /* set default values */
314   register HDGRID *gp;
315   {
# Line 357 | Line 332 | register HDGRID        *gp;
332                  sprintf(vval(OCTREE), "%s.oct", froot);
333                  vdef(OCTREE)++;
334          }
360        if (!vdef(OBSTRUCTIONS)) {
361                vval(OBSTRUCTIONS) = "T";
362                vdef(OBSTRUCTIONS)++;
363        }
335          if (!vdef(VDIST)) {
336                  vval(VDIST) = "F";
337                  vdef(VDIST)++;
338          }
368        if (!vdef(OCCUPANCY)) {
369                vval(OCCUPANCY) = "U";
370                vdef(OCCUPANCY)++;
371        }
339                                  /* append rendering options */
340          if (vdef(RENDER))
341                  rtargc += wordstring(rtargv+rtargc, vval(RENDER));
# Line 513 | Line 480 | PACKET *pl;
480   }
481  
482  
516 int
517 done_rtrace()                   /* clean up and close rtrace calculation */
518 {
519        int     status;
520                                        /* already closed? */
521        if (!nprocs)
522                return;
523                                        /* report activity */
524        wputs("closing rtrace process...\n");
525                                        /* flush beam queue */
526        done_packets(flush_queue());
527                                        /* close rtrace */
528        if ((status = end_rtrace()))
529                error(WARNING, "bad exit status from rtrace");
530        if (vdef(REPORT))               /* report time */
531                report(0);
532        return(status);                 /* return status */
533 }
534
535
536 new_rtrace()                    /* restart rtrace calculation */
537 {
538        char    combuf[128];
539
540        if (nprocs > 0)                 /* already running? */
541                return;
542        wputs("restarting rtrace process...\n");
543        if (vdef(RIF)) {                /* rerun rad to update octree */
544                sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF));
545                if (system(combuf))
546                        error(WARNING, "error running rad");
547        }
548        if (start_rtrace() < 1)         /* start rtrace */
549                error(WARNING, "cannot restart rtrace");
550        else if (vdef(REPORT))
551                report(0);
552 }
553
554
555 getradfile(rfargs)              /* run rad and get needed variables */
556 char    *rfargs;
557 {
558        static short    mvar[] = {OCTREE,-1};
559        static char     tf1[] = TEMPLATE;
560        char    tf2[64];
561        char    combuf[256];
562        char    *pippt;
563        register int    i;
564        register char   *cp;
565                                        /* create rad command */
566        mktemp(tf1);
567        sprintf(tf2, "%s.rif", tf1);
568        sprintf(combuf,
569                "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
570                        rfargs, tf1);
571        cp = combuf;
572        while (*cp){
573                if (*cp == '|') pippt = cp;
574                cp++;
575        }                               /* match unset variables */
576        for (i = 0; mvar[i] >= 0; i++)
577                if (!vdef(mvar[i])) {
578                        *cp++ = '|';
579                        strcpy(cp, vnam(mvar[i]));
580                        while (*cp) cp++;
581                        pippt = NULL;
582                }
583        if (pippt != NULL)
584                strcpy(pippt, "> /dev/null");   /* nothing to match */
585        else
586                sprintf(cp, ")[ \t]*=' > %s", tf2);
587        if (system(combuf)) {
588                unlink(tf2);                    /* clean up */
589                unlink(tf1);
590                error(SYSTEM, "cannot execute rad command");
591        }
592        if (pippt == NULL) {
593                loadvars(tf2);                  /* load variables */
594                unlink(tf2);
595        }
596        rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
597        unlink(tf1);                    /* clean up */
598 }
599
600
483   rootname(rn, fn)                /* remove tail from end of fn */
484   register char   *rn, *fn;
485   {
486          char    *tp, *dp;
487  
488          for (tp = NULL, dp = rn; *rn = *fn++; rn++)
489 <                if (ISDIRSEP(*rn))
489 >                if (*rn == '/')
490                          dp = rn;
491                  else if (*rn == '.')
492                          tp = rn;
# Line 653 | Line 535 | int    ec;
535   {
536          int     status = 0;
537  
538 <        if (hdlist[0] != NULL) {        /* flush holodeck */
538 >        if (hdlist[0] != NULL) {        /* close holodeck */
539                  if (nprocs > 0)
540 <                        status = done_rtrace();
659 <                hdflush(NULL);
540 >                        status = done_rtrace();         /* calls hdsync() */
541                  if (ncprocs > 0 && vdef(REPORT)) {
542                          long    fsiz, fuse;
543                          fsiz = hdfilen(hdlist[0]->fd);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines