Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "vbsp.h"
  9. #include "color.h"
  10. /*
  11. ==============================================================================
  12. LEAF FILE GENERATION
  13. Save out name.line for qe3 to read
  14. ==============================================================================
  15. */
  16. /*
  17. =============
  18. LeakFile
  19. Finds the shortest possible chain of portals
  20. that leads from the outside leaf to a specifically
  21. occupied leaf
  22. =============
  23. */
  24. void LeakFile (tree_t *tree)
  25. {
  26. Vector mid;
  27. FILE *linefile;
  28. char filename[1024];
  29. node_t *node;
  30. int count;
  31. if (!tree->outside_node.occupied)
  32. return;
  33. tree->leaked = true;
  34. qprintf ("--- LeakFile ---\n");
  35. //
  36. // write the points to the file
  37. //
  38. sprintf (filename, "%s.lin", source);
  39. linefile = fopen (filename, "w");
  40. if (!linefile)
  41. Error ("Couldn't open %s\n", filename);
  42. count = 0;
  43. node = &tree->outside_node;
  44. while (node->occupied > 1)
  45. {
  46. portal_t *nextportal = NULL;
  47. node_t *nextnode = NULL;
  48. int s = 0;
  49. // find the best portal exit
  50. int next = node->occupied;
  51. for (portal_t *p=node->portals ; p ; p = p->next[!s])
  52. {
  53. s = (p->nodes[0] == node);
  54. if (p->nodes[s]->occupied
  55. && p->nodes[s]->occupied < next)
  56. {
  57. nextportal = p;
  58. nextnode = p->nodes[s];
  59. next = nextnode->occupied;
  60. }
  61. }
  62. node = nextnode;
  63. WindingCenter (nextportal->winding, mid);
  64. fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);
  65. count++;
  66. }
  67. // Add the occupant's origin to the leakfile.
  68. Vector origin;
  69. GetVectorForKey (node->occupant, "origin", origin);
  70. fprintf (linefile, "%f %f %f\n", origin[0], origin[1], origin[2]);
  71. qprintf ("%5i point linefile\n", count+1);
  72. fclose (linefile);
  73. // Emit a leak warning.
  74. const char *cl = ValueForKey (node->occupant, "classname");
  75. Color red(255,0,0,255);
  76. ColorSpewMessage( SPEW_MESSAGE, &red, "Entity %s (%.2f %.2f %.2f) leaked!\n", cl, origin[0], origin[1], origin[2] );
  77. }
  78. void AreaportalLeakFile( tree_t *tree, portal_t *pStartPortal, portal_t *pEndPortal, node_t *pStart )
  79. {
  80. Vector mid;
  81. FILE *linefile;
  82. char filename[1024];
  83. node_t *node;
  84. int count;
  85. // wrote a leak line file already, don't overwrite it with the areaportal leak file
  86. if ( tree->leaked )
  87. return;
  88. tree->leaked = true;
  89. qprintf ("--- LeakFile ---\n");
  90. //
  91. // write the points to the file
  92. //
  93. sprintf (filename, "%s.lin", source);
  94. linefile = fopen (filename, "w");
  95. if (!linefile)
  96. Error ("Couldn't open %s\n", filename);
  97. count = 2;
  98. WindingCenter (pEndPortal->winding, mid);
  99. fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);
  100. mid = 0.5 * (pStart->mins + pStart->maxs);
  101. fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);
  102. node = pStart;
  103. while (node->occupied >= 1)
  104. {
  105. portal_t *nextportal = NULL;
  106. node_t *nextnode = NULL;
  107. int s = 0;
  108. // find the best portal exit
  109. int next = node->occupied;
  110. for (portal_t *p=node->portals ; p ; p = p->next[!s])
  111. {
  112. s = (p->nodes[0] == node);
  113. if (p->nodes[s]->occupied
  114. && p->nodes[s]->occupied < next)
  115. {
  116. nextportal = p;
  117. nextnode = p->nodes[s];
  118. next = nextnode->occupied;
  119. }
  120. }
  121. if ( !nextnode )
  122. break;
  123. node = nextnode;
  124. WindingCenter (nextportal->winding, mid);
  125. fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);
  126. count++;
  127. }
  128. // add the occupant center
  129. if ( node )
  130. {
  131. mid = 0.5 * (node->mins + node->maxs);
  132. fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);
  133. count++;
  134. }
  135. WindingCenter (pStartPortal->winding, mid);
  136. count++;
  137. fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);
  138. qprintf ("%5i point linefile\n", count);
  139. fclose (linefile);
  140. Warning( "Wrote %s\n", filename );
  141. Color red(255,0,0,255);
  142. ColorSpewMessage( SPEW_MESSAGE, &red, "Areaportal leak ! File: %s ", filename );
  143. }