ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/rt/rmain.c
(Generate patch)

Comparing ray/src/rt/rmain.c (file contents):
Revision 1.47 by greg, Mon Oct 21 12:58:03 1991 UTC vs.
Revision 2.41 by greg, Sat Jul 6 21:59:00 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1996 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 11 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11   */
12  
13                                          /* for flaky pre-processors */
14 < #ifndef  RPICT
15 < #define  RPICT          0
14 > #ifndef  RPICT
15 > #define  RPICT          0
16   #endif
17 < #ifndef  RTRACE
18 < #define  RTRACE         0
17 > #ifndef  RTRACE
18 > #define  RTRACE         0
19   #endif
20 < #ifndef  RVIEW
21 < #define  RVIEW          0
20 > #ifndef  RVIEW
21 > #define  RVIEW          0
22   #endif
23  
24   #include  "ray.h"
25  
26 + #include  "resolu.h"
27 +
28   #include  "octree.h"
29  
30 + #include  <sys/types.h>
31 +
32   #include  <signal.h>
33  
34   #include  "view.h"
35  
36 < #ifndef  DEFPATH
37 < #define  DEFPATH        ":/usr/local/lib/ray"
36 > #include  "paths.h"
37 >                                        /* persistent processes define */
38 > #ifdef  F_SETLKW
39 > #if  RPICT|RTRACE
40 > #define  PERSIST        1               /* normal persist */
41 > #define  PARALLEL       2               /* parallel persist */
42 > #define  PCHILD         3               /* child of normal persist */
43   #endif
35 #ifndef  ULIBVAR
36 #define  ULIBVAR        "RAYPATH"
44   #endif
45  
46   char  *progname;                        /* argv[0] */
47  
48   char  *octname;                         /* octree name */
49  
50 < char  *libpath;                         /* library directory list */
50 > char  *getlibpath();                    /* library directory list */
51  
52   char  *sigerr[NSIG];                    /* signal error messages */
53  
54 + char  *shm_boundary = NULL;             /* boundary of shared memory */
55 +
56   extern char  VersionID[];               /* version ID string */
57  
58   extern int  stderr_v();                 /* standard error output */
# Line 54 | Line 63 | int  (*cmdvec)() = NULL;               /* command error vector */
63   int  (*trace)() = NULL;                 /* trace call */
64   int  do_irrad = 0;                      /* compute irradiance? */
65  
66 < extern long  time();
58 < long  tstart;                           /* start time */
66 > char  *errfile = NULL;                  /* error output file */
67  
68 + extern time_t  time();
69 + time_t  tstart;                         /* start time */
70 +
71   extern int  ambnotify();                /* new object notify functions */
72 + #if  RTRACE
73 + extern int  tranotify();
74 + int  (*addobjnotify[])() = {ambnotify, tranotify, NULL};
75 + extern char  *tralist[];                /* trace include/exclude list */
76 + extern int  traincl;                    /* include == 1, exclude == 0 */
77 + #else
78   int  (*addobjnotify[])() = {ambnotify, NULL};
79 + #endif
80  
81   CUBE  thescene;                         /* our scene */
82 + OBJECT  nsceneobjs;                     /* number of objects in our scene */
83  
84 + extern unsigned long  raynum, nrays;    /* ray counts */
85 +
86   extern int  imm_irrad;                  /* calculate immediate irradiance? */
87  
88   extern int  ralrm;                      /* seconds between reports */
89  
90   extern int  greyscale;                  /* map colors to brightness? */
91   extern char  *devname;                  /* output device name */
92 + extern double  exposure;                /* exposure compensation */
93  
94 + extern char  *formstr();                /* string from format */
95   extern int  inform;                     /* input format */
96   extern int  outform;                    /* output format */
97   extern char  *outvals;                  /* output values */
98  
99   extern VIEW  ourview;                   /* viewing parameters */
100  
101 + extern char  rifname[];                 /* rad input file name */
102 +
103   extern int  hresolu;                    /* horizontal resolution */
104   extern int  vresolu;                    /* vertical resolution */
105   extern double  pixaspect;               /* pixel aspect ratio */
# Line 88 | Line 113 | extern double  shadthresh;             /* shadow threshold */
113   extern double  shadcert;                /* shadow testing certainty */
114   extern int  directrelay;                /* number of source relays */
115   extern int  vspretest;                  /* virtual source pretest density */
116 < extern int  directinvis;                /* light sources invisible to eye? */
116 > extern int  directvis;                  /* light sources visible to eye? */
117   extern double  srcsizerat;              /* maximum source size/dist. ratio */
118  
119 + extern double  specthresh;              /* specular sampling threshold */
120 + extern double  specjitter;              /* specular sampling jitter */
121 +
122 + extern COLOR  cextinction;              /* global extinction coefficient */
123 + extern COLOR  salbedo;                  /* global scattering albedo */
124 + extern double  seccg;                   /* global scattering eccentricity */
125 + extern double  ssampdist;               /* scatter sampling distance */
126 +
127 + extern int  backvis;                    /* back face visibility */
128 +
129   extern int  maxdepth;                   /* maximum recursion depth */
130   extern double  minweight;               /* minimum ray weight */
131  
132   extern COLOR  ambval;                   /* ambient value */
133 + extern int  ambvwt;                     /* initial weight for ambient value */
134   extern double  ambacc;                  /* ambient accuracy */
135   extern int  ambres;                     /* ambient resolution */
136   extern int  ambdiv;                     /* ambient divisions */
# Line 108 | Line 144 | main(argc, argv)
144   int  argc;
145   char  *argv[];
146   {
147 < #define  check(olen,narg)       if (argv[i][olen] || narg >= argc-i) goto badopt
148 < #define  bool(olen,var)         switch (argv[i][olen]) { \
147 > #define  check(ol,al)           if (argv[i][ol] || \
148 >                                badarg(argc-i-1,argv+i+1,al)) \
149 >                                goto badopt
150 > #define  bool(olen,var)         switch (argv[i][olen]) { \
151                                  case '\0': var = !var; break; \
152                                  case 'y': case 'Y': case 't': case 'T': \
153                                  case '+': case '1': var = 1; break; \
154                                  case 'n': case 'N': case 'f': case 'F': \
155                                  case '-': case '0': var = 0; break; \
156                                  default: goto badopt; }
119        extern double  atof();
120        extern char  *getenv();
157          char  *err;
158          char  *recover = NULL;
159 +        char  *outfile = NULL;
160          char  *zfile = NULL;
124        char  *errfile = NULL;
161          char  *ambfile = NULL;
126        char  **amblp = amblist;
162          int  loadflags = ~IO_FILES;
163 <        int  rval, gotvfile = 0;
163 >        int  seqstart = 0;
164 >        int  persist = 0;
165 >        char  **amblp;
166 >        char  **tralp;
167 >        int  duped1;
168 >        int  rval;
169          int  i;
170                                          /* record start time */
171 <        tstart = time((long *)0);
171 >        tstart = time((time_t *)NULL);
172                                          /* global program name */
173 <        progname = argv[0];
134 <                                        /* get library path */
135 <        if ((libpath = getenv(ULIBVAR)) == NULL)
136 <                libpath = DEFPATH;
173 >        progname = argv[0] = fixargv0(argv[0]);
174                                          /* initialize object types */
175          initotypes();
176                                          /* initialize urand */
177          initurand(2048);
178                                          /* option city */
179 <        for (i = 1; i < argc && argv[i][0] == '-'; i++) {
179 >        for (i = 1; i < argc; i++) {
180 >                                                /* expand arguments */
181 >                while (rval = expandarg(&argc, &argv, i))
182 >                        if (rval < 0) {
183 >                                sprintf(errmsg, "cannot expand '%s'", argv[i]);
184 >                                error(SYSTEM, errmsg);
185 >                        }
186 >                if (argv[i] == NULL || argv[i][0] != '-')
187 >                        break;                  /* break from options */
188                  if (!strcmp(argv[i], "-version")) {
189                          puts(VersionID);
190                          quit(0);
# Line 167 | Line 212 | char  *argv[];
212                  case 'v':                               /* view file */
213                          if (argv[i][2] != 'f')
214                                  goto badopt;
215 <                        check(3,1);
216 <                        rval = viewfile(argv[++i], &ourview, 0, 0);
215 >                        check(3,"s");
216 >                        rval = viewfile(argv[++i], &ourview, NULL);
217                          if (rval < 0) {
218                                  sprintf(errmsg,
219                                  "cannot open view file \"%s\"",
# Line 179 | Line 224 | char  *argv[];
224                                          "bad view file \"%s\"",
225                                                  argv[i]);
226                                  error(USER, errmsg);
227 <                        } else
183 <                                gotvfile += rval;
227 >                        }
228                          break;
229   #endif
230 +                case 'b':                               /* back face vis. */
231 +                        if (argv[i][2] == 'v') {
232 +                                bool(3,backvis);
233 +                                break;
234 +                        }
235 + #if  RVIEW
236 +                        bool(2,greyscale);
237 +                        break;
238 + #else
239 +                        goto badopt;
240 + #endif
241                  case 'd':                               /* direct */
242                          switch (argv[i][2]) {
243                          case 't':                               /* threshold */
244 <                                check(3,1);
244 >                                check(3,"f");
245                                  shadthresh = atof(argv[++i]);
246                                  break;
247                          case 'c':                               /* certainty */
248 <                                check(3,1);
248 >                                check(3,"f");
249                                  shadcert = atof(argv[++i]);
250                                  break;
251                          case 'j':                               /* jitter */
252 <                                check(3,1);
252 >                                check(3,"f");
253                                  dstrsrc = atof(argv[++i]);
254                                  break;
255                          case 'r':                               /* relays */
256 <                                check(3,1);
256 >                                check(3,"i");
257                                  directrelay = atoi(argv[++i]);
258                                  break;
259                          case 'p':                               /* pretest */
260 <                                check(3,1);
260 >                                check(3,"i");
261                                  vspretest = atoi(argv[++i]);
262                                  break;
263 <                        case 'i':                               /* invis. */
264 <                                bool(3,directinvis);
263 >                        case 'v':                               /* visibility */
264 >                                bool(3,directvis);
265                                  break;
266                          case 's':                               /* size */
267 <                                check(3,1);
267 >                                check(3,"f");
268                                  srcsizerat = atof(argv[++i]);
269                                  break;
270                          default:
271                                  goto badopt;
272                          }
273                          break;
274 +                case 's':                               /* specular */
275 +                        switch (argv[i][2]) {
276 +                        case 't':                               /* threshold */
277 +                                check(3,"f");
278 +                                specthresh = atof(argv[++i]);
279 +                                break;
280 +                        case 'j':                               /* jitter */
281 +                                check(3,"f");
282 +                                specjitter = atof(argv[++i]);
283 +                                break;
284 +                        default:
285 +                                goto badopt;
286 +                        }
287 +                        break;
288   #if  RPICT|RVIEW
289 <                case 's':                               /* sample */
289 >                case 'p':                               /* pixel */
290                          switch (argv[i][2]) {
291 <                        case 'p':                               /* pixel */
292 <                                check(3,1);
291 >                        case 's':                               /* sample */
292 >                                check(3,"i");
293                                  psample = atoi(argv[++i]);
294                                  break;
295                          case 't':                               /* threshold */
296 <                                check(3,1);
296 >                                check(3,"f");
297                                  maxdiff = atof(argv[++i]);
298                                  break;
299   #if  RPICT
300                          case 'j':                               /* jitter */
301 <                                check(3,1);
301 >                                check(3,"f");
302                                  dstrpix = atof(argv[++i]);
303                                  break;
304 +                        case 'a':                               /* aspect */
305 +                                check(3,"f");
306 +                                pixaspect = atof(argv[++i]);
307 +                                break;
308   #endif
309 + #if  RVIEW
310 +                        case 'e':                               /* exposure */
311 +                                check(3,"f");
312 +                                exposure = atof(argv[++i]);
313 +                                if (argv[i][0] == '+' || argv[i][0] == '-')
314 +                                        exposure = pow(2.0, exposure);
315 +                                break;
316 + #endif
317                          default:
318                                  goto badopt;
319                          }
# Line 240 | Line 321 | char  *argv[];
321   #endif
322   #if  RPICT|RTRACE
323                  case 'x':                               /* x resolution */
324 <                        check(2,1);
324 >                        check(2,"i");
325                          hresolu = atoi(argv[++i]);
326                          break;
327                  case 'y':                               /* y resolution */
328 <                        check(2,1);
328 >                        check(2,"i");
329                          vresolu = atoi(argv[++i]);
330                          break;
331   #endif
251 #if  RPICT      
252                case 'p':                               /* pixel aspect */
253                        check(2,1);
254                        pixaspect = atof(argv[++i]);
255                        break;
256 #endif
332                  case 'w':                               /* warnings */
333                          rval = wrnvec != NULL;
334                          bool(2,rval);
335 <                        wrnvec = rval ? stderr_v : NULL;
335 >                        if (rval) wrnvec = stderr_v;
336 >                        else wrnvec = NULL;
337                          break;
338                  case 'e':                               /* error file */
339 <                        check(2,1);
339 >                        check(2,"s");
340                          errfile = argv[++i];
341                          break;
342                  case 'l':                               /* limit */
343                          switch (argv[i][2]) {
344                          case 'r':                               /* recursion */
345 <                                check(3,1);
345 >                                check(3,"i");
346                                  maxdepth = atoi(argv[++i]);
347                                  break;
348                          case 'w':                               /* weight */
349 <                                check(3,1);
349 >                                check(3,"f");
350                                  minweight = atof(argv[++i]);
351                                  break;
352                          default:
# Line 281 | Line 357 | char  *argv[];
357                          bool(2,do_irrad);
358                          break;
359   #if  RPICT
360 +                case 'S':                               /* slave index */
361 +                        check(2,"i");
362 +                        seqstart = atoi(argv[++i]);
363 +                        break;
364 +                case 'o':                               /* output file */
365 +                        check(2,"s");
366 +                        outfile = argv[++i];
367 +                        break;
368                  case 'z':                               /* z file */
369 <                        check(2,1);
369 >                        check(2,"s");
370                          zfile = argv[++i];
371                          break;
372                  case 'r':                               /* recover file */
373 <                        check(2,1);
373 >                        if (argv[i][2] == 'o') {                /* +output */
374 >                                check(3,"s");
375 >                                outfile = argv[i+1];
376 >                        } else
377 >                                check(2,"s");
378                          recover = argv[++i];
291                        rval = viewfile(recover, &ourview, &hresolu, &vresolu);
292                        if (rval <= 0) {
293                                sprintf(errmsg,
294                        "cannot recover view parameters from \"%s\"", recover);
295                                error(WARNING, errmsg);
296                        } else {
297                                gotvfile += rval;
298                                pixaspect = 0.0;
299                        }
379                          break;
380                  case 't':                               /* timer */
381 <                        check(2,1);
381 >                        check(2,"i");
382                          ralrm = atoi(argv[++i]);
383                          break;
384   #endif
385                  case 'a':                               /* ambient */
386                          switch (argv[i][2]) {
387                          case 'v':                               /* value */
388 <                                check(3,3);
388 >                                check(3,"fff");
389                                  setcolor(ambval, atof(argv[i+1]),
390                                                  atof(argv[i+2]),
391                                                  atof(argv[i+3]));
392                                  i += 3;
393                                  break;
394 +                        case 'w':                               /* weight */
395 +                                check(3,"i");
396 +                                ambvwt = atoi(argv[++i]);
397 +                                break;
398                          case 'a':                               /* accuracy */
399 <                                check(3,1);
399 >                                check(3,"f");
400                                  ambacc = atof(argv[++i]);
401                                  break;
402                          case 'r':                               /* resolution */
403 <                                check(3,1);
403 >                                check(3,"i");
404                                  ambres = atoi(argv[++i]);
405                                  break;
406                          case 'd':                               /* divisions */
407 <                                check(3,1);
407 >                                check(3,"i");
408                                  ambdiv = atoi(argv[++i]);
409                                  break;
410                          case 's':                               /* super-samp */
411 <                                check(3,1);
411 >                                check(3,"i");
412                                  ambssamp = atoi(argv[++i]);
413                                  break;
414                          case 'b':                               /* bounces */
415 <                                check(3,1);
415 >                                check(3,"i");
416                                  ambounce = atoi(argv[++i]);
417                                  break;
418                          case 'i':                               /* include */
419 <                                check(3,1);
419 >                        case 'I':
420 >                                check(3,"s");
421                                  if (ambincl != 1) {
422                                          ambincl = 1;
423                                          amblp = amblist;
424                                  }
425 <                                *amblp++ = argv[++i];
425 >                                if (argv[i][2] == 'I') {        /* file */
426 >                                        rval = wordfile(amblp,
427 >                                        getpath(argv[++i],getlibpath(),R_OK));
428 >                                        if (rval < 0) {
429 >                                                sprintf(errmsg,
430 >                                "cannot open ambient include file \"%s\"",
431 >                                                                argv[i]);
432 >                                                error(SYSTEM, errmsg);
433 >                                        }
434 >                                        amblp += rval;
435 >                                } else {
436 >                                        *amblp++ = argv[++i];
437 >                                        *amblp = NULL;
438 >                                }
439                                  break;
440                          case 'e':                               /* exclude */
441 <                                check(3,1);
441 >                        case 'E':
442 >                                check(3,"s");
443                                  if (ambincl != 0) {
444                                          ambincl = 0;
445                                          amblp = amblist;
446                                  }
447 <                                *amblp++ = argv[++i];
447 >                                if (argv[i][2] == 'E') {        /* file */
448 >                                        rval = wordfile(amblp,
449 >                                        getpath(argv[++i],getlibpath(),R_OK));
450 >                                        if (rval < 0) {
451 >                                                sprintf(errmsg,
452 >                                "cannot open ambient exclude file \"%s\"",
453 >                                                                argv[i]);
454 >                                                error(SYSTEM, errmsg);
455 >                                        }
456 >                                        amblp += rval;
457 >                                } else {
458 >                                        *amblp++ = argv[++i];
459 >                                        *amblp = NULL;
460 >                                }
461                                  break;
462                          case 'f':                               /* file */
463 <                                check(3,1);
463 >                                check(3,"s");
464                                  ambfile= argv[++i];
465                                  break;
466                          default:
467                                  goto badopt;
468                          }
469                          break;
470 +                case 'm':                               /* medium */
471 +                        switch (argv[i][2]) {
472 +                        case 'e':                               /* extinction */
473 +                                check(3,"fff");
474 +                                setcolor(cextinction, atof(argv[i+1]),
475 +                                                atof(argv[i+2]),
476 +                                                atof(argv[i+3]));
477 +                                i += 3;
478 +                                break;
479 +                        case 'a':                               /* albedo */
480 +                                check(3,"fff");
481 +                                setcolor(salbedo, atof(argv[i+1]),
482 +                                                atof(argv[i+2]),
483 +                                                atof(argv[i+3]));
484 +                                i += 3;
485 +                                break;
486 +                        case 'g':                               /* eccentr. */
487 +                                check(3,"f");
488 +                                seccg = atof(argv[++i]);
489 +                                break;
490 +                        case 's':                               /* sampling */
491 +                                check(3,"f");
492 +                                ssampdist = atof(argv[++i]);
493 +                                break;
494 +                        default:
495 +                                goto badopt;
496 +                        }
497 +                        break;
498   #if  RTRACE
499                  case 'I':                               /* immed. irradiance */
500                          bool(2,imm_irrad);
# Line 377 | Line 516 | char  *argv[];
516                          case 'a':                               /* ascii */
517                          case 'f':                               /* float */
518                          case 'd':                               /* double */
519 <                                check(4,0);
519 >                        case 'c':                               /* color */
520 >                                check(4,"");
521                                  outform = argv[i][3];
522                                  break;
523                          default:
# Line 393 | Line 533 | char  *argv[];
533                          loadflags = rval ? loadflags | IO_INFO :
534                                          loadflags & ~IO_INFO;
535                          break;
536 +                case 't':                               /* trace */
537 +                        switch (argv[i][2]) {
538 +                        case 'i':                               /* include */
539 +                        case 'I':
540 +                                check(3,"s");
541 +                                if (traincl != 1) {
542 +                                        traincl = 1;
543 +                                        tralp = tralist;
544 +                                }
545 +                                if (argv[i][2] == 'I') {        /* file */
546 +                                        rval = wordfile(tralp,
547 +                                        getpath(argv[++i],getlibpath(),R_OK));
548 +                                        if (rval < 0) {
549 +                                                sprintf(errmsg,
550 +                                "cannot open trace include file \"%s\"",
551 +                                                                argv[i]);
552 +                                                error(SYSTEM, errmsg);
553 +                                        }
554 +                                        tralp += rval;
555 +                                } else {
556 +                                        *tralp++ = argv[++i];
557 +                                        *tralp = NULL;
558 +                                }
559 +                                break;
560 +                        case 'e':                               /* exclude */
561 +                        case 'E':
562 +                                check(3,"s");
563 +                                if (traincl != 0) {
564 +                                        traincl = 0;
565 +                                        tralp = tralist;
566 +                                }
567 +                                if (argv[i][2] == 'E') {        /* file */
568 +                                        rval = wordfile(tralp,
569 +                                        getpath(argv[++i],getlibpath(),R_OK));
570 +                                        if (rval < 0) {
571 +                                                sprintf(errmsg,
572 +                                "cannot open trace exclude file \"%s\"",
573 +                                                                argv[i]);
574 +                                                error(SYSTEM, errmsg);
575 +                                        }
576 +                                        tralp += rval;
577 +                                } else {
578 +                                        *tralp++ = argv[++i];
579 +                                        *tralp = NULL;
580 +                                }
581 +                                break;
582 +                        default:
583 +                                goto badopt;
584 +                        }
585 +                        break;
586   #endif
587   #if  RVIEW
398                case 'b':                               /* black and white */
399                        check(2,0);
400                        greyscale = !greyscale;
401                        break;
588                  case 'o':                               /* output device */
589 <                        check(2,1);
589 >                        check(2,"s");
590                          devname = argv[++i];
591                          break;
592 +                case 'R':                               /* render input file */
593 +                        check(2,"s");
594 +                        strcpy(rifname, argv[++i]);
595 +                        break;
596   #endif
597 + #ifdef  PERSIST
598 +                case 'P':                               /* persist file */
599 +                        if (argv[i][2] == 'P') {
600 +                                check(3,"s");
601 +                                persist = PARALLEL;
602 +                        } else {
603 +                                check(2,"s");
604 +                                persist = PERSIST;
605 +                        }
606 +                        persistfile(argv[++i]);
607 +                        break;
608 + #endif
609                  default:
610                          goto badopt;
611                  }
612          }
411        *amblp = NULL;
613   #if  RPICT|RVIEW
614          err = setview(&ourview);        /* set viewing parameters */
615          if (err != NULL)
616                  error(USER, err);
617   #endif
417 #if  RPICT
418        normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu);
419 #endif
618                                          /* set up signal handling */
619          sigdie(SIGINT, "Interrupt");
620          sigdie(SIGHUP, "Hangup");
621          sigdie(SIGTERM, "Terminate");
622          sigdie(SIGPIPE, "Broken pipe");
623          sigdie(SIGALRM, "Alarm clock");
624 < #ifdef  SIGXCPU
624 > #ifdef  SIGXCPU
625          sigdie(SIGXCPU, "CPU limit exceeded");
626          sigdie(SIGXFSZ, "File size exceeded");
627   #endif
# Line 434 | Line 632 | char  *argv[];
632                  fprintf(stderr, "**************\n*** PID %5d: ",
633                                  getpid());
634                  printargs(argc, argv, stderr);
635 <                fputs("\n", stderr);
635 >                putc('\n', stderr);
636                  fflush(stderr);
637          }
638 < #ifdef  NICE
638 > #ifdef  NICE
639          nice(NICE);                     /* lower priority */
640   #endif
641                                          /* get octree */
# Line 450 | Line 648 | char  *argv[];
648                  octname = argv[i];
649          else
650                  goto badopt;
651 < #if  RVIEW|RTRACE
652 <        if (octname == NULL)
651 >        if (
652 > #if  RPICT
653 >                seqstart > 0 &&
654 > #endif
655 >                        octname == NULL)
656                  error(USER, "missing octree argument");
657 +                                        /* set up output */
658 + #ifdef  PERSIST
659 +        if (persist) {
660 + #if  RPICT
661 +                if (recover != NULL)
662 +                        error(USER, "persist option used with recover file");
663 +                if (seqstart <= 0)
664 +                        error(USER, "persist option only for sequences");
665 +                if (outfile == NULL)
666   #endif
667 +                duped1 = dup(fileno(stdout));   /* don't lose our output */
668 +                openheader();
669 +        }
670 + #if  RPICT
671 +        else
672 + #endif
673 + #endif
674 + #if  RPICT
675 +        if (outfile != NULL)
676 +                openheader();
677 + #endif
678 + #ifdef  MSDOS
679 + #if  RTRACE
680 +        if (outform != 'a')
681 + #endif
682 +        setmode(fileno(stdout), O_BINARY);
683 +        if (octname == NULL)
684 +                setmode(fileno(stdin), O_BINARY);
685 + #endif
686          readoct(octname, loadflags, &thescene, NULL);
687 +        nsceneobjs = nobjects;
688  
689          if (loadflags & IO_INFO) {      /* print header */
690                  printargs(i, argv, stdout);
691                  printf("SOFTWARE= %s\n", VersionID);
462 #if  RPICT
463                if (gotvfile) {
464                        printf(VIEWSTR);
465                        fprintview(&ourview, stdout);
466                        printf("\n");
467                }
468                if (pixaspect < .99 || pixaspect > 1.01)
469                        fputaspect(pixaspect, stdout);
470                fputformat(COLRFMT, stdout);
471 #endif
692   #if  RTRACE
693 <                fputformat(     outform=='a' ? "ascii" :
694 <                                outform=='f' ? "float" :
475 <                                "double",       stdout  );
693 >                fputformat(formstr(outform), stdout);
694 >                putchar('\n');
695   #endif
477                printf("\n");
696          }
697  
698          marksources();                  /* find and mark sources */
699  
700          setambient(ambfile);            /* initialize ambient calculation */
701  
702 + #ifdef  PERSIST
703 +        if (persist) {
704 +                fflush(stdout);
705 +                if (outfile == NULL) {          /* reconnect stdout */
706 +                        dup2(duped1, fileno(stdout));
707 +                        close(duped1);
708 +                }
709 +                if (persist == PARALLEL) {      /* multiprocessing */
710 +                        preload_objs();         /* preload scene */
711 +                        strcpy(shm_boundary=bmalloc(16), "SHM_BOUNDARY");
712 +                        while ((rval=fork()) == 0) {    /* keep on forkin' */
713 +                                pflock(1);
714 +                                pfhold();
715 +                                tstart = time((time_t *)NULL);
716 +                        }
717 +                        if (rval < 0)
718 +                                error(SYSTEM, "cannot fork child for persist function");
719 +                        pfdetach();             /* parent exits */
720 +                }
721 +        }
722 + runagain:
723 +        if (persist)
724 +                if (outfile == NULL)                    /* if out to stdout */
725 +                        dupheader();                    /* send header */
726 +                else                                    /* if out to file */
727 +                        duped1 = dup(fileno(stdout));   /* hang onto pipe */
728 + #endif
729   #if  RPICT
730 <        render(zfile, recover);         /* render the scene */
730 >        rpict(seqstart, outfile, zfile, recover);
731   #endif
732   #if  RTRACE
733 <        rtrace(NULL);                   /* trace rays from stdin */
733 >        rtrace(NULL);
734   #endif
735   #if  RVIEW
736 <        rview();                        /* go */
736 >        rview();
737   #endif
738 +        ambsync();                      /* flush ambient file */
739 + #ifdef  PERSIST
740 +        if (persist == PERSIST) {       /* first run-through */
741 +                if ((rval=fork()) == 0) {       /* child loops until killed */
742 +                        pflock(1);
743 +                        persist = PCHILD;
744 +                } else {                        /* original process exits */
745 +                        if (rval < 0)
746 +                                error(SYSTEM, "cannot fork child for persist function");
747 +                        pfdetach();             /* parent exits */
748 +                }
749 +        }
750 +        if (persist == PCHILD) {        /* wait for a signal then go again */
751 +                if (outfile != NULL)
752 +                        close(duped1);          /* release output handle */
753 +                pfhold();
754 +                tstart = time((time_t *)NULL);  /* reinitialize */
755 +                raynum = nrays = 0;
756 +                goto runagain;
757 +        }
758 + #endif
759          quit(0);
760  
761   badopt:
762          sprintf(errmsg, "command line error at '%s'", argv[i]);
763          error(USER, errmsg);
764  
765 < #undef  check
766 < #undef  bool
765 > #undef  check
766 > #undef  bool
767   }
768  
769  
# Line 512 | Line 778 | char  *s;
778   wputs(s)                                /* warning output */
779   char  *s;
780   {
781 +        int  lasterrno = errno;         /* save errno */
782 +
783          if (wrnvec != NULL)
784                  (*wrnvec)(s);
785 +
786 +        errno = lasterrno;
787   }
788  
789  
# Line 552 | Line 822 | int  signo;
822          if (gotsig++)                   /* two signals and we're gone! */
823                  _exit(signo);
824  
825 +        alarm(15);                      /* allow 15 seconds to clean up */
826 +        signal(SIGALRM, SIG_DFL);       /* make certain we do die */
827          eputs("signal - ");
828          eputs(sigerr[signo]);
829          eputs("\n");
# Line 580 | Line 852 | printdefaults()                        /* print default values to stdout */
852   #endif
853          printf(do_irrad ? "-i+\t\t\t\t# irradiance calculation on\n" :
854                          "-i-\t\t\t\t# irradiance calculation off\n");
855 + #if  RVIEW
856 +        printf(greyscale ? "-b+\t\t\t\t# greyscale on\n" :
857 +                        "-b-\t\t\t\t# greyscale off\n");
858 + #endif
859   #if  RPICT|RVIEW
860          printf("-vt%c\t\t\t\t# view type %s\n", ourview.type,
861                          ourview.type==VT_PER ? "perspective" :
862                          ourview.type==VT_PAR ? "parallel" :
863                          ourview.type==VT_HEM ? "hemispherical" :
864                          ourview.type==VT_ANG ? "angular" :
865 +                        ourview.type==VT_CYL ? "cylindrical" :
866                          "unknown");
867          printf("-vp %f %f %f\t# view point\n",
868                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
869 <        printf("-vd %f %f %f\t# view direction\n",
869 >        printf("-vd %f %f %f\t# view direction\n",
870                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
871 <        printf("-vu %f %f %f\t# view up\n",
871 >        printf("-vu %f %f %f\t# view up\n",
872                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
873          printf("-vh %f\t\t\t# view horizontal size\n", ourview.horiz);
874          printf("-vv %f\t\t\t# view vertical size\n", ourview.vert);
875 +        printf("-vo %f\t\t\t# view fore clipping plane\n", ourview.vfore);
876 +        printf("-va %f\t\t\t# view aft clipping plane\n", ourview.vaft);
877          printf("-vs %f\t\t\t# view shift\n", ourview.hoff);
878          printf("-vl %f\t\t\t# view lift\n", ourview.voff);
879   #endif
# Line 603 | Line 882 | printdefaults()                        /* print default values to stdout */
882          printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
883   #endif
884   #if  RPICT
885 <        printf("-p  %f\t\t\t# pixel aspect ratio\n", pixaspect);
885 >        printf("-pa %f\t\t\t# pixel aspect ratio\n", pixaspect);
886 >        printf("-pj %f\t\t\t# pixel jitter\n", dstrpix);
887   #endif
888 + #if  RVIEW
889 +        printf("-pe %f\t\t\t# pixel exposure\n", exposure);
890 + #endif
891   #if  RPICT|RVIEW
892 <        printf("-sp %-9d\t\t\t# sample pixel\n", psample);
893 <        printf("-st %f\t\t\t# sample threshold\n", maxdiff);
892 >        printf("-ps %-9d\t\t\t# pixel sample\n", psample);
893 >        printf("-pt %f\t\t\t# pixel threshold\n", maxdiff);
894   #endif
895 < #if  RPICT
896 <        printf("-sj %f\t\t\t# sample jitter\n", dstrpix);
614 < #endif
895 >        printf(backvis ? "-bv+\t\t\t\t# back face visibility on\n" :
896 >                        "-bv-\t\t\t\t# back face visibility off\n");
897          printf("-dt %f\t\t\t# direct threshold\n", shadthresh);
898          printf("-dc %f\t\t\t# direct certainty\n", shadcert);
899          printf("-dj %f\t\t\t# direct jitter\n", dstrsrc);
900          printf("-ds %f\t\t\t# direct sampling\n", srcsizerat);
901          printf("-dr %-9d\t\t\t# direct relays\n", directrelay);
902          printf("-dp %-9d\t\t\t# direct pretest density\n", vspretest);
903 <        printf(directinvis ? "-di+\t\t\t\t# direct invisibility on\n" :
904 <                        "-di-\t\t\t\t# direct invisibility off\n");
903 >        printf(directvis ? "-dv+\t\t\t\t# direct visibility on\n" :
904 >                        "-dv-\t\t\t\t# direct visibility off\n");
905 >        printf("-sj %f\t\t\t# specular jitter\n", specjitter);
906 >        printf("-st %f\t\t\t# specular threshold\n", specthresh);
907          printf("-av %f %f %f\t# ambient value\n", colval(ambval,RED),
908                          colval(ambval,GRN), colval(ambval, BLU));
909 +        printf("-aw %-9d\t\t\t# ambient value weight\n", ambvwt);
910          printf("-ab %-9d\t\t\t# ambient bounces\n", ambounce);
911          printf("-aa %f\t\t\t# ambient accuracy\n", ambacc);
912          printf("-ar %-9d\t\t\t# ambient resolution\n", ambres);
913          printf("-ad %-9d\t\t\t# ambient divisions\n", ambdiv);
914          printf("-as %-9d\t\t\t# ambient super-samples\n", ambssamp);
915 +        printf("-me %.2e %.2e %.2e\t# extinction coefficient\n",
916 +                        colval(cextinction,RED),
917 +                        colval(cextinction,GRN),
918 +                        colval(cextinction,BLU));
919 +        printf("-ma %f %f %f\t# scattering albedo\n", colval(salbedo,RED),
920 +                        colval(salbedo,GRN), colval(salbedo,BLU));
921 +        printf("-mg %f\t\t\t# scattering eccentricity\n", seccg);
922 +        printf("-ms %f\t\t\t# mist sampling distance\n", ssampdist);
923          printf("-lr %-9d\t\t\t# limit reflection\n", maxdepth);
924          printf("-lw %f\t\t\t# limit weight\n", minweight);
925   #if  RPICT
# Line 637 | Line 930 | printdefaults()                        /* print default values to stdout */
930   #endif
931   #if  RTRACE
932          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
933 <                        inform, outform,
641 <                        inform=='a' ? "ascii" :
642 <                        inform=='f' ? "float" : "double",
643 <                        outform=='a' ? "ascii" :
644 <                        outform=='f' ? "float" : "double");
933 >                        inform, outform, formstr(inform), formstr(outform));
934          printf("-o%s\t\t\t\t# output", outvals);
935          for (cp = outvals; *cp; cp++)
936                  switch (*cp) {
# Line 650 | Line 939 | printdefaults()                        /* print default values to stdout */
939                  case 'd': printf(" direction"); break;
940                  case 'v': printf(" value"); break;
941                  case 'l': printf(" length"); break;
942 +                case 'L': printf(" first_length"); break;
943                  case 'p': printf(" point"); break;
944                  case 'n': printf(" normal"); break;
945 +                case 'N': printf(" unperturbed_normal"); break;
946                  case 's': printf(" surface"); break;
947                  case 'w': printf(" weight"); break;
948                  case 'm': printf(" modifier"); break;
949                  }
950 <        printf("\n");
950 >        putchar('\n');
951   #endif
952          printf(wrnvec != NULL ? "-w+\t\t\t\t# warning messages on\n" :
953                          "-w-\t\t\t\t# warning messages off\n");

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)