PathNode.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/PathNode.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 5/08/01 2:31p $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __PATHNODE_H
  39. #define __PATHNODE_H
  40. #include "matrix3d.h"
  41. #include "refcount.h"
  42. #include "binheap.h"
  43. #include "mempool.h"
  44. #include "pathfindportal.h"
  45. /////////////////////////////////////////////////////////////////////////
  46. // Forward declarations
  47. /////////////////////////////////////////////////////////////////////////
  48. class PathfindSectorClass;
  49. /////////////////////////////////////////////////////////////////////////
  50. //
  51. // PathNodeClass
  52. //
  53. /////////////////////////////////////////////////////////////////////////
  54. class PathNodeClass : public RefCountClass, public HeapNodeClass<float>, public AutoPoolClass<PathNodeClass, 512>
  55. {
  56. public:
  57. /////////////////////////////////////////////////////////////////////////
  58. // Public constructors/destructors
  59. /////////////////////////////////////////////////////////////////////////
  60. PathNodeClass (void)
  61. : m_Sector (NULL),
  62. m_ParentNode (NULL),
  63. m_Portal (NULL),
  64. m_TotalCost (0),
  65. m_HeuristicCost (0),
  66. m_TraversalCost (0),
  67. m_OnFinalPath (false),
  68. m_EnterTransform (1),
  69. m_Transform (1),
  70. m_HeapLocation (0),
  71. m_InClosedList (false) { }
  72. ~PathNodeClass (void) { }
  73. /////////////////////////////////////////////////////////////////////////
  74. // Public methods
  75. /////////////////////////////////////////////////////////////////////////
  76. PathfindSectorClass * Peek_Sector (void);
  77. PathfindPortalClass * Peek_Portal (void);
  78. PathNodeClass * Peek_Parent_Node (void);
  79. void Set_Sector (PathfindSectorClass *sector);
  80. void Set_Portal (PathfindPortalClass *portal);
  81. void Set_Parent_Node (PathNodeClass *node);
  82. float Get_Total_Cost (void) const;
  83. float Get_Heuristic_Cost (void) const;
  84. void Set_Heuristic_Cost (float cost);
  85. float Get_Traversal_Cost (void) const;
  86. void Set_Traversal_Cost (float cost);
  87. Vector3 Get_Position (void) const;
  88. const Matrix3D & Get_Transform (void) const;
  89. void Set_Transform (const Matrix3D &tm);
  90. const Matrix3D & Get_Enter_Transform (void) const;
  91. void Set_Enter_Transform (const Matrix3D &tm);
  92. bool Is_On_Final_Path (void) const;
  93. void On_Final_Path (bool on_path);
  94. // For distributed (multi-frame) solve...
  95. bool Is_In_Closed_List (void) const;
  96. void Reconnect_To_Portal (void);
  97. void Disconnect_From_Portal (void);
  98. // From HeapNodeClass
  99. uint32 Get_Heap_Location (void) const;
  100. void Set_Heap_Location (uint32 location);
  101. float Heap_Key (void) const;
  102. protected:
  103. /////////////////////////////////////////////////////////////////////////
  104. // Protected methods
  105. /////////////////////////////////////////////////////////////////////////
  106. void Eval_Total_Cost (void);
  107. private:
  108. /////////////////////////////////////////////////////////////////////////
  109. // Private member data
  110. /////////////////////////////////////////////////////////////////////////
  111. PathfindPortalClass * m_Portal;
  112. PathfindSectorClass * m_Sector;
  113. PathNodeClass * m_ParentNode;
  114. float m_TotalCost;
  115. float m_HeuristicCost;
  116. float m_TraversalCost;
  117. Matrix3D m_EnterTransform;
  118. Matrix3D m_Transform;
  119. bool m_OnFinalPath;
  120. bool m_InClosedList;
  121. uint32 m_HeapLocation;
  122. };
  123. /////////////////////////////////////////////////////////////////////////
  124. //
  125. // Inlines
  126. //
  127. /////////////////////////////////////////////////////////////////////////
  128. inline PathfindSectorClass *
  129. PathNodeClass::Peek_Sector (void) { return m_Sector; }
  130. inline PathfindPortalClass *
  131. PathNodeClass::Peek_Portal (void) { return m_Portal; }
  132. inline PathNodeClass *
  133. PathNodeClass::Peek_Parent_Node (void) { return m_ParentNode; }
  134. inline void
  135. PathNodeClass::Set_Sector (PathfindSectorClass *sector) { m_Sector = sector; }
  136. inline void
  137. PathNodeClass::Set_Portal (PathfindPortalClass *portal) { m_Portal = portal; }
  138. inline void
  139. PathNodeClass::Set_Parent_Node (PathNodeClass *node) { m_ParentNode = node; }
  140. inline float
  141. PathNodeClass::Get_Total_Cost (void) const { return m_TotalCost; }
  142. inline float
  143. PathNodeClass::Get_Heuristic_Cost (void) const { return m_HeuristicCost; }
  144. inline void
  145. PathNodeClass::Set_Heuristic_Cost (float cost) { m_HeuristicCost = cost; Eval_Total_Cost (); }
  146. inline float
  147. PathNodeClass::Get_Traversal_Cost (void) const { return m_TraversalCost; }
  148. inline void
  149. PathNodeClass::Set_Traversal_Cost (float cost) { m_TraversalCost = cost; Eval_Total_Cost (); }
  150. inline const Matrix3D &
  151. PathNodeClass::Get_Transform (void) const { return m_Transform; }
  152. inline void
  153. PathNodeClass::Set_Transform (const Matrix3D &tm) { m_Transform = tm; }
  154. inline Vector3
  155. PathNodeClass::Get_Position (void) const { return m_Transform.Get_Translation (); }
  156. inline const Matrix3D &
  157. PathNodeClass::Get_Enter_Transform (void) const { return m_EnterTransform; }
  158. inline void
  159. PathNodeClass::Set_Enter_Transform (const Matrix3D &tm) { m_EnterTransform = tm; }
  160. inline void
  161. PathNodeClass::Eval_Total_Cost (void) { m_TotalCost = m_HeuristicCost + m_TraversalCost; }
  162. inline bool
  163. PathNodeClass::Is_On_Final_Path (void) const { return m_OnFinalPath; }
  164. inline void
  165. PathNodeClass::On_Final_Path (bool on_path) { m_OnFinalPath = on_path; }
  166. inline uint32
  167. PathNodeClass::Get_Heap_Location (void) const
  168. {
  169. return m_HeapLocation;
  170. }
  171. inline void
  172. PathNodeClass::Set_Heap_Location (uint32 location)
  173. {
  174. m_HeapLocation = location;
  175. if (m_Portal != NULL) {
  176. m_Portal->Set_Heap_Location (location);
  177. }
  178. if (location == 0) {
  179. m_InClosedList = true;
  180. } else {
  181. m_InClosedList = false;
  182. }
  183. return ;
  184. }
  185. inline float
  186. PathNodeClass::Heap_Key (void) const
  187. {
  188. return m_TotalCost;
  189. }
  190. inline bool
  191. PathNodeClass::Is_In_Closed_List (void) const
  192. {
  193. return m_InClosedList;
  194. }
  195. inline void
  196. PathNodeClass::Disconnect_From_Portal (void)
  197. {
  198. WWASSERT (m_Portal != NULL);
  199. m_Portal->m_ClosedListPtr = NULL;
  200. m_Portal->Set_Heap_Location (0);
  201. return ;
  202. }
  203. inline void
  204. PathNodeClass::Reconnect_To_Portal (void)
  205. {
  206. if (m_Portal != NULL) {
  207. if (m_InClosedList) {
  208. m_Portal->m_ClosedListPtr = this;
  209. } else {
  210. m_Portal->Set_Heap_Location (m_HeapLocation);
  211. }
  212. }
  213. return ;
  214. }
  215. #endif //__PATHNODE_H