-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtree.c
158 lines (121 loc) · 3.5 KB
/
tree.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* -------------------------------------------------------------------------------
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
For a list of contributors, see the accompanying CONTRIBUTORS file.
This file is part of GtkRadiant.
GtkRadiant is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GtkRadiant is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GtkRadiant; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
----------------------------------------------------------------------------------
This code has been altered significantly from its original form, to support
several games based on the Quake III Arena engine, in the form of "Q3Map2."
------------------------------------------------------------------------------- */
/* marker */
#define TREE_C
/* dependencies */
#include "kmap2.h"
void RemovePortalFromNode(portal_t * portal, node_t * l);
node_t *NodeForPoint(node_t * node, vec3_t origin)
{
plane_t *plane;
vec_t d;
while(node->planenum != PLANENUM_LEAF)
{
plane = &mapplanes[node->planenum];
d = DotProduct(origin, plane->normal) - plane->dist;
if(d >= 0)
node = node->children[0];
else
node = node->children[1];
}
return node;
}
/*
=============
FreeTreePortals_r
=============
*/
void FreeTreePortals_r(node_t * node)
{
portal_t *p, *nextp;
int s;
// free children
if(node->planenum != PLANENUM_LEAF)
{
FreeTreePortals_r(node->children[0]);
FreeTreePortals_r(node->children[1]);
}
// free portals
for(p = node->portals; p; p = nextp)
{
s = (p->nodes[1] == node);
nextp = p->next[s];
RemovePortalFromNode(p, p->nodes[!s]);
FreePortal(p);
}
node->portals = NULL;
}
/*
=============
FreeTree_r
=============
*/
void FreeTree_r(node_t * node)
{
// free children
if(node->planenum != PLANENUM_LEAF)
{
FreeTree_r(node->children[0]);
FreeTree_r(node->children[1]);
}
// free bspbrushes
FreeBrushList(node->brushlist);
// free the node
if(node->volume)
FreeBrush(node->volume);
free(node);
}
/*
=============
FreeTree
=============
*/
void FreeTree(tree_t * tree)
{
FreeTreePortals_r(tree->headnode);
FreeTree_r(tree->headnode);
free(tree);
}
//===============================================================
void PrintTree_r(node_t * node, int depth)
{
int i;
plane_t *plane;
brush_t *bb;
for(i = 0; i < depth; i++)
Sys_Printf(" ");
if(node->planenum == PLANENUM_LEAF)
{
if(!node->brushlist)
Sys_Printf("NULL\n");
else
{
for(bb = node->brushlist; bb; bb = bb->next)
Sys_Printf("%d ", bb->original->brushNum);
Sys_Printf("\n");
}
return;
}
plane = &mapplanes[node->planenum];
Sys_Printf("#%d (%5.2f %5.2f %5.2f):%5.2f\n", node->planenum,
plane->normal[0], plane->normal[1], plane->normal[2], plane->dist);
PrintTree_r(node->children[0], depth + 1);
PrintTree_r(node->children[1], depth + 1);
}