1 /* -------------------------------------------------------------------------------
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 ----------------------------------------------------------------------------------
24 This code has been altered significantly from its original form, to support
25 several games based on the Quake III Arena engine, in the form of "Q3Map2."
27 ------------------------------------------------------------------------------- */
42 void RemovePortalFromNode( portal_t *portal, node_t *l );
44 node_t *NodeForPoint( node_t *node, vec3_t origin ){
48 while ( node->planenum != PLANENUM_LEAF )
50 plane = &mapplanes[node->planenum];
51 d = DotProduct( origin, plane->normal ) - plane->dist;
53 node = node->children[0];
56 node = node->children[1];
70 void FreeTreePortals_r( node_t *node ){
75 if ( node->planenum != PLANENUM_LEAF ) {
76 FreeTreePortals_r( node->children[0] );
77 FreeTreePortals_r( node->children[1] );
81 for ( p = node->portals ; p ; p = nextp )
83 s = ( p->nodes[1] == node );
86 RemovePortalFromNode( p, p->nodes[!s] );
97 void FreeTree_r( node_t *node ){
99 if ( node->planenum != PLANENUM_LEAF ) {
100 FreeTree_r( node->children[0] );
101 FreeTree_r( node->children[1] );
105 FreeBrushList( node->brushlist );
108 if ( node->volume ) {
109 FreeBrush( node->volume );
121 void FreeTree( tree_t *tree ){
122 FreeTreePortals_r( tree->headnode );
123 FreeTree_r( tree->headnode );
127 //===============================================================
129 void PrintTree_r( node_t *node, int depth ){
134 for ( i = 0 ; i < depth ; i++ )
136 if ( node->planenum == PLANENUM_LEAF ) {
137 if ( !node->brushlist ) {
138 Sys_Printf( "NULL\n" );
142 for ( bb = node->brushlist ; bb ; bb = bb->next )
143 Sys_Printf( "%d ", bb->original->brushNum );
149 plane = &mapplanes[node->planenum];
150 Sys_Printf( "#%d (%5.2f %5.2f %5.2f):%5.2f\n", node->planenum,
151 plane->normal[0], plane->normal[1], plane->normal[2],
153 PrintTree_r( node->children[0], depth + 1 );
154 PrintTree_r( node->children[1], depth + 1 );