1 |
+ |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
+ |
|
3 |
+ |
#ifndef lint |
4 |
+ |
static char SCCSid[] = "$SunId$ SGI"; |
5 |
+ |
#endif |
6 |
+ |
|
7 |
|
/* |
8 |
|
* Routines for tracking beam compuatations |
9 |
|
*/ |
20 |
|
|
21 |
|
|
22 |
|
int |
23 |
< |
beamcmp(b0, b1) /* comparison for descending compute order */ |
23 |
> |
beamcmp(b0, b1) /* comparison for compute order */ |
24 |
|
register PACKHEAD *b0, *b1; |
25 |
|
{ |
26 |
|
return( b1->nr*(b0->nc+1) - b0->nr*(b1->nc+1) ); |
28 |
|
|
29 |
|
|
30 |
|
int |
31 |
< |
dispbeam(b, hp, bi) /* display a holodeck beam */ |
31 |
> |
beamidcmp(b0, b1) /* comparison for beam searching */ |
32 |
> |
register PACKHEAD *b0, *b1; |
33 |
> |
{ |
34 |
> |
register int c = b0->hd - b1->hd; |
35 |
> |
|
36 |
> |
if (c) return(c); |
37 |
> |
return(b0->bi - b1->bi); |
38 |
> |
} |
39 |
> |
|
40 |
> |
|
41 |
> |
int |
42 |
> |
dispbeam(b, hb) /* display a holodeck beam */ |
43 |
|
register BEAM *b; |
44 |
< |
HOLO *hp; |
28 |
< |
int bi; |
44 |
> |
register HDBEAMI *hb; |
45 |
|
{ |
46 |
|
static int n = 0; |
47 |
|
static PACKHEAD *p = NULL; |
58 |
|
/* assign packet fields */ |
59 |
|
bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL)); |
60 |
|
p->nr = p->nc = b->nrm; |
61 |
< |
for (p->hd = 0; hdlist[p->hd] != hp; p->hd++) |
61 |
> |
for (p->hd = 0; hdlist[p->hd] != hb->h; p->hd++) |
62 |
|
if (hdlist[p->hd] == NULL) |
63 |
|
error(CONSISTENCY, "unregistered holodeck in dispbeam"); |
64 |
< |
p->bi = bi; |
64 |
> |
p->bi = hb->b; |
65 |
|
disp_packet(p); /* display it */ |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
|
bundle_set(op, clist, nents) /* bundle set operation */ |
70 |
|
int op; |
71 |
< |
register PACKHEAD *clist; |
71 |
> |
PACKHEAD *clist; |
72 |
|
int nents; |
73 |
|
{ |
74 |
< |
int oldnr; |
75 |
< |
register HDBEAMI *hb; |
76 |
< |
register int i, n; |
77 |
< |
/* look for common members */ |
78 |
< |
for (n = 0; n < nents; n++) { |
79 |
< |
for (i = 0; i < complen; i++) |
80 |
< |
if (clist[n].bi == complist[i].bi && |
81 |
< |
clist[n].hd == complist[i].hd) { |
82 |
< |
oldnr = complist[i].nr; |
83 |
< |
clist[n].nc = complist[i].nc; |
84 |
< |
switch (op) { |
85 |
< |
case BS_ADD: /* add to count */ |
86 |
< |
complist[i].nr += clist[n].nr; |
87 |
< |
clist[n].nr = 0; |
88 |
< |
break; |
89 |
< |
case BS_ADJ: /* reset count */ |
90 |
< |
complist[i].nr = clist[n].nr; |
91 |
< |
clist[n].nr = 0; |
92 |
< |
break; |
93 |
< |
case BS_DEL: /* delete count */ |
94 |
< |
if (clist[n].nr == 0 || |
95 |
< |
clist[n].nr >= complist[i].nr) |
96 |
< |
complist[i].nr = 0; |
97 |
< |
else |
98 |
< |
complist[i].nr -= clist[n].nr; |
99 |
< |
break; |
100 |
< |
} |
101 |
< |
if (complist[i].nr != oldnr) |
102 |
< |
lastin = -1; /* flag sort */ |
103 |
< |
break; |
104 |
< |
} |
105 |
< |
if (i >= complen) |
106 |
< |
clist[n].nc = bnrays(hdlist[clist[n].hd], clist[n].bi); |
74 |
> |
int oldnr, n; |
75 |
> |
HDBEAMI *hbarr; |
76 |
> |
register PACKHEAD *csm; |
77 |
> |
register int i; |
78 |
> |
/* search for common members */ |
79 |
> |
qsort((char *)clist, nents, sizeof(PACKHEAD), beamidcmp); |
80 |
> |
for (csm = clist+nents; csm-- > clist; ) |
81 |
> |
csm->nc = -1; |
82 |
> |
for (i = 0; i < complen; i++) { |
83 |
> |
csm = (PACKHEAD *)bsearch((char *)(complist+i), (char *)clist, |
84 |
> |
nents, sizeof(PACKHEAD), beamidcmp); |
85 |
> |
if (csm == NULL) |
86 |
> |
continue; |
87 |
> |
oldnr = complist[i].nr; |
88 |
> |
csm->nc = complist[i].nc; |
89 |
> |
switch (op) { |
90 |
> |
case BS_ADD: /* add to count */ |
91 |
> |
complist[i].nr += csm->nr; |
92 |
> |
csm->nr = 0; |
93 |
> |
break; |
94 |
> |
case BS_ADJ: /* reset count */ |
95 |
> |
complist[i].nr = csm->nr; |
96 |
> |
csm->nr = 0; |
97 |
> |
break; |
98 |
> |
case BS_DEL: /* delete count */ |
99 |
> |
if (csm->nr == 0 || csm->nr >= complist[i].nr) |
100 |
> |
complist[i].nr = 0; |
101 |
> |
else |
102 |
> |
complist[i].nr -= csm->nr; |
103 |
> |
break; |
104 |
> |
} |
105 |
> |
if (complist[i].nr != oldnr) |
106 |
> |
lastin = -1; /* flag sort */ |
107 |
|
} |
108 |
+ |
/* computed rays for each uncommon beams */ |
109 |
+ |
for (csm = clist+nents; csm-- > clist; ) |
110 |
+ |
if (csm->nc < 0) |
111 |
+ |
csm->nc = bnrays(hdlist[csm->hd], csm->bi); |
112 |
|
/* complete list operations */ |
113 |
|
switch (op) { |
114 |
|
case BS_NEW: /* new computation set */ |
130 |
|
sortcomplist(); /* sort updated list & new entries */ |
131 |
|
qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp); |
132 |
|
/* what can't we satisfy? */ |
133 |
< |
for (n = 0; n < nents && clist[n].nr > clist[n].nc; n++) |
133 |
> |
for (i = nents, csm = clist; i-- && csm->nr > csm->nc; csm++) |
134 |
|
; |
135 |
+ |
n = csm - clist; |
136 |
|
if (op == BS_ADJ) { /* don't regenerate adjusted beams */ |
137 |
|
for (i = n; i < nents && clist[i].nr > 0; i++) |
138 |
|
; |
162 |
|
if (outdev == NULL) /* nothing to display? */ |
163 |
|
return; |
164 |
|
/* load and display beams we have */ |
165 |
< |
hb = (HDBEAMI *)malloc(nents*sizeof(HDBEAMI)); |
166 |
< |
for (i = 0; i < nents; i++) { |
167 |
< |
hb[i].h = hdlist[clist[i].hd]; |
168 |
< |
hb[i].b = clist[i].bi; |
165 |
> |
hbarr = (HDBEAMI *)malloc(nents*sizeof(HDBEAMI)); |
166 |
> |
for (i = nents; i--; ) { |
167 |
> |
hbarr[i].h = hdlist[clist[i].hd]; |
168 |
> |
hbarr[i].b = clist[i].bi; |
169 |
|
} |
170 |
< |
hdloadbeams(hb, nents, dispbeam); |
171 |
< |
free((char *)hb); |
170 |
> |
hdloadbeams(hbarr, nents, dispbeam); |
171 |
> |
free((char *)hbarr); |
172 |
|
return; |
173 |
|
memerr: |
174 |
|
error(SYSTEM, "out of memory in bundle_set"); |