2001-07-30 04:33:59 +00:00
|
|
|
/*
|
|
|
|
clip_hull.c
|
|
|
|
|
|
|
|
dynamic bsp clipping hull management
|
|
|
|
|
|
|
|
Copyright (C) 2001 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2001/7/28
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2002-08-22 18:38:07 +00:00
|
|
|
|
2001-07-30 04:33:59 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "QF/clip_hull.h"
|
|
|
|
#include "QF/model.h"
|
|
|
|
|
2021-02-01 05:39:00 +00:00
|
|
|
#include "mod_internal.h"
|
2002-08-25 16:35:22 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE clip_hull_t *
|
2002-08-25 16:35:22 +00:00
|
|
|
MOD_Alloc_Hull (int nodes, int planes)
|
2001-07-30 04:33:59 +00:00
|
|
|
{
|
|
|
|
clip_hull_t *ch;
|
2002-08-25 14:25:38 +00:00
|
|
|
int size, i;
|
2001-07-30 04:33:59 +00:00
|
|
|
|
|
|
|
size = sizeof (hull_t);
|
2022-05-19 06:13:07 +00:00
|
|
|
size += sizeof (dclipnode_t) * nodes + sizeof (plane_t) * planes;
|
2001-07-30 04:33:59 +00:00
|
|
|
size *= MAX_MAP_HULLS;
|
|
|
|
size += sizeof (clip_hull_t);
|
|
|
|
|
|
|
|
ch = calloc (size, 1);
|
|
|
|
if (!ch)
|
|
|
|
return 0;
|
2002-08-22 18:38:07 +00:00
|
|
|
ch->hulls[0] = (hull_t *) &ch[1];
|
2001-07-30 04:33:59 +00:00
|
|
|
for (i = 1; i < MAX_MAP_HULLS; i++)
|
|
|
|
ch->hulls[i] = &ch->hulls[i - 1][1];
|
2022-05-19 06:13:07 +00:00
|
|
|
ch->hulls[0]->clipnodes = (dclipnode_t *) &ch->hulls[i - 1][1];
|
2011-11-14 02:18:22 +00:00
|
|
|
ch->hulls[0]->planes = (plane_t *) &ch->hulls[0]->clipnodes[nodes];
|
2001-07-30 04:33:59 +00:00
|
|
|
for (i = 1; i < MAX_MAP_HULLS; i++) {
|
2002-08-22 18:38:07 +00:00
|
|
|
ch->hulls[i]->clipnodes =
|
2022-05-19 06:13:07 +00:00
|
|
|
(dclipnode_t *) &ch->hulls[i - 1]->planes[planes];
|
2011-11-14 02:18:22 +00:00
|
|
|
ch->hulls[i]->planes = (plane_t *) &ch->hulls[i]->clipnodes[nodes];
|
2001-07-30 04:33:59 +00:00
|
|
|
}
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2002-08-25 16:35:22 +00:00
|
|
|
MOD_Free_Hull (clip_hull_t *ch)
|
2001-07-30 04:33:59 +00:00
|
|
|
{
|
|
|
|
free (ch);
|
|
|
|
}
|
2012-12-29 07:07:30 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
recurse_clip_tree (hull_t *hull, int num, int depth)
|
|
|
|
{
|
2022-05-19 06:13:07 +00:00
|
|
|
dclipnode_t *node;
|
2012-12-29 07:07:30 +00:00
|
|
|
|
|
|
|
if (num < 0) {
|
|
|
|
if (depth > hull->depth)
|
|
|
|
hull->depth = depth;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
node = hull->clipnodes + num;
|
|
|
|
recurse_clip_tree (hull, node->children[0], depth + 1);
|
|
|
|
recurse_clip_tree (hull, node->children[1], depth + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Mod_FindClipDepth (hull_t *hull)
|
|
|
|
{
|
|
|
|
hull->depth = 0;
|
|
|
|
if (hull->clipnodes) // no hull 3?
|
|
|
|
recurse_clip_tree (hull, hull->firstclipnode, 1);
|
|
|
|
}
|