Counter Strike : Global Offensive Source Code
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.

166 lines
3.9 KiB

  1. //========= Copyright � 1996-2005, 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. DEFINE_LOGGING_CHANNEL_NO_TAGS( LOG_GENERAL, "General" );
  17. /*
  18. =============
  19. LeakFile
  20. Finds the shortest possible chain of portals
  21. that leads from the outside leaf to a specifically
  22. occupied leaf
  23. =============
  24. */
  25. void LeakFile (tree_t *tree)
  26. {
  27. Vector mid;
  28. FILE *linefile;
  29. char filename[1024];
  30. node_t *node;
  31. int count;
  32. if (!tree->outside_node.occupied)
  33. return;
  34. tree->leaked = true;
  35. qprintf ("--- LeakFile ---\n");
  36. //
  37. // write the points to the file
  38. //
  39. sprintf (filename, "%s.lin", source);
  40. linefile = fopen (filename, "w");
  41. if (!linefile)
  42. Error ("Couldn't open %s\n", filename);
  43. count = 0;
  44. node = &tree->outside_node;
  45. while (node->occupied > 1)
  46. {
  47. portal_t *nextportal = NULL;
  48. node_t *nextnode = NULL;
  49. int s = 0;
  50. // find the best portal exit
  51. int next = node->occupied;
  52. for (portal_t *p=node->portals ; p ; p = p->next[!s])
  53. {
  54. s = (p->nodes[0] == node);
  55. if (p->nodes[s]->occupied
  56. && p->nodes[s]->occupied < next)
  57. {
  58. nextportal = p;
  59. nextnode = p->nodes[s];
  60. next = nextnode->occupied;
  61. }
  62. }
  63. node = nextnode;
  64. WindingCenter (nextportal->winding, mid);
  65. fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);
  66. count++;
  67. }
  68. // Add the occupant's origin to the leakfile.
  69. Vector origin;
  70. GetVectorForKey (node->occupant, "origin", origin);
  71. fprintf (linefile, "%f %f %f\n", origin[0], origin[1], origin[2]);
  72. qprintf ("%5i point linefile\n", count+1);
  73. fclose (linefile);
  74. // Emit a leak warning.
  75. const char *cl = ValueForKey (node->occupant, "classname");
  76. Log_Msg( LOG_GENERAL, Color( 255, 0, 0, 255 ), "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. Log_Msg( LOG_GENERAL, Color( 255, 0, 0, 255 ), "Areaportal leak ! File: %s ", filename );
  142. }