doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
leakfile.cpp
Go to the documentation of this file.
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 
node_t * nodes[2]
Definition: dmap.h:166
int occupied
Definition: dmap.h:156
char mapFileBase[1024]
Definition: dmap.h:235
Definition: dmap.h:172
idFileSystem * fileSystem
Definition: FileSystem.cpp:500
Definition: Vector.h:316
struct uPortal_s * next[2]
Definition: dmap.h:167
uEntity_t * occupant
Definition: dmap.h:157
GLdouble s
Definition: glext.h:2935
idDict epairs
Definition: MapFile.h:166
GLuint GLuint GLsizei count
Definition: glext.h:2845
idCommon * common
Definition: Common.cpp:206
struct uPortal_s * portals
Definition: dmap.h:159
idVec3 GetVector(const char *key, const char *defaultString=NULL) const
Definition: Dict.h:260
idWinding * winding
Definition: dmap.h:168
virtual void Printf(const char *fmt,...) id_attribute((format(printf
virtual const char * RelativePathToOSPath(const char *relativePath, const char *basePath="fs_devpath")=0
idVec3 GetCenter(void) const
Definition: Winding.cpp:639
Definition: Str.h:116
const char * c_str(void) const
Definition: Str.h:487
Definition: dmap.h:138
dmapGlobals_t dmapGlobals
Definition: dmap.cpp:34
virtual void Error(const char *fmt,...) id_attribute((format(printf
GLfloat GLfloat p
Definition: glext.h:4674
idMapEntity * mapEntity
Definition: dmap.h:47
int sprintf(idStr &string, const char *fmt,...)
Definition: Str.cpp:1528
void LeakFile(tree_t *tree)
Definition: leakfile.cpp:53
node_t outside_node
Definition: dmap.h:174