2 Copyright (C) 1999-2006 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)
32 while (node->planenum != PLANENUM_LEAF)
34 plane = &mapplanes[node->planenum];
35 d = DotProduct (origin, plane->normal) - plane->dist;
37 node = node->children[0];
39 node = node->children[1];
52 void FreeTreePortals_r (node_t *node)
58 if (node->planenum != PLANENUM_LEAF)
60 FreeTreePortals_r (node->children[0]);
61 FreeTreePortals_r (node->children[1]);
65 for (p=node->portals ; p ; p=nextp)
67 s = (p->nodes[1] == node);
70 RemovePortalFromNode (p, p->nodes[!s]);
81 void FreeTree_r (node_t *node)
86 if (node->planenum != PLANENUM_LEAF)
88 FreeTree_r (node->children[0]);
89 FreeTree_r (node->children[1]);
93 FreeBrushList (node->brushlist);
96 for (f=node->faces ; f ; f=nextf)
104 FreeBrush (node->volume);
117 void FreeTree (tree_t *tree)
119 FreeTreePortals_r (tree->headnode);
120 FreeTree_r (tree->headnode);
124 //===============================================================
126 void PrintTree_r (node_t *node, int depth)
132 for (i=0 ; i<depth ; i++)
134 if (node->planenum == PLANENUM_LEAF)
136 if (!node->brushlist)
137 Sys_Printf ("NULL\n");
140 for (bb=node->brushlist ; bb ; bb=bb->next)
141 Sys_Printf ("%i ", bb->original->brushnum);
147 plane = &mapplanes[node->planenum];
148 Sys_Printf ("#%i (%5.2f %5.2f %5.2f):%5.2f\n", node->planenum,
149 plane->normal[0], plane->normal[1], plane->normal[2],
151 PrintTree_r (node->children[0], depth+1);
152 PrintTree_r (node->children[1], depth+1);
156 =========================================================
158 NODES THAT DON'T SEPERATE DIFFERENT CONTENTS CAN BE PRUNED
160 =========================================================
170 void PruneNodes_r (node_t *node)
172 bspbrush_t *b, *next;
174 if (node->planenum == PLANENUM_LEAF)
176 PruneNodes_r (node->children[0]);
177 PruneNodes_r (node->children[1]);
179 if ( (node->children[0]->contents & CONTENTS_SOLID)
180 && (node->children[1]->contents & CONTENTS_SOLID) )
183 Error ("node->faces seperating CONTENTS_SOLID");
184 if (node->children[0]->faces || node->children[1]->faces)
185 Error ("!node->faces with children");
188 node->planenum = PLANENUM_LEAF;
189 node->contents = CONTENTS_SOLID;
190 node->detail_seperator = false;
193 Error ("PruneNodes: node->brushlist");
195 // combine brush lists
196 node->brushlist = node->children[1]->brushlist;
198 for (b=node->children[0]->brushlist ; b ; b=next)
201 b->next = node->brushlist;
210 void PruneNodes (node_t *node)
212 Sys_FPrintf( SYS_VRB, "--- PruneNodes ---\n");
215 Sys_FPrintf( SYS_VRB, "%5i pruned nodes\n", c_pruned);
218 //===========================================================