1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
14 |
|
|
15 |
|
|
16 |
|
packrays(rod, p) /* pack ray origins and directions */ |
17 |
< |
register float *rod; |
17 |
> |
float *rod; |
18 |
|
register PACKET *p; |
19 |
|
{ |
20 |
< |
static FVECT ro, rd; |
20 |
> |
static int nmh = 0; |
21 |
> |
static int *mhtab; |
22 |
> |
FVECT ro, rd; |
23 |
> |
register BEAM *bp; |
24 |
|
GCOORD gc[2]; |
25 |
< |
int ila[2], hsh; |
25 |
> |
int ila[4], offset; |
26 |
|
double d, sl[4]; |
27 |
< |
register int i; |
27 |
> |
register int i, j, k; |
28 |
|
|
29 |
|
if (!hdbcoord(gc, hdlist[p->hd], p->bi)) |
30 |
|
error(CONSISTENCY, "bad beam index in packrays"); |
31 |
+ |
/* uniqueness hash */ |
32 |
+ |
if ((bp = hdgetbeam(hdlist[p->hd], p->bi)) != NULL) { |
33 |
+ |
if (2*bp->nrm > nmh) { |
34 |
+ |
if (nmh) free((char *)mhtab); |
35 |
+ |
nmh = 2*bp->nrm + 1; |
36 |
+ |
mhtab = (int *)malloc(nmh*sizeof(int)); |
37 |
+ |
if (mhtab == NULL) |
38 |
+ |
error(SYSTEM, "out of memory in packrays"); |
39 |
+ |
} |
40 |
+ |
for (k = nmh; k--; ) |
41 |
+ |
mhtab[k] = -1; |
42 |
+ |
for (i = bp->nrm; i--; ) { |
43 |
+ |
ila[0] = hdbray(bp)[i].r[0][0]; |
44 |
+ |
ila[1] = hdbray(bp)[i].r[0][1]; |
45 |
+ |
ila[2] = hdbray(bp)[i].r[1][0]; |
46 |
+ |
ila[3] = hdbray(bp)[i].r[1][1]; |
47 |
+ |
for (k = ilhash(ila,4); mhtab[k%nmh] >= 0; k++) |
48 |
+ |
; |
49 |
+ |
mhtab[k%nmh] = i; |
50 |
+ |
} |
51 |
+ |
} |
52 |
+ |
/* init each ray */ |
53 |
|
ila[0] = p->hd; ila[1] = p->bi; |
54 |
< |
hsh = ilhash(ila,2) + p->nc; |
54 |
> |
offset = ilhash(ila,2) + p->nc; |
55 |
|
for (i = 0; i < p->nr; i++) { |
56 |
< |
multisamp(sl, 4, urand(hsh+i)); |
57 |
< |
p->ra[i].r[0][0] = sl[0] * 256.; |
58 |
< |
p->ra[i].r[0][1] = sl[1] * 256.; |
59 |
< |
p->ra[i].r[1][0] = sl[2] * 256.; |
60 |
< |
p->ra[i].r[1][1] = sl[3] * 256.; |
56 |
> |
do { /* next unique ray */ |
57 |
> |
multisamp(sl, 4, urand(offset+i)); |
58 |
> |
p->ra[i].r[0][0] = ila[0] = sl[0] * 256.; |
59 |
> |
p->ra[i].r[0][1] = ila[1] = sl[1] * 256.; |
60 |
> |
p->ra[i].r[1][0] = ila[2] = sl[2] * 256.; |
61 |
> |
p->ra[i].r[1][1] = ila[3] = sl[3] * 256.; |
62 |
> |
if (bp == NULL) |
63 |
> |
break; |
64 |
> |
for (k = ilhash(ila,4); (j = mhtab[k%nmh]) >= 0; k++) |
65 |
> |
if (hdbray(bp)[j].r[0][0] == |
66 |
> |
p->ra[i].r[0][0] && |
67 |
> |
hdbray(bp)[j].r[0][1] == |
68 |
> |
p->ra[i].r[0][1] && |
69 |
> |
hdbray(bp)[j].r[1][0] == |
70 |
> |
p->ra[i].r[1][0] && |
71 |
> |
hdbray(bp)[j].r[1][1] == |
72 |
> |
p->ra[i].r[1][1]) { |
73 |
> |
offset += bp->nrm - j; |
74 |
> |
break; |
75 |
> |
} |
76 |
> |
} while (j >= 0); |
77 |
|
d = hdray(ro, rd, hdlist[p->hd], gc, p->ra[i].r); |
78 |
+ |
if (!vdef(OBSTRUCTIONS)) |
79 |
+ |
d *= frandom(); /* random offset */ |
80 |
|
if (p->offset != NULL) { |
81 |
< |
VSUM(ro, ro, rd, d); /* exterior only */ |
81 |
> |
VSUM(ro, ro, rd, d); /* advance ray */ |
82 |
|
p->offset[i] = d; |
83 |
|
} |
84 |
|
VCOPY(rod, ro); |
115 |
|
/* already closed? */ |
116 |
|
if (!nprocs) |
117 |
|
return; |
75 |
– |
wputs("closing rtrace process...\n"); |
118 |
|
/* flush beam queue */ |
119 |
|
done_packets(flush_queue()); |
120 |
|
/* sync holodeck */ |
122 |
|
/* close rtrace */ |
123 |
|
if ((status = end_rtrace())) |
124 |
|
error(WARNING, "bad exit status from rtrace"); |
125 |
< |
if (vdef(REPORT)) /* report time */ |
125 |
> |
if (vdef(REPORT)) { /* report time */ |
126 |
> |
eputs("rtrace process closed\n"); |
127 |
|
report(0); |
128 |
+ |
} |
129 |
|
return(status); /* return status */ |
130 |
|
} |
131 |
|
|
136 |
|
|
137 |
|
if (nprocs > 0) /* already running? */ |
138 |
|
return; |
95 |
– |
wputs("restarting rtrace process...\n"); |
139 |
|
starttime = time(NULL); /* reset start time and counts */ |
140 |
|
npacksdone = nraysdone = 0L; |
141 |
|
if (vdef(TIME)) /* reset end time */ |
147 |
|
} |
148 |
|
if (start_rtrace() < 1) /* start rtrace */ |
149 |
|
error(WARNING, "cannot restart rtrace"); |
150 |
< |
else if (vdef(REPORT)) |
150 |
> |
else if (vdef(REPORT)) { |
151 |
> |
eputs("rtrace process restarted\n"); |
152 |
|
report(0); |
153 |
+ |
} |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
getradfile() /* run rad and get needed variables */ |
158 |
|
{ |
159 |
< |
static short mvar[] = {OCTREE,-1}; |
159 |
> |
static short mvar[] = {OCTREE,EYESEP,-1}; |
160 |
|
static char tf1[] = TEMPLATE; |
161 |
|
char tf2[64]; |
162 |
|
char combuf[256]; |
165 |
|
register char *cp; |
166 |
|
/* check if rad file specified */ |
167 |
|
if (!vdef(RIF)) |
168 |
< |
return; |
168 |
> |
return(0); |
169 |
|
/* create rad command */ |
170 |
|
mktemp(tf1); |
171 |
|
sprintf(tf2, "%s.rif", tf1); |
188 |
|
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
189 |
|
else |
190 |
|
sprintf(cp, ")[ \t]*=' > %s", tf2); |
191 |
< |
if (system(combuf)) { |
192 |
< |
unlink(tf2); /* clean up */ |
193 |
< |
unlink(tf1); |
194 |
< |
error(SYSTEM, "cannot execute rad command"); |
150 |
< |
} |
191 |
> |
#ifdef DEBUG |
192 |
> |
wputs(combuf); wputs("\n"); |
193 |
> |
#endif |
194 |
> |
system(combuf); /* ignore exit code */ |
195 |
|
if (pippt == NULL) { |
196 |
|
loadvars(tf2); /* load variables */ |
197 |
|
unlink(tf2); |
198 |
|
} |
199 |
|
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
200 |
|
unlink(tf1); /* clean up */ |
201 |
+ |
return(1); |
202 |
|
} |
203 |
|
|
204 |
|
|