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

Comparing ray/src/util/rad.c (file contents):
Revision 2.80 by schorsch, Sat Oct 23 18:55:53 2004 UTC vs.
Revision 2.135 by greg, Sat Jun 7 05:09:46 2025 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9  
10   #include <ctype.h>
11   #include <time.h>
12 + #include <signal.h>
13  
14   #include "platform.h"
15   #include "rtprocess.h"
16   #include "view.h"
16 #include "paths.h"
17   #include "vars.h"
18  
19 < #ifdef _WIN32
19 > #if defined(_WIN32) || defined(_WIN64)
20    #define DELCMD "del"
21    #define RENAMECMD "rename"
22   #else
# Line 24 | Line 24 | static const char      RCSid[] = "$Id$";
24    #define RENAMECMD "mv"
25    #include <sys/types.h>
26    #include <sys/wait.h>
27 +  #include <signal.h>
28   #endif
29  
30                                  /* variables (alphabetical by name) */
# Line 35 | Line 36 | static const char      RCSid[] = "$Id$";
36   #define INDIRECT        5               /* indirection in lighting */
37   #define MATERIAL        6               /* material files */
38   #define MKILLUM         7               /* mkillum options */
39 < #define OBJECT          8               /* object files */
40 < #define OCONV           9               /* oconv options */
41 < #define OCTREE          10              /* octree file name */
42 < #define OPTFILE         11              /* rendering options file */
43 < #define PENUMBRAS       12              /* shadow penumbras are desired */
44 < #define PFILT           13              /* pfilt options */
45 < #define PICTURE         14              /* picture file root name */
46 < #define QUALITY         15              /* desired rendering quality */
47 < #define RAWFILE         16              /* raw picture file root name */
48 < #define RENDER          17              /* rendering options */
49 < #define REPORT          18              /* report frequency and errfile */
50 < #define RESOLUTION      19              /* maximum picture resolution */
51 < #define SCENE           20              /* scene files */
52 < #define UP              21              /* view up (X, Y or Z) */
53 < #define VARIABILITY     22              /* level of light variability */
54 < #define VIEWS           23              /* view(s) for picture(s) */
55 < #define ZFILE           24              /* distance file root name */
56 < #define ZONE            25              /* simulation zone */
39 > #define MKPMAP          8               /* mkpmap options */
40 > #define OBJECT          9               /* object files */
41 > #define OCONV           10              /* oconv options */
42 > #define OCTREE          11              /* octree file name */
43 > #define OPTFILE         12              /* rendering options file */
44 > #define PCMAP           13              /* caustic photon map */
45 > #define PENUMBRAS       14              /* shadow penumbras are desired */
46 > #define PFILT           15              /* pfilt options */
47 > #define PGMAP           16              /* global photon map */
48 > #define PICTURE         17              /* picture file root name */
49 > #define QUALITY         18              /* desired rendering quality */
50 > #define RAWFILE         19              /* raw picture file root name */
51 > #define RENDER          20              /* rendering options */
52 > #define REPORT          21              /* report frequency and errfile */
53 > #define RESOLUTION      22              /* maximum picture resolution */
54 > #define RPICT           23              /* rpict parameters */
55 > #define RVU             24              /* rvu parameters */
56 > #define SCENE           25              /* scene files */
57 > #define UP              26              /* view up (X, Y or Z) */
58 > #define VARIABILITY     27              /* level of light variability */
59 > #define VIEWS           28              /* view(s) for picture(s) */
60 > #define ZFILE           29              /* distance file root name */
61 > #define ZONE            30              /* simulation zone */
62                                  /* total number of variables */
63 < int NVARS = 26;
63 > int NVARS = 31;
64  
65   VARIABLE        vv[] = {                /* variable-value pairs */
66 <        {"AMBFILE",     3,      0,      NULL,   onevalue},
66 >        {"AMBFILE",     3,      0,      NULL,   strvalue},
67          {"DETAIL",      3,      0,      NULL,   qualvalue},
68          {"EXPOSURE",    3,      0,      NULL,   fltvalue},
69          {"EYESEP",      3,      0,      NULL,   fltvalue},
# Line 65 | Line 71 | VARIABLE       vv[] = {                /* variable-value pairs */
71          {"INDIRECT",    3,      0,      NULL,   intvalue},
72          {"materials",   3,      0,      NULL,   catvalues},
73          {"mkillum",     3,      0,      NULL,   catvalues},
74 +        {"mkpmap",      3,      0,      NULL,   catvalues},
75          {"objects",     3,      0,      NULL,   catvalues},
76          {"oconv",       3,      0,      NULL,   catvalues},
77 <        {"OCTREE",      3,      0,      NULL,   onevalue},
78 <        {"OPTFILE",     3,      0,      NULL,   onevalue},
77 >        {"OCTREE",      3,      0,      NULL,   strvalue},
78 >        {"OPTFILE",     3,      0,      NULL,   strvalue},
79 >        {"PCMAP",       2,      0,      NULL,   strvalue},
80          {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
81          {"pfilt",       2,      0,      NULL,   catvalues},
82 <        {"PICTURE",     3,      0,      NULL,   onevalue},
82 >        {"PGMAP",       2,      0,      NULL,   strvalue},
83 >        {"PICTURE",     3,      0,      NULL,   strvalue},
84          {"QUALITY",     3,      0,      NULL,   qualvalue},
85 <        {"RAWFILE",     3,      0,      NULL,   onevalue},
85 >        {"RAWFILE",     3,      0,      NULL,   strvalue},
86          {"render",      3,      0,      NULL,   catvalues},
87          {"REPORT",      3,      0,      NULL,   onevalue},
88          {"RESOLUTION",  3,      0,      NULL,   onevalue},
89 +        {"rpict",       3,      0,      NULL,   catvalues},
90 +        {"rvu",         3,      0,      NULL,   catvalues},
91          {"scene",       3,      0,      NULL,   catvalues},
92          {"UP",          2,      0,      NULL,   onevalue},
93          {"VARIABILITY", 3,      0,      NULL,   qualvalue},
94          {"view",        2,      0,      NULL,   NULL},
95 <        {"ZFILE",       2,      0,      NULL,   onevalue},
95 >        {"ZFILE",       2,      0,      NULL,   strvalue},
96          {"ZONE",        2,      0,      NULL,   onevalue},
97   };
98  
# Line 103 | Line 114 | time_t oct0date;               /* date of pre-mkillum octree */
114   char    *oct1name;              /* name of post-mkillum octree */
115   time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
116  
117 + char    *pgmapname;             /* name of global photon map */
118 + time_t  pgmapdate;              /* date of global photon map (>= oct1date) */
119 + char    *pcmapname;             /* name of caustic photon map */
120 + time_t  pcmapdate;              /* date of caustic photon map (>= oct1date) */
121 +
122   int     nowarn = 0;             /* no warnings */
123   int     explicate = 0;          /* explicate variables */
124   int     silent = 0;             /* do work silently */
# Line 112 | Line 128 | int    sayview = 0;            /* print view out */
128   char    *rvdevice = NULL;       /* rvu output device */
129   char    *viewselect = NULL;     /* specific view only */
130  
131 + #define DEF_RPICT_PATH  "rpict"         /* default rpict path */
132 +
133 + #define R_CMDMAX        (5*PATH_MAX+512)
134 +                                /* command paths */
135 + char    c_oconv[256] = "oconv";
136 + char    c_mkillum[256] = "mkillum";
137 + char    c_mkpmap[256] = "mkpmap";
138 + char    c_rvu[256] = "rvu";
139 + char    c_rpict[256] = DEF_RPICT_PATH;
140 + char    c_rpiece[] = "rpiece";
141 + char    c_pfilt[256] = "pfilt";
142 +
143   int     overture = 0;           /* overture calculation needed */
144  
145   int     children_running = 0;   /* set negative in children */
146  
119 char    *progname;              /* global argv[0] */
147   char    *rifname;               /* global rad input file name */
148  
149   char    radname[PATH_MAX];      /* root Radiance file name */
# Line 130 | Line 157 | static void checkfiles(void);
157   static void getoctcube(double   org[3], double  *sizp);
158   static void setdefaults(void);
159   static void oconv(void);
160 + static void mkpmap(void);
161   static char * addarg(char       *op, char       *arg);
162   static void oconvopts(char      *oo);
163   static void mkillumopts(char    *mo);
164 + static void mkpmapopts(char     *mo);
165   static void checkambfile(void);
166   static double ambval(void);
167   static void renderopts(char     *op, char       *po);
# Line 151 | Line 180 | static int touch(char  *fn);
180   static int runcom(char  *cs);
181   static int rmfile(char  *fn);
182   static int mvfile(char  *fold, char     *fnew);
183 < static int next_process(void);
183 > static int next_process(int     reserve);
184   static void wait_process(int    all);
185   static void finish_process(void);
186   static void badvalue(int        vc);
# Line 167 | Line 196 | main(
196          char    ropts[512];
197          char    popts[64];
198          int     i;
199 <
200 <        progname = argv[0];
199 >                                /* set global progname */
200 >        fixargv0(argv[0]);
201                                  /* get options */
202          for (i = 1; i < argc && argv[i][0] == '-'; i++)
203                  switch (argv[i][1]) {
# Line 207 | Line 236 | main(
236          if (i >= argc)
237                  goto userr;
238          rifname = argv[i];
210                                /* check command-line options */
211        if ((nprocs > 1) & (viewselect != NULL))
212                nprocs = 1;
239                                  /* assign Radiance root file name */
240          rootname(radname, rifname);
241                                  /* load variable values */
242          loadvars(rifname);
243                                  /* get any additional assignments */
244 <        for (i++; i < argc; i++)
245 <                if (setvariable(argv[i], matchvar) < 0) {
246 <                        fprintf(stderr, "%s: unknown variable: %s\n",
244 >        for (i++; i < argc; i++) {
245 >                int     rv = setvariable(argv[i], matchvar);
246 >                if (rv < 0) {
247 >                        fprintf(stderr, "%s: unknown setting: %s\n",
248                                          progname, argv[i]);
249                          quit(1);
250                  }
251 +                if (!rv)
252 +                        fprintf(stderr,
253 +                        "%s: bad variable assignment: %s (ignored)\n",
254 +                                        progname, argv[i]);
255 +        }
256                                  /* check assignments */
257          checkvalues();
258                                  /* check files and dates */
# Line 232 | Line 264 | main(
264                  printvars(stdout);
265                                  /* build octree (and run mkillum) */
266          oconv();
267 +                                /* run mkpmap if indicated */
268 +        mkpmap();
269                                  /* check date on ambient file */
270          checkambfile();
271                                  /* run simulation */
# Line 253 | Line 287 | userr:
287  
288   static void
289   rootname(               /* remove tail from end of fn */
290 <        register char   *rn,
291 <        register char   *fn
290 >        char    *rn,
291 >        char    *fn
292   )
293   {
294          char    *tp, *dp;
# Line 271 | Line 305 | rootname(              /* remove tail from end of fn */
305  
306   static time_t
307   checklast(                      /* check files and find most recent */
308 <        register char   *fnames
308 >        char    *fnames
309   )
310   {
311          char    thisfile[PATH_MAX];
# Line 301 | Line 335 | newfname(              /* create modified file name */
335          int     pred
336   )
337   {
338 <        register char   *cp;
339 <        register int    n;
338 >        char    *cp;
339 >        int     n;
340          int     suffix;
341  
342          n = 0; cp = orig; suffix = -1;          /* suffix position, length */
# Line 324 | Line 358 | newfname(              /* create modified file name */
358   static void
359   checkfiles(void)                        /* check for existence and modified times */
360   {
361 +        char    fntemp[256];
362          time_t  objdate;
363  
364          if (!vdef(OCTREE)) {
# Line 353 | Line 388 | checkfiles(void)                       /* check for existence and modified
388                                  vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
389                  quit(1);
390          }
391 +        if (vdef(PGMAP)) {
392 +                if (!*sskip2(vval(PGMAP),1)) {
393 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
394 +                                        progname, vnam(PGMAP));
395 +                        quit(1);
396 +                }
397 +                atos(fntemp, sizeof(fntemp), vval(PGMAP));
398 +                pgmapname = savqstr(fntemp);
399 +                pgmapdate = fdate(pgmapname);
400 +        }
401 +        if (vdef(PCMAP)) {
402 +                if (!*sskip2(vval(PCMAP),1)) {
403 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
404 +                                        progname, vnam(PCMAP));
405 +                        quit(1);
406 +                }
407 +                atos(fntemp, sizeof(fntemp), vval(PCMAP));
408 +                pcmapname = savqstr(fntemp);
409 +                pcmapdate = fdate(pcmapname);
410 +        }
411          matdate = checklast(vval(MATERIAL));
412   }      
413  
# Line 367 | Line 422 | getoctcube(            /* get octree bounding cube */
422          double  min[3], max[3];
423          char    buf[1024];
424          FILE    *fp;
425 <        register int    i;
425 >        int     i;
426  
427          if (osiz <= FTINY) {
428                  if (!nprocs && fdate(oct1name) <
# Line 472 | Line 527 | static void
527   oconv(void)                             /* run oconv and mkillum if necessary */
528   {
529          static char     illumtmp[] = "ilXXXXXX";
530 <        char    combuf[PATH_MAX], ocopts[64], mkopts[1024];
530 >        char    combuf[R_CMDMAX], ocopts[64], mkopts[1024];
531  
532          oconvopts(ocopts);              /* get options */
533          if (octreedate < scenedate) {   /* check date on original octree */
# Line 480 | Line 535 | oconv(void)                            /* run oconv and mkillum if necessary *
535                          touch(vval(OCTREE));
536                  else {                          /* build command */
537                          if (vdef(MATERIAL))
538 <                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
539 <                                                vval(MATERIAL), vval(SCENE),
540 <                                                vval(OCTREE));
538 >                                sprintf(combuf, "%s%s %s %s > %s", c_oconv,
539 >                                                ocopts, vval(MATERIAL),
540 >                                                vval(SCENE), vval(OCTREE));
541                          else
542 <                                sprintf(combuf, "oconv%s %s > %s", ocopts,
542 >                                sprintf(combuf, "%s%s %s > %s", c_oconv, ocopts,
543                                                  vval(SCENE), vval(OCTREE));
544                          
545                          if (runcom(combuf)) {           /* run it */
# Line 506 | Line 561 | oconv(void)                            /* run oconv and mkillum if necessary *
561                  return;
562                                                  /* make octree0 */
563          if ((oct0date < scenedate) | (oct0date < illumdate)) {
564 <                if (touchonly && oct0date)
565 <                        touch(oct0name);
566 <                else {                          /* build command */
564 >                if (touchonly && (oct0date || oct1date)) {
565 >                        if (oct0date)
566 >                                touch(oct0name);
567 >                } else {                        /* build command */
568                          if (octreedate)
569 <                                sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
570 <                                        vval(OCTREE), vval(ILLUM), oct0name);
569 >                                sprintf(combuf, "%s%s -i %s %s > %s", c_oconv,
570 >                                        ocopts, vval(OCTREE),
571 >                                        vval(ILLUM), oct0name);
572                          else if (vdef(MATERIAL))
573 <                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
574 <                                        vval(MATERIAL), vval(ILLUM), oct0name);
518 <                        else
519 <                                sprintf(combuf, "oconv%s %s > %s", ocopts,
573 >                                sprintf(combuf, "%s%s %s %s > %s", c_oconv,
574 >                                        ocopts, vval(MATERIAL),
575                                          vval(ILLUM), oct0name);
576 +                        else
577 +                                sprintf(combuf, "%s%s %s > %s", c_oconv,
578 +                                        ocopts, vval(ILLUM), oct0name);
579                          if (runcom(combuf)) {           /* run it */
580                                  fprintf(stderr,
581                                  "%s: error generating octree\n\t%s removed\n",
# Line 531 | Line 589 | oconv(void)                            /* run oconv and mkillum if necessary *
589                          oct0date = octreedate;
590                  if (oct0date < illumdate)       /* ditto */
591                          oct0date = illumdate;
592 <                }
592 >        }
593          if (touchonly && oct1date)
594                  touch(oct1name);
595          else {
596                  mkillumopts(mkopts);            /* build mkillum command */
597                  mktemp(illumtmp);
598 <                sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
598 >                sprintf(combuf, "%s%s %s \"<\" %s > %s", c_mkillum, mkopts,
599                                  oct0name, vval(ILLUM), illumtmp);
600                  if (runcom(combuf)) {                   /* run it */
601 <                        fprintf(stderr, "%s: error running mkillum\n",
602 <                                        progname);
601 >                        fprintf(stderr, "%s: error running %s\n",
602 >                                        progname, c_mkillum);
603                          unlink(illumtmp);
604                          quit(1);
605                  }
606 +                rmfile(oct0name);
607                                                  /* make octree1 (frozen) */
608                  if (octreedate)
609 <                        sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
610 <                                vval(OCTREE), illumtmp, oct1name);
609 >                        sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv,
610 >                                ocopts, vval(OCTREE), illumtmp, oct1name);
611                  else if (vdef(MATERIAL))
612 <                        sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
613 <                                vval(MATERIAL), illumtmp, oct1name);
612 >                        sprintf(combuf, "%s%s -f %s %s > %s", c_oconv,
613 >                                ocopts, vval(MATERIAL), illumtmp, oct1name);
614                  else
615 <                        sprintf(combuf, "oconv%s -f %s > %s", ocopts,
615 >                        sprintf(combuf, "%s%s -f %s > %s", c_oconv, ocopts,
616                                  illumtmp, oct1name);
617                  if (runcom(combuf)) {           /* run it */
618                          fprintf(stderr,
# Line 571 | Line 630 | oconv(void)                            /* run oconv and mkillum if necessary *
630   }
631  
632  
633 + static void
634 + mkpmap(void)                    /* run mkpmap if indicated */
635 + {
636 +        char    combuf[2048], *cp;
637 +        time_t  tnow;
638 +                                /* nothing to do? */
639 +        if ((pgmapname == NULL) | (pgmapdate >= oct1date) &&
640 +                        (pcmapname == NULL) | (pcmapdate >= oct1date))
641 +                return;
642 +                                /* just update existing file dates? */
643 +        if (touchonly && (pgmapname == NULL) | (pgmapdate > 0) &&
644 +                        (pcmapname == NULL) | (pcmapdate > 0)) {
645 +                if (pgmapname != NULL)
646 +                        touch(pgmapname);
647 +                if (pcmapname != NULL)
648 +                        touch(pcmapname);
649 +        } else {                /* else need to (re)run pkpmap */
650 +                strcpy(combuf, c_mkpmap);
651 +                for (cp = combuf; *cp; cp++)
652 +                        ;
653 +                mkpmapopts(cp);
654 +                                /* force file overwrite */
655 +                cp = addarg(cp, "-fo+");
656 +                if (vdef(REPORT)) {
657 +                        char    errfile[256];
658 +                        int     n;
659 +                        double  minutes;
660 +                        n = sscanf(vval(REPORT), "%lf %s", &minutes, errfile);
661 +                        if (n == 2)
662 +                                sprintf(cp, " -t %d -e %s", (int)(minutes*60), errfile);
663 +                        else if (n == 1)
664 +                                sprintf(cp, " -t %d", (int)(minutes*60));
665 +                        else
666 +                                badvalue(REPORT);
667 +                }
668 +                if (pgmapname != NULL && pgmapdate < oct1date) {
669 +                        cp = addarg(cp, "-apg");
670 +                        addarg(cp, vval(PGMAP));
671 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
672 +                        *cp = '\0';
673 +                }
674 +                if (pcmapname != NULL && pcmapdate < oct1date) {
675 +                        cp = addarg(cp, "-apc");
676 +                        addarg(cp, vval(PCMAP));
677 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
678 +                        *cp = '\0';
679 +                }
680 +                cp = addarg(cp, oct1name);
681 +                if (runcom(combuf)) {
682 +                        fprintf(stderr, "%s: error running %s\n",
683 +                                        progname, c_mkpmap);
684 +                        if (pgmapname != NULL && pgmapdate < oct1date)
685 +                                unlink(pgmapname);
686 +                        if (pcmapname != NULL && pcmapdate < oct1date)
687 +                                unlink(pcmapname);
688 +                        quit(1);
689 +                }
690 +        }
691 +        tnow = time((time_t *)NULL);
692 +        if (pgmapname != NULL)
693 +                pgmapdate = tnow;
694 +        if (pcmapname != NULL)
695 +                pcmapdate = tnow;
696 +        oct1date = tnow;        /* trigger ambient file removal if needed */
697 + }
698 +
699 +
700   static char *
701 < addarg(                         /* add argument and advance pointer */
702 < register char   *op,
703 < register char   *arg
701 > addarg(                         /* append argument and advance pointer */
702 > char    *op,
703 > char    *arg
704   )
705   {
706 +        while (*op)
707 +                op++;
708          *op = ' ';
709          while ( (*++op = *arg++) )
710                  ;
# Line 586 | Line 714 | register char  *arg
714  
715   static void
716   oconvopts(                              /* get oconv options */
717 <        register char   *oo
717 >        char    *oo
718   )
719   {
720          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
721  
722          *oo = '\0';
723 <        if (vdef(OCONV))
724 <                addarg(oo, vval(OCONV));
723 >        if (!vdef(OCONV))
724 >                return;
725 >        if (vval(OCONV)[0] != '-') {
726 >                atos(c_oconv, sizeof(c_oconv), vval(OCONV));
727 >                oo = addarg(oo, sskip2(vval(OCONV), 1));
728 >        } else
729 >                oo = addarg(oo, vval(OCONV));
730   }
731  
732  
# Line 604 | Line 737 | mkillumopts(                           /* get mkillum options */
737   {
738          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
739  
740 <        if (nprocs > 1) {
740 >        if (nprocs > 1)
741                  sprintf(mo, " -n %d", nprocs);
742 <                while (*mo)
743 <                        mo++;
742 >        else
743 >                *mo = '\0';
744 >        if (!vdef(MKILLUM))
745 >                return;
746 >        if (vval(MKILLUM)[0] != '-') {
747 >                atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM));
748 >                mo = addarg(mo, sskip2(vval(MKILLUM), 1));
749          } else
750 +                mo = addarg(mo, vval(MKILLUM));
751 + }
752 +
753 +
754 + static void
755 + mkpmapopts(                             /* get mkpmap options */
756 +        char    *mo
757 + )
758 + {
759 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
760 +
761 +        if (nprocs > 1)
762 +                sprintf(mo, " -n %d", nprocs);
763 +        else
764                  *mo = '\0';
765 <        if (vdef(MKILLUM))
766 <                addarg(mo, vval(MKILLUM));
765 >        if (!vdef(MKPMAP))
766 >                return;
767 >        if (vval(MKPMAP)[0] != '-') {
768 >                atos(c_mkpmap, sizeof(c_mkpmap), vval(MKPMAP));
769 >                mo = addarg(mo, sskip2(vval(MKPMAP), 1));
770 >        } else
771 >                mo = addarg(mo, vval(MKPMAP));
772   }
773  
774  
# Line 638 | Line 795 | ambval(void)                           /* compute ambient value */
795   {
796          if (vdef(EXPOSURE)) {
797                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
798 <                        return(.5/pow(2.,vflt(EXPOSURE)));
799 <                return(.5/vflt(EXPOSURE));
798 >                        return(.18/pow(2.,vflt(EXPOSURE)));
799 >                return(.18/vflt(EXPOSURE));
800          }
801          if (vlet(ZONE) == 'E')
802                  return(10.);
# Line 656 | Line 813 | renderopts(                    /* set rendering options */
813          char    *po
814   )
815   {
816 +        char    pmapf[256], *bw;
817 +
818 +        if (vdef(PGMAP)) {
819 +                *op = '\0';
820 +                bw = sskip2(vval(PGMAP), 2);
821 +                atos(pmapf, sizeof(pmapf), vval(PGMAP));
822 +                op = addarg(addarg(op, "-ap"), pmapf);
823 +                if (atoi(bw) > 0) op = addarg(op, bw);
824 +        }
825          switch(vscale(QUALITY)) {
826          case LOW:
827                  lowqopts(op, po);
# Line 667 | Line 833 | renderopts(                    /* set rendering options */
833                  hiqopts(op, po);
834                  break;
835          }
836 +        if (vdef(PCMAP)) {
837 +                bw = sskip2(vval(PCMAP), 2);
838 +                atos(pmapf, sizeof(pmapf), vval(PCMAP));
839 +                op = addarg(addarg(op, "-ap"), pmapf);
840 +                if (atoi(bw) > 0) op = addarg(op, bw);
841 +        }
842 +        if (vdef(RENDER)) {
843 +                op = addarg(op, vval(RENDER));
844 +                bw = strstr(vval(RENDER), "-aa ");
845 +                if (bw != NULL && atof(bw+4) <= FTINY)
846 +                        overture = 0;
847 +        }
848 +        if (rvdevice != NULL) {
849 +                if (vdef(RVU)) {
850 +                        if (vval(RVU)[0] != '-') {
851 +                                atos(c_rvu, sizeof(c_rvu), vval(RVU));
852 +                                po = addarg(po, sskip2(vval(RVU), 1));
853 +                        } else
854 +                                po = addarg(po, vval(RVU));
855 +                }
856 +        } else {
857 +                if (vdef(RPICT)) {
858 +                        if (vval(RPICT)[0] != '-') {
859 +                                atos(c_rpict, sizeof(c_rpict), vval(RPICT));
860 +                                po = addarg(po, sskip2(vval(RPICT), 1));
861 +                        } else
862 +                                po = addarg(po, vval(RPICT));
863 +                }
864 +        }
865   }
866  
867  
868   static void
869   lowqopts(                       /* low quality rendering options */
870 <        register char   *op,
870 >        char    *op,
871          char    *po
872   )
873   {
# Line 713 | Line 908 | lowqopts(                      /* low quality rendering options */
908                  op = addarg(op, "-ds .4");
909          else
910                  op = addarg(op, "-ds 0");
911 <        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
911 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -ss 0 -st .5");
912          if (vdef(AMBFILE)) {
913                  sprintf(op, " -af %s", vval(AMBFILE));
914                  op += strlen(op);
# Line 734 | Line 929 | lowqopts(                      /* low quality rendering options */
929          d = ambval();
930          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
931          op += strlen(op);
932 <        op = addarg(op, "-lr 6 -lw .01");
738 <        if (vdef(RENDER))
739 <                op = addarg(op, vval(RENDER));
932 >        op = addarg(op, "-lr 6 -lw .001");
933   }
934  
935  
936   static void
937   medqopts(                       /* medium quality rendering options */
938 <        register char   *op,
938 >        char    *op,
939          char    *po
940   )
941   {
# Line 787 | Line 980 | medqopts(                      /* medium quality rendering options */
980          }
981          po = addarg(po, "-pt .08");
982          if (vbool(PENUMBRAS))
983 <                op = addarg(op, "-ds .2 -dj .5");
983 >                op = addarg(op, "-ds .2 -dj .9");
984          else
985                  op = addarg(op, "-ds .3");
986 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
986 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss 1 -st .1");
987          if ( (overture = vint(INDIRECT)) ) {
988                  sprintf(op, " -ab %d", overture);
989                  op += strlen(op);
# Line 814 | Line 1007 | medqopts(                      /* medium quality rendering options */
1007          d = ambval();
1008          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
1009          op += strlen(op);
1010 <        op = addarg(op, "-lr 8 -lw .002");
818 <        if (vdef(RENDER))
819 <                op = addarg(op, vval(RENDER));
1010 >        op = addarg(op, "-lr 8 -lw 1e-4");
1011   }
1012  
1013  
1014   static void
1015   hiqopts(                                /* high quality rendering options */
1016 <        register char   *op,
1016 >        char    *op,
1017          char    *po
1018   )
1019   {
# Line 867 | Line 1058 | hiqopts(                               /* high quality rendering options */
1058          }
1059          po = addarg(po, "-pt .04");
1060          if (vbool(PENUMBRAS))
1061 <                op = addarg(op, "-ds .1 -dj .65");
1061 >                op = addarg(op, "-ds .1 -dj .9");
1062          else
1063                  op = addarg(op, "-ds .2");
1064 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
1064 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01");
1065          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
1066          op += strlen(op);
1067          if (vdef(AMBFILE)) {
# Line 892 | Line 1083 | hiqopts(                               /* high quality rendering options */
1083          d = ambval();
1084          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
1085          op += strlen(op);
1086 <        op = addarg(op, "-lr 12 -lw .0005");
896 <        if (vdef(RENDER))
897 <                op = addarg(op, vval(RENDER));
1086 >        op = addarg(op, "-lr 12 -lw 5e-6");
1087   }
1088  
1089  
1090 + #if defined(_WIN32) || defined(_WIN64)
1091   static void
1092 + setenv(                 /* set an environment variable */
1093 +        char    *vname,
1094 +        char    *value
1095 + )
1096 + {
1097 +        char    *evp;
1098 +
1099 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
1100 +        if (evp == NULL)
1101 +                syserr(progname);
1102 +        sprintf(evp, "%s=%s", vname, value);
1103 +        if (putenv(evp) != 0) {
1104 +                fprintf(stderr, "%s: out of environment space\n", progname);
1105 +                quit(1);
1106 +        }
1107 +        if (!silent)
1108 +                printf("set %s\n", evp);
1109 + }
1110 + #endif
1111 +
1112 +
1113 + static void
1114   xferopts(                               /* transfer options if indicated */
1115          char    *ro
1116   )
1117   {
1118          int     fd, n;
1119 <        register char   *cp;
1119 >        char    *cp;
1120          
1121          n = strlen(ro);
1122          if (n < 2)
# Line 922 | Line 1134 | xferopts(                              /* transfer options if indicated */
1134                          syserr(vval(OPTFILE));
1135                  sprintf(ro, " @%s", vval(OPTFILE));
1136          }
1137 < #ifdef _WIN32
1137 > #if defined(_WIN32) || defined(_WIN64)
1138          else if (n > 50) {
1139                  setenv("ROPT", ro+1);
1140                  strcpy(ro, " $ROPT");
# Line 933 | Line 1145 | xferopts(                              /* transfer options if indicated */
1145  
1146   static void
1147   pfiltopts(                              /* get pfilt options */
1148 <        register char   *po
1148 >        char    *po
1149   )
1150   {
1151          *po = '\0';
# Line 949 | Line 1161 | pfiltopts(                             /* get pfilt options */
1161                  po = addarg(po, "-m .25");
1162                  break;
1163          }
1164 <        if (vdef(PFILT))
1165 <                po = addarg(po, vval(PFILT));
1164 >        if (vdef(PFILT)) {
1165 >                if (vval(PFILT)[0] != '-') {
1166 >                        atos(c_pfilt, sizeof(c_pfilt), vval(PFILT));
1167 >                        po = addarg(po, sskip2(vval(PFILT), 1));
1168 >                } else
1169 >                        po = addarg(po, vval(PFILT));
1170 >        }
1171   }
1172  
1173  
1174   static int
1175   matchword(                      /* match white-delimited words */
1176 <        register char   *s1,
1177 <        register char   *s2
1176 >        char    *s1,
1177 >        char    *s2
1178   )
1179   {
1180          while (isspace(*s1)) s1++;
# Line 971 | Line 1188 | matchword(                     /* match white-delimited words */
1188  
1189   static char *
1190   specview(                               /* get proper view spec from vs */
1191 <        register char   *vs
1191 >        char    *vs
1192   )
1193   {
1194          static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
1195                          "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
1196          static char     viewopts[128];
1197 <        register char   *cp;
1197 >        char    *cp;
1198          int     xpos, ypos, zpos, viewtype, upax;
1199 <        register int    i;
1199 >        int     i;
1200          double  cent[3], dim[3], mult, d;
1201  
1202          if (vs == NULL || *vs == '-')
# Line 1012 | Line 1229 | specview(                              /* get proper view spec from vs */
1229          } else if (*vs == 'z') {
1230                  zpos = -1; vs++;
1231          }
1232 <        viewtype = 'v';
1233 <        if((*vs == 'v') | (*vs == 'l') | (*vs == 'a') | (*vs == 'h') | (*vs == 'c'))
1232 >        switch (*vs) {
1233 >        case VT_PER:
1234 >        case VT_PAR:
1235 >        case VT_ANG:
1236 >        case VT_HEM:
1237 >        case VT_PLS:
1238 >        case VT_CYL:
1239                  viewtype = *vs++;
1240 +                break;
1241 +        default:
1242 +                viewtype = VT_PER;
1243 +                break;
1244 +        }
1245          cp = viewopts;
1246          if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
1247                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
# Line 1029 | Line 1256 | specview(                              /* get proper view spec from vs */
1256                          cent[i] += .5*dim[i];
1257                  }
1258                  mult = vlet(ZONE)=='E' ? 2. : .45 ;
1259 <                sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
1259 >                sprintf(cp, " -vp %.3g %.3g %.3g -vd %.3g %.3g %.3g",
1260                                  cent[0]+xpos*mult*dim[0],
1261                                  cent[1]+ypos*mult*dim[1],
1262                                  cent[2]+zpos*mult*dim[2],
# Line 1056 | Line 1283 | specview(                              /* get proper view spec from vs */
1283                  }
1284                  cp = addarg(cp, vup[upax+3]);
1285                  switch (viewtype) {
1286 <                case 'v':
1286 >                case VT_PER:
1287                          cp = addarg(cp, "-vh 45 -vv 45");
1288                          break;
1289 <                case 'l':
1289 >                case VT_PAR:
1290                          d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1291 <                        sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1291 >                        sprintf(cp, " -vh %.3g -vv %.3g", d, d);
1292                          cp += strlen(cp);
1293                          break;
1294 <                case 'a':
1295 <                case 'h':
1294 >                case VT_ANG:
1295 >                case VT_HEM:
1296 >                case VT_PLS:
1297                          cp = addarg(cp, "-vh 180 -vv 180");
1298                          break;
1299 <                case 'c':
1299 >                case VT_CYL:
1300                          cp = addarg(cp, "-vh 180 -vv 90");
1301                          break;
1302                  }
# Line 1076 | Line 1304 | specview(                              /* get proper view spec from vs */
1304                  while (!isspace(*vs))           /* else skip id */
1305                          if (!*vs++)
1306                                  return(NULL);
1307 <                if (upax) {                     /* specify up vector */
1307 >                if (upax) {                     /* prepend up vector */
1308                          strcpy(cp, vup[upax+3]);
1309                          cp += strlen(cp);
1310                  }
# Line 1084 | Line 1312 | specview(                              /* get proper view spec from vs */
1312          if (cp == viewopts)             /* append any additional options */
1313                  vs++;           /* skip prefixed space if unneeded */
1314          strcpy(cp, vs);
1315 < #ifdef _WIN32
1315 > #if defined(_WIN32) || defined(_WIN64)
1316          if (strlen(viewopts) > 40) {
1317                  setenv("VIEW", viewopts);
1318                  return("$VIEW");
# Line 1100 | Line 1328 | getview(                               /* get view n, or NULL if none */
1328          char    *vn             /* returned view name */
1329   )
1330   {
1331 <        register char   *mv;
1331 >        char    *mv;
1332  
1333          if (viewselect != NULL) {               /* command-line selected */
1334                  if (n)                          /* only do one */
1335                          return(NULL);
1336 +                                        
1337 +                if (isint(viewselect)) {        /* view number? */
1338 +                        n = atoi(viewselect)-1;
1339 +                        goto numview;
1340 +                }
1341                  if (viewselect[0] == '-') {     /* already specified */
1342 <                        if (vn != NULL) *vn = '\0';
1342 >                        if (vn != NULL)
1343 >                                strcpy(vn, "0");
1344                          return(viewselect);
1345                  }
1346                  if (vn != NULL) {
# Line 1115 | Line 1349 | getview(                               /* get view n, or NULL if none */
1349                                  ;
1350                          *vn = '\0';
1351                  }
1118                                                /* view number? */
1119                if (isint(viewselect))
1120                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1352                                                  /* check list */
1353                  while ((mv = nvalue(VIEWS, n++)) != NULL)
1354                          if (matchword(viewselect, mv))
1355                                  return(specview(mv));
1356 +
1357                  return(specview(viewselect));   /* standard view? */
1358          }
1359 + numview:
1360          mv = nvalue(VIEWS, n);          /* use view n */
1361          if ((vn != NULL) & (mv != NULL)) {
1362 <                register char   *mv2 = mv;
1363 <                if (*mv2 != '-')
1362 >                if (*mv != '-') {
1363 >                        char    *mv2 = mv;
1364                          while (*mv2 && !isspace(*mv2))
1365                                  *vn++ = *mv2++;
1366 <                *vn = '\0';
1366 >                        *vn = '\0';
1367 >                } else
1368 >                        sprintf(vn, "%d", n+1);
1369          }
1370          return(specview(mv));
1371   }
# Line 1138 | Line 1373 | getview(                               /* get view n, or NULL if none */
1373  
1374   static int
1375   myprintview(                    /* print out selected view */
1376 <        register char   *vopts,
1376 >        char    *vopts,
1377          FILE    *fp
1378   )
1379   {
1380          VIEW    vwr;
1381          char    buf[128];
1382 <        register char   *cp;
1383 < #ifdef _WIN32
1382 >        char    *cp;
1383 > #if defined(_WIN32) || defined(_WIN64)
1384   /* XXX Should we allow something like this for all platforms? */
1385   /* XXX Or is it still required at all? */
1386   again:
1387   #endif
1388          if (vopts == NULL)
1389                  return(-1);
1390 < #ifdef _WIN32
1390 > #if defined(_WIN32) || defined(_WIN64)
1391          if (vopts[0] == '$') {
1392                  vopts = getenv(vopts+1);
1393                  goto again;
# Line 1179 | Line 1414 | rvu(                           /* run rvu with first view */
1414   )
1415   {
1416          char    *vw;
1417 <        char    combuf[PATH_MAX];
1417 >        char    combuf[R_CMDMAX];
1418                                          /* build command */
1419          if (touchonly || (vw = getview(0, NULL)) == NULL)
1420                  return;
1421          if (sayview)
1422                  myprintview(vw, stdout);
1423 <        sprintf(combuf, "rvu %s%s%s -R %s ", vw, po, opts, rifname);
1423 >        sprintf(combuf, "%s %s%s%s -R %s ", c_rvu, vw, opts, po, rifname);
1424 >        if (nprocs > 1)
1425 >                sprintf(combuf+strlen(combuf), "-n %d ", nprocs);
1426          if (rvdevice != NULL)
1427                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1428          if (vdef(EXPOSURE))
1429                  sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1430          strcat(combuf, oct1name);
1431          if (runcom(combuf)) {           /* run it */
1432 <                fprintf(stderr, "%s: error running rvu\n", progname);
1432 >                fprintf(stderr, "%s: error running %s\n", progname, c_rvu);
1433                  quit(1);
1434          }
1435   }
1436  
1437  
1438 + static int
1439 + syncf_done(                     /* check if an rpiece sync file is complete */
1440 +        char *sfname
1441 + )
1442 + {
1443 +        FILE    *fp = fopen(sfname, "r");
1444 +        int     todo = 1;
1445 +        int     x, y;
1446 +
1447 +        if (fp == NULL)
1448 +                return(0);
1449 +        if (fscanf(fp, "%d %d", &x, &y) != 2)
1450 +                goto checked;
1451 +        todo = x*y;             /* total number of tiles */
1452 +        if (fscanf(fp, "%d %d", &x, &y) != 2 || (x != 0) | (y != 0))
1453 +                goto checked;
1454 +                                /* XXX assume no redundant tiles */
1455 +        while (fscanf(fp, "%d %d", &x, &y) == 2)
1456 +                if (!--todo)
1457 +                        break;
1458 + checked:
1459 +        fclose(fp);
1460 +        return(!todo);
1461 + }
1462 +
1463 +
1464   static void
1465   rpict(                          /* run rpict and pfilt for each view */
1466          char    *opts,
1467          char    *po
1468   )
1469   {
1470 <        char    combuf[PATH_MAX];
1470 > #define do_rpiece       (sfile[0]!='\0')
1471 >        char    combuf[5*PATH_MAX+512];
1472          char    rawfile[PATH_MAX], picfile[PATH_MAX];
1473          char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1474 <        char    rppopt[128], *pfile = NULL;
1474 >        char    rppopt[32], sfile[PATH_MAX], *pfile = NULL;
1475          char    pfopts[128];
1476          char    vs[32], *vw;
1477          int     vn, mult;
1478          FILE    *fp;
1479          time_t  rfdt, pfdt;
1480 +        int     xres, yres;
1481 +        double  aspect;
1482 +        int     n;
1483                                          /* get pfilt options */
1484          pfiltopts(pfopts);
1485                                          /* get resolution, reporting */
# Line 1227 | Line 1494 | rpict(                         /* run rpict and pfilt for each view */
1494                  mult = 3;
1495                  break;
1496          }
1497 <        {
1498 <                int     xres, yres;
1499 <                double  aspect;
1500 <                int     n;
1501 <                n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1502 <                if (n == 3)
1503 <                        sprintf(res, "-x %d -y %d -pa %.3f",
1504 <                                        mult*xres, mult*yres, aspect);
1505 <                else if (n) {
1506 <                        if (n == 1) yres = xres;
1240 <                        sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1241 <                } else
1242 <                        badvalue(RESOLUTION);
1243 <        }
1497 >        n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1498 >        if (n == 3)
1499 >                sprintf(res, "-x %d -y %d -pa %.3f",
1500 >                                mult*xres, mult*yres, aspect);
1501 >        else if (n) {
1502 >                aspect = 1.;
1503 >                if (n == 1) yres = xres;
1504 >                sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1505 >        } else
1506 >                badvalue(RESOLUTION);
1507          rep[0] = '\0';
1508          if (vdef(REPORT)) {
1509                  double  minutes;
1247                int     n;
1510                  n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1511                  if (n == 2)
1512                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
# Line 1254 | Line 1516 | rpict(                         /* run rpict and pfilt for each view */
1516                          badvalue(REPORT);
1517          }
1518                                          /* set up parallel rendering */
1519 <        if ((nprocs > 1) & (!vdef(ZFILE))) {
1520 <                strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1521 <                pfile = rppopt+9;
1522 <                if (mktemp(pfile) == NULL)
1519 >        sfile[0] = '\0';
1520 >        if ((nprocs > 1) & !touchonly & !vdef(ZFILE) &&
1521 >                                        getview(0, vs) != NULL) {
1522 >                if (!strcmp(c_rpict, DEF_RPICT_PATH) &&
1523 >                                getview(1, NULL) == NULL) {
1524 >                        sprintf(sfile, "%s_%s_rpsync.txt",
1525 >                                vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE),
1526 >                                        vs);
1527 >                        strcpy(rppopt, "-PP pfXXXXXX");
1528 >                } else {
1529 >                        strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1530 >                }
1531 >                pfile = rppopt + strlen(rppopt) - 8;
1532 >                if (mktemp(pfile) == NULL) {
1533 >                        if (do_rpiece) {
1534 >                                fprintf(stderr, "%s: cannot create\n", pfile);
1535 >                                quit(1);
1536 >                        }
1537 >                        pfile[-5] = '\0';
1538                          pfile = NULL;
1539 +                }
1540          }
1541          vn = 0;                                 /* do each view */
1542          while ((vw = getview(vn++, vs)) != NULL) {
1543                  if (sayview)
1544                          myprintview(vw, stdout);
1545 <                if (!vs[0])
1268 <                        sprintf(vs, "%d", vn);
1269 <                sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1545 >                sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs);
1546                  if (vdef(ZFILE))
1547                          sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1548                  else
# Line 1287 | Line 1563 | rpict(                         /* run rpict and pfilt for each view */
1563                                  touch(picfile);
1564                          continue;
1565                  }
1566 <                if (next_process()) {           /* parallel running? */
1566 >                                                /* parallel running? */
1567 >                if (do_rpiece) {
1568 >                        if (rfdt < oct1date || !fdate(sfile)) {
1569 >                                int     xdiv = 8+nprocs/3, ydiv = 8+nprocs/3;
1570 >                                if (rfdt >= oct1date) {
1571 >                                        fprintf(stderr,
1572 >                "%s: partial output not created with %s\n", rawfile, c_rpiece);
1573 >                                        quit(1);
1574 >                                }
1575 >                                if (rfdt) {     /* start fresh */
1576 >                                        rmfile(rawfile);
1577 >                                        rfdt = 0;
1578 >                                }
1579 >                                if (!silent)
1580 >                                        printf("\techo %d %d > %s\n",
1581 >                                                        xdiv, ydiv, sfile);
1582 >                                if ((fp = fopen(sfile, "w")) == NULL) {
1583 >                                        fprintf(stderr, "%s: cannot create\n",
1584 >                                                        sfile);
1585 >                                        quit(1);
1586 >                                }
1587 >                                fprintf(fp, "%d %d\n", xdiv, ydiv);
1588 >                                fclose(fp);
1589 >                        }
1590 >                } else if (next_process(0)) {
1591                          if (pfile != NULL)
1592 <                                sleep(20);
1592 >                                sleep(10);
1593                          continue;
1594 <                }
1594 >                } else if (!inchild())
1595 >                        pfile = NULL;
1596                  /* XXX Remember to call finish_process() */
1597                                                  /* build rpict command */
1598 <                if (rfdt >= oct1date) {         /* recover */
1599 <                        sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1600 <                                rep, po, opts, zopt, rawfile, oct1name);
1601 <                        if (runcom(combuf))     /* run rpict */
1598 >                if (rfdt >= oct1date) {         /* already in progress */
1599 >                        if (do_rpiece) {
1600 >                                sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s",
1601 >                                                c_rpiece, sfile, rppopt, rep, vw,
1602 >                                                res, opts, po, rawfile, oct1name);
1603 >                                while (next_process(1)) {
1604 >                                        sleep(10);
1605 >                                        combuf[strlen(c_rpiece)+2] = 'F';
1606 >                                }
1607 >                        } else
1608 >                                sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict,
1609 >                                        rep, opts, po, zopt, rawfile, oct1name);
1610 >                        if (runcom(combuf))     /* run rpict/rpiece */
1611                                  goto rperror;
1612                  } else {
1613                          if (overture) {         /* run overture calculation */
1614                                  sprintf(combuf,
1615 <                                "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1616 <                                                rep, vw, opts,
1615 >                                        "%s%s %s%s%s -x 64 -y 64 -ps 1 %s > %s",
1616 >                                                c_rpict, rep, vw, opts, po,
1617                                                  oct1name, overfile);
1618 <                                if (runcom(combuf)) {
1619 <                                        fprintf(stderr,
1618 >                                if (!do_rpiece || !next_process(0)) {
1619 >                                        if (runcom(combuf)) {
1620 >                                                fprintf(stderr,
1621                                          "%s: error in overture for view %s\n",
1622 <                                                progname, vs);
1623 <                                        quit(1);
1624 <                                }
1622 >                                                        progname, vs);
1623 >                                                quit(1);
1624 >                                        }
1625   #ifndef NULL_DEVICE
1626 <                                rmfile(overfile);
1626 >                                        rmfile(overfile);
1627   #endif
1628 +                                } else if (do_rpiece)
1629 +                                        sleep(20);
1630                          }
1631 <                        sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1632 <                                        rep, vw, res, po, opts,
1633 <                                        zopt, oct1name, rawfile);
1634 <                        if (pfile != NULL && inchild()) {
1635 <                                                /* rpict persistent mode */
1636 <                                if (!silent) {
1631 >                        if (do_rpiece) {
1632 >                                sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s",
1633 >                                                c_rpiece, sfile, rppopt, rep, vw,
1634 >                                                res, opts, po, rawfile, oct1name);
1635 >                                while (next_process(1))
1636 >                                        sleep(10);
1637 >                        } else {
1638 >                                sprintf(combuf, "%s%s %s %s%s%s%s %s > %s",
1639 >                                                c_rpict, rep, vw, res, opts, po,
1640 >                                                zopt, oct1name, rawfile);
1641 >                        }
1642 >                        if ((pfile != NULL) & !do_rpiece) {
1643 >                                if (!silent)
1644                                          printf("\t%s\n", combuf);
1325                                        fflush(stdout);
1326                                }
1327                                sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1328                                                rep, rppopt, res, po, opts,
1329                                                oct1name, rawfile);
1645                                  fflush(stdout);
1646 +                                sprintf(combuf, "%s%s %s %s%s%s %s > %s",
1647 +                                                c_rpict, rep, rppopt, res,
1648 +                                                opts, po, oct1name, rawfile);
1649                                  fp = popen(combuf, "w");
1650                                  if (fp == NULL)
1651                                          goto rperror;
1652                                  myprintview(vw, fp);
1653                                  if (pclose(fp))
1654                                          goto rperror;
1655 <                        } else {                /* rpict normal mode */
1656 <                                if (runcom(combuf))
1657 <                                        goto rperror;
1655 >                        } else if (runcom(combuf))
1656 >                                goto rperror;
1657 >                }
1658 >                if (do_rpiece) {                /* need to finish raw, first */
1659 >                        finish_process();
1660 >                        wait_process(1);
1661 >                        if (!syncf_done(sfile)) {
1662 >                                fprintf(stderr,
1663 >                        "%s: %s did not complete rendering of view %s\n",
1664 >                                                progname, c_rpiece, vs);
1665 >                                quit(1);
1666                          }
1667                  }
1668                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1669                                                  /* build pfilt command */
1670 <                        if (mult > 1)
1671 <                                sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1672 <                                        pfopts, mult, mult, rawfile, picfile);
1670 >                        if (do_rpiece)
1671 >                                sprintf(combuf,
1672 >                                        "%s%s -x %d -y %d -p %.3f %s > %s",
1673 >                                        c_pfilt, pfopts, xres, yres, aspect,
1674 >                                        rawfile, picfile);
1675 >                        else if (mult > 1)
1676 >                                sprintf(combuf, "%s%s -x /%d -y /%d %s > %s",
1677 >                                        c_pfilt, pfopts, mult, mult,
1678 >                                        rawfile, picfile);
1679                          else
1680 <                                sprintf(combuf, "pfilt%s %s > %s", pfopts,
1681 <                                                rawfile, picfile);
1680 >                                sprintf(combuf, "%s%s %s > %s", c_pfilt,
1681 >                                        pfopts, rawfile, picfile);
1682                          if (runcom(combuf)) {   /* run pfilt */
1683                                  fprintf(stderr,
1684                                  "%s: error filtering view %s\n\t%s removed\n",
# Line 1357 | Line 1689 | rpict(                         /* run rpict and pfilt for each view */
1689                  }
1690                                                  /* remove/rename raw file */
1691                  if (vdef(RAWFILE)) {
1692 <                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1692 >                        sprintf(combuf, "%s_%s.hdr", vval(RAWFILE), vs);
1693                          mvfile(rawfile, combuf);
1694                  } else
1695                          rmfile(rawfile);
1696 <                finish_process();               /* exit if child */
1696 >                if (do_rpiece)                  /* done with sync file */
1697 >                        rmfile(sfile);
1698 >                else
1699 >                        finish_process();       /* exit if child */
1700          }
1701          wait_process(1);                /* wait for children to finish */
1702 <        if (pfile != NULL) {            /* clean up rpict persistent mode */
1703 <                int     pid;
1702 >        if (pfile != NULL) {            /* clean up persistent rpict */
1703 >                RT_PID  pid;
1704                  fp = fopen(pfile, "r");
1705                  if (fp != NULL) {
1706                          if (fscanf(fp, "%*s %d", &pid) != 1 ||
# Line 1378 | Line 1713 | rpict(                         /* run rpict and pfilt for each view */
1713   rperror:
1714          fprintf(stderr, "%s: error rendering view %s\n", progname, vs);
1715          quit(1);
1716 + #undef do_rpiece
1717   }
1718  
1719  
# Line 1390 | Line 1726 | touch(                 /* update a file */
1726                  printf("\ttouch %s\n", fn);
1727          if (!nprocs)
1728                  return(0);
1393 #ifdef notused
1394        if (access(fn, F_OK) == -1)             /* create it */
1395                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1396                        return(-1);
1397 #endif
1729          return(setfdate(fn, time((time_t *)NULL)));
1730   }
1731  
# Line 1408 | Line 1739 | runcom(                        /* run command */
1739                  printf("\t%s\n", cs);
1740          if (!nprocs)
1741                  return(0);
1742 <        fflush(stdout);         /* flush output and pass to shell */
1742 >        fflush(NULL);           /* flush output and pass to shell */
1743          return(system(cs));
1744   }
1745  
# Line 1442 | Line 1773 | mvfile(                /* move a file */
1773  
1774   #ifdef RHAS_FORK_EXEC
1775   static int
1776 < next_process(void)                      /* fork the next process (max. nprocs) */
1776 > next_process(int reserve)               /* fork the next process */
1777   {
1778 <        int     child_pid;
1778 >        RT_PID  child_pid;
1779  
1780          if (nprocs <= 1)
1781                  return(0);              /* it's us or no one */
# Line 1453 | Line 1784 | next_process(void)                     /* fork the next process (max. np
1784                                  progname);
1785                  quit(1);
1786          }
1787 +        if (reserve > 0 && children_running >= nprocs-reserve)
1788 +                return(0);              /* caller holding back process(es) */
1789          if (children_running >= nprocs)
1790                  wait_process(0);        /* wait for someone to finish */
1791 <        fflush(stdout);
1791 >        fflush(NULL);                   /* flush output */
1792          child_pid = fork();             /* split process */
1793          if (child_pid == 0) {           /* we're the child */
1794                  children_running = -1;
1795 +                nprocs = 1;
1796                  return(0);
1797          }
1798          if (child_pid > 0) {            /* we're the parent */
# Line 1474 | Line 1808 | wait_process(                  /* wait for process(es) to finish */
1808          int     all
1809   )
1810   {
1811 <        int     ourstatus = 0;
1812 <        int     pid, status;
1811 >        int     ourstatus = 0, status;
1812 >        RT_PID  pid;
1813  
1814          if (all)
1815                  all = children_running;
# Line 1500 | Line 1834 | wait_process(                  /* wait for process(es) to finish */
1834   }
1835   #else   /* ! RHAS_FORK_EXEC */
1836   static int
1837 < next_process(void)
1837 > next_process(int reserve)
1838   {
1839          return(0);                      /* cannot start new process */
1840   }
# Line 1512 | Line 1846 | int    all;
1846   }
1847   int
1848   kill(pid, sig) /* win|unix_process.c should also wait and kill */
1849 < int pid, sig;
1849 > RT_PID pid;
1850 > int sig;
1851   {
1852          return 0;
1853   }
# Line 1525 | Line 1860 | finish_process(void)                   /* exit a child process */
1860                  return;                 /* in parent -- noop */
1861          exit(0);
1862   }
1528
1529 #ifdef _WIN32
1530 setenv(vname, value)            /* set an environment variable */
1531 char    *vname, *value;
1532 {
1533        register char   *evp;
1534
1535        evp = bmalloc(strlen(vname)+strlen(value)+2);
1536        if (evp == NULL)
1537                syserr(progname);
1538        sprintf(evp, "%s=%s", vname, value);
1539        if (putenv(evp) != 0) {
1540                fprintf(stderr, "%s: out of environment space\n", progname);
1541                quit(1);
1542        }
1543        if (!silent)
1544                printf("set %s\n", evp);
1545 }
1546 #endif
1863  
1864  
1865   static void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines