leakfile.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1997-2006 Id Software, Inc.
  4. This file is part of Quake 2 Tools source code.
  5. Quake 2 Tools source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake 2 Tools source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Quake 2 Tools source code; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. #include "qbsp.h"
  19. /*
  20. ==============================================================================
  21. LEAF FILE GENERATION
  22. Save out name.line for qe3 to read
  23. ==============================================================================
  24. */
  25. /*
  26. =============
  27. LeakFile
  28. Finds the shortest possible chain of portals
  29. that leads from the outside leaf to a specifically
  30. occupied leaf
  31. =============
  32. */
  33. void LeakFile (tree_t *tree)
  34. {
  35. vec3_t mid;
  36. FILE *linefile;
  37. char filename[1024];
  38. node_t *node;
  39. int count;
  40. if (!tree->outside_node.occupied)
  41. return;
  42. qprintf ("--- LeakFile ---\n");
  43. //
  44. // write the points to the file
  45. //
  46. sprintf (filename, "%s.lin", source);
  47. linefile = fopen (filename, "w");
  48. if (!linefile)
  49. Error ("Couldn't open %s\n", filename);
  50. count = 0;
  51. node = &tree->outside_node;
  52. while (node->occupied > 1)
  53. {
  54. int next;
  55. portal_t *p, *nextportal;
  56. node_t *nextnode;
  57. int s;
  58. // find the best portal exit
  59. next = node->occupied;
  60. for (p=node->portals ; p ; p = p->next[!s])
  61. {
  62. s = (p->nodes[0] == node);
  63. if (p->nodes[s]->occupied
  64. && p->nodes[s]->occupied < next)
  65. {
  66. nextportal = p;
  67. nextnode = p->nodes[s];
  68. next = nextnode->occupied;
  69. }
  70. }
  71. node = nextnode;
  72. WindingCenter (nextportal->winding, mid);
  73. fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);
  74. count++;
  75. }
  76. // add the occupant center
  77. GetVectorForKey (node->occupant, "origin", mid);
  78. fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);
  79. qprintf ("%5i point linefile\n", count+1);
  80. fclose (linefile);
  81. }