12 |
|
#include "rhdisp.h" |
13 |
|
#include "rhdriver.h" |
14 |
|
|
15 |
+ |
#ifndef MAXDIST |
16 |
+ |
#define MAXDIST 42 /* maximum distance outside section */ |
17 |
+ |
#endif |
18 |
+ |
|
19 |
|
extern GCOORD *getviewcells(); |
20 |
|
|
21 |
|
static VIEW dvw; /* current view corresponding to beam list */ |
94 |
|
|
95 |
|
if (!cb1->wants) /* put orphans at the end, unsorted */ |
96 |
|
return(cb2->wants); |
97 |
+ |
if (!cb2->wants) |
98 |
+ |
return(-1); |
99 |
|
if ((c = cb1->bi - cb2->bi)) /* sort on beam index first */ |
100 |
|
return(c); |
101 |
|
return(cb1->hd - cb2->hd); /* use hd to resolve matches */ |
168 |
|
VIEW *v; |
169 |
|
int hr, vr; |
170 |
|
{ |
171 |
< |
register PACKHEAD *pa; |
171 |
> |
PACKHEAD *pa, *pa2; |
172 |
> |
register PACKHEAD *pp; |
173 |
> |
int n, n2; |
174 |
> |
FVECT gp; |
175 |
> |
int igp[3], vcflgs; |
176 |
|
register int i; |
177 |
< |
int n; |
178 |
< |
/* first handle additions */ |
179 |
< |
pa = (PACKHEAD *)malloc(xcbeams*sizeof(PACKHEAD)); |
180 |
< |
if (xcbeams && pa == NULL) |
177 |
> |
/* figure out center voxel(s) */ |
178 |
> |
n = -1; vcflgs = 0; |
179 |
> |
for (i = 0; i < 8 && voxel[i].hd >= 0; i++) { |
180 |
> |
if (voxel[i].hd != n) { |
181 |
> |
hdgrid(gp, hdlist[n=voxel[i].hd], v->vp); |
182 |
> |
igp[0] = gp[0]; igp[1] = gp[1]; igp[2] = gp[2]; |
183 |
> |
} |
184 |
> |
if (voxel[i].i[0] == igp[0] && voxel[i].i[1] == igp[1] && |
185 |
> |
voxel[i].i[2] == igp[2]) |
186 |
> |
vcflgs |= 1<<i; |
187 |
> |
} |
188 |
> |
/* get additions */ |
189 |
> |
pa2 = (PACKHEAD *)malloc(xcbeams*sizeof(PACKHEAD)); |
190 |
> |
if (xcbeams && pa2 == NULL) |
191 |
|
goto memerr; |
192 |
+ |
pa = pa2 + xcbeams; n2 = 0; |
193 |
|
for (i = xcbeams; i--; ) { |
194 |
< |
pa[i].hd = cbeam[ncbeams+i].hd; |
195 |
< |
pa[i].bi = cbeam[ncbeams+i].bi; |
196 |
< |
pa[i].nr = npixels(v, hr, vr, hdlist[pa[i].hd], pa[i].bi); |
194 |
> |
if (cbeam[ncbeams+i].wants & vcflgs) |
195 |
> |
pp = --pa; /* priority list */ |
196 |
> |
else |
197 |
> |
pp = pa2 + n2++; /* secondary list */ |
198 |
> |
pp->hd = cbeam[ncbeams+i].hd; |
199 |
> |
pp->bi = cbeam[ncbeams+i].bi; |
200 |
> |
pp->nr = npixels(v, hr, vr, hdlist[pp->hd], pp->bi) + 1; |
201 |
> |
pp->nc = 0; |
202 |
|
} |
203 |
< |
n = xcbeams; /* now sort list for deletions */ |
203 |
> |
n = xcbeams - n2; |
204 |
> |
/* now sort list for deletions */ |
205 |
|
cbeamsort(0); |
206 |
< |
pa = (PACKHEAD *)realloc((char *)pa, (n+xcbeams)*sizeof(PACKHEAD)); |
207 |
< |
if (n+xcbeams && pa == NULL) |
206 |
> |
pa2 = (PACKHEAD *)realloc((char *)pa2, (n+n2+xcbeams)*sizeof(PACKHEAD)); |
207 |
> |
if (n+n2+xcbeams && pa2 == NULL) |
208 |
|
goto memerr; |
209 |
+ |
pa = pa2 + n2; |
210 |
|
for (i = xcbeams; i--; ) { |
211 |
< |
pa[n+i].hd = cbeam[ncbeams+i].hd; |
212 |
< |
pa[n+i].bi = cbeam[ncbeams+i].bi; |
213 |
< |
pa[n+i].nr = 0; |
211 |
> |
pp = pa + n++; |
212 |
> |
pp->hd = cbeam[ncbeams+i].hd; |
213 |
> |
pp->bi = cbeam[ncbeams+i].bi; |
214 |
> |
pp->nr = 0; |
215 |
> |
pp->nc = 0; |
216 |
|
} |
217 |
< |
n += xcbeams; |
218 |
< |
xcbeams = 0; /* delete orphans */ |
219 |
< |
serv_request(DR_ADJSET, n*sizeof(PACKHEAD), (char *)pa); |
220 |
< |
free((char *)pa); |
217 |
> |
if (n) /* adjust the set */ |
218 |
> |
serv_request(DR_ADJSET, n*sizeof(PACKHEAD), (char *)pa); |
219 |
> |
if (n2) /* make secondary additions */ |
220 |
> |
serv_request(DR_ADDSET, n2*sizeof(PACKHEAD), (char *)pa2); |
221 |
> |
xcbeams = 0; /* clean up */ |
222 |
> |
free((char *)pa2); |
223 |
|
return; |
224 |
|
memerr: |
225 |
|
error(SYSTEM, "out of memory in cbeamadj"); |
246 |
|
pa[i].bi = bl[i].bi; |
247 |
|
pa[i].nr = v==NULL ? 0 : |
248 |
|
npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi); |
249 |
+ |
pa[i].nc = 0; |
250 |
|
} |
251 |
|
serv_request(op, n*sizeof(PACKHEAD), (char *)pa); |
252 |
|
free((char *)pa); |
328 |
|
n++; |
329 |
|
} |
330 |
|
} |
331 |
+ |
/* check for really stupid move */ |
332 |
+ |
if (bestd > MAXDIST) { |
333 |
+ |
error(COMMAND, "move past outer limits"); |
334 |
+ |
return(0); |
335 |
+ |
} |
336 |
|
/* warn of dangerous moves */ |
337 |
|
if (n < lastn && bestd >= lastd) |
338 |
|
error(WARNING, "moving outside holodeck section"); |
381 |
|
GCOORD *gcp; |
382 |
|
register struct cellact *cap; |
383 |
|
{ |
384 |
+ |
register HOLO *hp = hdlist[voxel[cap->vi].hd]; |
385 |
|
FVECT org, dir[4]; |
386 |
< |
FVECT gp, cv[4], vc; |
386 |
> |
FVECT vgp, cgp, vc; |
387 |
> |
FVECT v1, v2; |
388 |
|
struct beamact bo; |
389 |
+ |
int axmax, j; |
390 |
+ |
double d, avmax; |
391 |
|
register int i; |
392 |
< |
/* compute cell vertices */ |
393 |
< |
hdcell(cv, hdlist[voxel[cap->vi].hd], gcp); |
394 |
< |
/* compute cell and voxel centers */ |
395 |
< |
for (i = 0; i < 3; i++) { |
396 |
< |
org[i] = 0.5*(cv[0][i] + cv[2][i]); |
397 |
< |
gp[i] = voxel[cap->vi].i[i] + 0.5; |
398 |
< |
} |
399 |
< |
hdworld(vc, hdlist[voxel[cap->vi].hd], gp); |
400 |
< |
/* compute voxel pyramid using vector trick */ |
401 |
< |
for (i = 0; i < 3; i++) { |
402 |
< |
dir[0][i] = vc[i] - cv[0][i]; /* to 3 */ |
403 |
< |
dir[2][i] = vc[i] - cv[3][i]; /* to 0 */ |
404 |
< |
if (gcp->w & 1) { /* watch vertex order! */ |
405 |
< |
dir[1][i] = vc[i] - cv[2][i]; /* to 1 */ |
406 |
< |
dir[3][i] = vc[i] - cv[1][i]; /* to 2 */ |
407 |
< |
} else { |
408 |
< |
dir[1][i] = vc[i] - cv[1][i]; /* to 2 */ |
409 |
< |
dir[3][i] = vc[i] - cv[2][i]; /* to 1 */ |
392 |
> |
/* compute cell center */ |
393 |
> |
cgp[gcp->w>>1] = gcp->w&1 ? hp->grid[gcp->w>>1] : 0 ; |
394 |
> |
cgp[((gcp->w>>1)+1)%3] = gcp->i[0] + .5; |
395 |
> |
cgp[((gcp->w>>1)+2)%3] = gcp->i[1] + .5; |
396 |
> |
hdworld(org, hp, cgp); |
397 |
> |
/* compute direction to voxel center */ |
398 |
> |
for (i = 3; i--; ) |
399 |
> |
vgp[i] = voxel[cap->vi].i[i] + .5; |
400 |
> |
hdworld(vc, hp, vgp); |
401 |
> |
for (i = 3; i--; ) |
402 |
> |
vc[i] -= org[i]; |
403 |
> |
/* compute maximum area axis */ |
404 |
> |
axmax = -1; avmax = 0; |
405 |
> |
for (i = 3; i--; ) { |
406 |
> |
d = vgp[i] - cgp[i]; |
407 |
> |
if (d < 0.) d = -d; |
408 |
> |
if (d > avmax) { |
409 |
> |
avmax = d; |
410 |
> |
axmax = i; |
411 |
|
} |
412 |
|
} |
413 |
+ |
#ifdef DEBUG |
414 |
+ |
if (axmax < 0.) |
415 |
+ |
error(CONSISTENCY, "botched axis computation in docell"); |
416 |
+ |
#endif |
417 |
+ |
/* compute offset vectors */ |
418 |
+ |
d = 0.5/hp->grid[j=(axmax+1)%3]; |
419 |
+ |
for (i = 3; i--; ) |
420 |
+ |
v1[i] = hp->xv[j][i] * d; |
421 |
+ |
d = 0.5/hp->grid[j=(axmax+2)%3]; |
422 |
+ |
if (DOT(hp->wn[axmax], vc) < 0.) |
423 |
+ |
d = -d; /* reverse vertex ordering */ |
424 |
+ |
for (i = 3; i--; ) |
425 |
+ |
v2[i] = hp->xv[j][i] * d; |
426 |
+ |
/* compute voxel pyramid */ |
427 |
+ |
for (i = 3; i--; ) { |
428 |
+ |
dir[0][i] = vc[i] - v1[i] - v2[i]; |
429 |
+ |
dir[1][i] = vc[i] + v1[i] - v2[i]; |
430 |
+ |
dir[2][i] = vc[i] + v1[i] + v2[i]; |
431 |
+ |
dir[3][i] = vc[i] - v1[i] + v2[i]; |
432 |
+ |
} |
433 |
|
/* visit beams for opposite cells */ |
434 |
|
copystruct(&bo.ca, cap); |
435 |
|
copystruct(&bo.gc, gcp); |
436 |
< |
return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], dobeam, &bo)); |
436 |
> |
return(visit_cells(org, dir, hp, dobeam, &bo)); |
437 |
|
} |
438 |
|
|
439 |
|
|
469 |
|
ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew); |
470 |
|
/* set up actions */ |
471 |
|
oca.vi = nca.vi = voxi; |
409 |
– |
oca.rev = nca.rev = 0; |
472 |
|
oca.add = 0; nca.add = 1; |
473 |
|
if ((oca.rev = ocnt < 0)) |
474 |
|
ocnt = -ocnt; |
498 |
|
} |
499 |
|
|
500 |
|
|
501 |
+ |
int |
502 |
|
beam_sync() /* synchronize beams on server */ |
503 |
|
{ |
504 |
|
cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres); |
505 |
+ |
return(ncbeams); |
506 |
|
} |
507 |
|
|
508 |
|
|
509 |
< |
beam_view(vn) /* change beam view */ |
509 |
> |
beam_view(vn) /* change beam view (if advisable) */ |
510 |
|
VIEW *vn; |
511 |
|
{ |
512 |
|
struct cellact ca; |
513 |
|
VOXL vlnew[8]; |
514 |
|
int n, comn; |
515 |
|
|
516 |
< |
if (!vn->type) { /* clear our beam list */ |
516 |
> |
if (vn == NULL || !vn->type) { /* clear our beam list */ |
517 |
|
set_voxels(vlnew, 0); |
518 |
|
cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0); |
519 |
|
ncbeams = 0; |
520 |
< |
copystruct(&dvw, vn); |
521 |
< |
return; |
520 |
> |
dvw.type = 0; |
521 |
> |
return(1); |
522 |
|
} |
523 |
|
/* find our new voxels */ |
524 |
|
n = get_voxels(vlnew, vn->vp); |
525 |
+ |
if (dvw.type && !n) { |
526 |
+ |
copystruct(vn, &dvw); /* cancel move */ |
527 |
+ |
return(0); |
528 |
+ |
} |
529 |
|
/* set the new voxels */ |
530 |
|
comn = set_voxels(vlnew, n); |
531 |
|
if (!dvw.type) |
548 |
|
xcbeams = 0; /* truncate our list */ |
549 |
|
#endif |
550 |
|
copystruct(&dvw, vn); /* record new view */ |
551 |
+ |
return(1); |
552 |
|
} |