| 15 |
|
#include "octree.h" |
| 16 |
|
|
| 17 |
|
OCTREE *octblock[MAXOBLK]; /* our octree */ |
| 18 |
< |
static OCTREE ofreelist = EMPTY; /* free octree nodes */ |
| 18 |
> |
static OCTREE ofreelist = EMPTY; /* freed octree nodes */ |
| 19 |
|
static OCTREE treetop = 0; /* next free node */ |
| 20 |
|
|
| 21 |
|
|
| 33 |
|
errno = 0; |
| 34 |
|
if (octbi(freet) >= MAXOBLK) |
| 35 |
|
return(EMPTY); |
| 36 |
< |
if ((octblock[octbi(freet)] = (OCTREE *)malloc( |
| 36 |
> |
if ((octblock[octbi(freet)] = (OCTREE *)bmalloc( |
| 37 |
|
(unsigned)256*8*sizeof(OCTREE))) == NULL) |
| 38 |
|
return(EMPTY); |
| 39 |
|
} |
| 56 |
|
} |
| 57 |
|
|
| 58 |
|
|
| 59 |
+ |
octdone() /* free EVERYTHING */ |
| 60 |
+ |
{ |
| 61 |
+ |
register int i; |
| 62 |
+ |
|
| 63 |
+ |
for (i = 0; i < MAXOBLK; i++) { |
| 64 |
+ |
bfree((char *)octblock[i], (unsigned)256*8*sizeof(OCTREE)); |
| 65 |
+ |
octblock[i] = NULL; |
| 66 |
+ |
} |
| 67 |
+ |
ofreelist = EMPTY; |
| 68 |
+ |
treetop = 0; |
| 69 |
+ |
} |
| 70 |
+ |
|
| 71 |
+ |
|
| 72 |
|
OCTREE |
| 73 |
|
combine(ot) /* recursively combine nodes */ |
| 74 |
|
register OCTREE ot; |
| 82 |
|
for (i = 1; i < 8; i++) |
| 83 |
|
if ((octkid(ot, i) = combine(octkid(ot, i))) != ores) |
| 84 |
|
ores = ot; |
| 85 |
< |
if (!istree(ores)) /* all were identical leaves */ |
| 86 |
< |
octfree(ot); |
| 85 |
> |
if (!istree(ores)) { /* all were identical leaves */ |
| 86 |
> |
octkid(ot, 0) = ofreelist; |
| 87 |
> |
ofreelist = ot; |
| 88 |
> |
} |
| 89 |
|
return(ores); |
| 90 |
|
} |
| 91 |
|
|