12 |
|
#include "view.h" |
13 |
|
#include "resolu.h" |
14 |
|
|
15 |
+ |
#ifndef BLOADSIZE |
16 |
+ |
#define BLOADSIZE 1024 /* number of input beams to load at a time */ |
17 |
+ |
#endif |
18 |
+ |
|
19 |
+ |
int checkdepth = 1; /* check depth (!-f option)? */ |
20 |
+ |
int checkrepeats = 0; /* check for repeats (-c option)? */ |
21 |
|
int frompicz; /* input from pictures & depth-buffers? */ |
22 |
|
int noutsects; /* number of output sections */ |
23 |
|
char obstr, unobstr; /* flag pointer values */ |
32 |
|
int i; |
33 |
|
|
34 |
|
progname = argv[0]; |
35 |
< |
if (argc < 4) |
35 |
> |
frompicz = -1; |
36 |
> |
for (i = 2; i < argc && argv[i][0] == '-'; i++) |
37 |
> |
switch (argv[i][1]) { |
38 |
> |
case 'u': |
39 |
> |
checkrepeats = 1; |
40 |
> |
break; |
41 |
> |
case 'd': |
42 |
> |
checkdepth = 0; |
43 |
> |
break; |
44 |
> |
case 'h': |
45 |
> |
frompicz = 0; |
46 |
> |
break; |
47 |
> |
case 'p': |
48 |
> |
frompicz = 1; |
49 |
> |
break; |
50 |
> |
default: |
51 |
> |
goto userr; |
52 |
> |
} |
53 |
> |
if (i >= argc || frompicz < 0) |
54 |
|
goto userr; |
55 |
< |
if (!strcmp(argv[2], "-h")) |
32 |
< |
frompicz = 0; |
33 |
< |
else if (!strcmp(argv[2], "-pz")) |
34 |
< |
frompicz = 1; |
35 |
< |
else |
55 |
> |
if (frompicz && (argc-i)%2) |
56 |
|
goto userr; |
37 |
– |
if (frompicz && (argc-3)%2) |
38 |
– |
goto userr; |
57 |
|
noutsects = openholo(argv[1], 1); |
58 |
|
if (frompicz) |
59 |
< |
for (i = 3; i < argc; i += 2) |
59 |
> |
for ( ; i < argc; i += 2) |
60 |
|
addpicz(argv[i], argv[i+1]); |
61 |
|
else |
62 |
< |
for (i = 3; i < argc; i++) |
62 |
> |
for ( ; i < argc; i++) |
63 |
|
addholo(argv[i]); |
64 |
|
quit(0); |
65 |
|
userr: |
66 |
< |
fprintf(stderr, "Usage: %s output.hdk -h inp1.hdk ..\n", progname); |
49 |
< |
fprintf(stderr, " Or: %s output.hdk -pz inp1.pic inp1.zbf ..\n", |
66 |
> |
fprintf(stderr, "Usage: %s output.hdk [-u][-d] -h inp1.hdk ..\n", |
67 |
|
progname); |
68 |
+ |
fprintf(stderr, " Or: %s output.hdk [-u][-d] -pz inp1.pic inp1.zbf ..\n", |
69 |
+ |
progname); |
70 |
|
exit(1); |
71 |
|
} |
72 |
|
|
75 |
|
#define H_OBST 02 |
76 |
|
#define H_OBSF 04 |
77 |
|
|
78 |
+ |
int |
79 |
|
holheadline(s, hf) /* check holodeck header line */ |
80 |
|
register char *s; |
81 |
|
int *hf; |
87 |
|
*hf |= H_BADF; |
88 |
|
else |
89 |
|
*hf &= ~H_BADF; |
90 |
< |
return; |
90 |
> |
return(0); |
91 |
|
} |
92 |
|
if (!strncmp(s, "OBSTRUCTIONS=", 13)) { |
93 |
|
s += 13; |
98 |
|
*hf |= H_OBSF; |
99 |
|
else |
100 |
|
error(WARNING, "bad OBSTRUCTIONS value in holodeck"); |
101 |
< |
return; |
101 |
> |
return(0); |
102 |
|
} |
103 |
+ |
return(0); |
104 |
|
} |
105 |
|
|
106 |
|
int |
148 |
|
double d; |
149 |
|
COLR cv; |
150 |
|
{ |
151 |
< |
int sn; |
151 |
> |
int sn, bi, n; |
152 |
|
register HOLO *hp; |
153 |
|
GCOORD gc[2]; |
154 |
|
BYTE rr[2][2]; |
155 |
+ |
BEAM *bp; |
156 |
|
double d0, d1; |
157 |
+ |
unsigned dc; |
158 |
|
register RAYVAL *rv; |
159 |
|
/* check each output section */ |
160 |
|
for (sn = noutsects; sn--; ) { |
162 |
|
d0 = hdinter(gc, rr, &d1, hp, ro, rd); |
163 |
|
if (d <= d0 || d1 < -0.001) |
164 |
|
continue; /* missed section */ |
165 |
< |
if (hp->priv == &obstr && d0 < -0.001) |
166 |
< |
continue; /* ray starts too late */ |
167 |
< |
if (hp->priv == &unobstr && d < 0.999*d1) |
168 |
< |
continue; /* ray ends too soon */ |
169 |
< |
/* should we check for duplicates? */ |
170 |
< |
rv = hdnewrays(hp, hdbindex(hp, gc), 1); |
165 |
> |
if (checkdepth) { /* check depth */ |
166 |
> |
if (hp->priv == &obstr && d0 < -0.001) |
167 |
> |
continue; /* ray starts too late */ |
168 |
> |
if (hp->priv == &unobstr && d < 0.999*d1) |
169 |
> |
continue; /* ray ends too soon */ |
170 |
> |
} |
171 |
> |
dc = hdcode(hp, d-d0); |
172 |
> |
bi = hdbindex(hp, gc); /* check for duplicates */ |
173 |
> |
if (checkrepeats && (bp = hdgetbeam(hp, bi)) != NULL) { |
174 |
> |
for (n = bp->nrm, rv = hdbray(bp); n--; rv++) |
175 |
> |
if (rv->d == dc && |
176 |
> |
rv->r[0][0] == rr[0][0] && |
177 |
> |
rv->r[0][1] == rr[0][1] && |
178 |
> |
rv->r[1][0] == rr[1][0] && |
179 |
> |
rv->r[1][1] == rr[1][1]) |
180 |
> |
break; |
181 |
> |
if (n >= 0) |
182 |
> |
continue; /* found a matching ray */ |
183 |
> |
} |
184 |
> |
rv = hdnewrays(hp, bi, 1); |
185 |
> |
rv->d = dc; |
186 |
|
rv->r[0][0] = rr[0][0]; rv->r[0][1] = rr[0][1]; |
187 |
|
rv->r[1][0] = rr[1][0]; rv->r[1][1] = rr[1][1]; |
188 |
|
copycolr(rv->v, cv); |
151 |
– |
rv->d = hdcode(hp, d-d0); |
189 |
|
} |
190 |
|
} |
191 |
|
|
193 |
|
addholo(hdf) /* add a holodeck file */ |
194 |
|
char *hdf; |
195 |
|
{ |
196 |
+ |
HDBEAMI hbl[BLOADSIZE]; |
197 |
|
int fd; |
198 |
|
register HOLO *hp; |
199 |
|
register BEAM *bp; |
200 |
|
GCOORD gc[2]; |
201 |
|
FVECT ro, rd; |
202 |
|
double d; |
203 |
< |
int i, j; |
203 |
> |
int i, j, n, li; |
204 |
|
register int k; |
205 |
< |
|
206 |
< |
openholo(hdf, 0); /* open the holodeck for reading */ |
205 |
> |
/* open the holodeck for reading */ |
206 |
> |
openholo(hdf, 0); |
207 |
|
fd = hdlist[noutsects]->fd; /* remember the file handle */ |
208 |
|
while ((hp = hdlist[noutsects]) != NULL) { /* load each section */ |
209 |
< |
for (j = nbeams(hp); j > 0; j--) /* load each beam */ |
210 |
< |
if ((bp = hdgetbeam(hp, j)) != NULL) { |
211 |
< |
hdbcoord(gc, hp, j); |
209 |
> |
for (j = 0; j < nbeams(hp); j++) { /* load each beam */ |
210 |
> |
if (!(li = j % BLOADSIZE)) { /* optimize order */ |
211 |
> |
if (j+BLOADSIZE > nbeams(hp)) |
212 |
> |
k = n = nbeams(hp) - j; |
213 |
> |
else |
214 |
> |
k = n = BLOADSIZE; |
215 |
> |
while (k--) { |
216 |
> |
hbl[k].h = hp; |
217 |
> |
hbl[k].b = j+k+1; |
218 |
> |
} |
219 |
> |
qsort((char *)hbl, n, |
220 |
> |
sizeof(HDBEAMI), hdfilord); |
221 |
> |
} |
222 |
> |
if ((bp = hdgetbeam(hp, hbl[li].b)) != NULL) { |
223 |
> |
hdbcoord(gc, hp, hbl[li].b); |
224 |
|
for (k = bp->nrm; k--; ) { |
225 |
|
d = hdray(ro, rd, |
226 |
|
hp, gc, hdbray(bp)[k].r); |
231 |
|
d = hddepth(hp, hdbray(bp)[k].d) - d; |
232 |
|
addray(ro, rd, d, hdbray(bp)[k].v); |
233 |
|
} |
234 |
< |
hdfreebeam(hp, j); /* free the beam */ |
234 |
> |
hdfreebeam(hp, hbl[li].b); /* free beam */ |
235 |
|
} |
236 |
+ |
} |
237 |
|
hddone(hp); /* free the section */ |
238 |
|
} |
239 |
|
close(fd); /* close the file */ |
249 |
|
}; |
250 |
|
|
251 |
|
|
252 |
+ |
int |
253 |
|
picheadline(s, ph) /* process picture header line */ |
254 |
|
char *s; |
255 |
|
struct phead *ph; |
258 |
|
|
259 |
|
if (formatval(fmt, s)) { |
260 |
|
ph->badfmt = strcmp(fmt, COLRFMT); |
261 |
< |
return; |
261 |
> |
return(0); |
262 |
|
} |
263 |
|
if (isprims(s)) { |
264 |
|
ph->altprims++; /* don't want to deal with this */ |
265 |
< |
return; |
265 |
> |
return(0); |
266 |
|
} |
267 |
|
if (isexpos(s)) { |
268 |
|
ph->expos *= exposval(s); |
269 |
< |
return; |
269 |
> |
return(0); |
270 |
|
} |
271 |
|
if (isview(s)) { |
272 |
|
ph->gotview += sscanview(&ph->vw, s); |
273 |
< |
return; |
273 |
> |
return(0); |
274 |
|
} |
275 |
+ |
return(0); |
276 |
|
} |
277 |
|
|
278 |
|
|