2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
\r
5 This file is part of GtkRadiant.
\r
7 GtkRadiant is free software; you can redistribute it and/or modify
\r
8 it under the terms of the GNU General Public License as published by
\r
9 the Free Software Foundation; either version 2 of the License, or
\r
10 (at your option) any later version.
\r
12 GtkRadiant is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 GNU General Public License for more details.
\r
17 You should have received a copy of the GNU General Public License
\r
18 along with GtkRadiant; if not, write to the Free Software
\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\r
25 void RemovePortalFromNode (portal_t *portal, node_t *l);
\r
27 node_t *NodeForPoint (node_t *node, vec3_t origin)
\r
32 while (node->planenum != PLANENUM_LEAF)
\r
34 plane = &mapplanes[node->planenum];
\r
35 d = DotProduct (origin, plane->normal) - plane->dist;
\r
37 node = node->children[0];
\r
39 node = node->children[1];
\r
52 void FreeTreePortals_r (node_t *node)
\r
54 portal_t *p, *nextp;
\r
58 if (node->planenum != PLANENUM_LEAF)
\r
60 FreeTreePortals_r (node->children[0]);
\r
61 FreeTreePortals_r (node->children[1]);
\r
65 for (p=node->portals ; p ; p=nextp)
\r
67 s = (p->nodes[1] == node);
\r
70 RemovePortalFromNode (p, p->nodes[!s]);
\r
73 node->portals = NULL;
\r
81 void FreeTree_r (node_t *node)
\r
86 if (node->planenum != PLANENUM_LEAF)
\r
88 FreeTree_r (node->children[0]);
\r
89 FreeTree_r (node->children[1]);
\r
93 FreeBrushList (node->brushlist);
\r
96 for (f=node->faces ; f ; f=nextf)
\r
104 FreeBrush (node->volume);
\r
106 if (numthreads == 1)
\r
117 void FreeTree (tree_t *tree)
\r
119 FreeTreePortals_r (tree->headnode);
\r
120 FreeTree_r (tree->headnode);
\r
124 //===============================================================
\r
126 void PrintTree_r (node_t *node, int depth)
\r
132 for (i=0 ; i<depth ; i++)
\r
134 if (node->planenum == PLANENUM_LEAF)
\r
136 if (!node->brushlist)
\r
137 Sys_Printf ("NULL\n");
\r
140 for (bb=node->brushlist ; bb ; bb=bb->next)
\r
141 Sys_Printf ("%i ", bb->original->brushnum);
\r
147 plane = &mapplanes[node->planenum];
\r
148 Sys_Printf ("#%i (%5.2f %5.2f %5.2f):%5.2f\n", node->planenum,
\r
149 plane->normal[0], plane->normal[1], plane->normal[2],
\r
151 PrintTree_r (node->children[0], depth+1);
\r
152 PrintTree_r (node->children[1], depth+1);
\r
156 =========================================================
\r
158 NODES THAT DON'T SEPERATE DIFFERENT CONTENTS CAN BE PRUNED
\r
160 =========================================================
\r
170 void PruneNodes_r (node_t *node)
\r
172 bspbrush_t *b, *next;
\r
174 if (node->planenum == PLANENUM_LEAF)
\r
176 PruneNodes_r (node->children[0]);
\r
177 PruneNodes_r (node->children[1]);
\r
179 if ( (node->children[0]->contents & CONTENTS_SOLID)
\r
180 && (node->children[1]->contents & CONTENTS_SOLID) )
\r
183 Error ("node->faces seperating CONTENTS_SOLID");
\r
184 if (node->children[0]->faces || node->children[1]->faces)
\r
185 Error ("!node->faces with children");
\r
187 // FIXME: free stuff
\r
188 node->planenum = PLANENUM_LEAF;
\r
189 node->contents = CONTENTS_SOLID;
\r
190 node->detail_seperator = false;
\r
192 if (node->brushlist)
\r
193 Error ("PruneNodes: node->brushlist");
\r
195 // combine brush lists
\r
196 node->brushlist = node->children[1]->brushlist;
\r
198 for (b=node->children[0]->brushlist ; b ; b=next)
\r
201 b->next = node->brushlist;
\r
202 node->brushlist = b;
\r
210 void PruneNodes (node_t *node)
\r
212 Sys_FPrintf( SYS_VRB, "--- PruneNodes ---\n");
\r
214 PruneNodes_r (node);
\r
215 Sys_FPrintf( SYS_VRB, "%5i pruned nodes\n", c_pruned);
\r
218 //===========================================================
\r