Debian Codegraph @

tools/quake2/q2map/leakfile.c

raw symbols SCIP
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 vec3_t mid;
116 FILE *linefile;
117 char filename[1024];
118 node_t *node;
119 int count;
120 xmlNodePtr xml_node, point;
121
122 if ( !tree->outside_node.occupied ) {
123 return NULL;
124 }
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
137 xml_node = xmlNewNode( NULL, "polyline" );
138
139 count = 0;
140 node = &tree->outside_node;
141 while ( node->occupied > 1 )
142 {
143 int next;
144 portal_t *p, *nextportal;
145 node_t *nextnode;
146 int s;
147
148 // find the best portal exit
149 next = node->occupied;
150 for ( p = node->portals ; p ; p = p->next[!s] )
151 {
152 s = ( p->nodes[0] == node );
153 if ( p->nodes[s]->occupied
154 && p->nodes[s]->occupied < next ) {
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 }