]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake2/q2map/leakfile.c
transfer from internal tree r5311 branches/1.4-gpl
[xonotic/netradiant.git] / tools / quake2 / q2map / leakfile.c
1 /*\r
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.\r
4 \r
5 This file is part of GtkRadiant.\r
6 \r
7 GtkRadiant is free software; you can redistribute it and/or modify\r
8 it under the terms of the GNU General Public License as published by\r
9 the Free Software Foundation; either version 2 of the License, or\r
10 (at your option) any later version.\r
11 \r
12 GtkRadiant is distributed in the hope that it will be useful,\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 GNU General Public License for more details.\r
16 \r
17 You should have received a copy of the GNU General Public License\r
18 along with GtkRadiant; if not, write to the Free Software\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
20 */\r
21 \r
22 #include "qbsp.h"\r
23 \r
24 /*\r
25 ==============================================================================\r
26 \r
27 LEAF FILE GENERATION\r
28 \r
29 Save out name.line for qe3 to read\r
30 ==============================================================================\r
31 */\r
32 \r
33 \r
34 /*\r
35 =============\r
36 LeakFile\r
37 \r
38 Finds the shortest possible chain of portals\r
39 that leads from the outside leaf to a specifically\r
40 occupied leaf\r
41 =============\r
42 */\r
43 \r
44 /*\r
45 void LeakFile (tree_t *tree)\r
46 {\r
47         vec3_t  mid;\r
48         FILE    *linefile;\r
49         char    filename[1024];\r
50         node_t  *node;\r
51         int             count;\r
52 \r
53         if (!tree->outside_node.occupied)\r
54                 return;\r
55 \r
56         Sys_Printf ("--- LeakFile ---\n");\r
57 \r
58         //\r
59         // write the points to the file\r
60         //\r
61         sprintf (filename, "%s.lin", source);\r
62         linefile = fopen (filename, "w");\r
63         if (!linefile)\r
64                 Error ("Couldn't open %s\n", filename);\r
65 \r
66         count = 0;\r
67         node = &tree->outside_node;\r
68         while (node->occupied > 1)\r
69         {\r
70                 int                     next;\r
71                 portal_t        *p, *nextportal;\r
72                 node_t          *nextnode;\r
73                 int                     s;\r
74 \r
75                 // find the best portal exit\r
76                 next = node->occupied;\r
77                 for (p=node->portals ; p ; p = p->next[!s])\r
78                 {\r
79                         s = (p->nodes[0] == node);\r
80                         if (p->nodes[s]->occupied\r
81                                 && p->nodes[s]->occupied < next)\r
82                         {\r
83                                 nextportal = p;\r
84                                 nextnode = p->nodes[s];\r
85                                 next = nextnode->occupied;\r
86                         }\r
87                 }\r
88                 node = nextnode;\r
89                 WindingCenter (nextportal->winding, mid);\r
90                 fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);\r
91                 count++;\r
92         }\r
93         // add the occupant center\r
94         GetVectorForKey (node->occupant, "origin", mid);\r
95 \r
96         fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);\r
97         Sys_Printf ("%5i point linefile\n", count+1);\r
98 \r
99         fclose (linefile);\r
100 }\r
101 */\r
102 \r
103 /*\r
104 =============\r
105 LeakFile\r
106 \r
107 Finds the shortest possible chain of portals\r
108 that leads from the outside leaf to a specifically\r
109 occupied leaf\r
110 \r
111 TTimo: builds a polyline xml node\r
112 =============\r
113 */\r
114 xmlNodePtr LeakFile (tree_t *tree)\r
115 {\r
116         vec3_t  mid;\r
117         FILE    *linefile;\r
118         char    filename[1024];\r
119         node_t  *node;\r
120         int             count;\r
121         xmlNodePtr xml_node, point;\r
122 \r
123         if (!tree->outside_node.occupied)\r
124                 return NULL;\r
125 \r
126         Sys_FPrintf (SYS_VRB,"--- LeakFile ---\n");\r
127 \r
128         //\r
129         // write the points to the file\r
130         //\r
131         sprintf (filename, "%s.lin", source);\r
132         linefile = fopen (filename, "w");\r
133         if (!linefile)\r
134                 Error ("Couldn't open %s\n", filename);\r
135 \r
136         xml_node = xmlNewNode (NULL, "polyline");\r
137 \r
138         count = 0;\r
139         node = &tree->outside_node;\r
140         while (node->occupied > 1)\r
141         {\r
142                 int                     next;\r
143                 portal_t        *p, *nextportal;\r
144                 node_t          *nextnode;\r
145                 int                     s;\r
146 \r
147                 // find the best portal exit\r
148                 next = node->occupied;\r
149                 for (p=node->portals ; p ; p = p->next[!s])\r
150                 {\r
151                         s = (p->nodes[0] == node);\r
152                         if (p->nodes[s]->occupied\r
153                                 && p->nodes[s]->occupied < next)\r
154                         {\r
155                                 nextportal = p;\r
156                                 nextnode = p->nodes[s];\r
157                                 next = nextnode->occupied;\r
158                         }\r
159                 }\r
160                 node = nextnode;\r
161                 WindingCenter (nextportal->winding, mid);\r
162                 fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);\r
163                 point = xml_NodeForVec(mid);\r
164                 xmlAddChild(xml_node, point);\r
165                 count++;\r
166         }\r
167         // add the occupant center\r
168         GetVectorForKey (node->occupant, "origin", mid);\r
169 \r
170         fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);\r
171         point = xml_NodeForVec(mid);\r
172         xmlAddChild(xml_node, point);\r
173         Sys_FPrintf( SYS_VRB, "%9d point linefile\n", count+1);\r
174 \r
175         fclose (linefile);\r
176         \r
177         return xml_node;\r
178 }\r
179 \r
180 \r