ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rxpiece.cpp
(Generate patch)

Comparing ray/src/rt/rxpiece.cpp (file contents):
Revision 2.3 by greg, Tue Sep 17 00:25:41 2024 UTC vs.
Revision 2.7 by greg, Wed Nov 6 18:28:52 2024 UTC

# Line 14 | Line 14 | static const char      RCSid[] = "$Id$";
14  
15   #include  "platform.h"
16   #include  "RpictSimulManager.h"
17 + #include  "ambient.h"
18 + #include  "pmapray.h"
19   #include  "random.h"
20  
21   extern char  *progname;                 /* argv[0] */
# Line 35 | Line 37 | double  mblur = 0.;                    /* motion blur parameter (unused
37  
38   double  dblur = 0.;                     /* depth-of-field blur parameter */
39  
40 < int  nproc = 1;                         /* number of processes to run */
40 > int  nproc = 1;                         /* number of processes to run (-1 in child) */
41  
42   RpictSimulManager       myRPmanager;    // global simulation manager
43  
# Line 55 | Line 57 | static RenderDataType rpiece(char *pout, RenderDataTyp
57                  "OutputCS=RGB,XYZ,prims,spec\n"
58  
59  
60 + // Exit program
61   void
62   quit(int code)                          /* quit program */
63   {
64 <        exit(code);
64 >        if (nproc < 0) {
65 >                ray_pnprocs = -1;       // hack to avoid cleanup in child
66 >                _exit(code);
67 >        }
68 >        exit(code);                     // parent still frees everything (*yawn*)
69   }
70  
71  
# Line 315 | Line 322 | main(int  argc, char  *argv[])
322                                          // render tiles
323          dtype = rpiece(outfile, dtype, zfile);
324  
325 <        quit(dtype==RDTnone);           // clean up and exit
325 >        ambsync();                      // flush ambient cache
326  
327 +        ray_done_pmap();                /* PMAP: free photon maps */
328 +
329 +        quit(dtype==RDTnone);           // status is 1 on failure
330 +
331   badopt:
332          sprintf(errmsg, "command line error at '%s'", argv[i]);
333          error(USER, errmsg);
# Line 332 | Line 343 | wputs(                         /* warning output function */
343          const char      *s
344   )
345   {
346 +        if (!erract[WARNING].pf)
347 +                return;         // warnings were disabled!
348          int  lasterrno = errno;
349          eputs(s);
350          errno = lasterrno;
# Line 499 | Line 512 | children_finished()
512  
513          if (cpid == 0) {                // children render tiles
514                  sleep(nproc - cnt);     // avoid race conditions
515 +                nproc = -1;             // flag as child
516                  return false;
517          }
518          cow_doneshare();                // parent frees memory and waits
# Line 598 | Line 612 | rpiece(char *pout, RenderDataType dt, char *zout)
612  
613          const bool      newOutput = (access(pout, F_OK) < 0);
614          FILE            *pdfp[2];
615 <        if (!newOutput) {                       // output exists?
615 >        if (newOutput) {                        // new output file?
616 >                CHECK((tileGrid[0] <= 1) & (tileGrid[1] <= 1),
617 >                                 USER, "bad tiling specification");
618 >        } else {
619                  dt = myRPmanager.ReopenOutput(pdfp, pout, zout);
620                  if (dt == RDTnone)
621 <                        quit(1);
621 >                        return RDTnone;
622                  if (!fscnresolu(&hresolu, &vresolu, pdfp[0]))
623                          error(USER, "missing picture resolution");
624                  pixaspect = .0;                 // need to leave this as is
625                  myRPmanager.NewHeader(pout);    // get prev. header info
626                  const char *    tval = myRPmanager.GetHeadStr("TILED=");
627                  if (tval) sscanf(tval, "%d %d", &tileGrid[0], &tileGrid[1]);
628 <                if (!myRPmanager.GetView()) {
629 <                        sprintf(errmsg, "missing view in picture file '%s'", pout);
613 <                        error(USER, errmsg);
614 <                }
628 >                CHECK(myRPmanager.GetView()==NULL,
629 >                                USER, "missing view in picture file");
630                  ourview = *myRPmanager.GetView();
631          }
632          int     hvdim[2] = {hresolu, vresolu};  // set up tiled frame
# Line 633 | Line 648 | rpiece(char *pout, RenderDataType dt, char *zout)
648                  myRPmanager.AddHeader(buf);
649                  dt = myRPmanager.NewOutput(pdfp, pout, dt, zout);
650                  if (dt == RDTnone)
651 <                        quit(1);
651 >                        return RDTnone;
652                  fprtresolu(hresolu, vresolu, pdfp[0]);
653 <        }
654 <        if (RDTdepthT(dt) == RDTdshort) {
640 <                if (newOutput)
653 >                fflush(pdfp[0]);
654 >                if (RDTdepthT(dt) == RDTdshort) {
655                          fprtresolu(hresolu, vresolu, pdfp[1]);
656 <                else if (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) ||
657 <                                (hvdim[0] != hresolu) | (hvdim[1] != vresolu))
658 <                        error(USER, "mismatched depth file resolution");
659 <        }
656 >                        fflush(pdfp[1]);
657 >                }
658 >        } else if (RDTdepthT(dt) == RDTdshort &&
659 >                        (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) ||
660 >                                (hvdim[0] != hresolu) | (hvdim[1] != vresolu)))
661 >                error(USER, "mismatched depth file resolution");
662                                                  // prepare (flat) pixel buffer
663          const long      pdata_beg = ftell(pdfp[0]);
664          const size_t    pixSiz = (RDTcolorT(dt)==RDTrgbe)|(RDTcolorT(dt)==RDTxyze) ? sizeof(COLR)
# Line 653 | Line 669 | rpiece(char *pout, RenderDataType dt, char *zout)
669          if (pmlen&7) pmlen += 8 - (pmlen&7);    // 8-byte alignment to be safe
670          pmlen += sizeof(TileProg)*tileGrid[0]*tileGrid[1];
671                                                  // map picture file to memory
672 <        if (ftruncate(fileno(pdfp[0]), pmlen) < 0)
672 >        if (newOutput && ftruncate(fileno(pdfp[0]), pmlen) < 0)
673                  error(SYSTEM, "cannot extend picture buffer");
674          uby8 *          pixMap = (uby8 *)mmap(NULL, pmlen, PROT_READ|PROT_WRITE,
675                                                  MAP_SHARED, fileno(pdfp[0]), 0);
# Line 666 | Line 682 | rpiece(char *pout, RenderDataType dt, char *zout)
682          const size_t    zmlen = zdata_beg + zdpSiz*hresolu*vresolu;
683          uby8 *          zdMap = NULL;
684          if (RDTdepthT(dt)) {
685 <                if (ftruncate(fileno(pdfp[1]), zmlen) < 0)
685 >                if (newOutput && ftruncate(fileno(pdfp[1]), zmlen) < 0)
686                          error(SYSTEM, "cannot extend depth buffer");
687                  zdMap = (uby8 *)mmap(NULL, zmlen, PROT_READ|PROT_WRITE,
688                                                  MAP_SHARED, fileno(pdfp[1]), 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines