7 |
|
|
8 |
|
#include "copyright.h" |
9 |
|
|
10 |
< |
#include "ray.h" |
10 |
> |
#include <time.h> |
11 |
> |
#include <signal.h> |
12 |
|
|
13 |
+ |
#include "platform.h" |
14 |
+ |
#include "rtprocess.h" /* getpid() */ |
15 |
+ |
#include "ray.h" |
16 |
|
#include "source.h" |
13 |
– |
|
17 |
|
#include "ambient.h" |
15 |
– |
|
18 |
|
#include "random.h" |
17 |
– |
|
19 |
|
#include "paths.h" |
19 |
– |
|
20 |
– |
#include <sys/types.h> |
21 |
– |
|
22 |
– |
#include <signal.h> |
23 |
– |
|
20 |
|
#include "view.h" |
21 |
+ |
#include "pmapray.h" |
22 |
|
|
26 |
– |
#include "paths.h" |
23 |
|
/* persistent processes define */ |
24 |
|
#ifdef F_SETLKW |
25 |
|
#define PERSIST 1 /* normal persist */ |
28 |
|
#endif |
29 |
|
|
30 |
|
char *progname; /* argv[0] */ |
35 |
– |
|
31 |
|
char *octname; /* octree name */ |
37 |
– |
|
32 |
|
char *sigerr[NSIG]; /* signal error messages */ |
39 |
– |
|
33 |
|
char *shm_boundary = NULL; /* boundary of shared memory */ |
41 |
– |
|
34 |
|
char *errfile = NULL; /* error output file */ |
35 |
|
|
36 |
|
extern time_t time(); |
50 |
|
|
51 |
|
extern double mblur; /* motion blur parameter */ |
52 |
|
|
53 |
< |
void onsig(); |
62 |
< |
void sigdie(); |
63 |
< |
void printdefaults(); |
53 |
> |
extern double dblur; /* depth-of-field blur parameter */ |
54 |
|
|
55 |
+ |
static void onsig(int signo); |
56 |
+ |
static void sigdie(int signo, char *msg); |
57 |
+ |
static void printdefaults(void); |
58 |
|
|
59 |
+ |
|
60 |
|
int |
61 |
< |
main(argc, argv) |
68 |
< |
int argc; |
69 |
< |
char *argv[]; |
61 |
> |
main(int argc, char *argv[]) |
62 |
|
{ |
63 |
|
#define check(ol,al) if (argv[i][ol] || \ |
64 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
77 |
|
int loadflags = ~IO_FILES; |
78 |
|
int seqstart = 0; |
79 |
|
int persist = 0; |
80 |
< |
int duped1; |
80 |
> |
int duped1 = -1; |
81 |
|
int rval; |
82 |
|
int i; |
83 |
|
/* record start time */ |
155 |
|
check(3,"f"); |
156 |
|
mblur = atof(argv[++i]); |
157 |
|
break; |
158 |
+ |
case 'd': /* aperture */ |
159 |
+ |
check(3,"f"); |
160 |
+ |
dblur = atof(argv[++i]); |
161 |
+ |
break; |
162 |
|
default: |
163 |
|
goto badopt; |
164 |
|
} |
227 |
|
/* initialize object types */ |
228 |
|
initotypes(); |
229 |
|
/* initialize urand */ |
230 |
< |
initurand(2048); |
230 |
> |
if (rand_samp) { |
231 |
> |
srandom((long)time(0)); |
232 |
> |
initurand(0); |
233 |
> |
} else { |
234 |
> |
srandom(0L); |
235 |
> |
initurand(2048); |
236 |
> |
} |
237 |
|
/* set up signal handling */ |
238 |
|
sigdie(SIGINT, "Interrupt"); |
239 |
+ |
#ifdef SIGHUP |
240 |
|
sigdie(SIGHUP, "Hangup"); |
241 |
+ |
#endif |
242 |
|
sigdie(SIGTERM, "Terminate"); |
243 |
+ |
#ifdef SIGPIPE |
244 |
|
sigdie(SIGPIPE, "Broken pipe"); |
245 |
+ |
#endif |
246 |
+ |
#ifdef SIGALRM |
247 |
|
sigdie(SIGALRM, "Alarm clock"); |
248 |
+ |
#endif |
249 |
|
#ifdef SIGXCPU |
250 |
|
sigdie(SIGXCPU, "CPU limit exceeded"); |
251 |
|
sigdie(SIGXFSZ, "File size exceeded"); |
286 |
|
#endif |
287 |
|
if (outfile != NULL) |
288 |
|
openheader(); |
289 |
< |
#ifdef MSDOS |
290 |
< |
setmode(fileno(stdout), O_BINARY); |
289 |
> |
#if defined(_WIN32) || defined(_WIN64) |
290 |
> |
SET_FILE_BINARY(stdout); |
291 |
|
if (octname == NULL) |
292 |
< |
setmode(fileno(stdin), O_BINARY); |
292 |
> |
SET_FILE_BINARY(stdin); |
293 |
|
#endif |
294 |
|
readoct(octname, loadflags, &thescene, NULL); |
295 |
|
nsceneobjs = nobjects; |
297 |
|
if (loadflags & IO_INFO) { /* print header */ |
298 |
|
printargs(i, argv, stdout); |
299 |
|
printf("SOFTWARE= %s\n", VersionID); |
292 |
– |
fputnow(stdout); |
300 |
|
} |
301 |
+ |
|
302 |
+ |
ray_init_pmap(); /* PMAP: set up & load photon maps */ |
303 |
|
|
304 |
|
marksources(); /* find and mark sources */ |
305 |
|
|
306 |
|
setambient(); /* initialize ambient calculation */ |
307 |
< |
|
307 |
> |
|
308 |
|
#ifdef PERSIST |
309 |
|
if (persist) { |
310 |
|
fflush(stdout); |
320 |
|
pflock(1); |
321 |
|
pfhold(); |
322 |
|
tstart = time((time_t *)NULL); |
323 |
+ |
ambsync(); /* load new values */ |
324 |
|
} |
325 |
|
if (rval < 0) |
326 |
|
error(SYSTEM, "cannot fork child for persist function"); |
327 |
< |
pfdetach(); /* parent exits */ |
327 |
> |
pfdetach(); /* parent will run then exit */ |
328 |
|
} |
329 |
|
} |
330 |
|
runagain: |
331 |
< |
if (persist) |
331 |
> |
if (persist) { |
332 |
|
if (outfile == NULL) /* if out to stdout */ |
333 |
|
dupheader(); /* send header */ |
334 |
|
else /* if out to file */ |
335 |
|
duped1 = dup(fileno(stdout)); /* hang onto pipe */ |
336 |
+ |
} |
337 |
|
#endif |
338 |
|
/* batch render picture(s) */ |
339 |
|
rpict(seqstart, outfile, zfile, recover); |
359 |
|
goto runagain; |
360 |
|
} |
361 |
|
#endif |
362 |
+ |
|
363 |
+ |
|
364 |
+ |
ray_done_pmap(); /* PMAP: free photon maps */ |
365 |
+ |
|
366 |
|
quit(0); |
367 |
|
|
368 |
|
badopt: |
369 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
370 |
|
error(USER, errmsg); |
371 |
+ |
return 1; /* pro forma return */ |
372 |
|
|
373 |
|
#undef check |
374 |
|
#undef bool |
376 |
|
|
377 |
|
|
378 |
|
void |
379 |
< |
wputs(s) /* warning output function */ |
380 |
< |
char *s; |
379 |
> |
wputs( /* warning output function */ |
380 |
> |
char *s |
381 |
> |
) |
382 |
|
{ |
383 |
|
int lasterrno = errno; |
384 |
|
eputs(s); |
387 |
|
|
388 |
|
|
389 |
|
void |
390 |
< |
eputs(s) /* put string to stderr */ |
391 |
< |
register char *s; |
390 |
> |
eputs( /* put string to stderr */ |
391 |
> |
register char *s |
392 |
> |
) |
393 |
|
{ |
394 |
|
static int midline = 0; |
395 |
|
|
407 |
|
} |
408 |
|
|
409 |
|
|
410 |
< |
void |
411 |
< |
onsig(signo) /* fatal signal */ |
412 |
< |
int signo; |
410 |
> |
static void |
411 |
> |
onsig( /* fatal signal */ |
412 |
> |
int signo |
413 |
> |
) |
414 |
|
{ |
415 |
|
static int gotsig = 0; |
416 |
|
|
417 |
|
if (gotsig++) /* two signals and we're gone! */ |
418 |
|
_exit(signo); |
419 |
|
|
420 |
+ |
#ifdef SIGALRM /* XXX how critical is this? */ |
421 |
|
alarm(15); /* allow 15 seconds to clean up */ |
422 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
423 |
+ |
#endif |
424 |
|
eputs("signal - "); |
425 |
|
eputs(sigerr[signo]); |
426 |
|
eputs("\n"); |
428 |
|
} |
429 |
|
|
430 |
|
|
431 |
< |
void |
432 |
< |
sigdie(signo, msg) /* set fatal signal */ |
433 |
< |
int signo; |
434 |
< |
char *msg; |
431 |
> |
static void |
432 |
> |
sigdie( /* set fatal signal */ |
433 |
> |
int signo, |
434 |
> |
char *msg |
435 |
> |
) |
436 |
|
{ |
437 |
|
if (signal(signo, onsig) == SIG_IGN) |
438 |
|
signal(signo, SIG_IGN); |
440 |
|
} |
441 |
|
|
442 |
|
|
443 |
< |
void |
444 |
< |
printdefaults() /* print default values to stdout */ |
443 |
> |
static void |
444 |
> |
printdefaults(void) /* print default values to stdout */ |
445 |
|
{ |
424 |
– |
register char *cp; |
425 |
– |
|
446 |
|
printf("-vt%c\t\t\t\t# view type %s\n", ourview.type, |
447 |
|
ourview.type==VT_PER ? "perspective" : |
448 |
|
ourview.type==VT_PAR ? "parallel" : |
449 |
|
ourview.type==VT_HEM ? "hemispherical" : |
450 |
|
ourview.type==VT_ANG ? "angular" : |
451 |
|
ourview.type==VT_CYL ? "cylindrical" : |
452 |
+ |
ourview.type==VT_PLS ? "planisphere" : |
453 |
|
"unknown"); |
454 |
|
printf("-vp %f %f %f\t# view point\n", |
455 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
468 |
|
printf("-pa %f\t\t\t# pixel aspect ratio\n", pixaspect); |
469 |
|
printf("-pj %f\t\t\t# pixel jitter\n", dstrpix); |
470 |
|
printf("-pm %f\t\t\t# pixel motion\n", mblur); |
471 |
+ |
printf("-pd %f\t\t\t# pixel depth-of-field\n", dblur); |
472 |
|
printf("-ps %-9d\t\t\t# pixel sample\n", psample); |
473 |
|
printf("-pt %f\t\t\t# pixel threshold\n", maxdiff); |
474 |
|
printf("-t %-9d\t\t\t# time between reports\n", ralrm); |