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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines