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.

199 lines
5.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef AI_NETWORKMANAGER_H
  7. #define AI_NETWORKMANAGER_H
  8. #include "utlvector.h"
  9. #include "bitstring.h"
  10. #if defined( _WIN32 )
  11. #pragma once
  12. #endif
  13. class CAI_NetworkEditTools;
  14. class CAI_Network;
  15. class CAI_Node;
  16. class CAI_Link;
  17. class CAI_TestHull;
  18. //-----------------------------------------------------------------------------
  19. // CAI_NetworkManager
  20. //
  21. // Purpose: The entity in the level responsible for building the network if it
  22. // isn't there, saving & loading of the network, and holding the
  23. // CAI_Network instance.
  24. //
  25. //-----------------------------------------------------------------------------
  26. class CAI_NetworkManager : public CPointEntity
  27. {
  28. public:
  29. static void InitializeAINetworks();
  30. DECLARE_DATADESC();
  31. DECLARE_CLASS( CAI_NetworkManager, CPointEntity );
  32. public:
  33. CAI_NetworkManager(void);
  34. virtual ~CAI_NetworkManager(void);
  35. void Spawn ();
  36. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() | FCAP_DONT_SAVE; }
  37. void RebuildNetworkGraph(); // Used in WC edit mode
  38. void StartRebuild(); // Used in WC edit mode
  39. void LoadNetworkGraph();
  40. static bool NetworksLoaded() { return gm_fNetworksLoaded; }
  41. bool IsInitialized() { return m_fInitalized; }
  42. void BuildNetworkGraph();
  43. static void DeleteAllAINetworks();
  44. void FixupHints();
  45. void MarkDontSaveGraph();
  46. public:
  47. CAI_NetworkEditTools * GetEditOps() { return m_pEditOps; }
  48. CAI_Network * GetNetwork() { return m_pNetwork; }
  49. private:
  50. void DelayedInit();
  51. void RebuildThink();
  52. void SaveNetworkGraph( void) ;
  53. static bool IsAIFileCurrent( const char *szMapName );
  54. static bool gm_fNetworksLoaded; // Have AINetworks been loaded
  55. bool m_bNeedGraphRebuild;
  56. CAI_NetworkEditTools * m_pEditOps;
  57. CAI_Network * m_pNetwork;
  58. bool m_fInitalized;
  59. bool m_bDontSaveGraph;
  60. };
  61. //-----------------------------------------------------------------------------
  62. abstract_class CAI_NetworkBuildHelper : public CLogicalEntity
  63. {
  64. DECLARE_CLASS( CAI_NetworkBuildHelper, CLogicalEntity );
  65. public:
  66. virtual void PostInitNodePosition( CAI_Network *pNetwork, CAI_Node *pNode ) = 0;
  67. };
  68. //-----------------------------------------------------------------------------
  69. class CAI_NetworkBuilder
  70. {
  71. public:
  72. void Build( CAI_Network *pNetwork );
  73. void Rebuild( CAI_Network *pNetwork );
  74. void InitNodePosition( CAI_Network *pNetwork, CAI_Node *pNode );
  75. void InitZones( CAI_Network *pNetwork );
  76. private:
  77. void InitVisibility( CAI_Network *pNetwork, CAI_Node *pNode );
  78. void InitNeighbors( CAI_Network *pNetwork, CAI_Node *pNode );
  79. void InitClimbNodePosition( CAI_Network *pNetwork, CAI_Node *pNode );
  80. void InitGroundNodePosition( CAI_Network *pNetwork, CAI_Node *pNode );
  81. void InitLinks( CAI_Network *pNetwork, CAI_Node *pNode );
  82. void ForceDynamicLinkNeighbors();
  83. void FloodFillZone( CAI_Node **ppNodes, CAI_Node *pNode, int zone );
  84. int ComputeConnection( CAI_Node *pSrcNode, CAI_Node *pDestNode, Hull_t hull );
  85. void BeginBuild();
  86. void EndBuild();
  87. CUtlVector<CVarBitVec> m_NeighborsTable;
  88. CVarBitVec m_DidSetNeighborsTable;
  89. CAI_TestHull * m_pTestHull;
  90. };
  91. extern CAI_NetworkBuilder g_AINetworkBuilder;
  92. //-----------------------------------------------------------------------------
  93. // CAI_NetworkEditTools
  94. //
  95. // Purpose: Bridge class to Hammer node editing functionality
  96. //
  97. //-----------------------------------------------------------------------------
  98. class CAI_NetworkEditTools
  99. {
  100. public:
  101. CAI_NetworkEditTools(CAI_NetworkManager *);
  102. ~CAI_NetworkEditTools();
  103. // ----------------------
  104. // Debug & Edit fields
  105. // ----------------------
  106. static CAI_Node * m_pLastDeletedNode; // For undo in wc edit mode
  107. static int m_iHullDrawNum; // Which hulls to draw
  108. static int m_iVisibilityNode; // Node I'm showing visibility for
  109. static int m_iGConnectivityNode; // Node I'm showing graph connectivity for
  110. static bool m_bAirEditMode; // Editing Air Nodes
  111. static bool m_bLinkEditMode; // Editing Links
  112. static float m_flAirEditDistance; // Distance editing Air Nodes
  113. static void DrawHull(Hull_t eHull);
  114. static void DrawNextHull(const char *ainet_name); // Draws next hull set for the named ai network
  115. static void SetDebugBits(const char *ainet_name,int debug_bit);
  116. static CAI_Node * FindAINodeNearestFacing( const Vector &origin, const Vector &facing, float threshold, int nNodeType);
  117. static CAI_Link * FindAILinkNearestFacing( const Vector &origin, const Vector &facing, float threshold);
  118. //---------------
  119. // WC Editing
  120. //---------------
  121. int m_nNextWCIndex; // Next unused index used by WC
  122. Vector * m_pWCPosition; // Array of vectors only used in wc edit mode
  123. //-----------------
  124. // Debugging Tools
  125. //-----------------
  126. int m_debugNetOverlays; // Which network debug overlays to draw
  127. void DrawAINetworkOverlay(void); // Draw network on the client
  128. void RecalcUsableNodesForHull(void); // Used only for debug drawing
  129. //-----------------
  130. void OnInit();
  131. int GetNodeIdFromWCId( int nWCId );
  132. int GetWCIdFromNodeId( int nNodeId );
  133. int * m_pNodeIndexTable; // Table of WC Id's to Engine Id's
  134. void ClearRebuildFlags();
  135. void SetRebuildFlags();
  136. void DrawEditInfoOverlay();
  137. #ifdef AI_PERF_MON
  138. //----------------------
  139. // Performance stats
  140. //----------------------
  141. static int m_nPerfStatNN;
  142. static int m_nPerfStatPB;
  143. static float m_fNextPerfStatTime;
  144. #endif
  145. CAI_NetworkManager *m_pManager;
  146. CAI_Network * m_pNetwork;
  147. };
  148. //-----------------------------------------------------------------------------
  149. #endif // AI_NETWORKMANAGER_H