AAS_local.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __AAS_LOCAL_H__
  21. #define __AAS_LOCAL_H__
  22. #include "AAS.h"
  23. #include "../Pvs.h"
  24. class idRoutingCache {
  25. friend class idAASLocal;
  26. public:
  27. idRoutingCache( int size );
  28. ~idRoutingCache( void );
  29. int Size( void ) const;
  30. private:
  31. int type; // portal or area cache
  32. int size; // size of cache
  33. int cluster; // cluster of the cache
  34. int areaNum; // area of the cache
  35. int travelFlags; // combinations of the travel flags
  36. idRoutingCache * next; // next in list
  37. idRoutingCache * prev; // previous in list
  38. idRoutingCache * time_next; // next in time based list
  39. idRoutingCache * time_prev; // previous in time based list
  40. unsigned short startTravelTime; // travel time to start with
  41. unsigned char * reachabilities; // reachabilities used for routing
  42. unsigned short * travelTimes; // travel time for every area
  43. };
  44. class idRoutingUpdate {
  45. friend class idAASLocal;
  46. private:
  47. int cluster; // cluster number of this update
  48. int areaNum; // area number of this update
  49. unsigned short tmpTravelTime; // temporary travel time
  50. unsigned short * areaTravelTimes; // travel times within the area
  51. idVec3 start; // start point into area
  52. idRoutingUpdate * next; // next in list
  53. idRoutingUpdate * prev; // prev in list
  54. bool isInList; // true if the update is in the list
  55. };
  56. class idRoutingObstacle {
  57. friend class idAASLocal;
  58. idRoutingObstacle( void ) { }
  59. private:
  60. idBounds bounds; // obstacle bounds
  61. idList<int> areas; // areas the bounds are in
  62. };
  63. class idAASLocal : public idAAS {
  64. public:
  65. idAASLocal( void );
  66. virtual ~idAASLocal( void );
  67. virtual bool Init( const idStr &mapName, unsigned int mapFileCRC );
  68. virtual void Shutdown( void );
  69. virtual void Stats( void ) const;
  70. virtual void Test( const idVec3 &origin );
  71. virtual const idAASSettings *GetSettings( void ) const;
  72. virtual int PointAreaNum( const idVec3 &origin ) const;
  73. virtual int PointReachableAreaNum( const idVec3 &origin, const idBounds &searchBounds, const int areaFlags ) const;
  74. virtual int BoundsReachableAreaNum( const idBounds &bounds, const int areaFlags ) const;
  75. virtual void PushPointIntoAreaNum( int areaNum, idVec3 &origin ) const;
  76. virtual idVec3 AreaCenter( int areaNum ) const;
  77. virtual int AreaFlags( int areaNum ) const;
  78. virtual int AreaTravelFlags( int areaNum ) const;
  79. virtual bool Trace( aasTrace_t &trace, const idVec3 &start, const idVec3 &end ) const;
  80. virtual const idPlane & GetPlane( int planeNum ) const;
  81. virtual int GetWallEdges( int areaNum, const idBounds &bounds, int travelFlags, int *edges, int maxEdges ) const;
  82. virtual void SortWallEdges( int *edges, int numEdges ) const;
  83. virtual void GetEdgeVertexNumbers( int edgeNum, int verts[2] ) const;
  84. virtual void GetEdge( int edgeNum, idVec3 &start, idVec3 &end ) const;
  85. virtual bool SetAreaState( const idBounds &bounds, const int areaContents, bool disabled );
  86. virtual aasHandle_t AddObstacle( const idBounds &bounds );
  87. virtual void RemoveObstacle( const aasHandle_t handle );
  88. virtual void RemoveAllObstacles( void );
  89. virtual int TravelTimeToGoalArea( int areaNum, const idVec3 &origin, int goalAreaNum, int travelFlags ) const;
  90. virtual bool RouteToGoalArea( int areaNum, const idVec3 origin, int goalAreaNum, int travelFlags, int &travelTime, idReachability **reach ) const;
  91. virtual bool WalkPathToGoal( aasPath_t &path, int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin, int travelFlags ) const;
  92. virtual bool WalkPathValid( int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin, int travelFlags, idVec3 &endPos, int &endAreaNum ) const;
  93. virtual bool FlyPathToGoal( aasPath_t &path, int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin, int travelFlags ) const;
  94. virtual bool FlyPathValid( int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin, int travelFlags, idVec3 &endPos, int &endAreaNum ) const;
  95. virtual void ShowWalkPath( const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin ) const;
  96. virtual void ShowFlyPath( const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin ) const;
  97. virtual bool FindNearestGoal( aasGoal_t &goal, int areaNum, const idVec3 origin, const idVec3 &target, int travelFlags, aasObstacle_t *obstacles, int numObstacles, idAASCallback &callback ) const;
  98. private:
  99. idAASFile * file;
  100. idStr name;
  101. private: // routing data
  102. idRoutingCache *** areaCacheIndex; // for each area in each cluster the travel times to all other areas in the cluster
  103. int areaCacheIndexSize; // number of area cache entries
  104. idRoutingCache ** portalCacheIndex; // for each area in the world the travel times from each portal
  105. int portalCacheIndexSize; // number of portal cache entries
  106. idRoutingUpdate * areaUpdate; // memory used to update the area routing cache
  107. idRoutingUpdate * portalUpdate; // memory used to update the portal routing cache
  108. unsigned short * goalAreaTravelTimes; // travel times to goal areas
  109. unsigned short * areaTravelTimes; // travel times through the areas
  110. int numAreaTravelTimes; // number of area travel times
  111. mutable idRoutingCache * cacheListStart; // start of list with cache sorted from oldest to newest
  112. mutable idRoutingCache * cacheListEnd; // end of list with cache sorted from oldest to newest
  113. mutable int totalCacheMemory; // total cache memory used
  114. idList<idRoutingObstacle *> obstacleList; // list with obstacles
  115. private: // routing
  116. bool SetupRouting( void );
  117. void ShutdownRouting( void );
  118. unsigned short AreaTravelTime( int areaNum, const idVec3 &start, const idVec3 &end ) const;
  119. void CalculateAreaTravelTimes( void );
  120. void DeleteAreaTravelTimes( void );
  121. void SetupRoutingCache( void );
  122. void DeleteClusterCache( int clusterNum );
  123. void DeletePortalCache( void );
  124. void ShutdownRoutingCache( void );
  125. void RoutingStats( void ) const;
  126. void LinkCache( idRoutingCache *cache ) const;
  127. void UnlinkCache( idRoutingCache *cache ) const;
  128. void DeleteOldestCache( void ) const;
  129. idReachability * GetAreaReachability( int areaNum, int reachabilityNum ) const;
  130. int ClusterAreaNum( int clusterNum, int areaNum ) const;
  131. void UpdateAreaRoutingCache( idRoutingCache *areaCache ) const;
  132. idRoutingCache * GetAreaRoutingCache( int clusterNum, int areaNum, int travelFlags ) const;
  133. void UpdatePortalRoutingCache( idRoutingCache *portalCache ) const;
  134. idRoutingCache * GetPortalRoutingCache( int clusterNum, int areaNum, int travelFlags ) const;
  135. void RemoveRoutingCacheUsingArea( int areaNum );
  136. void DisableArea( int areaNum );
  137. void EnableArea( int areaNum );
  138. bool SetAreaState_r( int nodeNum, const idBounds &bounds, const int areaContents, bool disabled );
  139. void GetBoundsAreas_r( int nodeNum, const idBounds &bounds, idList<int> &areas ) const;
  140. void SetObstacleState( const idRoutingObstacle *obstacle, bool enable );
  141. private: // pathing
  142. bool EdgeSplitPoint( idVec3 &split, int edgeNum, const idPlane &plane ) const;
  143. bool FloorEdgeSplitPoint( idVec3 &split, int areaNum, const idPlane &splitPlane, const idPlane &frontPlane, bool closest ) const;
  144. idVec3 SubSampleWalkPath( int areaNum, const idVec3 &origin, const idVec3 &start, const idVec3 &end, int travelFlags, int &endAreaNum ) const;
  145. idVec3 SubSampleFlyPath( int areaNum, const idVec3 &origin, const idVec3 &start, const idVec3 &end, int travelFlags, int &endAreaNum ) const;
  146. private: // debug
  147. const idBounds & DefaultSearchBounds( void ) const;
  148. void DrawCone( const idVec3 &origin, const idVec3 &dir, float radius, const idVec4 &color ) const;
  149. void DrawArea( int areaNum ) const;
  150. void DrawFace( int faceNum, bool side ) const;
  151. void DrawEdge( int edgeNum, bool arrow ) const;
  152. void DrawReachability( const idReachability *reach ) const;
  153. void ShowArea( const idVec3 &origin ) const;
  154. void ShowWallEdges( const idVec3 &origin ) const;
  155. void ShowHideArea( const idVec3 &origin, int targerAreaNum ) const;
  156. bool PullPlayer( const idVec3 &origin, int toAreaNum ) const;
  157. void RandomPullPlayer( const idVec3 &origin ) const;
  158. void ShowPushIntoArea( const idVec3 &origin ) const;
  159. };
  160. #endif /* !__AAS_LOCAL_H__ */