12 |
|
#include "rhdisp.h" |
13 |
|
#include "rhdriver.h" |
14 |
|
|
15 |
< |
extern int *getviewcells(); |
15 |
> |
extern GCOORD *getviewcells(); |
16 |
|
|
17 |
|
typedef struct { |
18 |
|
int hd; /* holodeck section number (-1 if inactive) */ |
39 |
|
struct cellact { |
40 |
|
short vi; /* voxel index */ |
41 |
|
short add; /* zero means delete */ |
42 |
+ |
short rev; /* reverse ray direction? */ |
43 |
|
}; /* action for cell */ |
44 |
|
|
45 |
|
struct beamact { |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
< |
cbeamadd(bl, n, v, hr, vr) /* add beams to server list */ |
159 |
> |
cbeamop(op, bl, n, v, hr, vr) /* update beams on server list */ |
160 |
> |
int op; |
161 |
|
register struct beamcomp *bl; |
162 |
|
int n; |
163 |
|
VIEW *v; |
171 |
|
pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD)); |
172 |
|
if (pa == NULL) |
173 |
|
error(SYSTEM, "out of memory in cbeamadd"); |
172 |
– |
for (i = 0; i < n; i++) |
173 |
– |
pa[i].nr = npixels(v, hr, vr, |
174 |
– |
hdlist[pa[i].hd=bl[i].hd], |
175 |
– |
pa[i].bi=bl[i].bi) / 8; |
176 |
– |
|
177 |
– |
serv_request(DR_ADDSET, n*sizeof(PACKHEAD), (char *)pa); |
178 |
– |
free((char *)pa); |
179 |
– |
} |
180 |
– |
|
181 |
– |
|
182 |
– |
cbeamdel(bl, n) /* delete unwanted beam requests */ |
183 |
– |
register struct beamcomp *bl; |
184 |
– |
int n; |
185 |
– |
{ |
186 |
– |
register PACKHEAD *pa; |
187 |
– |
register int i; |
188 |
– |
|
189 |
– |
if (n <= 0) |
190 |
– |
return; |
191 |
– |
pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD)); |
192 |
– |
if (pa == NULL) |
193 |
– |
error(SYSTEM, "out of memory in cbeamdel"); |
174 |
|
for (i = 0; i < n; i++) { |
175 |
|
pa[i].hd = bl[i].hd; |
176 |
|
pa[i].bi = bl[i].bi; |
177 |
< |
pa[i].nr = 0; /* removes any request */ |
177 |
> |
pa[i].nr = v==NULL ? 0 : |
178 |
> |
npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi); |
179 |
|
} |
180 |
< |
serv_request(DR_DELSET, n*sizeof(PACKHEAD), (char *)pa); |
180 |
> |
serv_request(op, n*sizeof(PACKHEAD), (char *)pa); |
181 |
|
free((char *)pa); |
182 |
|
} |
183 |
|
|
226 |
|
VOXL vl[8]; |
227 |
|
FVECT vp; |
228 |
|
{ |
229 |
+ |
static int lastn = 0, lastd = -1; |
230 |
|
int n = 0; |
231 |
|
FVECT gp; |
232 |
|
double d; |
257 |
|
n++; |
258 |
|
} |
259 |
|
} |
260 |
< |
return(n); |
260 |
> |
/* warn of dangerous moves */ |
261 |
> |
if (n < lastn && bestd >= lastd) |
262 |
> |
error(WARNING, "moving outside holodeck section"); |
263 |
> |
else if (n > lastn && bestd <= lastd) |
264 |
> |
error(WARNING, "moving inside holodeck section"); |
265 |
> |
lastd = bestd; |
266 |
> |
return(lastn = n); |
267 |
|
} |
268 |
|
|
269 |
|
|
275 |
|
GCOORD gc[2]; |
276 |
|
int bi, i; |
277 |
|
/* compute beam index */ |
278 |
< |
copystruct(gc, gcp); |
279 |
< |
copystruct(gc+1, &bp->gc); |
278 |
> |
if (bp->ca.rev) { |
279 |
> |
copystruct(gc, &bp->gc); |
280 |
> |
copystruct(gc+1, gcp); |
281 |
> |
} else { |
282 |
> |
copystruct(gc, gcp); |
283 |
> |
copystruct(gc+1, &bp->gc); |
284 |
> |
} |
285 |
|
if ((bi = hdbindex(hdlist[voxel[bp->ca.vi].hd], gc)) <= 0) |
286 |
|
error(CONSISTENCY, "bad grid coordinate in dobeam"); |
287 |
|
if (bp->ca.add) { /* add it in */ |
341 |
|
struct cellact *cap; |
342 |
|
VIEW *vp; |
343 |
|
{ |
344 |
+ |
int orient; |
345 |
|
FVECT org, dir[4]; |
346 |
|
/* compute view pyramid */ |
347 |
< |
if (vp->type == VT_PAR) goto viewerr; |
348 |
< |
if (viewray(org, dir[0], vp, 0., 0.) < -FTINY) goto viewerr; |
349 |
< |
if (viewray(org, dir[1], vp, 0., 1.) < -FTINY) goto viewerr; |
350 |
< |
if (viewray(org, dir[2], vp, 1., 1.) < -FTINY) goto viewerr; |
357 |
< |
if (viewray(org, dir[3], vp, 1., 0.) < -FTINY) goto viewerr; |
347 |
> |
orient = viewpyramid(org, dir, hdlist[voxel[cap->vi].hd], vp); |
348 |
> |
if (!orient) |
349 |
> |
error(INTERNAL, "unusable view in doview"); |
350 |
> |
cap->rev = orient < 0; |
351 |
|
/* visit cells within pyramid */ |
352 |
|
return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], docell, cap)); |
360 |
– |
viewerr: |
361 |
– |
error(INTERNAL, "unusable view in doview"); |
353 |
|
} |
354 |
|
|
355 |
|
|
358 |
|
VIEW *vold, *vnew; |
359 |
|
{ |
360 |
|
int netchange = 0; |
361 |
< |
int *ocl, *ncl; |
371 |
< |
struct cellact ca; |
361 |
> |
struct cellact oca, nca; |
362 |
|
int ocnt, ncnt; |
363 |
|
int c; |
364 |
|
register GCOORD *ogcp, *ngcp; |
365 |
|
/* get old and new cell lists */ |
366 |
< |
ocl = getviewcells(hdlist[voxel[voxi].hd], vold); |
367 |
< |
ncl = getviewcells(hdlist[voxel[voxi].hd], vnew); |
368 |
< |
if (ocl != NULL) { |
369 |
< |
ocnt = *ocl; ogcp = (GCOORD *)(ocl+1); |
370 |
< |
} else { |
371 |
< |
ocnt = 0; ogcp = NULL; |
372 |
< |
} |
373 |
< |
if (ncl != NULL) { |
374 |
< |
ncnt = *ncl; ngcp = (GCOORD *)(ncl+1); |
375 |
< |
} else { |
376 |
< |
ncnt = 0; ngcp = NULL; |
377 |
< |
} |
378 |
< |
ca.vi = voxi; /* add and delete cells */ |
379 |
< |
while (ocnt > 0 & ncnt > 0) |
380 |
< |
if ((c = cellcmp(ogcp, ngcp)) > 0) { |
381 |
< |
ca.add = 1; /* new cell */ |
382 |
< |
netchange += docell(ngcp++, &ca); |
383 |
< |
ncnt--; |
384 |
< |
} else if (c < 0) { |
385 |
< |
ca.add = 0; /* obsolete cell */ |
386 |
< |
netchange -= docell(ogcp++, &ca); |
387 |
< |
ocnt--; |
398 |
< |
} else { |
399 |
< |
ogcp++; ocnt--; /* unchanged cell */ |
400 |
< |
ngcp++; ncnt--; |
401 |
< |
} |
366 |
> |
ogcp = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold); |
367 |
> |
ngcp = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew); |
368 |
> |
/* set up actions */ |
369 |
> |
oca.vi = nca.vi = voxi; |
370 |
> |
oca.rev = nca.rev = 0; |
371 |
> |
oca.add = 0; nca.add = 1; |
372 |
> |
if ((oca.rev = ocnt < 0)) |
373 |
> |
ocnt = -ocnt; |
374 |
> |
if ((nca.rev = ncnt < 0)) |
375 |
> |
ncnt = -ncnt; |
376 |
> |
if (nca.rev == oca.rev) /* add and delete cells in order */ |
377 |
> |
while (ocnt > 0 & ncnt > 0) |
378 |
> |
if ((c = cellcmp(ogcp, ngcp)) > 0) { /* new cell */ |
379 |
> |
netchange += docell(ngcp++, &nca); |
380 |
> |
ncnt--; |
381 |
> |
} else if (c < 0) { /* old cell */ |
382 |
> |
netchange -= docell(ogcp++, &oca); |
383 |
> |
ocnt--; |
384 |
> |
} else { /* same cell */ |
385 |
> |
ogcp++; ocnt--; |
386 |
> |
ngcp++; ncnt--; |
387 |
> |
} |
388 |
|
/* take care of list tails */ |
389 |
< |
for (ca.add = 1; ncnt > 0; ncnt--) |
390 |
< |
netchange += docell(ngcp++, &ca); |
391 |
< |
for (ca.add = 0; ocnt > 0; ocnt--) |
392 |
< |
netchange -= docell(ogcp++, &ca); |
389 |
> |
for ( ; ncnt > 0; ncnt--) |
390 |
> |
netchange += docell(ngcp++, &nca); |
391 |
> |
for ( ; ocnt > 0; ocnt--) |
392 |
> |
netchange -= docell(ogcp++, &oca); |
393 |
|
/* clean up */ |
394 |
< |
if (ocl != NULL) free((char *)ocl); |
395 |
< |
if (ncl != NULL) free((char *)ncl); |
394 |
> |
if (ogcp != NULL) free((char *)ogcp); |
395 |
> |
if (ngcp != NULL) free((char *)ngcp); |
396 |
|
return(netchange); |
397 |
|
} |
398 |
|
|
399 |
|
|
400 |
+ |
beam_sync() /* synchronize beams on server */ |
401 |
+ |
{ |
402 |
+ |
cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres); |
403 |
+ |
} |
404 |
+ |
|
405 |
+ |
|
406 |
|
beam_view(vo, vn) /* change beam view */ |
407 |
|
VIEW *vo, *vn; |
408 |
|
{ |
412 |
|
|
413 |
|
if (!vn->type) { /* clear our beam list */ |
414 |
|
set_voxels(vlnew, 0); |
415 |
< |
cbeamdel(cbeam, ncbeams); |
415 |
> |
cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0); |
416 |
|
ncbeams = 0; |
417 |
|
return; |
418 |
|
} |
429 |
|
else /* else add all new cells */ |
430 |
|
doview(&ca, vn); |
431 |
|
/* inform server of new beams */ |
432 |
< |
cbeamadd(cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres); |
432 |
> |
cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres); |
433 |
|
/* sort list to put orphans at end */ |
434 |
|
cbeamsort(0); |
435 |
|
/* tell server to delete orphans */ |
436 |
< |
cbeamdel(cbeam+ncbeams, xcbeams); |
436 |
> |
cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0); |
437 |
|
xcbeams = 0; /* truncate our list */ |
438 |
|
} |