Pathfind.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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/Pathfind.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 10/15/01 5:19p $*
  29. * *
  30. * $Revision:: 20 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __PATHFIND_H
  39. #define __PATHFIND_H
  40. #include "aabtreecull.h"
  41. #include "pathfindsector.h"
  42. #include "widgetuser.h"
  43. /////////////////////////////////////////////////////////////////////////
  44. // Forward declarations
  45. /////////////////////////////////////////////////////////////////////////
  46. class Vector3;
  47. class ChunkSaveClass;
  48. class ChunkLoadClass;
  49. class PhysClass;
  50. class PathDebugPlotterClass;
  51. class PathfindPortalClass;
  52. class WaypathClass;
  53. class PathfindWaypathSectorClass;
  54. class PathfindWaypathPortalClass;
  55. /////////////////////////////////////////////////////////////////////////
  56. //
  57. // PathfindClass
  58. //
  59. /////////////////////////////////////////////////////////////////////////
  60. class PathfindClass
  61. {
  62. public:
  63. typedef enum
  64. {
  65. WAYPATH_PORTAL_ID_START = 64000,
  66. TEMP_PORTAL_ID_START = 128000
  67. } PORTAL_ID_RANGES;
  68. /////////////////////////////////////////////////////////////////////////
  69. // Public constructors/destructors
  70. /////////////////////////////////////////////////////////////////////////
  71. PathfindClass (void);
  72. ~PathfindClass (void);
  73. /////////////////////////////////////////////////////////////////////////
  74. // Public methods
  75. /////////////////////////////////////////////////////////////////////////
  76. //
  77. // Database methods
  78. //
  79. void Add_Sector (PathfindSectorClass *sector, bool add_to_tree = true);
  80. int Add_Portal (PathfindPortalClass *portal);
  81. PathfindPortalClass * Peek_Portal (int portal_index);
  82. PathfindSectorClass * Peek_Sector (int sector_index);
  83. int Get_Sector_Index (PathfindSectorClass *sector);
  84. void Re_Partition_Sector_Tree (void);
  85. PathfindSectorClass * Find_Sector (const Vector3 &position, float sector_fudge = 0, PathfindSectorClass *exclude_sector = NULL);
  86. void Collect_Sectors (DynamicVectorClass<PathfindSectorClass *> &list, const AABoxClass &box, PathfindSectorClass *exclude_sector = NULL);
  87. bool Find_Random_Spot (const Vector3 &center, float max_dist, Vector3 *dest);
  88. bool Save (ChunkSaveClass &csave);
  89. bool Load (ChunkLoadClass &cload);
  90. int Add_Temporary_Portal (PathfindSectorClass *sector_from, PathfindSectorClass *sector_to, const Vector3 &start_pos, const Vector3 &dest_pos);
  91. //
  92. // Statistics
  93. //
  94. const AABoxClass & Get_Bounding_Box (void) { return m_SectorTree.Get_Bounding_Box (); }
  95. bool Does_Pathfind_Data_Exist (void) { return bool(m_SectorList.Count () > 0); }
  96. //
  97. // Waypath methods
  98. //
  99. void Add_Waypath (WaypathClass *waypath);
  100. bool Remove_Waypath (WaypathClass *waypath);
  101. WaypathClass * Find_Waypath (int id) const;
  102. int Count_Waypaths_Starting_In_Box (const AABoxClass & box);
  103. WaypathClass * Get_Waypath_Starting_In_Box (const AABoxClass & box,int i);
  104. //
  105. // Waypath integration
  106. //
  107. void Generate_Waypath_Sectors_And_Portals (void);
  108. void Free_Waypath_Sectors_And_Portals (void);
  109. //
  110. // Height database lookup
  111. //
  112. float Get_Height_Value (const Vector3 &pos);
  113. //
  114. // Debug methods
  115. //
  116. bool Are_Sectors_Displayed (void) const { return m_SectorsDisplayed; }
  117. bool Are_Portals_Displayed (void) const { return m_PortalsDisplayed; }
  118. void Display_Sectors (bool onoff);
  119. void Display_Portals (bool onoff);
  120. void Render_Debug_Widgets (RenderInfoClass &rinfo);
  121. //
  122. // Cleanup methods
  123. //
  124. void Reset_Sectors (void);
  125. void Reset_Portals (void);
  126. void Reset_Waypaths (void);
  127. //
  128. // Sector list access
  129. //
  130. void Get_Sector_List (DynamicVectorClass<PathfindSectorClass *> &list) { list = m_SectorList; }
  131. //
  132. // Intersection methods
  133. //
  134. void Find_Portals (const Vector3 &p0, const Vector3 &p1, DynamicVectorClass<PathfindPortalClass *> &list, bool action_portals_only = false);
  135. /////////////////////////////////////////////////////////////////////////
  136. // Static methods
  137. /////////////////////////////////////////////////////////////////////////
  138. static PathfindClass * Get_Instance (void) { return _Pathfinder; }
  139. static int _MemoryFootprint;
  140. protected:
  141. /////////////////////////////////////////////////////////////////////////
  142. // Protected methods
  143. /////////////////////////////////////////////////////////////////////////
  144. bool Save_Portals (ChunkSaveClass &csave);
  145. bool Save_Waypaths (ChunkSaveClass &csave);
  146. bool Save_Sector (ChunkSaveClass &csave, PathfindSectorClass *sector);
  147. bool Load_Sector (ChunkLoadClass &cload);
  148. bool Load_Portal (ChunkLoadClass &cload, PathfindPortalClass *portal);
  149. bool Save_Culling_System (ChunkSaveClass &csave);
  150. bool Load_Culling_System (ChunkLoadClass &cload);
  151. void Generate_Waypath_Sector_And_Portals (WaypathClass *waypath);
  152. void Add_Intersection_Portals_To_List (DynamicVectorClass<PathfindWaypathPortalClass *> &portal_list, WaypathClass *waypath, PathfindWaypathSectorClass *dest_sector);
  153. int Add_Waypath_Portal (PathfindWaypathPortalClass *portal);
  154. private:
  155. /////////////////////////////////////////////////////////////////////////
  156. // Static member data
  157. /////////////////////////////////////////////////////////////////////////
  158. static PathfindClass * _Pathfinder;
  159. /////////////////////////////////////////////////////////////////////////
  160. // Private data types
  161. /////////////////////////////////////////////////////////////////////////
  162. typedef TypedAABTreeCullSystemClass<PathfindSectorClass> SectorCullingSystem;
  163. typedef DynamicVectorClass<PathfindSectorClass *> SECTOR_LIST;
  164. typedef DynamicVectorClass<PathfindPortalClass *> PORTAL_LIST;
  165. typedef DynamicVectorClass<PhysClass *> DISPLAY_LIST;
  166. typedef DynamicVectorClass<WaypathClass *> WAYPATH_LIST;
  167. /////////////////////////////////////////////////////////////////////////
  168. // Private member data
  169. /////////////////////////////////////////////////////////////////////////
  170. SectorCullingSystem m_SectorTree;
  171. SECTOR_LIST m_SectorList;
  172. PORTAL_LIST m_PortalList;
  173. DISPLAY_LIST m_SectorDisplayList;
  174. WAYPATH_LIST m_WaypathList;
  175. bool m_SectorsDisplayed;
  176. bool m_PortalsDisplayed;
  177. PathDebugPlotterClass *m_Plotter;
  178. PORTAL_LIST m_TemporaryPortalList;
  179. PORTAL_LIST m_WaypathPortalList;
  180. WidgetUserClass m_SectorDisplayWidgets;
  181. WidgetUserClass m_PortalDisplayWidgets;
  182. };
  183. /////////////////////////////////////////////////////////////////////////
  184. // Peek_Sector
  185. /////////////////////////////////////////////////////////////////////////
  186. inline PathfindSectorClass *
  187. PathfindClass::Peek_Sector (int sector_index)
  188. {
  189. if (sector_index >= 0 && sector_index < m_SectorList.Count ()) {
  190. return m_SectorList[sector_index];
  191. } else {
  192. return NULL;
  193. }
  194. }
  195. #endif //__PATHFIND_H