68 |
|
|
69 |
|
/* rtrace command and defaults */ |
70 |
|
char *rtargv[256] = { "rtrace", "-dt", "0", "-dj", ".5", "-dr", "3", |
71 |
< |
"-ab", "1", "-ad", "512", }; |
71 |
> |
"-ab", "1", "-ad", "128", }; |
72 |
|
int rtargc = 11; |
73 |
|
/* overriding rtrace options */ |
74 |
|
char *myrtopts[] = { "-o~~TmWdp", "-h-", |
113 |
|
void tracecontribs(FILE *fp); |
114 |
|
struct rtproc *wait_rproc(void); |
115 |
|
struct rtproc *get_rproc(void); |
116 |
< |
void process_rays(struct rtproc *rtp); |
116 |
> |
void queue_raytree(struct rtproc *rtp); |
117 |
> |
void process_queue(void); |
118 |
|
|
119 |
|
void putcontrib(const DCOLOR cnt, FILE *fout); |
120 |
|
void add_contrib(const char *modn); |
189 |
|
case '\0': |
190 |
|
header = !header; |
191 |
|
continue; |
192 |
< |
case '+': case '1': case 'T': case 't': |
192 |
> |
case '+': case '1': |
193 |
> |
case 'T': case 't': |
194 |
> |
case 'Y': case 'y': |
195 |
|
header = 1; |
196 |
|
continue; |
197 |
< |
case '-': case '0': case 'F': case 'f': |
197 |
> |
case '-': case '0': |
198 |
> |
case 'F': case 'f': |
199 |
> |
case 'N': case 'n': |
200 |
|
header = 0; |
201 |
|
continue; |
202 |
|
} |
350 |
|
scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0); |
351 |
|
scompile("Px=$4;Py=$5;Pz=$6;", NULL, 0); |
352 |
|
/* set up signal handling */ |
353 |
< |
#ifdef SIGPIPE /* not present on Windows */ |
353 |
> |
signal(SIGINT, quit); |
354 |
> |
#ifdef SIGHUP |
355 |
> |
signal(SIGHUP, quit); |
356 |
> |
#endif |
357 |
> |
#ifdef SIGTERM |
358 |
> |
signal(SIGTERM, quit); |
359 |
> |
#endif |
360 |
> |
#ifdef SIGPIPE |
361 |
|
signal(SIGPIPE, quit); |
362 |
|
#endif |
363 |
|
rtp = &rt0; /* start rtrace process(es) */ |
691 |
|
} |
692 |
|
} |
693 |
|
|
694 |
< |
/* process (or save) ray tree produced by rtrace process */ |
694 |
> |
/* queue completed ray tree produced by rtrace process */ |
695 |
|
void |
696 |
< |
process_rays(struct rtproc *rtp) |
696 |
> |
queue_raytree(struct rtproc *rtp) |
697 |
|
{ |
698 |
< |
struct rtproc *rtu; |
699 |
< |
/* check if time to process it */ |
700 |
< |
if (rtp->raynum == lastdone+1) { |
698 |
> |
struct rtproc *rtu, *rtl = NULL; |
699 |
> |
/* insert following ray order */ |
700 |
> |
for (rtu = rt_unproc; rtu != NULL; rtu = (rtl=rtu)->next) |
701 |
> |
if (rtp->raynum < rtu->raynum) |
702 |
> |
break; |
703 |
> |
rtu = (struct rtproc *)malloc(sizeof(struct rtproc)); |
704 |
> |
if (rtu == NULL) |
705 |
> |
error(SYSTEM, "out of memory in queue_raytree"); |
706 |
> |
*rtu = *rtp; |
707 |
> |
if (rtl == NULL) { |
708 |
> |
rtu->next = rt_unproc; |
709 |
> |
rt_unproc = rtu; |
710 |
> |
} else { |
711 |
> |
rtu->next = rtl->next; |
712 |
> |
rtl->next = rtu; |
713 |
> |
} |
714 |
> |
rtp->raynum = 0; /* clear path for next ray tree */ |
715 |
> |
rtp->bsiz = 0; |
716 |
> |
rtp->buf = NULL; |
717 |
> |
rtp->nbr = 0; |
718 |
> |
} |
719 |
> |
|
720 |
> |
/* process completed ray trees from our queue */ |
721 |
> |
void |
722 |
> |
process_queue(void) |
723 |
> |
{ |
724 |
> |
char modname[128]; |
725 |
> |
/* ray-ordered queue */ |
726 |
> |
while (rt_unproc != NULL && rt_unproc->raynum == lastdone+1) { |
727 |
> |
struct rtproc *rtp = rt_unproc; |
728 |
|
int n = rtp->nbr; |
729 |
|
const char *cp = rtp->buf; |
691 |
– |
char modname[128]; |
730 |
|
while (n > 0) { /* process rays */ |
731 |
|
register char *mnp = modname; |
732 |
|
/* skip leading tabs */ |
750 |
|
} |
751 |
|
done_contrib(); /* sum up contributions & output */ |
752 |
|
lastdone = rtp->raynum; |
753 |
< |
free(rtp->buf); |
754 |
< |
/* catch up with unprocessed list */ |
755 |
< |
while (rt_unproc != NULL && rt_unproc->raynum == lastdone+1) { |
718 |
< |
process_rays(rt_unproc); |
719 |
< |
rt_unproc = (rtu=rt_unproc)->next; |
720 |
< |
free(rtu); |
721 |
< |
} |
722 |
< |
} else { /* else insert in unprocessed list */ |
723 |
< |
struct rtproc *rtl = NULL; |
724 |
< |
for (rtu = rt_unproc; rtu != NULL; rtu = (rtl=rtu)->next) |
725 |
< |
if (rtp->raynum < rtu->raynum) |
726 |
< |
break; |
727 |
< |
rtu = (struct rtproc *)malloc(sizeof(struct rtproc)); |
728 |
< |
if (rtu == NULL) |
729 |
< |
error(SYSTEM, "out of memory in process_rays"); |
730 |
< |
*rtu = *rtp; |
731 |
< |
if (rtl == NULL) { |
732 |
< |
rtu->next = rt_unproc; |
733 |
< |
rt_unproc = rtu; |
734 |
< |
} else { |
735 |
< |
rtu->next = rtl->next; |
736 |
< |
rtl->next = rtu; |
737 |
< |
} |
753 |
> |
free(rtp->buf); /* free up buffer space */ |
754 |
> |
rt_unproc = rtp->next; |
755 |
> |
free(rtp); /* done with this ray tree */ |
756 |
|
} |
739 |
– |
rtp->raynum = 0; /* clear path for next ray tree */ |
740 |
– |
rtp->bsiz = 0; |
741 |
– |
rtp->buf = NULL; |
742 |
– |
rtp->nbr = 0; |
757 |
|
} |
758 |
|
|
759 |
|
/* wait for rtrace process to finish with ray tree */ |
810 |
|
if (rt->nbr >= 4 && !memcmp(rt->buf+rt->nbr-4, |
811 |
|
"~\t~\t", 4)) { |
812 |
|
rt->nbr -= 4; /* elide terminator */ |
813 |
< |
process_rays(rt); |
813 |
> |
queue_raytree(rt); |
814 |
|
rtfree = rt; /* ready for next ray */ |
815 |
|
} |
816 |
|
} |
841 |
|
while ((iblen = getinp(inpbuf, fin)) > 0) { |
842 |
|
if (lastray+1 < lastray) { /* counter rollover? */ |
843 |
|
while (wait_rproc() != NULL) |
844 |
< |
; |
844 |
> |
process_queue(); |
845 |
|
lastdone = lastray = 0; |
846 |
|
} |
847 |
|
rtp = get_rproc(); /* get avail. rtrace process */ |
848 |
< |
rtp->raynum = ++lastray; /* assign this ray to it */ |
848 |
> |
rtp->raynum = ++lastray; /* assign ray to it */ |
849 |
|
writebuf(rtp->pd.w, inpbuf, iblen); |
850 |
|
if (!--raysleft) |
851 |
< |
break; /* explicit EOF */ |
851 |
> |
break; |
852 |
> |
process_queue(); /* catch up with results */ |
853 |
|
} |
854 |
|
while (wait_rproc() != NULL) /* process outstanding rays */ |
855 |
< |
; |
855 |
> |
process_queue(); |
856 |
|
if (raysleft > 0) |
857 |
|
error(USER, "unexpected EOF on input"); |
858 |
|
} |