| 6 |
|
*/ |
| 7 |
|
|
| 8 |
|
#include "rholo.h" |
| 9 |
– |
#include "view.h" |
| 9 |
|
|
| 10 |
|
#ifndef NFRAG2CHUNK |
| 11 |
|
#define NFRAG2CHUNK 4096 /* number of fragments to start chunking */ |
| 20 |
|
|
| 21 |
|
#define rchunk(n) (((n)+(RPACKSIZ/2))/RPACKSIZ) |
| 22 |
|
|
| 24 |
– |
extern time_t time(); |
| 25 |
– |
|
| 23 |
|
int chunkycmp = 0; /* clump beams together on disk */ |
| 24 |
|
|
| 25 |
|
static PACKHEAD *complist=NULL; /* list of beams to compute */ |
| 27 |
|
static int listpos=0; /* current list position for next_packet */ |
| 28 |
|
static int lastin= -1; /* last ordered position in list */ |
| 29 |
|
|
| 30 |
+ |
static void sortcomplist(void); |
| 31 |
+ |
static void mergeclists(PACKHEAD *cdest, PACKHEAD *cl1, int n1, PACKHEAD *cl2, int n2); |
| 32 |
+ |
static void view_list(FILE *fp); |
| 33 |
+ |
static void ambient_list(void); |
| 34 |
+ |
static double beamvolume(HOLO *hp, int bi); |
| 35 |
+ |
static void dispbeam(BEAM *b, HDBEAMI *hb); |
| 36 |
|
|
| 37 |
< |
int |
| 37 |
> |
|
| 38 |
> |
|
| 39 |
> |
static int |
| 40 |
|
beamcmp(b0, b1) /* comparison for compute order */ |
| 41 |
|
register PACKHEAD *b0, *b1; |
| 42 |
|
{ |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
|
| 83 |
< |
int |
| 84 |
< |
dispbeam(b, hb) /* display a holodeck beam */ |
| 85 |
< |
register BEAM *b; |
| 86 |
< |
register HDBEAMI *hb; |
| 83 |
> |
static void |
| 84 |
> |
dispbeam( /* display a holodeck beam */ |
| 85 |
> |
register BEAM *b, |
| 86 |
> |
register HDBEAMI *hb |
| 87 |
> |
) |
| 88 |
|
{ |
| 89 |
|
static int n = 0; |
| 90 |
|
static PACKHEAD *p = NULL; |
| 94 |
|
if (b->nrm > n) { /* (re)allocate packet holder */ |
| 95 |
|
n = b->nrm; |
| 96 |
|
if (p == NULL) p = (PACKHEAD *)malloc(packsiz(n)); |
| 97 |
< |
else p = (PACKHEAD *)realloc((char *)p, packsiz(n)); |
| 97 |
> |
else p = (PACKHEAD *)realloc((void *)p, packsiz(n)); |
| 98 |
|
CHECK(p==NULL, SYSTEM, "out of memory in dispbeam"); |
| 99 |
|
} |
| 100 |
|
/* assign packet fields */ |
| 101 |
< |
bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL)); |
| 101 |
> |
memcpy((void *)packra(p), (void *)hdbray(b), b->nrm*sizeof(RAYVAL)); |
| 102 |
|
p->nr = p->nc = b->nrm; |
| 103 |
|
for (p->hd = 0; hdlist[p->hd] != hb->h; p->hd++) |
| 104 |
|
if (hdlist[p->hd] == NULL) |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
|
| 115 |
< |
bundle_set(op, clist, nents) /* bundle set operation */ |
| 116 |
< |
int op; |
| 117 |
< |
PACKHEAD *clist; |
| 118 |
< |
int nents; |
| 115 |
> |
extern void |
| 116 |
> |
bundle_set( /* bundle set operation */ |
| 117 |
> |
int op, |
| 118 |
> |
PACKHEAD *clist, |
| 119 |
> |
int nents |
| 120 |
> |
) |
| 121 |
|
{ |
| 122 |
|
int oldnr, n; |
| 123 |
|
HDBEAMI *hbarr; |
| 126 |
|
/* search for common members */ |
| 127 |
|
for (csm = clist+nents; csm-- > clist; ) |
| 128 |
|
csm->nc = -1; |
| 129 |
< |
qsort((char *)clist, nents, sizeof(PACKHEAD), beamidcmp); |
| 129 |
> |
qsort((void *)clist, nents, sizeof(PACKHEAD), beamidcmp); |
| 130 |
|
for (i = 0; i < complen; i++) { |
| 131 |
< |
csm = (PACKHEAD *)bsearch((char *)(complist+i), (char *)clist, |
| 131 |
> |
csm = (PACKHEAD *)bsearch((void *)(complist+i), (void *)clist, |
| 132 |
|
nents, sizeof(PACKHEAD), beamidcmp); |
| 133 |
|
if (csm == NULL) |
| 134 |
|
continue; |
| 174 |
|
complist = (PACKHEAD *)malloc(nents*sizeof(PACKHEAD)); |
| 175 |
|
if (complist == NULL) |
| 176 |
|
goto memerr; |
| 177 |
< |
bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD)); |
| 177 |
> |
memcpy((void *)complist, (void *)clist, nents*sizeof(PACKHEAD)); |
| 178 |
|
break; |
| 179 |
|
case BS_ADD: /* add to computation set */ |
| 180 |
|
case BS_MAX: /* maximum of quantities */ |
| 182 |
|
if (nents <= 0) |
| 183 |
|
return; |
| 184 |
|
sortcomplist(); /* sort updated list & new entries */ |
| 185 |
< |
qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp); |
| 185 |
> |
qsort((void *)clist, nents, sizeof(PACKHEAD), beamcmp); |
| 186 |
|
/* what can't we satisfy? */ |
| 187 |
|
for (i = nents, csm = clist; i-- && csm->nr > csm->nc; csm++) |
| 188 |
|
; |
| 233 |
|
} |
| 234 |
|
|
| 235 |
|
|
| 236 |
< |
double |
| 237 |
< |
beamvolume(hp, bi) /* compute approximate volume of a beam */ |
| 238 |
< |
HOLO *hp; |
| 239 |
< |
int bi; |
| 236 |
> |
static double |
| 237 |
> |
beamvolume( /* compute approximate volume of a beam */ |
| 238 |
> |
HOLO *hp, |
| 239 |
> |
int bi |
| 240 |
> |
) |
| 241 |
|
{ |
| 242 |
|
GCOORD gc[2]; |
| 243 |
|
FVECT cp[4], edgeA, edgeB, cent[2]; |
| 244 |
< |
FVECT v, crossp[2], diffv; |
| 244 |
> |
FVECT crossp[2], diffv; |
| 245 |
|
double vol[2]; |
| 246 |
|
register int i; |
| 247 |
|
/* get grid coordinates */ |
| 267 |
|
} |
| 268 |
|
|
| 269 |
|
|
| 270 |
< |
ambient_list() /* compute ambient beam list */ |
| 270 |
> |
static void |
| 271 |
> |
ambient_list(void) /* compute ambient beam list */ |
| 272 |
|
{ |
| 273 |
< |
int4 wtotal, minrt; |
| 273 |
> |
int32 wtotal, minrt; |
| 274 |
|
double frac; |
| 275 |
|
int i; |
| 276 |
|
register int j, k; |
| 309 |
|
} |
| 310 |
|
|
| 311 |
|
|
| 312 |
< |
view_list(fp) /* assign beam priority from view list */ |
| 313 |
< |
FILE *fp; |
| 312 |
> |
static void |
| 313 |
> |
view_list( /* assign beam priority from view list */ |
| 314 |
> |
FILE *fp |
| 315 |
> |
) |
| 316 |
|
{ |
| 317 |
|
double pa = 1.; |
| 318 |
|
VIEW curview; |
| 320 |
|
char *err; |
| 321 |
|
BEAMLIST blist; |
| 322 |
|
|
| 323 |
< |
copystruct(&curview, &stdview); |
| 323 |
> |
curview = stdview; |
| 324 |
|
while (nextview(&curview, fp) != EOF) { |
| 325 |
|
if ((err = setview(&curview)) != NULL) { |
| 326 |
|
error(WARNING, err); |
| 335 |
|
} |
| 336 |
|
|
| 337 |
|
|
| 338 |
< |
init_global() /* initialize global ray computation */ |
| 338 |
> |
extern void |
| 339 |
> |
init_global(void) /* initialize global ray computation */ |
| 340 |
|
{ |
| 328 |
– |
register int k; |
| 341 |
|
/* free old list and empty queue */ |
| 342 |
|
if (complen > 0) { |
| 343 |
|
free((void *)complist); |
| 355 |
|
} |
| 356 |
|
|
| 357 |
|
|
| 358 |
< |
mergeclists(cdest, cl1, n1, cl2, n2) /* merge two sorted lists */ |
| 359 |
< |
register PACKHEAD *cdest; |
| 360 |
< |
register PACKHEAD *cl1, *cl2; |
| 361 |
< |
int n1, n2; |
| 358 |
> |
static void |
| 359 |
> |
mergeclists( /* merge two sorted lists */ |
| 360 |
> |
register PACKHEAD *cdest, |
| 361 |
> |
register PACKHEAD *cl1, |
| 362 |
> |
int n1, |
| 363 |
> |
register PACKHEAD *cl2, |
| 364 |
> |
int n2 |
| 365 |
> |
) |
| 366 |
|
{ |
| 367 |
|
register int cmp; |
| 368 |
|
|
| 371 |
|
else if (!n2) cmp = -1; |
| 372 |
|
else cmp = beamcmp(cl1, cl2); |
| 373 |
|
if (cmp > 0) { |
| 374 |
< |
copystruct(cdest, cl2); |
| 374 |
> |
*cdest = *cl2; |
| 375 |
|
cl2++; n2--; |
| 376 |
|
} else { |
| 377 |
< |
copystruct(cdest, cl1); |
| 377 |
> |
*cdest = *cl1; |
| 378 |
|
cl1++; n1--; |
| 379 |
|
} |
| 380 |
|
cdest++; |
| 382 |
|
} |
| 383 |
|
|
| 384 |
|
|
| 385 |
< |
sortcomplist() /* fix our list order */ |
| 385 |
> |
static void |
| 386 |
> |
sortcomplist(void) /* fix our list order */ |
| 387 |
|
{ |
| 388 |
|
PACKHEAD *list2; |
| 389 |
|
int listlen; |
| 404 |
|
#endif |
| 405 |
|
} |
| 406 |
|
if (lastin < 0 || listpos*4 >= complen*3) |
| 407 |
< |
qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp); |
| 407 |
> |
qsort((void *)complist, complen, sizeof(PACKHEAD), beamcmp); |
| 408 |
|
else if (listpos) { /* else sort and merge sublist */ |
| 409 |
|
list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD)); |
| 410 |
|
CHECK(list2==NULL, SYSTEM, "out of memory in sortcomplist"); |
| 411 |
< |
bcopy((char *)complist,(char *)list2,listpos*sizeof(PACKHEAD)); |
| 412 |
< |
qsort((char *)list2, listpos, sizeof(PACKHEAD), beamcmp); |
| 411 |
> |
memcpy((void *)list2,(void *)complist,listpos*sizeof(PACKHEAD)); |
| 412 |
> |
qsort((void *)list2, listpos, sizeof(PACKHEAD), beamcmp); |
| 413 |
|
mergeclists(complist, list2, listpos, |
| 414 |
|
complist+listpos, complen-listpos); |
| 415 |
|
free((void *)list2); |
| 422 |
|
complist = NULL; |
| 423 |
|
complen = 0; |
| 424 |
|
} else if (i < complen-1) { |
| 425 |
< |
list2 = (PACKHEAD *)realloc((char *)complist, |
| 425 |
> |
list2 = (PACKHEAD *)realloc((void *)complist, |
| 426 |
|
(i+1)*sizeof(PACKHEAD)); |
| 427 |
|
if (list2 != NULL) |
| 428 |
|
complist = list2; |
| 441 |
|
* list and start again from the beginning. Since |
| 442 |
|
* a merge sort is used, the sorting costs are minimal. |
| 443 |
|
*/ |
| 444 |
< |
next_packet(p, n) /* prepare packet for computation */ |
| 445 |
< |
register PACKET *p; |
| 446 |
< |
int n; |
| 444 |
> |
extern int |
| 445 |
> |
next_packet( /* prepare packet for computation */ |
| 446 |
> |
register PACKET *p, |
| 447 |
> |
int n |
| 448 |
> |
) |
| 449 |
|
{ |
| 431 |
– |
register int i; |
| 432 |
– |
|
| 450 |
|
if (listpos > lastin) /* time to sort the list */ |
| 451 |
|
sortcomplist(); |
| 452 |
|
if (complen <= 0) |