91 |
|
FILE *fp; |
92 |
|
int fd; |
93 |
|
int hflags = 0; |
94 |
< |
int4 nextloc; |
94 |
> |
long nextloc; |
95 |
|
int n; |
96 |
|
/* open holodeck file */ |
97 |
|
if ((fp = fopen(fname, append ? "r+" : "r")) == NULL) { |
109 |
|
nextloc = ftell(fp); /* get stdio position */ |
110 |
|
fclose(fp); /* done with stdio */ |
111 |
|
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
112 |
< |
lseek(fd, (long)nextloc, 0); |
112 |
> |
lseek(fd, nextloc, 0); |
113 |
|
read(fd, (char *)&nextloc, sizeof(nextloc)); |
114 |
|
hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr : |
115 |
|
hflags&H_OBSF ? &unobstr : (char *)NULL; |
159 |
|
int fd; |
160 |
|
register HOLO *hp; |
161 |
|
register BEAM *bp; |
162 |
+ |
register HDBEAMI *hbl; |
163 |
|
GCOORD gc[2]; |
164 |
|
FVECT ro, rd; |
165 |
|
double d; |
166 |
|
int i, j; |
167 |
|
register int k; |
168 |
< |
|
169 |
< |
openholo(hdf, 0); /* open the holodeck for reading */ |
168 |
> |
/* open the holodeck for reading */ |
169 |
> |
openholo(hdf, 0); |
170 |
|
fd = hdlist[noutsects]->fd; /* remember the file handle */ |
171 |
|
while ((hp = hdlist[noutsects]) != NULL) { /* load each section */ |
172 |
< |
for (j = nbeams(hp); j > 0; j--) /* load each beam */ |
173 |
< |
if ((bp = hdgetbeam(hp, j)) != NULL) { |
174 |
< |
hdbcoord(gc, hp, j); |
172 |
> |
hbl = (HDBEAMI *)malloc(nbeams(hp)*sizeof(HDBEAMI)); |
173 |
> |
if (hbl == NULL) |
174 |
> |
error(SYSTEM, "out of memory in addholo"); |
175 |
> |
for (j = nbeams(hp); j > 0; j--) { /* sort the beams */ |
176 |
> |
hbl[j].h = hp; |
177 |
> |
hbl[j].b = j; |
178 |
> |
} |
179 |
> |
qsort((char *)hbl, nbeams(hp), sizeof(HDBEAMI), hdfilord); |
180 |
> |
for (j = 0; j < nbeams(hp); j++) /* load each beam */ |
181 |
> |
if ((bp = hdgetbeam(hp, hbl[j].b)) != NULL) { |
182 |
> |
hdbcoord(gc, hp, hbl[j].b); |
183 |
|
for (k = bp->nrm; k--; ) { |
184 |
|
d = hdray(ro, rd, |
185 |
|
hp, gc, hdbray(bp)[k].r); |
190 |
|
d = hddepth(hp, hdbray(bp)[k].d) - d; |
191 |
|
addray(ro, rd, d, hdbray(bp)[k].v); |
192 |
|
} |
193 |
< |
hdfreebeam(hp, j); /* free the beam */ |
193 |
> |
hdfreebeam(hp, hbl[j].b); /* free beam */ |
194 |
|
} |
195 |
+ |
free((char *)hbl); /* free beam list */ |
196 |
|
hddone(hp); /* free the section */ |
197 |
|
} |
198 |
|
close(fd); /* close the file */ |