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] */ |
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 |
|
|
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 |
|
|
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); |
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; |
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 |
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 |
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) { |
641 |
< |
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) |