leakfile.c (2502B)
1 /* 2 =========================================================================== 3 Copyright (C) 1999-2005 Id Software, Inc. 4 5 This file is part of Quake III Arena source code. 6 7 Quake III Arena source code is free software; you can redistribute it 8 and/or modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the License, 10 or (at your option) any later version. 11 12 Quake III Arena source code is distributed in the hope that it will be 13 useful, 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 Foobar; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 =========================================================================== 21 */ 22 23 #include "qbsp.h" 24 25 /* 26 ============================================================================== 27 28 LEAF FILE GENERATION 29 30 Save out name.line for qe3 to read 31 ============================================================================== 32 */ 33 34 35 /* 36 ============= 37 LeakFile 38 39 Finds the shortest possible chain of portals 40 that leads from the outside leaf to a specifically 41 occupied leaf 42 ============= 43 */ 44 void LeakFile (tree_t *tree) 45 { 46 vec3_t mid; 47 FILE *linefile; 48 char filename[1024]; 49 node_t *node; 50 int count; 51 52 if (!tree->outside_node.occupied) 53 return; 54 55 qprintf ("--- LeakFile ---\n"); 56 57 // 58 // write the points to the file 59 // 60 sprintf (filename, "%s.lin", source); 61 linefile = fopen (filename, "w"); 62 if (!linefile) 63 Error ("Couldn't open %s\n", filename); 64 65 count = 0; 66 node = &tree->outside_node; 67 while (node->occupied > 1) 68 { 69 int next; 70 portal_t *p, *nextportal; 71 node_t *nextnode; 72 int s; 73 74 // find the best portal exit 75 next = node->occupied; 76 for (p=node->portals ; p ; p = p->next[!s]) 77 { 78 s = (p->nodes[0] == node); 79 if (p->nodes[s]->occupied 80 && p->nodes[s]->occupied < next) 81 { 82 nextportal = p; 83 nextnode = p->nodes[s]; 84 next = nextnode->occupied; 85 } 86 } 87 node = nextnode; 88 WindingCenter (nextportal->winding, mid); 89 fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]); 90 count++; 91 } 92 // add the occupant center 93 GetVectorForKey (node->occupant, "origin", mid); 94 95 fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]); 96 qprintf ("%5i point linefile\n", count+1); 97 98 fclose (linefile); 99 } 100