16 |
|
|
17 |
|
#include "object.h" |
18 |
|
|
19 |
< |
#include "otypes.h" |
19 |
> |
#ifndef OSTSIZ |
20 |
> |
#ifdef BIGMEM |
21 |
> |
#define OSTSIZ 262139 /* object table size (a prime!) */ |
22 |
> |
#else |
23 |
> |
#define OSTSIZ 32749 /* object table size (a prime!) */ |
24 |
> |
#endif |
25 |
> |
#endif |
26 |
|
|
21 |
– |
#define OSTSIZ 3037 /* object table size (a prime!) */ |
22 |
– |
|
27 |
|
static OBJECT *ostable[OSTSIZ]; /* the object set table */ |
28 |
|
|
29 |
|
|
48 |
|
{ |
49 |
|
register int i; |
50 |
|
|
51 |
< |
for (i = (*os++)--; i > 0 && *os < obj; i--, os++) |
52 |
< |
; |
51 |
> |
i = (*os)--; |
52 |
> |
os++; |
53 |
> |
while (i > 0 && *os < obj) { |
54 |
> |
i--; |
55 |
> |
os++; |
56 |
> |
} |
57 |
|
while (--i > 0) { |
58 |
|
os[0] = os[1]; |
59 |
|
os++; |
68 |
|
int upper, lower; |
69 |
|
register int cm, i; |
70 |
|
|
71 |
+ |
if ((i = os[0]) <= 6) { /* linear search algorithm */ |
72 |
+ |
cm = obj; |
73 |
+ |
while (i-- > 0) |
74 |
+ |
if (*++os == cm) |
75 |
+ |
return(1); |
76 |
+ |
return(0); |
77 |
+ |
} |
78 |
|
lower = 1; |
79 |
< |
upper = cm = os[0] + 1; |
80 |
< |
|
79 |
> |
upper = cm = i + 1; |
80 |
> |
/* binary search algorithm */ |
81 |
|
while ((i = (lower + upper) >> 1) != cm) { |
82 |
|
cm = obj - os[i]; |
83 |
|
if (cm > 0) |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
+ |
OBJECT * |
118 |
+ |
setsave(os) /* allocate space and save set */ |
119 |
+ |
register OBJECT *os; |
120 |
+ |
{ |
121 |
+ |
OBJECT *osnew; |
122 |
+ |
register OBJECT *oset; |
123 |
+ |
register int i; |
124 |
+ |
|
125 |
+ |
if ((osnew = oset = (OBJECT *)malloc((*os+1)*sizeof(OBJECT))) == NULL) |
126 |
+ |
error(SYSTEM, "out of memory in setsave\n"); |
127 |
+ |
for (i = *os; i-- >= 0; ) /* inline setcopy */ |
128 |
+ |
*oset++ = *os++; |
129 |
+ |
return(osnew); |
130 |
+ |
} |
131 |
+ |
|
132 |
+ |
|
133 |
+ |
setunion(osr, os1, os2) /* osr = os1 Union os2 */ |
134 |
+ |
register OBJECT *osr, *os1, *os2; |
135 |
+ |
{ |
136 |
+ |
register int i1, i2; |
137 |
+ |
|
138 |
+ |
osr[0] = 0; |
139 |
+ |
for (i1 = i2 = 1; i1 <= os1[0] || i2 <= os2[0]; ) { |
140 |
+ |
while (i1 <= os1[0] && (i2 > os2[0] || os1[i1] <= os2[i2])) { |
141 |
+ |
osr[++osr[0]] = os1[i1]; |
142 |
+ |
if (i2 <= os2[0] && os2[i2] == os1[i1]) |
143 |
+ |
i2++; |
144 |
+ |
i1++; |
145 |
+ |
} |
146 |
+ |
while (i2 <= os2[0] && (i1 > os1[0] || os2[i2] < os1[i1])) |
147 |
+ |
osr[++osr[0]] = os2[i2++]; |
148 |
+ |
} |
149 |
+ |
} |
150 |
+ |
|
151 |
+ |
|
152 |
+ |
setintersect(osr, os1, os2) /* osr = os1 Intersect os2 */ |
153 |
+ |
register OBJECT *osr, *os1, *os2; |
154 |
+ |
{ |
155 |
+ |
register int i1, i2; |
156 |
+ |
|
157 |
+ |
osr[0] = 0; |
158 |
+ |
if (os1[0] <= 0) |
159 |
+ |
return; |
160 |
+ |
for (i1 = i2 = 1; i2 <= os2[0]; ) { |
161 |
+ |
while (os1[i1] < os2[i2]) |
162 |
+ |
if (++i1 > os1[0]) |
163 |
+ |
return; |
164 |
+ |
while (os2[i2] < os1[i1]) |
165 |
+ |
if (++i2 > os2[0]) |
166 |
+ |
return; |
167 |
+ |
if (os1[i1] == os2[i2]) |
168 |
+ |
osr[++osr[0]] = os2[i2++]; |
169 |
+ |
} |
170 |
+ |
} |
171 |
+ |
|
172 |
+ |
|
173 |
|
OCTREE |
174 |
|
fullnode(oset) /* return octree for object set */ |
175 |
|
OBJECT *oset; |
235 |
|
|
236 |
|
if (!isfull(ot)) |
237 |
|
goto noderr; |
238 |
< |
i = oseti(ot); |
239 |
< |
if ((os = ostable[i%OSTSIZ]) == NULL) |
238 |
> |
ot = oseti(ot); |
239 |
> |
if ((os = ostable[ot%OSTSIZ]) == NULL) |
240 |
|
goto noderr; |
241 |
< |
for (i /= OSTSIZ; i--; os += *os + 1) |
241 |
> |
for (i = ot/OSTSIZ; i--; os += *os + 1) |
242 |
|
if (*os <= 0) |
243 |
|
goto noderr; |
244 |
|
for (i = *os; i-- >= 0; ) /* copy set here */ |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
< |
nonsurfinset(orig, nobjs) /* check sets for non-surfaces */ |
253 |
< |
int orig, nobjs; |
252 |
> |
int |
253 |
> |
dosets(f) /* loop through all sets */ |
254 |
> |
int (*f)(); |
255 |
|
{ |
256 |
+ |
int res = 0; |
257 |
|
int n; |
185 |
– |
OBJECT *nonset; |
258 |
|
register OBJECT *os; |
259 |
< |
register OBJECT i; |
188 |
< |
/* count non-surfaces */ |
189 |
< |
n = 0; |
190 |
< |
for (i = orig; i < orig+nobjs; i++) |
191 |
< |
if (!issurface(objptr(i)->otype)) |
192 |
< |
n++; |
193 |
< |
if (n <= 0) |
194 |
< |
return(0); |
195 |
< |
/* allocate set */ |
196 |
< |
if ((nonset = (OBJECT *)malloc((n+1)*sizeof(OBJECT))) == NULL) |
197 |
< |
return(0); /* give up if we haven't enough mem */ |
198 |
< |
/* fill set */ |
199 |
< |
os = nonset; |
200 |
< |
*os = n; |
201 |
< |
for (i = orig; i < orig+nobjs; i++) |
202 |
< |
if (!issurface(objptr(i)->otype)) |
203 |
< |
*++os = i; |
204 |
< |
/* now check all sets */ |
259 |
> |
|
260 |
|
for (n = 0; n < OSTSIZ; n++) { |
261 |
|
if ((os = ostable[n]) == NULL) |
262 |
|
continue; |
263 |
< |
while ((i = *os++) > 0) |
264 |
< |
while (i--) { |
265 |
< |
if (*os >= nonset[1] |
266 |
< |
&& *os <= nonset[nonset[0]] |
212 |
< |
&& inset(nonset, *os)) |
213 |
< |
goto done; |
214 |
< |
os++; |
215 |
< |
} |
263 |
> |
while (*os > 0) { |
264 |
> |
res += (*f)(os); |
265 |
> |
os += *os + 1; |
266 |
> |
} |
267 |
|
} |
268 |
< |
done: |
269 |
< |
free((char *)nonset); |
270 |
< |
return(n < OSTSIZ); |
268 |
> |
return(res); |
269 |
> |
} |
270 |
> |
|
271 |
> |
|
272 |
> |
donesets() /* free ALL SETS in our table */ |
273 |
> |
{ |
274 |
> |
register int n; |
275 |
> |
|
276 |
> |
for (n = 0; n < OSTSIZ; n++) |
277 |
> |
if (ostable[n] != NULL) { |
278 |
> |
free((char *)ostable[n]); |
279 |
> |
ostable[n] = NULL; |
280 |
> |
} |
281 |
|
} |