]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake2/q2map/tree.c
eol style
[xonotic/netradiant.git] / tools / quake2 / q2map / tree.c
index ec5b5b7c67e1cbbdb784fe365a706f89cd9ba10a..6ca4aa1623057a17893bc723d9a9f77388304fe6 100644 (file)
-/*\r
-Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
-For a list of contributors, see the accompanying CONTRIBUTORS file.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
-*/\r
-#include "qbsp.h"\r
-\r
-extern int     c_nodes;\r
-\r
-void RemovePortalFromNode (portal_t *portal, node_t *l);\r
-\r
-node_t *NodeForPoint (node_t *node, vec3_t origin)\r
-{\r
-       plane_t *plane;\r
-       vec_t   d;\r
-\r
-       while (node->planenum != PLANENUM_LEAF)\r
-       {\r
-               plane = &mapplanes[node->planenum];\r
-               d = DotProduct (origin, plane->normal) - plane->dist;\r
-               if (d >= 0)\r
-                       node = node->children[0];\r
-               else\r
-                       node = node->children[1];\r
-       }\r
-\r
-       return node;\r
-}\r
-\r
-\r
-\r
-/*\r
-=============\r
-FreeTreePortals_r\r
-=============\r
-*/\r
-void FreeTreePortals_r (node_t *node)\r
-{\r
-       portal_t        *p, *nextp;\r
-       int                     s;\r
-\r
-       // free children\r
-       if (node->planenum != PLANENUM_LEAF)\r
-       {\r
-               FreeTreePortals_r (node->children[0]);\r
-               FreeTreePortals_r (node->children[1]);\r
-       }\r
-\r
-       // free portals\r
-       for (p=node->portals ; p ; p=nextp)\r
-       {\r
-               s = (p->nodes[1] == node);\r
-               nextp = p->next[s];\r
-\r
-               RemovePortalFromNode (p, p->nodes[!s]);\r
-               FreePortal (p);\r
-       }\r
-       node->portals = NULL;\r
-}\r
-\r
-/*\r
-=============\r
-FreeTree_r\r
-=============\r
-*/\r
-void FreeTree_r (node_t *node)\r
-{\r
-       face_t          *f, *nextf;\r
-\r
-       // free children\r
-       if (node->planenum != PLANENUM_LEAF)\r
-       {\r
-               FreeTree_r (node->children[0]);\r
-               FreeTree_r (node->children[1]);\r
-       }\r
-\r
-       // free bspbrushes\r
-       FreeBrushList (node->brushlist);\r
-\r
-       // free faces\r
-       for (f=node->faces ; f ; f=nextf)\r
-       {\r
-               nextf = f->next;\r
-               FreeFace (f);\r
-       }\r
-\r
-       // free the node\r
-       if (node->volume)\r
-               FreeBrush (node->volume);\r
-\r
-       if (numthreads == 1)\r
-               c_nodes--;\r
-       free (node);\r
-}\r
-\r
-\r
-/*\r
-=============\r
-FreeTree\r
-=============\r
-*/\r
-void FreeTree (tree_t *tree)\r
-{\r
-       FreeTreePortals_r (tree->headnode);\r
-       FreeTree_r (tree->headnode);\r
-       free (tree);\r
-}\r
-\r
-//===============================================================\r
-\r
-void PrintTree_r (node_t *node, int depth)\r
-{\r
-       int             i;\r
-       plane_t *plane;\r
-       bspbrush_t      *bb;\r
-\r
-       for (i=0 ; i<depth ; i++)\r
-               Sys_Printf ("  ");\r
-       if (node->planenum == PLANENUM_LEAF)\r
-       {\r
-               if (!node->brushlist)\r
-                       Sys_Printf ("NULL\n");\r
-               else\r
-               {\r
-                       for (bb=node->brushlist ; bb ; bb=bb->next)\r
-                               Sys_Printf ("%i ", bb->original->brushnum);\r
-                       Sys_Printf ("\n");\r
-               }\r
-               return;\r
-       }\r
-\r
-       plane = &mapplanes[node->planenum];\r
-       Sys_Printf ("#%i (%5.2f %5.2f %5.2f):%5.2f\n", node->planenum,\r
-               plane->normal[0], plane->normal[1], plane->normal[2],\r
-               plane->dist);\r
-       PrintTree_r (node->children[0], depth+1);\r
-       PrintTree_r (node->children[1], depth+1);\r
-}\r
-\r
-/*\r
-=========================================================\r
-\r
-NODES THAT DON'T SEPERATE DIFFERENT CONTENTS CAN BE PRUNED\r
-\r
-=========================================================\r
-*/\r
-\r
-int    c_pruned;\r
-\r
-/*\r
-============\r
-PruneNodes_r\r
-============\r
-*/\r
-void PruneNodes_r (node_t *node)\r
-{\r
-       bspbrush_t              *b, *next;\r
-\r
-       if (node->planenum == PLANENUM_LEAF)\r
-               return;\r
-       PruneNodes_r (node->children[0]);\r
-       PruneNodes_r (node->children[1]);\r
-\r
-       if ( (node->children[0]->contents & CONTENTS_SOLID)\r
-       && (node->children[1]->contents & CONTENTS_SOLID) )\r
-       {\r
-               if (node->faces)\r
-                       Error ("node->faces seperating CONTENTS_SOLID");\r
-               if (node->children[0]->faces || node->children[1]->faces)\r
-                       Error ("!node->faces with children");\r
-\r
-               // FIXME: free stuff\r
-               node->planenum = PLANENUM_LEAF;\r
-               node->contents = CONTENTS_SOLID;\r
-               node->detail_seperator = false;\r
-\r
-               if (node->brushlist)\r
-                       Error ("PruneNodes: node->brushlist");\r
-\r
-               // combine brush lists\r
-               node->brushlist = node->children[1]->brushlist;\r
-\r
-               for (b=node->children[0]->brushlist ; b ; b=next)\r
-               {\r
-                       next = b->next;\r
-                       b->next = node->brushlist;\r
-                       node->brushlist = b;\r
-               }\r
-\r
-               c_pruned++;\r
-       }\r
-}\r
-\r
-\r
-void PruneNodes (node_t *node)\r
-{\r
-       Sys_FPrintf( SYS_VRB, "--- PruneNodes ---\n");\r
-       c_pruned = 0;\r
-       PruneNodes_r (node);\r
-       Sys_FPrintf( SYS_VRB, "%5i pruned nodes\n", c_pruned);\r
-}\r
-\r
-//===========================================================\r
+/*
+Copyright (C) 1999-2007 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
+*/
+#include "qbsp.h"
+
+extern int     c_nodes;
+
+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)
+{
+       face_t          *f, *nextf;
+
+       // free children
+       if (node->planenum != PLANENUM_LEAF)
+       {
+               FreeTree_r (node->children[0]);
+               FreeTree_r (node->children[1]);
+       }
+
+       // free bspbrushes
+       FreeBrushList (node->brushlist);
+
+       // free faces
+       for (f=node->faces ; f ; f=nextf)
+       {
+               nextf = f->next;
+               FreeFace (f);
+       }
+
+       // free the node
+       if (node->volume)
+               FreeBrush (node->volume);
+
+       if (numthreads == 1)
+               c_nodes--;
+       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;
+       bspbrush_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 ("%i ", bb->original->brushnum);
+                       Sys_Printf ("\n");
+               }
+               return;
+       }
+
+       plane = &mapplanes[node->planenum];
+       Sys_Printf ("#%i (%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);
+}
+
+/*
+=========================================================
+
+NODES THAT DON'T SEPERATE DIFFERENT CONTENTS CAN BE PRUNED
+
+=========================================================
+*/
+
+int    c_pruned;
+
+/*
+============
+PruneNodes_r
+============
+*/
+void PruneNodes_r (node_t *node)
+{
+       bspbrush_t              *b, *next;
+
+       if (node->planenum == PLANENUM_LEAF)
+               return;
+       PruneNodes_r (node->children[0]);
+       PruneNodes_r (node->children[1]);
+
+       if ( (node->children[0]->contents & CONTENTS_SOLID)
+       && (node->children[1]->contents & CONTENTS_SOLID) )
+       {
+               if (node->faces)
+                       Error ("node->faces seperating CONTENTS_SOLID");
+               if (node->children[0]->faces || node->children[1]->faces)
+                       Error ("!node->faces with children");
+
+               // FIXME: free stuff
+               node->planenum = PLANENUM_LEAF;
+               node->contents = CONTENTS_SOLID;
+               node->detail_seperator = false;
+
+               if (node->brushlist)
+                       Error ("PruneNodes: node->brushlist");
+
+               // combine brush lists
+               node->brushlist = node->children[1]->brushlist;
+
+               for (b=node->children[0]->brushlist ; b ; b=next)
+               {
+                       next = b->next;
+                       b->next = node->brushlist;
+                       node->brushlist = b;
+               }
+
+               c_pruned++;
+       }
+}
+
+
+void PruneNodes (node_t *node)
+{
+       Sys_FPrintf( SYS_VRB, "--- PruneNodes ---\n");
+       c_pruned = 0;
+       PruneNodes_r (node);
+       Sys_FPrintf( SYS_VRB, "%5i pruned nodes\n", c_pruned);
+}
+
+//===========================================================