5 |
|
#endif |
6 |
|
|
7 |
|
/* |
8 |
< |
* Holodeck beam tracking |
8 |
> |
* Holodeck beam tracking for display process |
9 |
|
*/ |
10 |
|
|
11 |
|
#include "rholo.h" |
12 |
|
#include "rhdisp.h" |
13 |
|
#include "rhdriver.h" |
14 |
|
|
15 |
< |
extern int *getviewcells(); |
15 |
> |
extern GCOORD *getviewcells(); |
16 |
|
|
17 |
+ |
static VIEW dvw; /* current view corresponding to beam list */ |
18 |
+ |
|
19 |
|
typedef struct { |
20 |
< |
int hd; /* holodeck section number */ |
20 |
> |
int hd; /* holodeck section number (-1 if inactive) */ |
21 |
|
int i[3]; /* voxel index (may be outside section) */ |
22 |
|
} VOXL; /* a voxel */ |
23 |
|
|
38 |
|
static int xcbeams = 0; /* extra (unregistered) beams past ncbeams */ |
39 |
|
static int maxcbeam = 0; /* size of cbeam array */ |
40 |
|
|
39 |
– |
|
41 |
|
struct cellact { |
42 |
|
short vi; /* voxel index */ |
43 |
|
short add; /* zero means delete */ |
44 |
+ |
short rev; /* reverse ray direction? */ |
45 |
|
}; /* action for cell */ |
46 |
|
|
45 |
– |
|
47 |
|
struct beamact { |
48 |
|
struct cellact ca; /* cell action */ |
49 |
|
GCOORD gc; /* grid coordinate */ |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
< |
cbeamadd(bl, n, v, hr, vr) /* add beams to server list */ |
161 |
> |
cbeamop(op, bl, n, v, hr, vr) /* update beams on server list */ |
162 |
> |
int op; |
163 |
|
register struct beamcomp *bl; |
164 |
|
int n; |
165 |
|
VIEW *v; |
173 |
|
pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD)); |
174 |
|
if (pa == NULL) |
175 |
|
error(SYSTEM, "out of memory in cbeamadd"); |
174 |
– |
for (i = 0; i < n; i++) |
175 |
– |
pa[i].nr = npixels(v, hr, vr, |
176 |
– |
hdlist[pa[i].hd=bl[i].hd], |
177 |
– |
pa[i].bi=bl[i].bi) / 8; |
178 |
– |
|
179 |
– |
serv_request(DR_ADDSET, n*sizeof(PACKHEAD), (char *)pa); |
180 |
– |
free((char *)pa); |
181 |
– |
} |
182 |
– |
|
183 |
– |
|
184 |
– |
cbeamdel(bl, n) /* delete unwanted beam requests */ |
185 |
– |
register struct beamcomp *bl; |
186 |
– |
int n; |
187 |
– |
{ |
188 |
– |
register PACKHEAD *pa; |
189 |
– |
register int i; |
190 |
– |
|
191 |
– |
if (n <= 0) |
192 |
– |
return; |
193 |
– |
pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD)); |
194 |
– |
if (pa == NULL) |
195 |
– |
error(SYSTEM, "out of memory in cbeamdel"); |
176 |
|
for (i = 0; i < n; i++) { |
177 |
|
pa[i].hd = bl[i].hd; |
178 |
|
pa[i].bi = bl[i].bi; |
179 |
< |
pa[i].nr = 0; /* removes any request */ |
179 |
> |
pa[i].nr = v==NULL ? 0 : |
180 |
> |
npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi); |
181 |
|
} |
182 |
< |
serv_request(DR_DELSET, n*sizeof(PACKHEAD), (char *)pa); |
182 |
> |
serv_request(op, n*sizeof(PACKHEAD), (char *)pa); |
183 |
|
free((char *)pa); |
184 |
|
} |
185 |
|
|
228 |
|
VOXL vl[8]; |
229 |
|
FVECT vp; |
230 |
|
{ |
231 |
+ |
static int lastn = 0, lastd = -1; |
232 |
|
int n = 0; |
233 |
|
FVECT gp; |
234 |
|
double d; |
259 |
|
n++; |
260 |
|
} |
261 |
|
} |
262 |
< |
return(n); |
262 |
> |
/* warn of dangerous moves */ |
263 |
> |
if (n < lastn && bestd >= lastd) |
264 |
> |
error(WARNING, "moving outside holodeck section"); |
265 |
> |
else if (n > lastn && bestd <= lastd) |
266 |
> |
error(WARNING, "moving inside holodeck section"); |
267 |
> |
lastd = bestd; |
268 |
> |
return(lastn = n); |
269 |
|
} |
270 |
|
|
271 |
|
|
277 |
|
GCOORD gc[2]; |
278 |
|
int bi, i; |
279 |
|
/* compute beam index */ |
280 |
< |
copystruct(gc, gcp); |
281 |
< |
copystruct(gc+1, &bp->gc); |
280 |
> |
if (bp->ca.rev) { |
281 |
> |
copystruct(gc, &bp->gc); |
282 |
> |
copystruct(gc+1, gcp); |
283 |
> |
} else { |
284 |
> |
copystruct(gc, gcp); |
285 |
> |
copystruct(gc+1, &bp->gc); |
286 |
> |
} |
287 |
|
if ((bi = hdbindex(hdlist[voxel[bp->ca.vi].hd], gc)) <= 0) |
288 |
< |
return(0); /* should report an error? */ |
288 |
> |
error(CONSISTENCY, "bad grid coordinate in dobeam"); |
289 |
|
if (bp->ca.add) { /* add it in */ |
290 |
|
i = getcbeam(voxel[bp->ca.vi].hd, bi); |
291 |
|
cbeam[i].wants |= 1<<bp->ca.vi; /* say we want it */ |
343 |
|
struct cellact *cap; |
344 |
|
VIEW *vp; |
345 |
|
{ |
346 |
+ |
int orient; |
347 |
|
FVECT org, dir[4]; |
348 |
|
/* compute view pyramid */ |
349 |
< |
if (vp->type == VT_PAR) goto viewerr; |
350 |
< |
if (viewray(org, dir[0], vp, 0., 0.) < -FTINY) goto viewerr; |
351 |
< |
if (viewray(org, dir[1], vp, 0., 1.) < -FTINY) goto viewerr; |
352 |
< |
if (viewray(org, dir[2], vp, 1., 1.) < -FTINY) goto viewerr; |
359 |
< |
if (viewray(org, dir[3], vp, 1., 0.) < -FTINY) goto viewerr; |
349 |
> |
orient = viewpyramid(org, dir, hdlist[voxel[cap->vi].hd], vp); |
350 |
> |
if (!orient) |
351 |
> |
error(INTERNAL, "unusable view in doview"); |
352 |
> |
cap->rev = orient < 0; |
353 |
|
/* visit cells within pyramid */ |
354 |
|
return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], docell, cap)); |
362 |
– |
viewerr: |
363 |
– |
error(INTERNAL, "unusable view in doview"); |
355 |
|
} |
356 |
|
|
357 |
|
|
360 |
|
VIEW *vold, *vnew; |
361 |
|
{ |
362 |
|
int netchange = 0; |
363 |
< |
int *ocl, *ncl; |
373 |
< |
struct cellact ca; |
363 |
> |
struct cellact oca, nca; |
364 |
|
int ocnt, ncnt; |
365 |
|
int c; |
366 |
+ |
GCOORD *ogcl, *ngcl; |
367 |
|
register GCOORD *ogcp, *ngcp; |
368 |
|
/* get old and new cell lists */ |
369 |
< |
ocl = getviewcells(hdlist[voxel[voxi].hd], vold); |
370 |
< |
ncl = getviewcells(hdlist[voxel[voxi].hd], vnew); |
371 |
< |
if (ocl != NULL) { |
372 |
< |
ocnt = *ocl; ogcp = (GCOORD *)(ocl+1); |
373 |
< |
} else { |
374 |
< |
ocnt = 0; ogcp = NULL; |
375 |
< |
} |
376 |
< |
if (ncl != NULL) { |
377 |
< |
ncnt = *ncl; ngcp = (GCOORD *)(ncl+1); |
378 |
< |
} else { |
379 |
< |
ncnt = 0; ngcp = NULL; |
380 |
< |
} |
381 |
< |
ca.vi = voxi; /* add and delete cells */ |
382 |
< |
while (ocnt > 0 & ncnt > 0) |
383 |
< |
if ((c = cellcmp(ogcp, ngcp)) > 0) { |
384 |
< |
ca.add = 1; /* new cell */ |
385 |
< |
netchange += docell(ngcp++, &ca); |
386 |
< |
ncnt--; |
387 |
< |
} else if (c < 0) { |
388 |
< |
ca.add = 0; /* obsolete cell */ |
389 |
< |
netchange -= docell(ogcp++, &ca); |
390 |
< |
ocnt--; |
400 |
< |
} else { |
401 |
< |
ogcp++; ocnt--; /* unchanged cell */ |
402 |
< |
ngcp++; ncnt--; |
403 |
< |
} |
369 |
> |
ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold); |
370 |
> |
ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew); |
371 |
> |
/* set up actions */ |
372 |
> |
oca.vi = nca.vi = voxi; |
373 |
> |
oca.rev = nca.rev = 0; |
374 |
> |
oca.add = 0; nca.add = 1; |
375 |
> |
if ((oca.rev = ocnt < 0)) |
376 |
> |
ocnt = -ocnt; |
377 |
> |
if ((nca.rev = ncnt < 0)) |
378 |
> |
ncnt = -ncnt; |
379 |
> |
if (nca.rev == oca.rev) /* add and delete cells in order */ |
380 |
> |
while (ocnt > 0 & ncnt > 0) |
381 |
> |
if ((c = cellcmp(ogcp, ngcp)) > 0) { /* new cell */ |
382 |
> |
netchange += docell(ngcp++, &nca); |
383 |
> |
ncnt--; |
384 |
> |
} else if (c < 0) { /* old cell */ |
385 |
> |
netchange -= docell(ogcp++, &oca); |
386 |
> |
ocnt--; |
387 |
> |
} else { /* same cell */ |
388 |
> |
ogcp++; ocnt--; |
389 |
> |
ngcp++; ncnt--; |
390 |
> |
} |
391 |
|
/* take care of list tails */ |
392 |
< |
for (ca.add = 1; ncnt > 0; ncnt--) |
393 |
< |
docell(ngcp++, &ca); |
394 |
< |
for (ca.add = 0; ocnt > 0; ocnt--) |
395 |
< |
docell(ogcp++, &ca); |
392 |
> |
for ( ; ncnt > 0; ncnt--) |
393 |
> |
netchange += docell(ngcp++, &nca); |
394 |
> |
for ( ; ocnt > 0; ocnt--) |
395 |
> |
netchange -= docell(ogcp++, &oca); |
396 |
|
/* clean up */ |
397 |
< |
if (ocl != NULL) free((char *)ocl); |
398 |
< |
if (ncl != NULL) free((char *)ncl); |
397 |
> |
if (ogcl != NULL) free((char *)ogcl); |
398 |
> |
if (ngcl != NULL) free((char *)ngcl); |
399 |
|
return(netchange); |
400 |
|
} |
401 |
|
|
402 |
|
|
403 |
< |
beam_view(vo, vn) /* change beam view */ |
417 |
< |
VIEW *vo, *vn; |
403 |
> |
beam_sync() /* synchronize beams on server */ |
404 |
|
{ |
405 |
+ |
cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres); |
406 |
+ |
} |
407 |
+ |
|
408 |
+ |
|
409 |
+ |
beam_view(vn) /* change beam view */ |
410 |
+ |
VIEW *vn; |
411 |
+ |
{ |
412 |
|
struct cellact ca; |
413 |
|
VOXL vlnew[8]; |
414 |
|
int n, comn; |
415 |
|
|
416 |
|
if (!vn->type) { /* clear our beam list */ |
417 |
|
set_voxels(vlnew, 0); |
418 |
< |
cbeamdel(cbeam, ncbeams); |
418 |
> |
cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0); |
419 |
|
ncbeams = 0; |
420 |
+ |
copystruct(&dvw, vn); |
421 |
|
return; |
422 |
|
} |
423 |
|
/* find our new voxels */ |
424 |
|
n = get_voxels(vlnew, vn->vp); |
425 |
|
/* set the new voxels */ |
426 |
|
comn = set_voxels(vlnew, n); |
427 |
< |
if (!vo->type) |
427 |
> |
if (!dvw.type) |
428 |
|
comn = 0; |
429 |
|
ca.add = 1; /* update our beam list */ |
430 |
|
for (ca.vi = n; ca.vi--; ) |
431 |
|
if (comn & 1<<ca.vi) /* change which cells we see */ |
432 |
< |
mvview(ca.vi, vo, vn); |
432 |
> |
mvview(ca.vi, &dvw, vn); |
433 |
|
else /* else add all new cells */ |
434 |
|
doview(&ca, vn); |
435 |
|
/* inform server of new beams */ |
436 |
< |
cbeamadd(cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres); |
436 |
> |
cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres); |
437 |
|
/* sort list to put orphans at end */ |
438 |
|
cbeamsort(0); |
439 |
|
/* tell server to delete orphans */ |
440 |
< |
cbeamdel(cbeam+ncbeams, xcbeams); |
440 |
> |
cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0); |
441 |
|
xcbeams = 0; /* truncate our list */ |
442 |
+ |
copystruct(&dvw, vn); /* record new view */ |
443 |
|
} |