Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

tree.c

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 #include "qbsp.h"
00023 
00024 
00025 extern  int c_nodes;
00026 
00027 void RemovePortalFromNode (portal_t *portal, node_t *l);
00028 
00029 node_t *NodeForPoint (node_t *node, vec3_t origin)
00030 {
00031     plane_t *plane;
00032     vec_t   d;
00033 
00034     while (node->planenum != PLANENUM_LEAF)
00035     {
00036         plane = &mapplanes[node->planenum];
00037         d = DotProduct (origin, plane->normal) - plane->dist;
00038         if (d >= 0)
00039             node = node->children[0];
00040         else
00041             node = node->children[1];
00042     }
00043 
00044     return node;
00045 }
00046 
00047 
00048 
00049 /*
00050 =============
00051 FreeTreePortals_r
00052 =============
00053 */
00054 void FreeTreePortals_r (node_t *node)
00055 {
00056     portal_t    *p, *nextp;
00057     int         s;
00058 
00059     // free children
00060     if (node->planenum != PLANENUM_LEAF)
00061     {
00062         FreeTreePortals_r (node->children[0]);
00063         FreeTreePortals_r (node->children[1]);
00064     }
00065 
00066     // free portals
00067     for (p=node->portals ; p ; p=nextp)
00068     {
00069         s = (p->nodes[1] == node);
00070         nextp = p->next[s];
00071 
00072         RemovePortalFromNode (p, p->nodes[!s]);
00073         FreePortal (p);
00074     }
00075     node->portals = NULL;
00076 }
00077 
00078 /*
00079 =============
00080 FreeTree_r
00081 =============
00082 */
00083 void FreeTree_r (node_t *node)
00084 {
00085     // free children
00086     if (node->planenum != PLANENUM_LEAF)
00087     {
00088         FreeTree_r (node->children[0]);
00089         FreeTree_r (node->children[1]);
00090     }
00091 
00092     // free bspbrushes
00093     FreeBrushList (node->brushlist);
00094 
00095     // free the node
00096     if (node->volume)
00097         FreeBrush (node->volume);
00098 
00099     if (numthreads == 1)
00100         c_nodes--;
00101     free (node);
00102 }
00103 
00104 
00105 /*
00106 =============
00107 FreeTree
00108 =============
00109 */
00110 void FreeTree (tree_t *tree)
00111 {
00112     FreeTreePortals_r (tree->headnode);
00113     FreeTree_r (tree->headnode);
00114     free (tree);
00115 }
00116 
00117 //===============================================================
00118 
00119 void PrintTree_r (node_t *node, int depth)
00120 {
00121     int     i;
00122     plane_t *plane;
00123     bspbrush_t  *bb;
00124 
00125     for (i=0 ; i<depth ; i++)
00126         _printf ("  ");
00127     if (node->planenum == PLANENUM_LEAF)
00128     {
00129         if (!node->brushlist)
00130             _printf ("NULL\n");
00131         else
00132         {
00133             for (bb=node->brushlist ; bb ; bb=bb->next)
00134                 _printf ("%i ", bb->original->brushnum);
00135             _printf ("\n");
00136         }
00137         return;
00138     }
00139 
00140     plane = &mapplanes[node->planenum];
00141     _printf ("#%i (%5.2f %5.2f %5.2f):%5.2f\n", node->planenum,
00142         plane->normal[0], plane->normal[1], plane->normal[2],
00143         plane->dist);
00144     PrintTree_r (node->children[0], depth+1);
00145     PrintTree_r (node->children[1], depth+1);
00146 }

Generated on Thu Aug 25 12:37:20 2005 for Quake III Arena by  doxygen 1.3.9.1