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.

135 lines
4.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // nav_node.h
  9. // Navigation Nodes are used when generating a Navigation Mesh by point sampling the map
  10. // Author: Michael S. Booth ([email protected]), January 2003
  11. #ifndef _CS_NAV_NODE_H_
  12. #define _CS_NAV_NODE_H_
  13. #include "cs_nav.h"
  14. // If DEBUG_NAV_NODES is true, nav_show_nodes controls drawing node positions, and
  15. // nav_show_node_id allows you to show the IDs of nodes that didn't get used to create areas.
  16. #ifdef _DEBUG
  17. #define DEBUG_NAV_NODES 1
  18. #else
  19. #define DEBUG_NAV_NODES 0
  20. #endif
  21. //--------------------------------------------------------------------------------------------------------------
  22. /**
  23. * Navigation Nodes.
  24. * These Nodes encapsulate world locations, and ways to get from one location to an adjacent one.
  25. * Note that these links are not necessarily commutative (falling off of a ledge, for example).
  26. */
  27. class CSNavNode
  28. {
  29. public:
  30. CSNavNode( const Vector &pos, const Vector &normal, CSNavNode *parent = NULL );
  31. static CSNavNode *GetNode( const Vector &pos ); ///< return navigation node at the position, or NULL if none exists
  32. CSNavNode *GetConnectedNode( NavDirType dir ) const; ///< get navigation node connected in given direction, or NULL if cant go that way
  33. const Vector *GetPosition( void ) const;
  34. const Vector *GetNormal( void ) const { return &m_normal; }
  35. unsigned int GetID( void ) const { return m_id; }
  36. static CSNavNode *GetFirst( void ) { return m_list; }
  37. static unsigned int GetListLength( void ) { return m_listLength; }
  38. CSNavNode *GetNext( void ) { return m_next; }
  39. void Draw( void );
  40. void ConnectTo( CSNavNode *node, NavDirType dir ); ///< create a connection FROM this node TO the given node, in the given direction
  41. CSNavNode *GetParent( void ) const;
  42. void MarkAsVisited( NavDirType dir ); ///< mark the given direction as having been visited
  43. BOOL HasVisited( NavDirType dir ); ///< return TRUE if the given direction has already been searched
  44. BOOL IsBiLinked( NavDirType dir ) const; ///< node is bidirectionally linked to another node in the given direction
  45. BOOL IsClosedCell( void ) const; ///< node is the NW corner of a bi-linked quad of nodes
  46. void Cover( void ) { m_isCovered = true; } ///< @todo Should pass in area that is covering
  47. BOOL IsCovered( void ) const { return m_isCovered; } ///< return true if this node has been covered by an area
  48. void AssignArea( CNavArea *area ); ///< assign the given area to this node
  49. CNavArea *GetArea( void ) const; ///< return associated area
  50. void SetAttributes( unsigned char bits ) { m_attributeFlags = bits; }
  51. unsigned char GetAttributes( void ) const { return m_attributeFlags; }
  52. private:
  53. friend class CNavMesh;
  54. void CheckCrouch( void );
  55. Vector m_pos; ///< position of this node in the world
  56. Vector m_normal; ///< surface normal at this location
  57. CSNavNode *m_to[ NUM_DIRECTIONS ]; ///< links to north, south, east, and west. NULL if no link
  58. unsigned int m_id; ///< unique ID of this node
  59. unsigned char m_attributeFlags; ///< set of attribute bit flags (see NavAttributeType)
  60. static CSNavNode *m_list; ///< the master list of all nodes for this map
  61. static unsigned int m_listLength;
  62. static unsigned int m_nextID;
  63. CSNavNode *m_next; ///< next link in master list
  64. // below are only needed when generating
  65. unsigned char m_visited; ///< flags for automatic node generation. If direction bit is clear, that direction hasn't been explored yet.
  66. CSNavNode *m_parent; ///< the node prior to this in the search, which we pop back to when this node's search is done (a stack)
  67. bool m_isCovered; ///< true when this node is "covered" by a CNavArea
  68. CNavArea *m_area; ///< the area this node is contained within
  69. bool m_crouch[ NUM_CORNERS ];
  70. };
  71. //--------------------------------------------------------------------------------------------------------------
  72. //
  73. // Inlines
  74. //
  75. inline CSNavNode *CSNavNode::GetConnectedNode( NavDirType dir ) const
  76. {
  77. return m_to[ dir ];
  78. }
  79. inline const Vector *CSNavNode::GetPosition( void ) const
  80. {
  81. return &m_pos;
  82. }
  83. inline CSNavNode *CSNavNode::GetParent( void ) const
  84. {
  85. return m_parent;
  86. }
  87. inline void CSNavNode::MarkAsVisited( NavDirType dir )
  88. {
  89. m_visited |= (1 << dir);
  90. }
  91. inline BOOL CSNavNode::HasVisited( NavDirType dir )
  92. {
  93. if (m_visited & (1 << dir))
  94. return true;
  95. return false;
  96. }
  97. inline void CSNavNode::AssignArea( CNavArea *area )
  98. {
  99. m_area = area;
  100. }
  101. inline CNavArea *CSNavNode::GetArea( void ) const
  102. {
  103. return m_area;
  104. }
  105. #endif // _CS_NAV_NODE_H_