1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Routines for tracking beam compuatations |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include "rholo.h" |
8 |
> |
#include <time.h> |
9 |
> |
#include <string.h> |
10 |
> |
#include <stdio.h> |
11 |
> |
|
12 |
|
#include "view.h" |
13 |
< |
#include <sys/types.h> |
13 |
> |
#include "rholo.h" |
14 |
|
|
15 |
|
#ifndef NFRAG2CHUNK |
16 |
|
#define NFRAG2CHUNK 4096 /* number of fragments to start chunking */ |
25 |
|
|
26 |
|
#define rchunk(n) (((n)+(RPACKSIZ/2))/RPACKSIZ) |
27 |
|
|
28 |
– |
extern time_t time(); |
29 |
– |
|
28 |
|
int chunkycmp = 0; /* clump beams together on disk */ |
29 |
|
|
30 |
|
static PACKHEAD *complist=NULL; /* list of beams to compute */ |
32 |
|
static int listpos=0; /* current list position for next_packet */ |
33 |
|
static int lastin= -1; /* last ordered position in list */ |
34 |
|
|
35 |
+ |
static void sortcomplist(void); |
36 |
+ |
static void mergeclists(PACKHEAD *cdest, PACKHEAD *cl1, int n1, PACKHEAD *cl2, int n2); |
37 |
+ |
static void view_list(FILE *fp); |
38 |
+ |
static void ambient_list(void); |
39 |
+ |
static double beamvolume(HOLO *hp, int bi); |
40 |
+ |
static void dispbeam(BEAM *b, HDBEAMI *hb); |
41 |
|
|
42 |
< |
int |
42 |
> |
|
43 |
> |
|
44 |
> |
static int |
45 |
|
beamcmp(b0, b1) /* comparison for compute order */ |
46 |
|
register PACKHEAD *b0, *b1; |
47 |
|
{ |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
< |
int |
89 |
< |
dispbeam(b, hb) /* display a holodeck beam */ |
90 |
< |
register BEAM *b; |
91 |
< |
register HDBEAMI *hb; |
88 |
> |
static void |
89 |
> |
dispbeam( /* display a holodeck beam */ |
90 |
> |
register BEAM *b, |
91 |
> |
register HDBEAMI *hb |
92 |
> |
) |
93 |
|
{ |
94 |
|
static int n = 0; |
95 |
|
static PACKHEAD *p = NULL; |
99 |
|
if (b->nrm > n) { /* (re)allocate packet holder */ |
100 |
|
n = b->nrm; |
101 |
|
if (p == NULL) p = (PACKHEAD *)malloc(packsiz(n)); |
102 |
< |
else p = (PACKHEAD *)realloc((char *)p, packsiz(n)); |
102 |
> |
else p = (PACKHEAD *)realloc((void *)p, packsiz(n)); |
103 |
|
CHECK(p==NULL, SYSTEM, "out of memory in dispbeam"); |
104 |
|
} |
105 |
|
/* assign packet fields */ |
106 |
< |
bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL)); |
106 |
> |
memcpy((void *)packra(p), (void *)hdbray(b), b->nrm*sizeof(RAYVAL)); |
107 |
|
p->nr = p->nc = b->nrm; |
108 |
|
for (p->hd = 0; hdlist[p->hd] != hb->h; p->hd++) |
109 |
|
if (hdlist[p->hd] == NULL) |
111 |
|
p->bi = hb->b; |
112 |
|
disp_packet(p); /* display it */ |
113 |
|
if (n >= 1024) { /* free ridiculous packets */ |
114 |
< |
free((char *)p); |
114 |
> |
free((void *)p); |
115 |
|
p = NULL; n = 0; |
116 |
|
} |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
< |
bundle_set(op, clist, nents) /* bundle set operation */ |
121 |
< |
int op; |
122 |
< |
PACKHEAD *clist; |
123 |
< |
int nents; |
120 |
> |
extern void |
121 |
> |
bundle_set( /* bundle set operation */ |
122 |
> |
int op, |
123 |
> |
PACKHEAD *clist, |
124 |
> |
int nents |
125 |
> |
) |
126 |
|
{ |
127 |
|
int oldnr, n; |
128 |
|
HDBEAMI *hbarr; |
131 |
|
/* search for common members */ |
132 |
|
for (csm = clist+nents; csm-- > clist; ) |
133 |
|
csm->nc = -1; |
134 |
< |
qsort((char *)clist, nents, sizeof(PACKHEAD), beamidcmp); |
134 |
> |
qsort((void *)clist, nents, sizeof(PACKHEAD), beamidcmp); |
135 |
|
for (i = 0; i < complen; i++) { |
136 |
< |
csm = (PACKHEAD *)bsearch((char *)(complist+i), (char *)clist, |
136 |
> |
csm = (PACKHEAD *)bsearch((void *)(complist+i), (void *)clist, |
137 |
|
nents, sizeof(PACKHEAD), beamidcmp); |
138 |
|
if (csm == NULL) |
139 |
|
continue; |
172 |
|
case BS_NEW: /* new computation set */ |
173 |
|
listpos = 0; lastin = -1; |
174 |
|
if (complen) /* free old list */ |
175 |
< |
free((char *)complist); |
175 |
> |
free((void *)complist); |
176 |
|
complist = NULL; |
177 |
|
if (!(complen = nents)) |
178 |
|
return; |
179 |
|
complist = (PACKHEAD *)malloc(nents*sizeof(PACKHEAD)); |
180 |
|
if (complist == NULL) |
181 |
|
goto memerr; |
182 |
< |
bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD)); |
182 |
> |
memcpy((void *)complist, (void *)clist, nents*sizeof(PACKHEAD)); |
183 |
|
break; |
184 |
|
case BS_ADD: /* add to computation set */ |
185 |
|
case BS_MAX: /* maximum of quantities */ |
187 |
|
if (nents <= 0) |
188 |
|
return; |
189 |
|
sortcomplist(); /* sort updated list & new entries */ |
190 |
< |
qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp); |
190 |
> |
qsort((void *)clist, nents, sizeof(PACKHEAD), beamcmp); |
191 |
|
/* what can't we satisfy? */ |
192 |
|
for (i = nents, csm = clist; i-- && csm->nr > csm->nc; csm++) |
193 |
|
; |
206 |
|
/* merge lists */ |
207 |
|
mergeclists(newlist, clist, n, complist, complen); |
208 |
|
if (complen) |
209 |
< |
free((char *)complist); |
209 |
> |
free((void *)complist); |
210 |
|
complist = newlist; |
211 |
|
complen += n; |
212 |
|
} |
227 |
|
hbarr[i].b = clist[i].bi; |
228 |
|
} |
229 |
|
hdloadbeams(hbarr, nents, dispbeam); |
230 |
< |
free((char *)hbarr); |
230 |
> |
free((void *)hbarr); |
231 |
|
if (hdfragflags&FF_READ) { |
232 |
|
listpos = 0; |
233 |
|
lastin = -1; /* need to re-sort list */ |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
< |
double |
242 |
< |
beamvolume(hp, bi) /* compute approximate volume of a beam */ |
243 |
< |
HOLO *hp; |
244 |
< |
int bi; |
241 |
> |
static double |
242 |
> |
beamvolume( /* compute approximate volume of a beam */ |
243 |
> |
HOLO *hp, |
244 |
> |
int bi |
245 |
> |
) |
246 |
|
{ |
247 |
|
GCOORD gc[2]; |
248 |
|
FVECT cp[4], edgeA, edgeB, cent[2]; |
249 |
< |
FVECT v, crossp[2], diffv; |
249 |
> |
FVECT crossp[2], diffv; |
250 |
|
double vol[2]; |
251 |
|
register int i; |
252 |
|
/* get grid coordinates */ |
272 |
|
} |
273 |
|
|
274 |
|
|
275 |
< |
ambient_list() /* compute ambient beam list */ |
275 |
> |
static void |
276 |
> |
ambient_list(void) /* compute ambient beam list */ |
277 |
|
{ |
278 |
< |
int4 wtotal, minrt; |
278 |
> |
int32 wtotal, minrt; |
279 |
|
double frac; |
280 |
|
int i; |
281 |
|
register int j, k; |
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); |
335 |
|
normaspect(viewaspect(&curview), &pa, &xr, &yr); |
336 |
|
viewbeams(&curview, xr, yr, &blist); |
337 |
|
bundle_set(BS_MAX, blist.bl, blist.nb); |
338 |
< |
free((char *)blist.bl); |
338 |
> |
free((void *)blist.bl); |
339 |
|
} |
340 |
|
} |
341 |
|
|
342 |
|
|
343 |
< |
init_global() /* initialize global ray computation */ |
343 |
> |
extern void |
344 |
> |
init_global(void) /* initialize global ray computation */ |
345 |
|
{ |
332 |
– |
register int k; |
346 |
|
/* free old list and empty queue */ |
347 |
|
if (complen > 0) { |
348 |
< |
free((char *)complist); |
348 |
> |
free((void *)complist); |
349 |
|
done_packets(flush_queue()); |
350 |
|
} |
351 |
|
/* reseed random number generator */ |
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 |
> |
register PACKHEAD *cdest, |
366 |
> |
register PACKHEAD *cl1, |
367 |
> |
int n1, |
368 |
> |
register PACKHEAD *cl2, |
369 |
> |
int n2 |
370 |
> |
) |
371 |
|
{ |
372 |
|
register int cmp; |
373 |
|
|
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; |
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((char *)list2); |
420 |
> |
free((void *)list2); |
421 |
|
} |
422 |
|
/* drop satisfied requests */ |
423 |
|
for (i = complen; i-- && complist[i].nr <= complist[i].nc; ) |
424 |
|
; |
425 |
|
if (i < 0) { |
426 |
< |
free((char *)complist); |
426 |
> |
free((void *)complist); |
427 |
|
complist = NULL; |
428 |
|
complen = 0; |
429 |
|
} else if (i < complen-1) { |
430 |
< |
list2 = (PACKHEAD *)realloc((char *)complist, |
430 |
> |
list2 = (PACKHEAD *)realloc((void *)complist, |
431 |
|
(i+1)*sizeof(PACKHEAD)); |
432 |
|
if (list2 != NULL) |
433 |
|
complist = 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 |
> |
extern int |
450 |
> |
next_packet( /* prepare packet for computation */ |
451 |
> |
register PACKET *p, |
452 |
> |
int n |
453 |
> |
) |
454 |
|
{ |
435 |
– |
register int i; |
436 |
– |
|
455 |
|
if (listpos > lastin) /* time to sort the list */ |
456 |
|
sortcomplist(); |
457 |
|
if (complen <= 0) |