16 |
|
|
17 |
|
#include "object.h" |
18 |
|
|
19 |
– |
#include "otypes.h" |
20 |
– |
|
19 |
|
#ifndef OSTSIZ |
20 |
|
#ifdef BIGMEM |
21 |
< |
#define OSTSIZ 56437 /* object table size (a prime!) */ |
21 |
> |
#define OSTSIZ 262139 /* object table size (a prime!) */ |
22 |
|
#else |
23 |
< |
#define OSTSIZ 12329 /* object table size (a prime!) */ |
23 |
> |
#define OSTSIZ 32749 /* object table size (a prime!) */ |
24 |
|
#endif |
25 |
|
#endif |
26 |
|
|
70 |
|
|
71 |
|
lower = 1; |
72 |
|
upper = cm = os[0] + 1; |
73 |
< |
|
73 |
> |
/* binary search algorithm */ |
74 |
|
while ((i = (lower + upper) >> 1) != cm) { |
75 |
|
cm = obj - os[i]; |
76 |
|
if (cm > 0) |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
+ |
OBJECT * |
111 |
+ |
setsave(os) /* allocate space and save set */ |
112 |
+ |
register OBJECT *os; |
113 |
+ |
{ |
114 |
+ |
OBJECT *osnew; |
115 |
+ |
register OBJECT *oset; |
116 |
+ |
register int i; |
117 |
+ |
|
118 |
+ |
if ((osnew = oset = (OBJECT *)malloc((*os+1)*sizeof(OBJECT))) == NULL) |
119 |
+ |
error(SYSTEM, "out of memory in setsave\n"); |
120 |
+ |
for (i = *os; i-- >= 0; ) /* inline setcopy */ |
121 |
+ |
*oset++ = *os++; |
122 |
+ |
return(osnew); |
123 |
+ |
} |
124 |
+ |
|
125 |
+ |
|
126 |
+ |
setunion(osr, os1, os2) /* osr = os1 Union os2 */ |
127 |
+ |
register OBJECT *osr, *os1, *os2; |
128 |
+ |
{ |
129 |
+ |
register int i1, i2; |
130 |
+ |
|
131 |
+ |
osr[0] = 0; |
132 |
+ |
for (i1 = i2 = 1; i1 <= os1[0] || i2 <= os2[0]; ) { |
133 |
+ |
while (i1 <= os1[0] && (i2 > os2[0] || os1[i1] <= os2[i2])) { |
134 |
+ |
osr[++osr[0]] = os1[i1]; |
135 |
+ |
if (i2 <= os2[0] && os2[i2] == os1[i1]) |
136 |
+ |
i2++; |
137 |
+ |
i1++; |
138 |
+ |
} |
139 |
+ |
while (i2 <= os2[0] && (i1 > os1[0] || os2[i2] < os1[i1])) |
140 |
+ |
osr[++osr[0]] = os2[i2++]; |
141 |
+ |
} |
142 |
+ |
} |
143 |
+ |
|
144 |
+ |
|
145 |
+ |
setintersect(osr, os1, os2) /* osr = os1 Intersect os2 */ |
146 |
+ |
register OBJECT *osr, *os1, *os2; |
147 |
+ |
{ |
148 |
+ |
register int i1, i2; |
149 |
+ |
|
150 |
+ |
osr[0] = 0; |
151 |
+ |
if (os1[0] <= 0) |
152 |
+ |
return; |
153 |
+ |
for (i1 = i2 = 1; i2 <= os2[0]; ) { |
154 |
+ |
while (os1[i1] < os2[i2]) |
155 |
+ |
if (++i1 > os1[0]) |
156 |
+ |
return; |
157 |
+ |
while (os2[i2] < os1[i1]) |
158 |
+ |
if (++i2 > os2[0]) |
159 |
+ |
return; |
160 |
+ |
if (os1[i1] == os2[i2]) |
161 |
+ |
osr[++osr[0]] = os2[i2++]; |
162 |
+ |
} |
163 |
+ |
} |
164 |
+ |
|
165 |
+ |
|
166 |
|
OCTREE |
167 |
|
fullnode(oset) /* return octree for object set */ |
168 |
|
OBJECT *oset; |
228 |
|
|
229 |
|
if (!isfull(ot)) |
230 |
|
goto noderr; |
231 |
< |
i = oseti(ot); |
232 |
< |
if ((os = ostable[i%OSTSIZ]) == NULL) |
231 |
> |
ot = oseti(ot); |
232 |
> |
if ((os = ostable[ot%OSTSIZ]) == NULL) |
233 |
|
goto noderr; |
234 |
< |
for (i /= OSTSIZ; i--; os += *os + 1) |
234 |
> |
for (i = ot/OSTSIZ; i--; os += *os + 1) |
235 |
|
if (*os <= 0) |
236 |
|
goto noderr; |
237 |
|
for (i = *os; i-- >= 0; ) /* copy set here */ |
242 |
|
} |
243 |
|
|
244 |
|
|
245 |
< |
nonsurfinset(orig, nobjs) /* check sets for non-surfaces */ |
246 |
< |
int orig, nobjs; |
245 |
> |
int |
246 |
> |
dosets(f) /* loop through all sets */ |
247 |
> |
int (*f)(); |
248 |
|
{ |
249 |
+ |
int res = 0; |
250 |
|
int n; |
251 |
|
register OBJECT *os; |
196 |
– |
register OBJECT i, s; |
252 |
|
|
253 |
|
for (n = 0; n < OSTSIZ; n++) { |
254 |
|
if ((os = ostable[n]) == NULL) |
255 |
|
continue; |
256 |
< |
while ((i = *os++) > 0) |
257 |
< |
while (i--) { |
258 |
< |
s = *os; |
259 |
< |
if (s >= orig && s < orig+nobjs && |
205 |
< |
!issurface(objptr(s)->otype)) |
206 |
< |
return(1); |
207 |
< |
os++; |
208 |
< |
} |
256 |
> |
while (*os > 0) { |
257 |
> |
res += (*f)(os); |
258 |
> |
os += *os + 1; |
259 |
> |
} |
260 |
|
} |
261 |
< |
return(0); |
261 |
> |
return(res); |
262 |
> |
} |
263 |
> |
|
264 |
> |
|
265 |
> |
donesets() /* free ALL SETS in our table */ |
266 |
> |
{ |
267 |
> |
register int n; |
268 |
> |
|
269 |
> |
for (n = 0; n < OSTSIZ; n++) |
270 |
> |
if (ostable[n] != NULL) { |
271 |
> |
free((char *)ostable[n]); |
272 |
> |
ostable[n] = NULL; |
273 |
> |
} |
274 |
|
} |