Add a function to free a hull's portal information.

This commit is contained in:
Bill Currie 2011-12-08 14:58:08 +09:00
parent d3cf5c4b75
commit f9877ce0e0
2 changed files with 47 additions and 6 deletions

View file

@ -140,5 +140,6 @@ typedef struct nodeleaf_s {
} nodeleaf_t;
nodeleaf_t *MOD_BuildBrushes (hull_t *hull);
void MOD_FreeBrushes (hull_t *hull);
#endif // __world_h

View file

@ -47,18 +47,20 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
#include "world.h"
static clipleaf_t *
alloc_leaf (void)
{
return calloc (1, sizeof (clipleaf_t));
}
static clipport_t *
alloc_portal (void)
{
return calloc (1, sizeof (clipport_t));
}
static void
free_portal (clipport_t *portal)
{
FreeWinding (portal->winding);
FreeWinding (portal->edges);
free (portal);
}
static void
remove_portal (clipport_t *portal, clipleaf_t *leaf)
{
@ -75,6 +77,27 @@ remove_portal (clipport_t *portal, clipleaf_t *leaf)
}
}
static clipleaf_t *
alloc_leaf (void)
{
return calloc (1, sizeof (clipleaf_t));
}
static void
free_leaf (clipleaf_t *leaf)
{
if (!leaf)
return;
while (leaf->portals) {
clipport_t *portal = leaf->portals;
int side = portal->leafs[1] == leaf;
leaf->portals = portal->next[side];
remove_portal (portal, portal->leafs[side ^ 1]);
free_portal (portal);
}
free (leaf);
}
static void
add_portal (clipport_t *portal, clipleaf_t *front, clipleaf_t *back)
{
@ -195,3 +218,20 @@ MOD_BuildBrushes (hull_t *hull)
}
return nodeleafs;
}
void
MOD_FreeBrushes (hull_t *hull)
{
int i, j;
int numnodes;
if (!hull || !hull->nodeleafs)
return;
numnodes = hull->lastclipnode + 1;
for (i = 0; i < numnodes; i++) {
for (j = 0; j < 2; j++)
free_leaf (hull->nodeleafs[i].leafs[j]);
}
free (hull->nodeleafs);
hull->nodeleafs = 0;
}