2008-07-25 07:31:37 +00:00
|
|
|
/* -------------------------------------------------------------------------------
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
----------------------------------------------------------------------------------
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This code has been altered significantly from its original form, to support
|
|
|
|
several games based on the Quake III Arena engine, in the form of "Q3Map2."
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
------------------------------------------------------------------------------- */
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* marker */
|
|
|
|
#define TREE_C
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dependencies */
|
|
|
|
#include "q3map2.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void RemovePortalFromNode( portal_t *portal, node_t *l );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
node_t *NodeForPoint( node_t *node, vec3_t origin ){
|
|
|
|
plane_t *plane;
|
|
|
|
vec_t d;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( node->planenum != PLANENUM_LEAF )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
plane = &mapplanes[node->planenum];
|
2012-03-17 20:01:54 +00:00
|
|
|
d = DotProduct( origin, plane->normal ) - plane->dist;
|
|
|
|
if ( d >= 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
node = node->children[0];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
node = node->children[1];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
FreeTreePortals_r
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void FreeTreePortals_r( node_t *node ){
|
|
|
|
portal_t *p, *nextp;
|
|
|
|
int s;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// free children
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->planenum != PLANENUM_LEAF ) {
|
|
|
|
FreeTreePortals_r( node->children[0] );
|
|
|
|
FreeTreePortals_r( node->children[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// free portals
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( p = node->portals ; p ; p = nextp )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
s = ( p->nodes[1] == node );
|
2007-11-04 03:34:51 +00:00
|
|
|
nextp = p->next[s];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
RemovePortalFromNode( p, p->nodes[!s] );
|
|
|
|
FreePortal( p );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
node->portals = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
FreeTree_r
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void FreeTree_r( node_t *node ){
|
2007-11-04 03:34:51 +00:00
|
|
|
// free children
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->planenum != PLANENUM_LEAF ) {
|
|
|
|
FreeTree_r( node->children[0] );
|
|
|
|
FreeTree_r( node->children[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// free bspbrushes
|
2012-03-17 20:01:54 +00:00
|
|
|
FreeBrushList( node->brushlist );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// free the node
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->volume ) {
|
|
|
|
FreeBrush( node->volume );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
free( node );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
FreeTree
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void FreeTree( tree_t *tree ){
|
|
|
|
FreeTreePortals_r( tree->headnode );
|
|
|
|
FreeTree_r( tree->headnode );
|
|
|
|
free( tree );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===============================================================
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void PrintTree_r( node_t *node, int depth ){
|
|
|
|
int i;
|
|
|
|
plane_t *plane;
|
|
|
|
brush_t *bb;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < depth ; i++ )
|
|
|
|
Sys_Printf( " " );
|
|
|
|
if ( node->planenum == PLANENUM_LEAF ) {
|
|
|
|
if ( !node->brushlist ) {
|
|
|
|
Sys_Printf( "NULL\n" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( bb = node->brushlist ; bb ; bb = bb->next )
|
|
|
|
Sys_Printf( "%d ", bb->original->brushNum );
|
|
|
|
Sys_Printf( "\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
plane = &mapplanes[node->planenum];
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "#%d (%5.2f %5.2f %5.2f):%5.2f\n", node->planenum,
|
|
|
|
plane->normal[0], plane->normal[1], plane->normal[2],
|
|
|
|
plane->dist );
|
|
|
|
PrintTree_r( node->children[0], depth + 1 );
|
|
|
|
PrintTree_r( node->children[1], depth + 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|