16 |
|
#define MAXDIST 42 /* maximum distance outside section */ |
17 |
|
#endif |
18 |
|
|
19 |
+ |
#define MAXVOXEL 16 /* maximum number of active voxels */ |
20 |
+ |
|
21 |
|
extern GCOORD *getviewcells(); |
22 |
|
|
23 |
|
static VIEW dvw; /* current view corresponding to beam list */ |
27 |
|
int i[3]; /* voxel index (may be outside section) */ |
28 |
|
} VOXL; /* a voxel */ |
29 |
|
|
30 |
< |
static VOXL voxel[8] = { /* current voxel list */ |
29 |
< |
{-1}, {-1}, {-1}, {-1}, |
30 |
< |
{-1}, {-1}, {-1}, {-1} |
31 |
< |
}; |
30 |
> |
static VOXL voxel[MAXVOXEL] = {{-1}}; /* current voxel list */ |
31 |
|
|
32 |
|
#define CBEAMBLK 1024 /* cbeam allocation block size */ |
33 |
|
|
34 |
|
static struct beamcomp { |
35 |
< |
short wants; /* flags telling which voxels want us */ |
36 |
< |
short hd; /* holodeck section number */ |
35 |
> |
unsigned short wants; /* flags telling which voxels want us */ |
36 |
> |
unsigned short hd; /* holodeck section number */ |
37 |
|
int bi; /* beam index */ |
38 |
|
} *cbeam = NULL; /* current beam list */ |
39 |
|
|
192 |
|
|
193 |
|
int |
194 |
|
set_voxels(vl, n) /* set new voxel array */ |
195 |
< |
VOXL vl[8]; |
195 |
> |
VOXL vl[MAXVOXEL]; |
196 |
|
int n; |
197 |
|
{ |
198 |
|
short wmap[256]; |
199 |
< |
int vmap[8]; |
199 |
> |
int vmap[MAXVOXEL]; |
200 |
|
int comn = 0; |
201 |
|
int no; |
202 |
|
register int i, j; |
203 |
|
/* find common voxels */ |
204 |
< |
for (j = 0; j < 8 && voxel[j].hd >= 0; j++) { |
204 |
> |
for (j = 0; j < MAXVOXEL && voxel[j].hd >= 0; j++) { |
205 |
|
vmap[j] = -1; |
206 |
|
for (i = n; i--; ) |
207 |
|
if (!bcmp((char *)(vl+i), (char *)(voxel+j), |
223 |
|
cbeam[i].wants = wmap[cbeam[i].wants]; |
224 |
|
/* update our voxel list */ |
225 |
|
bcopy((char *)vl, (char *)voxel, n*sizeof(VOXL)); |
226 |
< |
for (j = n; j < 8; j++) |
227 |
< |
voxel[j].hd = -1; |
226 |
> |
if (n < MAXVOXEL) |
227 |
> |
voxel[n].hd = -1; |
228 |
|
return(comn); /* return bit array of common voxels */ |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
|
int |
233 |
|
get_voxels(vl, vp) /* find voxels corresponding to view point */ |
234 |
< |
VOXL vl[8]; |
234 |
> |
VOXL vl[MAXVOXEL]; |
235 |
|
FVECT vp; |
236 |
|
{ |
237 |
< |
int n = 0; |
237 |
> |
int first, n; |
238 |
|
FVECT gp; |
239 |
|
double d; |
240 |
|
int dist, bestd = 0x7fff; |
241 |
|
VOXL vox; |
242 |
|
register int i, j, k; |
243 |
+ |
/* count voxels in list already */ |
244 |
+ |
for (first = 0; first < MAXVOXEL && vl[first].hd >= 0; first++) |
245 |
+ |
; |
246 |
|
/* find closest voxels */ |
247 |
< |
for (i = 0; n < 8 && hdlist[i]; i++) { |
247 |
> |
for (n = first, i = 0; n < MAXVOXEL && hdlist[i]; i++) { |
248 |
|
hdgrid(gp, hdlist[i], vp); |
249 |
< |
for (j = 0; n < 8 && j < 8; j++) { |
249 |
> |
for (j = 0; n < MAXVOXEL && j < 8; j++) { |
250 |
|
dist = 0; |
251 |
|
for (k = 0; k < 3; k++) { |
252 |
|
d = gp[k] - .5 + (j>>k & 1); |
259 |
|
if (dist > bestd) /* others were closer */ |
260 |
|
continue; |
261 |
|
if (dist < bestd) { /* start closer list */ |
262 |
< |
n = 0; |
262 |
> |
n = first; |
263 |
|
bestd = dist; |
264 |
|
} |
265 |
+ |
/* check if already in list */ |
266 |
+ |
for (k = first; k--; ) |
267 |
+ |
if (vl[k].hd == i && |
268 |
+ |
vl[k].i[0] == vox.i[0] && |
269 |
+ |
vl[k].i[1] == vox.i[1] && |
270 |
+ |
vl[k].i[2] == vox.i[2]) |
271 |
+ |
break; |
272 |
+ |
if (k >= 0) |
273 |
+ |
continue; |
274 |
|
vox.hd = i; /* add this voxel */ |
275 |
|
copystruct(&vl[n], &vox); |
276 |
|
n++; |
281 |
|
error(COMMAND, "move past outer limits"); |
282 |
|
return(0); |
283 |
|
} |
284 |
+ |
if (n < MAXVOXEL) |
285 |
+ |
vl[n].hd = -1; |
286 |
|
return(n); |
287 |
|
} |
288 |
|
|
474 |
|
VIEW *vn; |
475 |
|
{ |
476 |
|
struct cellact ca; |
477 |
< |
VOXL vlnew[8]; |
477 |
> |
VOXL vlnew[MAXVOXEL]; |
478 |
|
int n, comn; |
479 |
|
|
480 |
|
if (vn == NULL || !vn->type) { /* clear our beam list */ |