]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/compilers/dmap/leakfile.cpp
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / tools / compilers / dmap / leakfile.cpp
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28
29 #include "../../../idlib/precompiled.h"
30 #pragma hdrstop
31
32 #include "dmap.h"
33
34 /*
35 ==============================================================================
36
37 LEAF FILE GENERATION
38
39 Save out name.line for qe3 to read
40 ==============================================================================
41 */
42
43
44 /*
45 =============
46 LeakFile
47
48 Finds the shortest possible chain of portals
49 that leads from the outside leaf to a specifically
50 occupied leaf
51 =============
52 */
53 void LeakFile (tree_t *tree)
54 {
55         idVec3  mid;
56         FILE    *linefile;
57         idStr   filename;
58         idStr   ospath;
59         node_t  *node;
60         int             count;
61
62         if (!tree->outside_node.occupied)
63                 return;
64
65         common->Printf ("--- LeakFile ---\n");
66
67         //
68         // write the points to the file
69         //
70         sprintf( filename, "%s.lin", dmapGlobals.mapFileBase );
71         ospath = fileSystem->RelativePathToOSPath( filename );
72         linefile = fopen( ospath, "w" );
73         if ( !linefile ) {
74                 common->Error( "Couldn't open %s\n", filename.c_str() );
75         }
76
77         count = 0;
78         node = &tree->outside_node;
79         while (node->occupied > 1)
80         {
81                 int                     next;
82                 uPortal_t       *p, *nextportal;
83                 node_t          *nextnode;
84                 int                     s;
85
86                 // find the best portal exit
87                 next = node->occupied;
88                 for (p=node->portals ; p ; p = p->next[!s])
89                 {
90                         s = (p->nodes[0] == node);
91                         if (p->nodes[s]->occupied
92                                 && p->nodes[s]->occupied < next)
93                         {
94                                 nextportal = p;
95                                 nextnode = p->nodes[s];
96                                 next = nextnode->occupied;
97                         }
98                 }
99                 node = nextnode;
100                 mid = nextportal->winding->GetCenter();
101                 fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);
102                 count++;
103         }
104         // add the occupant center
105         node->occupant->mapEntity->epairs.GetVector( "origin", "", mid );
106
107         fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);
108         common->Printf ("%5i point linefile\n", count+1);
109
110         fclose (linefile);
111 }
112