6 |
|
*/ |
7 |
|
|
8 |
|
#include "rholo.h" |
9 |
– |
#include "view.h" |
9 |
|
|
10 |
|
#ifndef NFRAG2CHUNK |
11 |
|
#define NFRAG2CHUNK 4096 /* number of fragments to start chunking */ |
12 |
|
#endif |
13 |
|
|
14 |
+ |
#ifndef MAXADISK |
15 |
+ |
#define MAXADISK 10240. /* maximum holodeck size (Megs) for ambient */ |
16 |
+ |
#endif |
17 |
+ |
|
18 |
|
#ifndef abs |
19 |
|
#define abs(x) ((x) > 0 ? (x) : -(x)) |
20 |
|
#endif |
24 |
|
|
25 |
|
#define rchunk(n) (((n)+(RPACKSIZ/2))/RPACKSIZ) |
26 |
|
|
24 |
– |
extern time_t time(); |
25 |
– |
|
27 |
|
int chunkycmp = 0; /* clump beams together on disk */ |
28 |
|
|
29 |
|
static PACKHEAD *complist=NULL; /* list of beams to compute */ |
31 |
|
static int listpos=0; /* current list position for next_packet */ |
32 |
|
static int lastin= -1; /* last ordered position in list */ |
33 |
|
|
34 |
+ |
static void sortcomplist(void); |
35 |
+ |
static void mergeclists(PACKHEAD *cdest, PACKHEAD *cl1, int n1, PACKHEAD *cl2, int n2); |
36 |
+ |
static void view_list(FILE *fp); |
37 |
+ |
static void ambient_list(void); |
38 |
+ |
static double beamvolume(HOLO *hp, int bi); |
39 |
+ |
static void dispbeam(BEAM *b, HDBEAMI *hb); |
40 |
|
|
41 |
< |
int |
41 |
> |
|
42 |
> |
|
43 |
> |
static int |
44 |
|
beamcmp(b0, b1) /* comparison for compute order */ |
45 |
< |
register PACKHEAD *b0, *b1; |
45 |
> |
PACKHEAD *b0, *b1; |
46 |
|
{ |
47 |
|
BEAMI *bip0, *bip1; |
48 |
< |
register long c; |
48 |
> |
long c; |
49 |
|
/* first check desired quantities */ |
50 |
|
if (chunkycmp) |
51 |
|
c = rchunk(b1->nr)*(rchunk(b0->nc)+1L) - |
75 |
|
|
76 |
|
int |
77 |
|
beamidcmp(b0, b1) /* comparison for beam searching */ |
78 |
< |
register PACKHEAD *b0, *b1; |
78 |
> |
PACKHEAD *b0, *b1; |
79 |
|
{ |
80 |
< |
register int c = b0->hd - b1->hd; |
80 |
> |
int c = b0->hd - b1->hd; |
81 |
|
|
82 |
|
if (c) return(c); |
83 |
|
return(b0->bi - b1->bi); |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
< |
int |
88 |
< |
dispbeam(b, hb) /* display a holodeck beam */ |
89 |
< |
register BEAM *b; |
90 |
< |
register HDBEAMI *hb; |
87 |
> |
static void |
88 |
> |
dispbeam( /* display a holodeck beam */ |
89 |
> |
BEAM *b, |
90 |
> |
HDBEAMI *hb |
91 |
> |
) |
92 |
|
{ |
93 |
|
static int n = 0; |
94 |
|
static PACKHEAD *p = NULL; |
102 |
|
CHECK(p==NULL, SYSTEM, "out of memory in dispbeam"); |
103 |
|
} |
104 |
|
/* assign packet fields */ |
105 |
< |
bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL)); |
105 |
> |
memcpy((void *)packra(p), (void *)hdbray(b), b->nrm*sizeof(RAYVAL)); |
106 |
|
p->nr = p->nc = b->nrm; |
107 |
|
for (p->hd = 0; hdlist[p->hd] != hb->h; p->hd++) |
108 |
|
if (hdlist[p->hd] == NULL) |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
< |
bundle_set(op, clist, nents) /* bundle set operation */ |
120 |
< |
int op; |
121 |
< |
PACKHEAD *clist; |
122 |
< |
int nents; |
119 |
> |
void |
120 |
> |
bundle_set( /* bundle set operation */ |
121 |
> |
int op, |
122 |
> |
PACKHEAD *clist, |
123 |
> |
int nents |
124 |
> |
) |
125 |
|
{ |
126 |
|
int oldnr, n; |
127 |
|
HDBEAMI *hbarr; |
128 |
< |
register PACKHEAD *csm; |
129 |
< |
register int i; |
128 |
> |
PACKHEAD *csm; |
129 |
> |
int i; |
130 |
|
/* search for common members */ |
131 |
|
for (csm = clist+nents; csm-- > clist; ) |
132 |
|
csm->nc = -1; |
133 |
< |
qsort((char *)clist, nents, sizeof(PACKHEAD), beamidcmp); |
133 |
> |
qsort((void *)clist, nents, sizeof(PACKHEAD), beamidcmp); |
134 |
|
for (i = 0; i < complen; i++) { |
135 |
< |
csm = (PACKHEAD *)bsearch((char *)(complist+i), (char *)clist, |
135 |
> |
csm = (PACKHEAD *)bsearch((void *)(complist+i), (void *)clist, |
136 |
|
nents, sizeof(PACKHEAD), beamidcmp); |
137 |
|
if (csm == NULL) |
138 |
|
continue; |
178 |
|
complist = (PACKHEAD *)malloc(nents*sizeof(PACKHEAD)); |
179 |
|
if (complist == NULL) |
180 |
|
goto memerr; |
181 |
< |
bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD)); |
181 |
> |
memcpy((void *)complist, (void *)clist, nents*sizeof(PACKHEAD)); |
182 |
|
break; |
183 |
|
case BS_ADD: /* add to computation set */ |
184 |
|
case BS_MAX: /* maximum of quantities */ |
186 |
|
if (nents <= 0) |
187 |
|
return; |
188 |
|
sortcomplist(); /* sort updated list & new entries */ |
189 |
< |
qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp); |
189 |
> |
qsort((void *)clist, nents, sizeof(PACKHEAD), beamcmp); |
190 |
|
/* what can't we satisfy? */ |
191 |
|
for (i = nents, csm = clist; i-- && csm->nr > csm->nc; csm++) |
192 |
|
; |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
< |
double |
241 |
< |
beamvolume(hp, bi) /* compute approximate volume of a beam */ |
242 |
< |
HOLO *hp; |
243 |
< |
int bi; |
240 |
> |
static double |
241 |
> |
beamvolume( /* compute approximate volume of a beam */ |
242 |
> |
HOLO *hp, |
243 |
> |
int bi |
244 |
> |
) |
245 |
|
{ |
246 |
|
GCOORD gc[2]; |
247 |
|
FVECT cp[4], edgeA, edgeB, cent[2]; |
248 |
< |
FVECT v, crossp[2], diffv; |
248 |
> |
FVECT crossp[2], diffv; |
249 |
|
double vol[2]; |
250 |
< |
register int i; |
250 |
> |
int i; |
251 |
|
/* get grid coordinates */ |
252 |
|
if (!hdbcoord(gc, hp, bi)) |
253 |
|
error(CONSISTENCY, "bad beam index in beamvolume"); |
271 |
|
} |
272 |
|
|
273 |
|
|
274 |
< |
ambient_list() /* compute ambient beam list */ |
274 |
> |
static void |
275 |
> |
ambient_list(void) /* compute ambient beam list */ |
276 |
|
{ |
277 |
< |
int4 wtotal, minrt; |
277 |
> |
int32 wtotal, minrt; |
278 |
|
double frac; |
279 |
|
int i; |
280 |
< |
register int j, k; |
280 |
> |
int j, k; |
281 |
|
|
282 |
|
complen = 0; |
283 |
|
for (j = 0; hdlist[j] != NULL; j++) |
287 |
|
/* compute beam weights */ |
288 |
|
k = 0; wtotal = 0; |
289 |
|
for (j = 0; hdlist[j] != NULL; j++) { |
290 |
+ |
/* 512. arbitrary -- adjusted below */ |
291 |
|
frac = 512. * VLEN(hdlist[j]->wg[0]) * |
292 |
|
VLEN(hdlist[j]->wg[1]) * |
293 |
|
VLEN(hdlist[j]->wg[2]); |
303 |
|
if (vdef(DISKSPACE)) |
304 |
|
frac = 1024.*1024.*vflt(DISKSPACE) / (wtotal*sizeof(RAYVAL)); |
305 |
|
else |
306 |
< |
frac = 1024.*1024.*2048. / (wtotal*sizeof(RAYVAL)); |
306 |
> |
frac = 1024.*1024.*MAXADISK / (wtotal*sizeof(RAYVAL)); |
307 |
|
minrt = .02*frac*wtotal/complen + .5; /* heuristic mimimum */ |
308 |
|
if (minrt > RPACKSIZ) |
309 |
|
minrt = RPACKSIZ; |
314 |
|
} |
315 |
|
|
316 |
|
|
317 |
< |
view_list(fp) /* assign beam priority from view list */ |
318 |
< |
FILE *fp; |
317 |
> |
static void |
318 |
> |
view_list( /* assign beam priority from view list */ |
319 |
> |
FILE *fp |
320 |
> |
) |
321 |
|
{ |
322 |
|
double pa = 1.; |
323 |
|
VIEW curview; |
325 |
|
char *err; |
326 |
|
BEAMLIST blist; |
327 |
|
|
328 |
< |
copystruct(&curview, &stdview); |
328 |
> |
curview = stdview; |
329 |
|
while (nextview(&curview, fp) != EOF) { |
330 |
|
if ((err = setview(&curview)) != NULL) { |
331 |
|
error(WARNING, err); |
340 |
|
} |
341 |
|
|
342 |
|
|
343 |
< |
init_global() /* initialize global ray computation */ |
343 |
> |
void |
344 |
> |
init_global(void) /* initialize global ray computation */ |
345 |
|
{ |
328 |
– |
register int k; |
346 |
|
/* free old list and empty queue */ |
347 |
|
if (complen > 0) { |
348 |
|
free((void *)complist); |
360 |
|
} |
361 |
|
|
362 |
|
|
363 |
< |
mergeclists(cdest, cl1, n1, cl2, n2) /* merge two sorted lists */ |
364 |
< |
register PACKHEAD *cdest; |
365 |
< |
register PACKHEAD *cl1, *cl2; |
366 |
< |
int n1, n2; |
363 |
> |
static void |
364 |
> |
mergeclists( /* merge two sorted lists */ |
365 |
> |
PACKHEAD *cdest, |
366 |
> |
PACKHEAD *cl1, |
367 |
> |
int n1, |
368 |
> |
PACKHEAD *cl2, |
369 |
> |
int n2 |
370 |
> |
) |
371 |
|
{ |
372 |
< |
register int cmp; |
372 |
> |
int cmp; |
373 |
|
|
374 |
|
while (n1 | n2) { |
375 |
|
if (!n1) cmp = 1; |
376 |
|
else if (!n2) cmp = -1; |
377 |
|
else cmp = beamcmp(cl1, cl2); |
378 |
|
if (cmp > 0) { |
379 |
< |
copystruct(cdest, cl2); |
379 |
> |
*cdest = *cl2; |
380 |
|
cl2++; n2--; |
381 |
|
} else { |
382 |
< |
copystruct(cdest, cl1); |
382 |
> |
*cdest = *cl1; |
383 |
|
cl1++; n1--; |
384 |
|
} |
385 |
|
cdest++; |
387 |
|
} |
388 |
|
|
389 |
|
|
390 |
< |
sortcomplist() /* fix our list order */ |
390 |
> |
static void |
391 |
> |
sortcomplist(void) /* fix our list order */ |
392 |
|
{ |
393 |
|
PACKHEAD *list2; |
394 |
|
int listlen; |
395 |
< |
register int i; |
395 |
> |
int i; |
396 |
|
|
397 |
|
if (complen <= 0) /* check to see if there is even a list */ |
398 |
|
return; |
409 |
|
#endif |
410 |
|
} |
411 |
|
if (lastin < 0 || listpos*4 >= complen*3) |
412 |
< |
qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp); |
412 |
> |
qsort((void *)complist, complen, sizeof(PACKHEAD), beamcmp); |
413 |
|
else if (listpos) { /* else sort and merge sublist */ |
414 |
|
list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD)); |
415 |
|
CHECK(list2==NULL, SYSTEM, "out of memory in sortcomplist"); |
416 |
< |
bcopy((char *)complist,(char *)list2,listpos*sizeof(PACKHEAD)); |
417 |
< |
qsort((char *)list2, listpos, sizeof(PACKHEAD), beamcmp); |
416 |
> |
memcpy((void *)list2,(void *)complist,listpos*sizeof(PACKHEAD)); |
417 |
> |
qsort((void *)list2, listpos, sizeof(PACKHEAD), beamcmp); |
418 |
|
mergeclists(complist, list2, listpos, |
419 |
|
complist+listpos, complen-listpos); |
420 |
|
free((void *)list2); |
446 |
|
* list and start again from the beginning. Since |
447 |
|
* a merge sort is used, the sorting costs are minimal. |
448 |
|
*/ |
449 |
< |
next_packet(p, n) /* prepare packet for computation */ |
450 |
< |
register PACKET *p; |
451 |
< |
int n; |
449 |
> |
int |
450 |
> |
next_packet( /* prepare packet for computation */ |
451 |
> |
PACKET *p, |
452 |
> |
int n |
453 |
> |
) |
454 |
|
{ |
431 |
– |
register int i; |
432 |
– |
|
455 |
|
if (listpos > lastin) /* time to sort the list */ |
456 |
|
sortcomplist(); |
457 |
|
if (complen <= 0) |