| 14 |
|
#include "color.h" |
| 15 |
|
#include "resolu.h" |
| 16 |
|
#include "lookup.h" |
| 17 |
– |
#include "random.h" |
| 17 |
|
#include "calcomp.h" |
| 18 |
|
|
| 19 |
+ |
#ifdef _WIN32 |
| 20 |
+ |
typedef long ssize_t; |
| 21 |
+ |
#endif |
| 22 |
+ |
|
| 23 |
|
#ifndef MAXMODLIST |
| 24 |
|
#define MAXMODLIST 1024 /* maximum modifiers we'll track */ |
| 25 |
|
#endif |
| 26 |
|
|
| 27 |
< |
size_t treebufsiz = BUFSIZ; /* current tree buffer size */ |
| 27 |
> |
ssize_t treebufsiz = BUFSIZ; /* current tree buffer size */ |
| 28 |
|
|
| 29 |
|
typedef double DCOLOR[3]; /* double-precision color */ |
| 30 |
|
|
| 111 |
|
char *myrtopts[] = { "-h-", "-x", "1", "-y", "0", |
| 112 |
|
"-dt", "0", "-as", "0", "-aa", "0", NULL }; |
| 113 |
|
|
| 114 |
< |
#define RTCOEFF "-o~~TmWdp" /* compute coefficients only */ |
| 115 |
< |
#define RTCONTRIB "-o~~TmVdp" /* compute ray contributions */ |
| 114 |
> |
#define RTCOEFF "-o~~~TmWdp" /* compute coefficients only */ |
| 115 |
> |
#define RTCONTRIB "-o~~~TmVdp" /* compute ray contributions */ |
| 116 |
|
|
| 117 |
|
struct rtproc rt0; /* head of rtrace process list */ |
| 118 |
|
|
| 706 |
|
printheader(FILE *fout, const char *info) |
| 707 |
|
{ |
| 708 |
|
extern char VersionID[]; |
| 709 |
< |
FILE *fin = fopen(octree, "r"); |
| 710 |
< |
|
| 711 |
< |
if (fin == NULL) |
| 712 |
< |
quit(1); |
| 713 |
< |
checkheader(fin, "ignore", fout); /* copy octree header */ |
| 714 |
< |
fclose(fin); |
| 709 |
> |
/* copy octree header */ |
| 710 |
> |
if (octree[0] == '!') { |
| 711 |
> |
newheader("RADIANCE", fout); |
| 712 |
> |
fputs(octree+1, fout); |
| 713 |
> |
if (octree[strlen(octree)-1] != '\n') |
| 714 |
> |
fputc('\n', fout); |
| 715 |
> |
} else { |
| 716 |
> |
FILE *fin = fopen(octree, "r"); |
| 717 |
> |
if (fin == NULL) |
| 718 |
> |
quit(1); |
| 719 |
> |
checkheader(fin, "ignore", fout); |
| 720 |
> |
fclose(fin); |
| 721 |
> |
} |
| 722 |
|
printargs(gargc-1, gargv, fout); /* add our command */ |
| 723 |
|
fprintf(fout, "SOFTWARE= %s\n", VersionID); |
| 724 |
|
fputnow(fout); |
| 1117 |
|
continue; |
| 1118 |
|
if (rt->buf == NULL) { |
| 1119 |
|
rt->bsiz = treebufsiz; |
| 1120 |
< |
rt->buf = (char *)malloc(treebufsiz); |
| 1120 |
> |
rt->buf = (char *)malloc(rt->bsiz); |
| 1121 |
|
} else if (rt->nbr + BUFSIZ > rt->bsiz) { |
| 1122 |
|
if (rt->bsiz + BUFSIZ <= treebufsiz) |
| 1123 |
|
rt->bsiz = treebufsiz; |
| 1124 |
< |
else |
| 1125 |
< |
treebufsiz = rt->bsiz += BUFSIZ; |
| 1124 |
> |
else if ((treebufsiz = rt->bsiz += BUFSIZ) < 0) |
| 1125 |
> |
error(INTERNAL, |
| 1126 |
> |
"ray buffer does not fit memory"); |
| 1127 |
|
rt->buf = (char *)realloc(rt->buf, rt->bsiz); |
| 1128 |
|
} |
| 1129 |
|
if (rt->buf == NULL) |
| 1130 |
|
error(SYSTEM, "out of memory in wait_rproc"); |
| 1131 |
< |
nr = read(rt->pd.r, rt->buf+rt->nbr, rt->bsiz-rt->nbr); |
| 1132 |
< |
if (nr <= 0) |
| 1131 |
> |
nr = rt->bsiz - rt->nbr; |
| 1132 |
> |
if (nr & ~0x7fffffff) /* avoid 32-bit OS issues */ |
| 1133 |
> |
nr = 0x7fffffff; |
| 1134 |
> |
nr = read(rt->pd.r, rt->buf+rt->nbr, nr); |
| 1135 |
> |
if (nr < 0) |
| 1136 |
> |
error(SYSTEM, "read error from rtrace"); |
| 1137 |
> |
if (!nr) |
| 1138 |
|
error(USER, "rtrace process died"); |
| 1139 |
|
rt->nbr += nr; /* advance & check */ |
| 1140 |
< |
if (rt->nbr >= 4 && !memcmp(rt->buf+rt->nbr-4, |
| 1141 |
< |
"~\t~\t", 4)) { |
| 1142 |
< |
rt->nbr -= 4; /* elide terminator */ |
| 1140 |
> |
if (rt->nbr >= 6 && !memcmp(rt->buf+rt->nbr-6, |
| 1141 |
> |
"~\t~\t~\t", 6)) { |
| 1142 |
> |
rt->nbr -= 6; /* elide terminator */ |
| 1143 |
|
queue_raytree(rt); |
| 1144 |
|
rtfree = rt; /* ready for next ray */ |
| 1145 |
|
} |
| 1181 |
|
lastray+1 < lastray) { |
| 1182 |
|
while (wait_rproc() != NULL) |
| 1183 |
|
process_queue(); |
| 1184 |
< |
if (lastray+1 < lastray) |
| 1169 |
< |
lastdone = lastray = 0; |
| 1184 |
> |
lastdone = lastray = 0; |
| 1185 |
|
} |
| 1186 |
|
rtp = get_rproc(); /* get avail. rtrace process */ |
| 1187 |
|
rtp->raynum = ++lastray; /* assign ray */ |