2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 void RemovePortalFromNode( portal_t *portal, node_t *l );
27 node_t *NodeForPoint( node_t *node, vec3_t origin ){
31 while ( node->planenum != PLANENUM_LEAF )
33 plane = &mapplanes[node->planenum];
34 d = DotProduct( origin, plane->normal ) - plane->dist;
36 node = node->children[0];
39 node = node->children[1];
53 void FreeTreePortals_r( node_t *node ){
58 if ( node->planenum != PLANENUM_LEAF ) {
59 FreeTreePortals_r( node->children[0] );
60 FreeTreePortals_r( node->children[1] );
64 for ( p = node->portals ; p ; p = nextp )
66 s = ( p->nodes[1] == node );
69 RemovePortalFromNode( p, p->nodes[!s] );
80 void FreeTree_r( node_t *node ){
84 if ( node->planenum != PLANENUM_LEAF ) {
85 FreeTree_r( node->children[0] );
86 FreeTree_r( node->children[1] );
90 FreeBrushList( node->brushlist );
93 for ( f = node->faces ; f ; f = nextf )
100 if ( node->volume ) {
101 FreeBrush( node->volume );
104 if ( numthreads == 1 ) {
116 void FreeTree( tree_t *tree ){
117 FreeTreePortals_r( tree->headnode );
118 FreeTree_r( tree->headnode );
122 //===============================================================
124 void PrintTree_r( node_t *node, int depth ){
129 for ( i = 0 ; i < depth ; i++ )
131 if ( node->planenum == PLANENUM_LEAF ) {
132 if ( !node->brushlist ) {
133 Sys_Printf( "NULL\n" );
137 for ( bb = node->brushlist ; bb ; bb = bb->next )
138 Sys_Printf( "%i ", bb->original->brushnum );
144 plane = &mapplanes[node->planenum];
145 Sys_Printf( "#%i (%5.2f %5.2f %5.2f):%5.2f\n", node->planenum,
146 plane->normal[0], plane->normal[1], plane->normal[2],
148 PrintTree_r( node->children[0], depth + 1 );
149 PrintTree_r( node->children[1], depth + 1 );
153 =========================================================
155 NODES THAT DON'T SEPERATE DIFFERENT CONTENTS CAN BE PRUNED
157 =========================================================
167 void PruneNodes_r( node_t *node ){
168 bspbrush_t *b, *next;
170 if ( node->planenum == PLANENUM_LEAF ) {
173 PruneNodes_r( node->children[0] );
174 PruneNodes_r( node->children[1] );
176 if ( ( node->children[0]->contents & CONTENTS_SOLID )
177 && ( node->children[1]->contents & CONTENTS_SOLID ) ) {
179 Error( "node->faces seperating CONTENTS_SOLID" );
181 if ( node->children[0]->faces || node->children[1]->faces ) {
182 Error( "!node->faces with children" );
186 node->planenum = PLANENUM_LEAF;
187 node->contents = CONTENTS_SOLID;
188 node->detail_seperator = false;
190 if ( node->brushlist ) {
191 Error( "PruneNodes: node->brushlist" );
194 // combine brush lists
195 node->brushlist = node->children[1]->brushlist;
197 for ( b = node->children[0]->brushlist ; b ; b = next )
200 b->next = node->brushlist;
209 void PruneNodes( node_t *node ){
210 Sys_FPrintf( SYS_VRB, "--- PruneNodes ---\n" );
212 PruneNodes_r( node );
213 Sys_FPrintf( SYS_VRB, "%5i pruned nodes\n", c_pruned );
216 //===========================================================