BVB Source Codes

CRYENGINE Show NavPath.h Source code

Return Download CRYENGINE: download NavPath.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:   NavPath.h
  6.    $Id$
  7.    Description:
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 13:1:2005   15:53 : Created by Kirill Bulatsev
  12.  
  13.  *********************************************************************/
  14. #ifndef __NavPath_H__
  15. #define __NavPath_H__
  16.  
  17. #if _MSC_VER > 1000
  18.         #pragma once
  19. #endif
  20.  
  21. #include <CryAISystem/IAgent.h>
  22. #include <CryNetwork/SerializeFwd.h>
  23. #include "AILog.h"
  24. #include "PathObstacles.h"
  25.  
  26. #include <CryMath/Cry_Color.h>
  27.  
  28. #include <list>
  29.  
  30. #include <CryAISystem/IPathfinder.h>
  31.  
  32. //====================================================================
  33. // CNavPath
  34. //====================================================================
  35. class CNavPath : public INavPath
  36. {
  37. public:
  38.         CNavPath();
  39.         virtual ~CNavPath();
  40.  
  41.         NavigationMeshID GetMeshID() const override;
  42.  
  43.         /// returns the path version - this is incremented every time the
  44.         /// path is modified (wrapping around is unlikely to be a problem!)
  45.         int GetVersion() const override { return m_version.v; }
  46.  
  47.         /// Set the path version, should not normally be used.
  48.         virtual void SetVersion(int v) override { m_version.v = v; }
  49.  
  50.         /// The original parameters used to generate the path will be stored
  51.         virtual void                  SetParams(const SNavPathParams& params) override { m_params = params; }
  52.         virtual const SNavPathParams& GetParams() const override                       { return m_params; }
  53.         virtual SNavPathParams&       GetParams() override                             { return m_params; }
  54.  
  55.         void                          Draw(const Vec3& drawOffset = Vec3Constants<float>::fVec3_Zero) const override;
  56.         void                          Dump(const char* name) const override;
  57.         // gets distance from the current path point to the end of the path - needs to
  58.         // be told if this path should be traversed as if it's in 2D
  59.         virtual float GetPathLength(bool b2D) const override;
  60.  
  61.         /// Add a point to the front of the path
  62.         void PushFront(const PathPointDescriptor& newPathPoint, bool force = false) override;
  63.  
  64.         /// Add a point to the back of the path
  65.         void PushBack(const PathPointDescriptor& newPathPoint, bool force = false) override;
  66.  
  67.         /// Clear all the path. dbgString can be used to indicate the calling context
  68.         /// If this path is owned by an object that might need to free smart-object
  69.         /// resources when the path is cleared, then clearing the path should be done
  70.         /// via CPipeUser::ClearPath()
  71.         void Clear(const char* dbgString) override;
  72.  
  73.         /// removes the current previous point (shifting all points) and sets nextPathPoint to the
  74.         /// new next path point (if it's available). If there are no points remaining, then returns false,
  75.         /// and the path will be left with just the path end
  76.         bool Advance(PathPointDescriptor& nextPathPoint) override;
  77.  
  78.         /// Indicates if this path finishes at approx the location that was requested, or
  79.         /// if it uses some other end position (e.g. from a partial path)
  80.         bool GetPathEndIsAsRequested() const override   { return m_pathEndIsAsRequested; }
  81.         void SetPathEndIsAsRequested(bool val) override { m_pathEndIsAsRequested = val; }
  82.  
  83.         /// Returns true if the path contains so few points it's not useable (returns false if 2 or more)
  84.         bool                       Empty() const override;
  85.         /// end of the path - returns 0 if empty
  86.         const PathPointDescriptor* GetLastPathPoint() const override     { return m_pathPoints.empty() ? 0 : &m_pathPoints.back(); }
  87.         /// previous path point - returns 0 if not available
  88.         const PathPointDescriptor* GetPrevPathPoint() const override     { return m_pathPoints.empty() ? 0 : &m_pathPoints.front(); }
  89.         /// next path point - returns 0 if not available
  90.         const PathPointDescriptor* GetNextPathPoint() const override     { return m_pathPoints.size() > 1 ? &(*(++m_pathPoints.begin())) : 0; }
  91.         /// next but 1 path point - returns 0 if not available
  92.         const PathPointDescriptor* GetNextNextPathPoint() const override { return m_pathPoints.size() > 2 ? &(*(++(++m_pathPoints.begin()))) : 0; }
  93.  
  94.         /// Gets the position of next path point. Returns defaultPos if the path is empty
  95.         const Vec3& GetNextPathPos(const Vec3& defaultPos = Vec3Constants<float>::fVec3_Zero) const override { const PathPointDescriptor* ppd = GetNextPathPoint(); return ppd ? ppd->vPos : defaultPos; }
  96.         /// Gets the end of the path. Returns defaultPos if the path is empty
  97.         const Vec3& GetLastPathPos(const Vec3& defaultPos = Vec3Constants<float>::fVec3_Zero) const override { const PathPointDescriptor* ppd = GetLastPathPoint(); return ppd ? ppd->vPos : defaultPos; }
  98.  
  99.         /// Returns the point that is dist ahead on the path, extrapolating if necessary.
  100.         /// Fills nextPointType with the nav type of the next point in the path from the given distance.
  101.         /// Returns false if there is no path points at all
  102.         bool GetPosAlongPath(Vec3& posOut, float dist = 0.f, bool b2D = false, bool bExtrapolateBeyondEnd = false, IAISystem::ENavigationType* pNextPointType = NULL) const override;
  103.  
  104.         /// Returns the distance from pos to the closest point on the path, looking a maximum of dist ahead.
  105.         /// Also the closest point, and the distance it is along the path are returned.
  106.         /// Returns -1 if there's no path.
  107.         /// Note that this starts from the start of the path, NOT the current position
  108.         float GetDistToPath(Vec3& pathPosOut, float& distAlongPathOut, const Vec3& pos, float dist, bool twoD) const override;
  109.  
  110.         /// Returns the closest direction to the current path and a given point.
  111.         void GetDirectionToPathFromPoint(const Vec3& point, Vec3& dirOut) const;
  112.  
  113.         /// Returns the distance along the path from the current look-ahead position to the
  114.         /// first smart object path segment. If there's no path, or no smart objects on the
  115.         /// path, then std::numeric_limits<float>::max() will be returned
  116.         float GetDistToSmartObject(bool b2D) const override;
  117.  
  118.         /// Returns a pointer to a smartobject nav data if the last path point exists and
  119.         /// its traversal method is one of the animation methods.
  120.         PathPointDescriptor::SmartObjectNavDataPtr  GetLastPathPointAnimNavSOData() const override;
  121.         const PathPointDescriptor::OffMeshLinkData* GetLastPathPointMNNSOData() const;
  122.         /// Sets the value of the previous path point, if it exists
  123.         void                                        SetPreviousPoint(const PathPointDescriptor& previousPoint) override;
  124.  
  125.         const TPathPoints& GetPath() const override                          { return m_pathPoints; }
  126.  
  127.         virtual void       SetPathPoints(const TPathPoints& points) override { m_pathPoints = points; ++m_version.v; }
  128.  
  129.         /// Returns the max distance we can find from the start position and any point in the path
  130.         float GetMaxDistanceFromStart() const;
  131.  
  132.         /// Returns AABB containing all the path between the current position and dist ahead
  133.         AABB GetAABB(float dist) const override;
  134.  
  135.         /// Calculates the path position and direction and (approx) radius of curvature distAhead beyond the current iterator
  136.         /// position. If the this position would be beyond the path end then it extrapolates.
  137.         /// If scaleOutputWithDist is set then it scales the lowestPathDotOut according to how far along the
  138.         /// path it is compared to distAhead
  139.         /// Returns false if there's not enough path to do the calculation - true if all is
  140.         /// well.
  141.         bool GetPathPropertiesAhead(float distAhead, bool twoD, Vec3& posOut, Vec3& dirOut,
  142.                                     float* invROut, float& lowestPathDotOut, bool scaleOutputWithDist) const override;
  143.  
  144.         /// Serialise the current request
  145.         void        Serialize(TSerialize ser);
  146.  
  147.         const Vec3& GetEndDir() const override             { return m_endDir; }
  148.         void        SetEndDir(const Vec3& endDir) override { m_endDir = endDir; }
  149.  
  150.         /// Obtains a new target direction and approximate distance to the path end (for speed control). Also updates
  151.         /// the current position along the path.
  152.         ///
  153.         /// isResolvingSticking indicates if the algorithm is trying to resolve agent sticking.
  154.         /// distToPathOut indicates the approximate perpendicular distance the agent is from the path.
  155.         /// pathDirOut, pathAheadPosOut and pathAheadDirOut are the path directions/position at the current
  156.         /// and look-ahead positions
  157.         /// currentPos/Vel are the tracer's current position/velocity.
  158.         /// lookAhead is the look-ahead distance for smoothing the path.
  159.         /// pathRadius is the radius of the core part of the path - the narrower the
  160.         /// path the more constrained the lookahead will be at corners
  161.         /// dt is the time since last update (mainly used to detect the tracer
  162.         /// getting stuck).
  163.         /// resolveSticking indicates if getting stuck should be handled - handling is
  164.         /// done by limiting the lookahead which can confuse vehicles that use
  165.         /// manouevering.
  166.         /// twoD indicates if this should work in 2D
  167.         /// Return value indicates if we're still tracing the path - false means we reached the end
  168.         bool UpdateAndSteerAlongPath(Vec3& dirOut, float& distToEndOut, float& distToPathOut, bool& isResolvingSticking,
  169.                                      Vec3& pathDirOut, Vec3& pathAheadDirOut, Vec3& pathAheadPosOut, Vec3 currentPos, const Vec3& currentVel,
  170.                                      float lookAhead, float pathRadius, float dt, bool resolveSticking, bool twoD) override;
  171.  
  172.         /// Iterates over the path and fills the navigation methods for the path segments.
  173.         /// Cuts the path at the path point where the next navSO animation should be played.
  174.         /// The trace goalop will follow the path and play the animation at the target location
  175.         /// and then regenerate the path to the target.
  176.         void PrepareNavigationalSmartObjectsForMNM(IAIPathAgent* pAgent);
  177.         /// Reinstates the path removed during the last PrepareNavigationalSmartObjects()
  178.         void ResurrectRemainingPath();
  179.  
  180.         /// trim the path to specified length.
  181.         void TrimPath(float length, bool twoD) override;
  182.  
  183.         /// after the path is being cut on smart object this function
  184.         /// can tell the length of the discarded path section
  185.         float GetDiscardedPathLength() const override { return m_fDiscardedPathLength; }
  186.  
  187.         /// Adjusts the path (or what's left of it) to steer it around the obstacles passed in.
  188.         /// These obstacles should already have been expanded if necessary to allow for pass
  189.         /// radius. Returns false if there was no way to adjust the path (in which case the path
  190.         /// may be partially adjusted)
  191.         bool AdjustPathAroundObstacles(const CPathObstacles& obstacles, IAISystem::tNavCapMask navCapMask);
  192.         bool AdjustPathAroundObstacles(const Vec3& currentpos, const AgentMovementAbility& movementAbility) override;
  193.  
  194.         /// Advances path state until it represents agentPos. If allowPathToFinish = false then
  195.         /// it won't allow the path to finish
  196.         /// Returns the remaining path length
  197.         float UpdatePathPosition(Vec3 agentPos, float pathLookahead, bool twoD, bool allowPathToFinish) override;
  198.  
  199.         /// Calculates a target position which is lookAhead along the path,
  200.         Vec3 CalculateTargetPos(Vec3 agentPos, float lookAhead, float minLookAheadAlongPath, float pathRadius, bool twoD) const override;
  201.         /// Returns true if the path can be modified to use request.targetPoint, and byproducts
  202.         /// of the test are cached in request.
  203.         ETriState CanTargetPointBeReached(CTargetPointRequest& request, const CAIActor* pAIActor, bool twoD) const override;
  204.         /// Returns true if the request is still valid/can be used, false otherwise.
  205.         bool      UseTargetPointRequest(const CTargetPointRequest& request, CAIActor* pAIActor, bool twoD) override;
  206.  
  207. private:
  208.         // Hiding these virtual methods here, so they are only accessible through the INavPath interface
  209.         // (i.e. Outside the AISystem module)
  210.         virtual void Release() override { delete this; };
  211.         virtual void CopyTo(INavPath* pRecipient) const override
  212.         {
  213.                 *static_cast<CNavPath*>(pRecipient) = *this;
  214.         }
  215.         virtual INavPath* Clone() const override
  216.         {
  217.                 return new CNavPath(*this);
  218.         };
  219.  
  220.         /// Makes the path avoid a single obstacle - return false if this is impossible.
  221.         /// It only works on m_pathPoints.
  222.         bool  AdjustPathAroundObstacle(const CPathObstacle& obstacle, IAISystem::tNavCapMask navCapMask);
  223.         bool  AdjustPathAroundObstacleShape2D(const SPathObstacleShape2D& obstacle, IAISystem::tNavCapMask navCapMask);
  224.         bool  CheckPath(const TPathPoints& pathList, float radius) const;
  225.         void  MovePathEndsOutOfObstacles(const CPathObstacles& obstacles);
  226.  
  227.         float GetPathDeviationDistance(Vec3& deviationOut, float criticalDeviation, bool twoD);
  228.  
  229.         TPathPoints m_pathPoints;
  230.         Vec3        m_endDir;
  231.  
  232.         struct SDebugLine
  233.         {
  234.                 Vec3   P0, P1;
  235.                 ColorF col;
  236.         };
  237.         void DebugLine(const Vec3& P0, const Vec3& P1, const ColorF& col) const;
  238.         mutable std::list<SDebugLine> m_debugLines;
  239.  
  240.         struct SDebugSphere
  241.         {
  242.                 Vec3   pos;
  243.                 float  r;
  244.                 ColorF col;
  245.         };
  246.         void DebugSphere(const Vec3& P, float r, const ColorF& col) const;
  247.         mutable std::list<SDebugSphere> m_debugSpheres;
  248.  
  249.         /// the current position on the path between previous and current point
  250.         float m_currentFrac;
  251.  
  252.         /// How long we've been stuck for - used to reduce the lookAhead
  253.         float m_stuckTime;
  254.  
  255.         /// Indicates if this path finishes at approx the location that was requested, or
  256.         /// if it uses some other end position (e.g. from a partial path)
  257.         bool m_pathEndIsAsRequested;
  258.  
  259.         /// parameters used to generate the request - in case the requester wants to regenerate
  260.         /// it
  261.         SNavPathParams m_params;
  262.  
  263.         /// the length of the path segment discarded after a smart object
  264.         float          m_fDiscardedPathLength;
  265.         TPathPoints    m_remainingPathPoints; // Path points that were discarded (saved to avoid regenerating the path)
  266.  
  267.         CPathObstacles m_obstacles; // Marcio: Crysis2
  268.  
  269.         /// Lets other things track when we've changed
  270.         /// also we change version when copied!
  271.         struct SVersion
  272.         {
  273.                 int v;
  274.                 void operator=(const SVersion& other) { v = other.v + 1; }
  275.                 SVersion() : v(-1) {}
  276.                 void Serialize(TSerialize ser);
  277.         };
  278.         SVersion m_version;
  279. };
  280.  
  281. #endif // __NavPath_H__
  282.  
downloadNavPath.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