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