BVB Source Codes

CRYENGINE Show PathObstacles.h Source code

Return Download CRYENGINE: download PathObstacles.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /********************************************************************
  4.    -------------------------------------------------------------------------
  5.    File name:   PathObstacles.h
  6.    $Id$
  7.    Description: interface for the CGraph class.
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    -
  12.  
  13.  *********************************************************************/
  14.  
  15. #ifndef PATHOBSTACLE_H
  16. #define PATHOBSTACLE_H
  17.  
  18. #if _MSC_VER > 1000
  19.         #pragma once
  20. #endif
  21.  
  22. #include "AILog.h"
  23. #include <vector>
  24. #include <set>
  25.  
  26. #ifdef CRYAISYSTEM_DEBUG
  27.         #define PATHOBSTACLES_DEBUG
  28. #endif
  29.  
  30. #include <CryAISystem/IPathfinder.h>
  31.  
  32. typedef std::vector<Vec3> TVectorOfVectors;
  33.  
  34. //===================================================================
  35. // SPathObstacleShape2D
  36. //===================================================================
  37. struct SPathObstacleShape2D
  38. {
  39.         SPathObstacleShape2D() { aabb.Reset(); minZ = maxZ = 0.0f; }
  40.         void         CalcAABB() { if (pts.empty()) aabb.Reset(); else aabb = AABB(&pts[0], pts.size()); }
  41.         /// Debugging consistency check.
  42.         unsigned int GetHash() const;
  43.  
  44.         TVectorOfVectors pts;
  45.         AABB             aabb;
  46.         float            minZ, maxZ; // backup of the height of all points in the shape before their AABB gets flattened; it's necessary to keep track of the height for CNavPath::AdjustPathAroundObstacleShape2D() to work reliably with "large" obstacles on slopes
  47. };
  48.  
  49. // NOTE Jun 1, 2007: <pvl> used just for debugging ATM
  50. bool operator==(const SPathObstacleShape2D& lhs, const SPathObstacleShape2D& rhs);
  51.  
  52. //===================================================================
  53. // SPathObstacleCircle2D
  54. //===================================================================
  55. struct SPathObstacleCircle2D
  56. {
  57.         /// Debugging consistency check.
  58.         unsigned int GetHash() const;
  59.  
  60.         Vec3         center;
  61.         float        radius;
  62. };
  63.  
  64. // NOTE Jun 1, 2007: <pvl> used just for debugging ATM
  65. bool operator==(const SPathObstacleCircle2D& lhs, const SPathObstacleCircle2D& rhs);
  66.  
  67. //===================================================================
  68. // CPathObstacle
  69. //===================================================================
  70. class CPathObstacle : public _reference_target_t
  71. {
  72. public:
  73.         enum EPathObstacleType
  74.         {
  75.                 ePOT_Unset,
  76.                 ePOT_Circle2D,
  77.                 ePOT_Shape2D,
  78.                 ePOT_Sphere3D
  79.         };
  80.  
  81.         CPathObstacle(EPathObstacleType type = ePOT_Unset);
  82.         ~CPathObstacle();
  83.         void           Free();
  84.         CPathObstacle& operator=(const CPathObstacle& other);
  85.         CPathObstacle(const CPathObstacle& other);
  86.  
  87.         EPathObstacleType            GetType() const     { return m_type; }
  88.         SPathObstacleShape2D&        GetShape2D()        { AIAssert(m_type == ePOT_Shape2D); return *((SPathObstacleShape2D*) m_pData); }
  89.         const SPathObstacleShape2D&  GetShape2D() const  { AIAssert(m_type == ePOT_Shape2D); return *((SPathObstacleShape2D*) m_pData); }
  90.         SPathObstacleCircle2D&       GetCircle2D()       { AIAssert(m_type == ePOT_Circle2D); return *((SPathObstacleCircle2D*) m_pData); }
  91.         const SPathObstacleCircle2D& GetCircle2D() const { AIAssert(m_type == ePOT_Circle2D); return *((SPathObstacleCircle2D*) m_pData); }
  92.  
  93.         /// Debugging consistency check.
  94.         unsigned int GetHash() const;
  95.  
  96. private:
  97.         EPathObstacleType m_type;
  98.         void*             m_pData;
  99. };
  100.  
  101. // NOTE Jun 1, 2007: <pvl> used just for debugging ATM
  102. //bool operator== (const CPathObstacle & lhs, const CPathObstacle & rhs);
  103.  
  104. typedef _smart_ptr<CPathObstacle>     CPathObstaclePtr;
  105.  
  106. typedef std::vector<CPathObstaclePtr> TPathObstacles;
  107.  
  108. inline bool operator==(const TPathObstacles& lhs, const TPathObstacles& rhs);
  109.  
  110. class CNavPath;
  111.  
  112. //===================================================================
  113. // CPathObstacles
  114. //===================================================================
  115. class CPathObstacles : public IPathObstacles
  116. {
  117. public:
  118.         CPathObstacles();
  119.         ~CPathObstacles();
  120.  
  121.         /// collect all the obstacles around the actor. If this is called in quick succession
  122.         /// when the actor hasn't moved then the old result will be used
  123.         void CalculateObstaclesAroundActor(const CPipeUser* pPipeUser);
  124.         void CalculateObstaclesAroundLocation(const Vec3& location, const AgentMovementAbility& movementAbility, const CNavPath* pNavPath);
  125.  
  126.         /// Gets the result
  127.         const TPathObstacles& GetCombinedObstacles() const { return m_combinedObstacles; }
  128.  
  129.         /// Indicates if pt is inside the obstacles
  130.         virtual bool IsPointInsideObstacles(const Vec3& pt) const override;
  131.  
  132.         /// Considers all ePOT_Shape2D obstacles and checks for whether given line segment is intersecting any of them or is at least close to them.
  133.         virtual bool IsLineSegmentIntersectingObstaclesOrCloseToThem(const Lineseg& linesegToTest, float maxDistanceToConsiderClose) const override;
  134.  
  135.         /// Indicates if path crosses through obstacles
  136.         virtual bool IsPathIntersectingObstacles(const NavigationMeshID meshID, const Vec3& start, const Vec3& end, float radius) const override;
  137.  
  138.         /// If pt is inside the combined obstacles this returns a new pt approx extraDist
  139.         /// outside the combined obstacles (but beware it may be pushed into another obstacle!). Otherwise
  140.         /// just returns pt.
  141.         Vec3        GetPointOutsideObstacles(const Vec3& pt, float extraDist) const;
  142.  
  143.         void        Reset();
  144.  
  145.         static void ResetOfStaticData();
  146.  
  147. private:
  148.         typedef std::vector<IPhysicalEntity*> TCheckedPhysicalEntities;
  149.         typedef std::vector<Sphere>           TDynamicObstacleSpheres;
  150.         struct SPathObstaclesInfo
  151.         {
  152.                 float                       minAvRadius;
  153.                 float                       maxSpeed;
  154.                 float                       maxDistToCheckAhead;
  155.                 float                       maxPathDeviation;
  156.  
  157.                 const CNavPath*             pNavPath;
  158.                 const CAIActor*             pAIActor;
  159.                 const AgentMovementAbility& movementAbility;
  160.  
  161.                 AABB                        foundObjectsAABB;
  162.  
  163.                 TPathObstacles&             outObstacles;
  164.                 TCheckedPhysicalEntities    queuedPhysicsEntities;
  165.                 TCheckedPhysicalEntities    checkedPhysicsEntities;
  166.                 TDynamicObstacleSpheres     dynamicObstacleSpheres;
  167.  
  168.                 SPathObstaclesInfo(TPathObstacles& _obstacles, const AgentMovementAbility& _movementAbility,
  169.                                    const CNavPath* _pNavPath, const CAIActor* _pAIActor, float _maxPathDeviation)
  170.                         : minAvRadius(0.0f)
  171.                         , maxSpeed(0.0f)
  172.                         , maxDistToCheckAhead(0.0f)
  173.                         , maxPathDeviation(_maxPathDeviation)
  174.                         , pNavPath(_pNavPath)
  175.                         , pAIActor(_pAIActor)
  176.                         , movementAbility(_movementAbility)
  177.                         , foundObjectsAABB(AABB::RESET)
  178.                         , outObstacles(_obstacles)
  179.                 {
  180.                 }
  181.         };
  182.  
  183.         void GetPathObstacles(TPathObstacles& obstacles, const AgentMovementAbility& movementAbility, const CNavPath* pNavPath, const CAIActor* pAIActor);
  184.         void GetPathObstacles_AIObject(CAIObject* pObject, SPathObstaclesInfo& pathObstaclesInfo, float maximumDistanceToPath) const;
  185.         void GetPathObstacles_Vehicle(CAIObject* pObject, SPathObstaclesInfo& pathObstaclesInfo) const;
  186.         void GetPathObstacles_PhysicalEntity(IPhysicalEntity* pEntity, SPathObstaclesInfo& pathObstaclesInfo, bool bIsPushable, float fCullShapeScale, const CNavPath& navPath) const;
  187.         void GetPathObstacles_DamageRegion(const Sphere& damageRegionSphere, SPathObstaclesInfo& pathObstaclesInfo) const;
  188.  
  189.         /// Returns if the given obstacle entity is pushable by this actor
  190.         /// outCullShapeScale - The scale [0,1] to apply to the cull shape for this entity
  191.         bool IsObstaclePushable(const CAIActor* pAIActor, IPhysicalEntity* pEntity, SPathObstaclesInfo& pathObstaclesInfo, float& outCullShapeScale) const;
  192.  
  193.         /// Returns true if the object has the property bUsedAsDynamicObstacle set as true, false otherwise
  194.         bool IsPhysicalEntityUsedAsDynamicObstacle(IPhysicalEntity* pPhysicalEntity) const;
  195.  
  196.         /// These are only used during path adjustment. However, if we were told to store debug then they won't
  197.         /// be cleared afterwards, and can get drawn using DrawPathAdjustmentShapes
  198.         TPathObstacles m_combinedObstacles;
  199.         TPathObstacles m_simplifiedObstacles;
  200.  
  201.         /// time that CalculateObstaclesAroundActor was last called (and a cached result wasn't used)
  202.         CTimeValue m_lastCalculateTime;
  203.         /// Our position when CalculateObstaclesAroundActor was last called (and a cached result wasn't used)
  204.         Vec3       m_lastCalculatePos;
  205.         /// version number of the path when last called (since the result depends on the path)
  206.         int        m_lastCalculatePathVersion;
  207.  
  208.         /// size of the cache of obstacle shapes
  209.         static int s_obstacleCacheSize;
  210.         typedef std::vector<struct SCachedObstacle*> TCachedObstacles;
  211.         /// cached obstacle shapes - so that the most recently used is at the back.
  212.         static TCachedObstacles s_cachedObstacles;
  213.  
  214.         static TPathObstacles   s_pathObstacles;
  215.  
  216.         typedef std::map<EntityId, bool> TCachedDynamicObstacleFlags;
  217.         static TCachedDynamicObstacleFlags s_dynamicObstacleFlags;
  218.         static const int                   s_maxDynamicObstacleFlags = 256;
  219.  
  220.         /// If there is a cached record for entity/extraRadius and its position matches the entity position then it will
  221.         /// be returned, and the cache reordered.
  222.         /// If the cached entity is found and its position doesn't match the cache will be removed and 0 returned
  223.         /// If the cached entity isn't found 0 will be returned.
  224.         static struct SCachedObstacle* GetOrClearCachedObstacle(IPhysicalEntity* entity, float extraRadius);
  225.         /// pushes a obstacle into the cache, and takes ownership of it. obstacle should have been created
  226.         /// on the heap
  227.         static void                    AddCachedObstacle(struct SCachedObstacle* obstacle);
  228.         static struct SCachedObstacle* GetNewCachedObstacle();
  229. public:
  230.         // debug for path adjustment
  231.         bool AddEntityBoxesToObstacles(IPhysicalEntity* entity, TPathObstacles& obstacles, float extraRadius, float terrainZ, const bool debug) const;
  232.         void DebugDraw() const;
  233.         struct SDebugBox
  234.         {
  235.                 OBB  obb;
  236.                 Quat q;
  237.                 Vec3 pos;
  238.         };
  239. #ifdef PATHOBSTACLES_DEBUG
  240.         mutable std::vector<SDebugBox> m_debugPathAdjustmentBoxes;
  241. #endif
  242. };
  243.  
  244. #endif
  245.  
downloadPathObstacles.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top