File: | tools/ufo2map/tree.cpp |
Location: | line 205, column 2 |
Description: | Value stored to 'node' is never read |
1 | /** |
2 | * @file |
3 | */ |
4 | |
5 | /* |
6 | Copyright (C) 1997-2001 Id Software, Inc. |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program 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. |
16 | |
17 | See the GNU General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU General Public License |
20 | along with this program; if not, write to the Free Software |
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22 | |
23 | */ |
24 | |
25 | #include "bsp.h" |
26 | |
27 | int c_nodes; |
28 | int c_nonvis; |
29 | |
30 | /** |
31 | * @sa AllocBrush |
32 | * @sa AllocTree |
33 | */ |
34 | node_t *AllocNode (void) |
35 | { |
36 | return Mem_AllocType(node_t)((node_t*)_Mem_Alloc(((sizeof(node_t))),true,(com_genericPool ),(0),"src/tools/ufo2map/tree.cpp",36)); |
37 | } |
38 | |
39 | static void FreeTreePortals_r (node_t *node) |
40 | { |
41 | portal_t *p, *nextp; |
42 | |
43 | /* free children */ |
44 | if (node->planenum != PLANENUM_LEAF-1) { |
45 | FreeTreePortals_r(node->children[0]); |
46 | FreeTreePortals_r(node->children[1]); |
47 | } |
48 | |
49 | /* free portals */ |
50 | for (p = node->portals; p; p = nextp) { |
51 | const int s = (p->nodes[1] == node); |
52 | nextp = p->next[s]; |
53 | |
54 | RemovePortalFromNode(p, p->nodes[!s]); |
55 | FreePortal(p); |
56 | } |
57 | node->portals = NULL__null; |
58 | } |
59 | |
60 | static void FreeTree_r (node_t *node) |
61 | { |
62 | face_t *f, *nextf; |
63 | |
64 | /* free children */ |
65 | if (node->planenum != PLANENUM_LEAF-1) { |
66 | FreeTree_r(node->children[0]); |
67 | FreeTree_r(node->children[1]); |
68 | } |
69 | |
70 | /* free bspbrushes */ |
71 | FreeBrushList(node->brushlist); |
72 | |
73 | /* free faces */ |
74 | for (f = node->faces; f; f = nextf) { |
75 | nextf = f->next; |
76 | FreeFace(f); |
77 | } |
78 | |
79 | /* free the node */ |
80 | if (node->volume) |
81 | FreeBrush(node->volume); |
82 | |
83 | if (threadstate.numthreads == 1) |
84 | c_nodes--; |
85 | Mem_Free(node)_Mem_Free((node),"src/tools/ufo2map/tree.cpp",85); |
86 | } |
87 | |
88 | |
89 | /** |
90 | * @brief Allocates a tree and initializes it |
91 | */ |
92 | tree_t *AllocTree (void) |
93 | { |
94 | tree_t *tree = Mem_AllocType(tree_t)((tree_t*)_Mem_Alloc(((sizeof(tree_t))),true,(com_genericPool ),(0),"src/tools/ufo2map/tree.cpp",94)); |
95 | |
96 | ClearBounds(tree->mins, tree->maxs); |
97 | |
98 | return tree; |
99 | } |
100 | |
101 | |
102 | void FreeTree (tree_t *tree) |
103 | { |
104 | FreeTreePortals_r(tree->headnode); |
105 | FreeTree_r(tree->headnode); |
106 | Mem_Free(tree)_Mem_Free((tree),"src/tools/ufo2map/tree.cpp",106); |
107 | } |
108 | |
109 | |
110 | static void CheckPlaneAgainstParents (uint16_t pnum, const node_t *node) |
111 | { |
112 | node_t *p; |
113 | |
114 | for (p = node->parent; p; p = p->parent) { |
115 | if (p->planenum == pnum) |
116 | Sys_Error("Tried parent"); |
117 | } |
118 | } |
119 | |
120 | static void LeafNode (node_t *node, bspbrush_t *brushes) |
121 | { |
122 | node->side = NULL__null; |
123 | node->planenum = PLANENUM_LEAF-1; |
124 | |
125 | Verb_Printf(VERB_DUMP, "LeafNode: scanning brushes.\n"); |
126 | |
127 | node->contentFlags = BrushListCalcContents(brushes); |
128 | node->brushlist = brushes; |
129 | } |
130 | |
131 | static node_t *BuildTree_r (node_t *node, bspbrush_t *brushes) |
132 | { |
133 | node_t *newnode; |
134 | side_t *bestside; |
135 | int i; |
136 | bspbrush_t *children[2]; |
137 | |
138 | if (threadstate.numthreads == 1) |
139 | c_nodes++; |
140 | |
141 | /* find the best plane to use as a splitter */ |
142 | bestside = SelectSplitSide(brushes, node->volume); |
143 | if (!bestside) { |
144 | /* leaf node */ |
145 | LeafNode(node, brushes); |
146 | Verb_Printf(VERB_DUMP, "BuildTree_r: Created a leaf node.\n"); |
147 | return node; |
148 | } |
149 | /* make sure the selected plane hasn't been used before. */ |
150 | CheckPlaneAgainstParents(bestside->planenum, node); |
151 | |
152 | Verb_Printf(VERB_DUMP, "BuildTree_r: splitting along plane %i\n", (int)bestside->planenum); |
153 | |
154 | /* this is a splitplane node */ |
155 | node->side = bestside; |
156 | node->planenum = bestside->planenum & ~1; /* always use front facing */ |
157 | |
158 | SplitBrushList(brushes, node->planenum, &children[0], &children[1]); |
159 | FreeBrushList(brushes); |
160 | |
161 | /* allocate children before recursing */ |
162 | for (i = 0; i < 2; i++) { |
163 | newnode = AllocNode(); |
164 | newnode->parent = node; |
165 | node->children[i] = newnode; |
166 | } |
167 | |
168 | SplitBrush(node->volume, node->planenum, &node->children[0]->volume, |
169 | &node->children[1]->volume); |
170 | |
171 | /* recursively process children */ |
172 | for (i = 0; i < 2; i++) { |
173 | node->children[i] = BuildTree_r(node->children[i], children[i]); |
174 | } |
175 | |
176 | return node; |
177 | } |
178 | |
179 | /** |
180 | * @brief The incoming list will be freed before exiting |
181 | */ |
182 | tree_t *BuildTree (bspbrush_t *brushlist, vec3_t mins, vec3_t maxs) |
183 | { |
184 | node_t *node; |
185 | tree_t *tree; |
186 | vec3_t blmins, blmaxs; |
187 | |
188 | Verb_Printf(VERB_EXTRA, "--- BrushBSP ---\n"); |
189 | |
190 | tree = AllocTree(); |
191 | |
192 | ClearBounds(blmins, blmaxs); |
193 | BrushlistCalcStats(brushlist, blmins, blmaxs); |
194 | AddPointToBounds(blmins, tree->mins, tree->maxs); |
195 | AddPointToBounds(blmaxs, tree->mins, tree->maxs); |
196 | |
197 | c_nodes = 0; |
198 | c_nonvis = 0; |
199 | node = AllocNode(); |
200 | |
201 | node->volume = BrushFromBounds(mins, maxs); |
202 | |
203 | tree->headnode = node; |
204 | |
205 | node = BuildTree_r(node, brushlist); |
Value stored to 'node' is never read | |
206 | |
207 | Verb_Printf(VERB_EXTRA, "%5i visible nodes\n", c_nodes / 2 - c_nonvis); |
208 | Verb_Printf(VERB_EXTRA, "%5i nonvis nodes\n", c_nonvis); |
209 | Verb_Printf(VERB_EXTRA, "%5i leafs\n", (c_nodes + 1) / 2); |
210 | return tree; |
211 | } |
212 | |
213 | /*========================================================= |
214 | NODES THAT DON'T SEPERATE DIFFERENT CONTENTS CAN BE PRUNED |
215 | =========================================================*/ |
216 | |
217 | static int c_pruned; |
218 | |
219 | /** |
220 | * @sa PruneNodes |
221 | * @brief Will cut solid nodes by recursing down the bsp tree |
222 | */ |
223 | static void PruneNodes_r (node_t *node) |
224 | { |
225 | bspbrush_t *b, *next; |
226 | |
227 | if (node->planenum == PLANENUM_LEAF-1) |
228 | return; |
229 | PruneNodes_r(node->children[0]); |
230 | PruneNodes_r(node->children[1]); |
231 | |
232 | if ((node->children[0]->contentFlags & CONTENTS_SOLID0x0001) |
233 | && (node->children[1]->contentFlags & CONTENTS_SOLID0x0001)) { |
234 | if (node->faces) |
235 | Sys_Error("node->faces seperating CONTENTS_SOLID"); |
236 | if (node->children[0]->faces || node->children[1]->faces) |
237 | Sys_Error("!node->faces with children"); |
238 | |
239 | /** @todo free stuff */ |
240 | node->planenum = PLANENUM_LEAF-1; |
241 | node->contentFlags = CONTENTS_SOLID0x0001; |
242 | |
243 | if (node->brushlist) |
244 | Sys_Error("PruneNodes: node->brushlist"); |
245 | |
246 | /* combine brush lists */ |
247 | node->brushlist = node->children[1]->brushlist; |
248 | |
249 | for (b = node->children[0]->brushlist; b; b = next) { |
250 | next = b->next; |
251 | b->next = node->brushlist; |
252 | node->brushlist = b; |
253 | } |
254 | |
255 | c_pruned++; |
256 | } |
257 | } |
258 | |
259 | /** |
260 | * @sa PruneNodes_r |
261 | */ |
262 | void PruneNodes (node_t *node) |
263 | { |
264 | Verb_Printf(VERB_EXTRA, "--- PruneNodes ---\n"); |
265 | c_pruned = 0; |
266 | PruneNodes_r(node); |
267 | Verb_Printf(VERB_EXTRA, "%5i pruned nodes\n", c_pruned); |
268 | } |