| 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 |
#define TREE_C |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
#include "q3map2.h" |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
void RemovePortalFromNode( portal_t *portal, node_t *l ); |
| 43 |
|
| 44 |
node_t *NodeForPoint( node_t *node, vec3_t origin ){ |
| 45 |
plane_t *plane; |
| 46 |
vec_t d; |
| 47 |
|
| 48 |
while ( node->planenum != PLANENUM_LEAF ) |
| 49 |
{ |
| 50 |
plane = &mapplanes[node->planenum]; |
| 51 |
d = DotProduct( origin, plane->normal ) - plane->dist; |
| 52 |
if ( d >= 0 ) { |
| 53 |
node = node->children[0]; |
| 54 |
} |
| 55 |
else{ |
| 56 |
node = node->children[1]; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
return node; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
void FreeTreePortals_r( node_t *node ){ |
| 71 |
portal_t *p, *nextp; |
| 72 |
int s; |
| 73 |
|
| 74 |
|
| 75 |
if ( node->planenum != PLANENUM_LEAF ) { |
| 76 |
FreeTreePortals_r( node->children[0] ); |
| 77 |
FreeTreePortals_r( node->children[1] ); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
for ( p = node->portals ; p ; p = nextp ) |
| 82 |
{ |
| 83 |
s = ( p->nodes[1] == node ); |
| 84 |
nextp = p->next[s]; |
| 85 |
|
| 86 |
RemovePortalFromNode( p, p->nodes[!s] ); |
| 87 |
FreePortal( p ); |
| 88 |
} |
| 89 |
node->portals = NULL; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
void FreeTree_r( node_t *node ){ |
| 98 |
|
| 99 |
if ( node->planenum != PLANENUM_LEAF ) { |
| 100 |
FreeTree_r( node->children[0] ); |
| 101 |
FreeTree_r( node->children[1] ); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
FreeBrushList( node->brushlist ); |
| 106 |
|
| 107 |
|
| 108 |
if ( node->volume ) { |
| 109 |
FreeBrush( node->volume ); |
| 110 |
} |
| 111 |
|
| 112 |
free( node ); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
void FreeTree( tree_t *tree ){ |
| 122 |
FreeTreePortals_r( tree->headnode ); |
| 123 |
FreeTree_r( tree->headnode ); |
| 124 |
free( tree ); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
void PrintTree_r( node_t *node, int depth ){ |
| 130 |
int i; |
| 131 |
plane_t *plane; |
| 132 |
brush_t *bb; |
| 133 |
|
| 134 |
for ( i = 0 ; i < depth ; i++ ) |
| 135 |
Sys_Printf( " " ); |
| 136 |
if ( node->planenum == PLANENUM_LEAF ) { |
| 137 |
if ( !node->brushlist ) { |
| 138 |
Sys_Printf( "NULL\n" ); |
| 139 |
} |
| 140 |
else |
| 141 |
{ |
| 142 |
for ( bb = node->brushlist ; bb ; bb = bb->next ) |
| 143 |
Sys_Printf( "%d ", bb->original->brushNum ); |
| 144 |
Sys_Printf( "\n" ); |
| 145 |
} |
| 146 |
return; |
| 147 |
} |
| 148 |
|
| 149 |
plane = &mapplanes[node->planenum]; |
| 150 |
Sys_Printf( "#%d (%5.2f %5.2f %5.2f):%5.2f\n", node->planenum, |
| 151 |
plane->normal[0], plane->normal[1], plane->normal[2], |
| 152 |
plane->dist ); |
| 153 |
PrintTree_r( node->children[0], depth + 1 ); |
| 154 |
PrintTree_r( node->children[1], depth + 1 ); |
| 155 |
} |