Debian Codegraph @

tools/quake3/q3map2/leakfile.c

raw symbols SCIP
1 /* -------------------------------------------------------------------------------
2
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
5
6 This file is part of GtkRadiant.
7
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
22 ----------------------------------------------------------------------------------
23
24 This code has been altered significantly from its original form, to support
25 several games based on the Quake III Arena engine, in the form of "Q3Map2."
26
27 ------------------------------------------------------------------------------- */
28
29
30
31 /* marker */
32 #define LEAKFILE_C
33
34
35
36 /* dependencies */
37 #include "q3map2.h"
38
39
40
41 /*
42 ==============================================================================
43
44 LEAK FILE GENERATION
45
46 Save out name.lin for qe3 to read
47 ==============================================================================
48 */
49
50
51 /*
52 =============
53 LeakFile
54
55 Finds the shortest possible chain of portals
56 that leads from the outside leaf to a specifically
57 occupied leaf
58
59 TTimo: builds a polyline xml node
60 =============
61 */
62 xmlNodePtr LeakFile( tree_t *tree, const char *filename ){
63 vec3_t mid;
64 FILE *linefile;
65 node_t *node;
66 int count;
67 xmlNodePtr xml_node, point;
68
69 if ( !tree->outside_node.occupied ) {
70 return NULL;
71 }
72
73 Sys_FPrintf( SYS_VRB,"--- LeakFile ---\n" );
74
75 //
76 // write the points to the file
77 //
78 linefile = fopen( filename, "w" );
79 if ( !linefile ) {
80 Error( "Couldn't open %s\n", filename );
81 }
82
83 xml_node = xmlNewNode( NULL, (xmlChar*)"polyline" );
84
85 count = 0;
86 node = &tree->outside_node;
87 while ( node->occupied > 1 )
88 {
89 int next;
90 portal_t *p, *nextportal = NULL;
91 node_t *nextnode = NULL;
92 int s;
93
94 // find the best portal exit
95 next = node->occupied;
96 for ( p = node->portals ; p ; p = p->next[!s] )
97 {
98 s = ( p->nodes[0] == node );
99 if ( p->nodes[s]->occupied
100 && p->nodes[s]->occupied < next ) {
101 nextportal = p;
102 nextnode = p->nodes[s];
103 next = nextnode->occupied;
104 }
105 }
106 node = nextnode;
107 WindingCenter( nextportal->winding, mid );
108 fprintf( linefile, "%f %f %f\n", mid[0], mid[1], mid[2] );
109 point = xml_NodeForVec( mid );
110 xmlAddChild( xml_node, point );
111 count++;
112 }
113 // add the occupant center
114 GetVectorForKey( node->occupant, "origin", mid );
115
116 fprintf( linefile, "%f %f %f\n", mid[0], mid[1], mid[2] );
117 point = xml_NodeForVec( mid );
118 xmlAddChild( xml_node, point );
119 Sys_FPrintf( SYS_VRB, "%9d point linefile\n", count + 1 );
120
121 fclose( linefile );
122
123 return xml_node;
124 }