pathsolve.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 : wwphys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/pathsolve.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 9/20/01 1:22p $*
  29. * *
  30. * $Revision:: 10 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __PATH_SOLVE_H
  39. #define __PATH_SOLVE_H
  40. #include "vector.h"
  41. #include "vector3.h"
  42. #include "hermitespline.h"
  43. #include "PathObject.h"
  44. #include "binheap.h"
  45. #include "refcount.h"
  46. #include "postloadable.h"
  47. /////////////////////////////////////////////////////////////////////////
  48. // Forward declarations
  49. /////////////////////////////////////////////////////////////////////////
  50. class PathfindPortalClass;
  51. class PathfindSectorClass;
  52. class PathNodeClass;
  53. class AABoxClass;
  54. class WayPathClass;
  55. class ChunkSaveClass;
  56. class ChunkLoadClass;
  57. typedef DynamicVectorClass<AABoxClass *> BOX_LIST;
  58. /////////////////////////////////////////////////////////////////////////
  59. //
  60. // PathSolveClass
  61. //
  62. /////////////////////////////////////////////////////////////////////////
  63. class PathSolveClass : public RefCountClass, public PostLoadableClass
  64. {
  65. public:
  66. /////////////////////////////////////////////////////////////////////////
  67. // Public friends
  68. /////////////////////////////////////////////////////////////////////////
  69. friend class PathMgrClass;
  70. /////////////////////////////////////////////////////////////////////////
  71. // Public data types
  72. /////////////////////////////////////////////////////////////////////////
  73. typedef enum
  74. {
  75. THINKING = 0,
  76. SOLVED_PATH,
  77. ERROR_INVALID_START_POS,
  78. ERROR_INVALID_DEST_POS,
  79. ERROR_NO_PATH,
  80. } STATE_DESC;
  81. /////////////////////////////////////////////////////////////////////////
  82. // Public constructors/destructors
  83. /////////////////////////////////////////////////////////////////////////
  84. PathSolveClass (void);
  85. PathSolveClass (const Vector3 &start, const Vector3 &end);
  86. ~PathSolveClass (void);
  87. /////////////////////////////////////////////////////////////////////////
  88. // Public methods
  89. /////////////////////////////////////////////////////////////////////////
  90. //
  91. // Path evaluation
  92. //
  93. STATE_DESC Timestep (unsigned int milliseconds = 2);
  94. //
  95. // Position methods
  96. //
  97. STATE_DESC Reset (const Vector3 &start, const Vector3 &end, float sector_fudge = 0);
  98. const Vector3 & Get_Start_Pos (void) const;
  99. const Vector3 & Get_Dest_Pos (void) const;
  100. STATE_DESC Get_State (void) const;
  101. //
  102. // Traversing object
  103. //
  104. void Set_Path_Object (PathObjectClass &path_object);
  105. void Get_Path_Object (PathObjectClass &path_object) const;
  106. //
  107. // Priority access
  108. //
  109. void Set_Priority (float priority) { m_Priority = priority; }
  110. float Get_Priority (void) const { return m_Priority; }
  111. //
  112. // Birth-time access
  113. //
  114. uint32 Get_Birth_Time (void) const { return m_BirthTime; }
  115. //
  116. // Volume access
  117. //
  118. void Get_Volumes (BOX_LIST &sector_list, BOX_LIST &portal_list);
  119. //
  120. // Save/load stuff
  121. //
  122. void Save (ChunkSaveClass &csave);
  123. void Load (ChunkLoadClass &cload);
  124. void On_Post_Load (void);
  125. //
  126. // Distributed (multi-frame solve) methods
  127. //
  128. void Process_Initial_Sector (void);
  129. void Unlink_Pathfind_Hooks (void);
  130. protected:
  131. /////////////////////////////////////////////////////////////////////////
  132. // Public data types
  133. /////////////////////////////////////////////////////////////////////////
  134. typedef struct PathDataStruct
  135. {
  136. PathDataStruct (void)
  137. : m_Portal (NULL), m_Point (0, 0, 0) { }
  138. PathDataStruct (PathfindPortalClass *portal, const Vector3 &point)
  139. : m_Portal (portal), m_Point (point) { }
  140. bool operator== (const PathDataStruct &src) { return false; }
  141. bool operator!= (const PathDataStruct &src) { return true; }
  142. PathfindPortalClass * m_Portal;
  143. Vector3 m_Point;
  144. Vector3 m_SectorCenter;
  145. Vector3 m_SectorExtent;
  146. };
  147. typedef DynamicVectorClass<PathNodeClass *> PATHNODE_LIST;
  148. typedef DynamicVectorClass<PathDataStruct> PATHPOINT_LIST;
  149. //
  150. // Raw path access
  151. //
  152. PATHPOINT_LIST & Get_Raw_Path (void) { return m_Path; }
  153. /////////////////////////////////////////////////////////////////////////
  154. // Protected methods
  155. /////////////////////////////////////////////////////////////////////////
  156. void Initialize (float sector_fudge = 0);
  157. void Resolve_Path (unsigned int milliseconds);
  158. void Process_Portals (PathNodeClass *node);
  159. void Submit_Node (float traversal_cost, PathNodeClass *current_node, PathfindPortalClass *portal, PathfindSectorClass *dest_sector, const Matrix3D &current_tm, const Matrix3D &ending_tm);
  160. void Reset_Lists (void);
  161. //
  162. // Post process methods
  163. //
  164. void Post_Process_Path (void);
  165. bool Does_Line_Go_Through_Portal (const Vector3 &start, const Vector3 &end, const AABoxClass &box);
  166. Vector3 Relax_Line (const Vector3 &start, const Vector3 &end, const AABoxClass &box);
  167. void Keep_Unit_Inside_Sectors (void);
  168. //
  169. // Portal access
  170. //
  171. bool Does_Object_Have_Access_To_Portal (PathfindPortalClass *portal);
  172. bool Can_Object_Go_Through_Portal (const Matrix3D &current_tm, PathfindSectorClass *sector, PathfindPortalClass *portal, Matrix3D *ending_tm);
  173. //
  174. // Distributed (multi-frame solve) methods
  175. //
  176. //void Begin_Distributed_Solve (void);
  177. //void End_Distributed_Solve (void);
  178. //
  179. // Save/load methods
  180. //
  181. void Load_Variables (ChunkLoadClass &cload);
  182. private:
  183. /////////////////////////////////////////////////////////////////////////
  184. // Static members
  185. /////////////////////////////////////////////////////////////////////////
  186. static __int64 _TicksPerMilliSec;
  187. /////////////////////////////////////////////////////////////////////////
  188. // Private member data
  189. /////////////////////////////////////////////////////////////////////////
  190. Vector3 m_StartPos;
  191. Vector3 m_DestPos;
  192. STATE_DESC m_State;
  193. float m_Priority;
  194. uint32 m_BirthTime;
  195. PathfindSectorClass * m_StartSector;
  196. PathfindSectorClass * m_DestSector;
  197. DynamicVectorClass<PathNodeClass *> m_NodeList;
  198. BinaryHeapClass<float> m_BinaryHeap;
  199. PathNodeClass * m_CompletedNode;
  200. PATHPOINT_LIST m_Path;
  201. PathObjectClass m_PathObject;
  202. static PATHNODE_LIST temp_node_list;
  203. /////////////////////////////////////////////////////////////////////////
  204. // Friends
  205. /////////////////////////////////////////////////////////////////////////
  206. friend class PathClass;
  207. };
  208. /////////////////////////////////////////////////////////////////////////
  209. // Inlines
  210. /////////////////////////////////////////////////////////////////////////
  211. inline PathSolveClass::STATE_DESC
  212. PathSolveClass::Get_State (void) const { return m_State; }
  213. inline const Vector3 &
  214. PathSolveClass::Get_Start_Pos (void) const { return m_StartPos; }
  215. inline const Vector3 &
  216. PathSolveClass::Get_Dest_Pos (void) const { return m_DestPos; }
  217. #endif //__PATH_SOLVE_H