BVB Source Codes

CRYENGINE Show Navigation.h Source code

Return Download CRYENGINE: download Navigation.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:   Navigation.h
  6.    $Id$
  7.    Description: interface for the CGraph class.
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - ?
  12.    - 4 May 2009   : Evgeny Adamenkov: Removed IRenderer
  13.  
  14.  *********************************************************************/
  15.  
  16. #ifndef NAVIGATION_H
  17. #define NAVIGATION_H
  18.  
  19. #include <CryAISystem/INavigation.h>
  20. #include "CTriangulator.h"
  21.  
  22. struct SpecialArea
  23. {
  24.         // (MATT) Note that this must correspond exactly to the enum in the Editor's Navigation.h {2009/06/17}
  25.         enum EType
  26.         {
  27.                 TYPE_WAYPOINT_HUMAN,
  28.                 TYPE_VOLUME,
  29.                 TYPE_FLIGHT,
  30.                 TYPE_WATER,
  31.                 TYPE_WAYPOINT_3DSURFACE,
  32.                 TYPE_FREE_2D,
  33.                 TYPE_TRIANGULATION,
  34.                 TYPE_LAYERED_NAV_MESH,
  35.                 TYPE_FLIGHT2,
  36.         };
  37.  
  38.         void SetPolygon(const ListPositions& polygon)
  39.         {
  40.                 lstPolygon = polygon;
  41.                 CalcAABB();
  42.         }
  43.         const ListPositions& GetPolygon() const
  44.         {
  45.                 return lstPolygon;
  46.         }
  47.  
  48.         const AABB& GetAABB() const
  49.         {
  50.                 return aabb;
  51.         }
  52.  
  53.         SpecialArea::EType   type                : 6;
  54.         EWaypointConnections waypointConnections : 6;
  55.         EAILightLevel        lightLevel          : 4;
  56.         int16                nBuildingID;
  57.  
  58.         float                fMinZ;
  59.         float                fMaxZ;
  60.         float                fHeight;
  61.         float                fNodeAutoConnectDistance;
  62.  
  63.         bool                 bAltered     : 1;
  64.         bool                 bCritterOnly : 1;
  65.  
  66.         SpecialArea()
  67.                 : nBuildingID(-1)
  68.                 , type(SpecialArea::TYPE_WAYPOINT_HUMAN)
  69.                 , waypointConnections(WPCON_DESIGNER_NONE)
  70.                 , fNodeAutoConnectDistance(.0f)
  71.                 , bAltered(false)
  72.                 , bCritterOnly(false)
  73.                 , lightLevel(AILL_NONE)
  74.         {
  75.                 fMinZ = FLT_MAX;
  76.                 fMaxZ = -FLT_MAX;
  77.                 fHeight = 0.0f;
  78.  
  79.                 aabb.Reset();
  80.         }
  81.  
  82. private:
  83.         ListPositions lstPolygon;
  84.         AABB          aabb;
  85.  
  86.         void          CalcAABB()
  87.         {
  88.                 aabb.Reset();
  89.                 for (ListPositions::const_iterator it = lstPolygon.begin(); it != lstPolygon.end(); ++it)
  90.                         aabb.Add(*it);
  91.         }
  92. };
  93.  
  94. typedef std::map<string, int>    SpecialAreaNames;
  95. typedef std::vector<SpecialArea> SpecialAreas;
  96. typedef std::vector<int16>       FreeSpecialAreaIDs;
  97.  
  98. struct SExtraLinkCostShape
  99. {
  100.         SExtraLinkCostShape(const ListPositions& shape, const AABB& aabb, float costFactor) : shape(shape), aabb(aabb), costFactor(costFactor), origCostFactor(costFactor) {}
  101.         SExtraLinkCostShape(const ListPositions& shape, float costFactor) : shape(shape), costFactor(costFactor), origCostFactor(costFactor)
  102.         {
  103.                 aabb.Reset();
  104.                 for (ListPositions::const_iterator it = shape.begin(); it != shape.end(); ++it)
  105.                         aabb.Add(*it);
  106.         }
  107.         ListPositions shape;
  108.         AABB          aabb;
  109.         // the cost factor can get modified at run-time - it will get reset at the same time
  110.         // as graph links get reset etc
  111.         float costFactor;
  112.         float origCostFactor;
  113. };
  114.  
  115. typedef std::map<string, SExtraLinkCostShape> ExtraLinkCostShapeMap;
  116.  
  117. struct CutEdgeIdx
  118. {
  119.         int idx1;
  120.         int idx2;
  121.  
  122.         CutEdgeIdx(int i1, int i2)
  123.         {
  124.                 idx1 = i1;
  125.                 idx2 = i2;
  126.         }
  127. };
  128.  
  129. typedef std::vector<CutEdgeIdx> NewCutsVector;
  130.  
  131. class CCryBufferedFileReader;
  132. // FIXME Jan 30, 2008: <pvl> these should probably be members of their respective
  133. // classes they save, they need to be visible both in Navigation.cpp
  134. // CAISystem.cpp so let's put them here until refactored further.
  135. void ReadArea(CCryBufferedFileReader& file, int version, string& name, SpecialArea& sa);
  136. bool ReadForbiddenArea(CCryBufferedFileReader& file, int version, CAIShape* shape);
  137. #if defined(SEG_WORLD)
  138. bool ReadPolygonArea(CCryBufferedFileReader& file, int version, string& name, ListPositions& pts, const Vec3& vSegmentOffset);
  139. #else
  140. bool ReadPolygonArea(CCryBufferedFileReader& file, int version, string& name, ListPositions& pts);
  141. #endif
  142. void ReadExtraLinkCostArea(CCryBufferedFileReader& file, int version, string& name, SExtraLinkCostShape& shape);
  143.  
  144. class CNavRegion;
  145. class CFlightNavRegion;
  146. class CFlightNavRegion2;
  147. class CVolumeNavRegion;
  148. class CRoadNavRegion;
  149. class CFree2DNavRegion;
  150. class CSmartObjectNavRegion;
  151. class CCompositeLayeredNavMeshRegion;
  152. class CCustomNavRegion;
  153.  
  154. class CNavigation : public INavigation
  155. {
  156. public:
  157.         explicit CNavigation(ISystem* pSystem);
  158.         ~CNavigation();
  159.  
  160.         // INavigation
  161.         virtual uint32 GetPath(const char* szPathName, Vec3* points, uint32 maxpoints) const;
  162.         virtual float  GetNearestPointOnPath(const char* szPathName, const Vec3& vPos, Vec3& vResult, bool& bLoopPath, float& totalLength) const;
  163.         virtual void   GetPointOnPathBySegNo(const char* szPathName, Vec3& vResult, float segNo) const;
  164.         virtual bool   IsSegmentValid(IAISystem::tNavCapMask navCap, float rad, const Vec3& posFrom, Vec3& posTo, IAISystem::ENavigationType& navTypeFrom) const;
  165.         //~INavigation
  166.  
  167.         ILINE const SpecialAreas& GetSpecialAreas() const
  168.         {
  169.                 return m_specialAreas;
  170.         }
  171.  
  172.         const SpecialArea* GetSpecialArea(const Vec3& pos, SpecialArea::EType areaType);
  173.         // Gets the special area with a particular building ID - may return 0 if it cannot be found
  174.         const SpecialArea* GetSpecialArea(int buildingID) const;
  175.         const SpecialArea* GetSpecialArea(const char* name) const;
  176.         const SpecialArea* GetSpecialAreaNearestPos(const Vec3& pos, SpecialArea::EType areaType);
  177.         const char*        GetSpecialAreaName(int buildingID) const;
  178.  
  179.         typedef std::vector<std::pair<string, const SpecialArea*>> VolumeRegions;
  180.         /// Fills in the container of special areas that relate to 3D volumes
  181.         void            GetVolumeRegions(VolumeRegions& volumeRegions) const;
  182.         const ShapeMap& GetDesignerPaths() const { return m_mapDesignerPaths; }
  183.  
  184.         // copies a designer path into provided list if a path of such name is found
  185.         bool  GetDesignerPath(const char* szName, SShape& path) const;
  186.  
  187.         bool  Init();
  188.         void  Reset(IAISystem::EResetReason reason);
  189.         void  ShutDown();
  190.         void  FlushSystemNavigation(bool bDeleteAll);
  191.         // Gets called after loading the mission
  192.         void  OnMissionLoaded();
  193.         // // loads the triangulation for this level and mission
  194.         void  LoadNavigationData(const char* szLevel, const char* szMission);
  195.  
  196.         float GetDynamicLinkConnectionTimeModifier() const;
  197.         void  BumpDynamicLinkConnectionUpdateTime(float modifier, size_t durationFrames);
  198.  
  199.         void  Serialize(TSerialize ser);
  200.  
  201.         // reads (designer paths) areas from file. clears the existing areas
  202. #if defined(SEG_WORLD)
  203.         // SEG_WORLD: adds offset to the areas read, and doesn't clear existing areas.
  204.         void ReadAreasFromFile(CCryBufferedFileReader&, int fileVersion, const Vec3& vSegmentOffset);
  205. #else
  206.         void ReadAreasFromFile(CCryBufferedFileReader&, int fileVersion);
  207. #endif
  208.         void ReadAreasFromFile_Old(CCryBufferedFileReader&, int fileVersion);
  209.  
  210.         // Offsets all areas when segmented world shifts
  211.         void OffsetAllAreas(const Vec3& additionalOffset);
  212.  
  213.         void Update(CTimeValue currentTime, float frameTime);
  214.         void UpdateNavRegions();
  215.  
  216.         void          FlushAllAreas();
  217.         void          FlushSpecialAreas();
  218.  
  219.         void          InsertSpecialArea(const char* name, const SpecialArea& sa);
  220.         void          EraseSpecialArea(const char* name);
  221.  
  222.         /// This is just for debugging
  223.         const char* GetNavigationShapeName(int nBuildingID) const;
  224.         /// Checks if navigation shape exists - called by editor
  225.         bool        DoesNavigationShapeExists(const char* szName, EnumAreaType areaType, bool road = false);
  226.         bool        CreateNavigationShape(const SNavigationShapeParams& params);
  227.         /// Deletes designer created path/shape - called by editor
  228.         void        DeleteNavigationShape(const char* szName);
  229.         void        DisableModifier(const char* name);
  230.  
  231.         bool        IsPointInForbiddenRegion(const Vec3& pos, bool checkAutoGenRegions = true) const                    { return false; }
  232.         bool        IsPointInForbiddenRegion(const Vec3& pos, const CAIShape** ppShape, bool checkAutoGenRegions) const { return false; }
  233.         /// Returns true if the point is inside the nav modifiers marked out as containing water
  234.         bool        IsPointInWaterAreas(const Vec3& pt) const;
  235.         /// Indicates if a point is in a special area, checking the height too
  236.         static bool IsPointInSpecialArea(const Vec3& pos, const SpecialArea& sa);
  237.         /// returns true if pos is inside a TRIANGULATION nav modifier, or if there are no
  238.         /// such modifiers.
  239.         /// NOTE this must only be called in editor (since it shouldn't be needed in game) - will assert that
  240.         /// this is the case!
  241.         bool IsPointInTriangulationAreas(const Vec3& pos) const;
  242.         /// if there's intersection vClosestPoint indicates the intersection point, and the edge normal
  243.         /// is optionally returned. If bForceNormalOutwards is set then in the case of forbidden
  244.         /// boundaries this normal is chosen to point (partly) towards vStart.
  245.         /// nameToSkip can optionally point to a string indicating a forbidden area area to not check
  246.         /// mode indicates if areas and/or boundaries should be checked
  247.         virtual bool IntersectsForbidden(const Vec3& vStart, const Vec3& vEnd, Vec3& vClosestPoint, const string* nameToSkip = 0, Vec3* pNormal = NULL,
  248.                                          INavigation::EIFMode mode = INavigation::IF_AREASBOUNDARIES, bool bForceNormalOutwards = false) const { return false; }
  249.         virtual bool IntersectsForbidden(const Vec3& vStart, const Vec3& vEnd, float radius, INavigation::EIFMode mode = INavigation::IF_AREASBOUNDARIES) const { return false; }
  250.         /// Checks for intersection with special areas of given type
  251.         /// if there's intersection vClosestPoint indicates the intersection point
  252.         bool         IntersectsSpecialArea(const Vec3& start, const Vec3& end, Vec3& closestPoint, SpecialArea::EType type) const;
  253.  
  254.         virtual bool IsPathForbidden(const Vec3& start, const Vec3& end) const             { return false; }
  255.         virtual bool IsPointForbidden(const Vec3& pos, float tol, Vec3* pNormal = 0) const { return false; }
  256.         /// Get the best point outside any forbidden region given the input point,
  257.         /// and optionally a start position to stay close to
  258.         virtual Vec3 GetPointOutsideForbidden(Vec3& pos, float distance, const Vec3* startPos = 0) const;
  259.  
  260.         bool         GetBuildingInfo(int nBuildingID, IAISystem::SBuildingInfo& info) const;
  261.         bool         IsPointInBuilding(const Vec3& pos, int nBuildingID) const;
  262.  
  263.         /// Returns nearest designer created path/shape.
  264.         /// The devalue parameter specifies how long the path will be unusable by others after the query.
  265.         /// If useStartNode is true the start point of the path is used to select nearest path instead of the nearest point on path.
  266.         virtual const char* GetNearestPathOfTypeInRange(IAIObject* requester, const Vec3& pos, float range, int type, float devalue, bool useStartNode);
  267.  
  268.         void                DisableNavigationInBrokenRegion(std::vector<Vec3>& outline);
  269.  
  270.         virtual void        ModifyNavCostFactor(const char* navModifierName, float factor) {}
  271.         /// returns the names of the region files generated during volume generation
  272.         virtual void        GetVolumeRegionFiles(const char* szLevel, const char* szMission, DynArray<CryStringT<char>>& filenames) const;
  273.  
  274.         /// Returns the base-class nav region - needs the graph only if type is waypoint (so you can
  275.         /// pass in 0 if you know it's not... but be careful!)
  276.         CNavRegion*                GetNavRegion(IAISystem::ENavigationType type, const CGraph* pGraph) const;
  277.         const std::vector<float>&  Get3DPassRadii() const { return m_3DPassRadii; }
  278.         IAISystem::ENavigationType CheckNavigationType(const Vec3& pos, int& nBuildingID, IAISystem::tNavCapMask navCapMask) const;
  279.  
  280.         void                       GetMemoryStatistics(ICrySizer* pSizer);
  281.         size_t                     GetMemoryUsage() const;
  282.  
  283. #ifdef CRYAISYSTEM_DEBUG
  284.         void DebugDraw() const;
  285. #endif //CRYAISYSTEM_DEBUG
  286.  
  287. private:
  288.         // <NAV REGION STUFF>
  289.         /// used during 3D nav generation - the pass radii of the entities that will use the navigation
  290.         std::vector<float> m_3DPassRadii;
  291.         // </NAV REGION STUFF>
  292.  
  293.         // <AI SHAPE STUFF>
  294.         ShapeMap           m_mapDesignerPaths;
  295.         SpecialAreas       m_specialAreas; // define where to disable automatic AI processing.
  296.         FreeSpecialAreaIDs m_freeSpecialAreaIDs;
  297.         SpecialAreaNames   m_specialAreaNames; // to speed up GetSpecialArea() in game mode
  298.  
  299.         unsigned int       m_nNumBuildings;
  300.         // </NAV MODIFIER STUFF>
  301.  
  302.         struct SValidationErrorMarker
  303.         {
  304.                 SValidationErrorMarker(const string& msg, const Vec3& pos, const OBB& obb, ColorB col) : msg(msg), pos(pos), obb(obb), col(col) {}
  305.                 SValidationErrorMarker(const string& msg, const Vec3& pos, ColorB col) : msg(msg), pos(pos), col(col)
  306.                 {
  307.                         obb.SetOBBfromAABB(Matrix33(IDENTITY), AABB(Vec3(-0.1f, -0.1f, -0.1f), Vec3(0.1f, 0.1f, 0.1f)));
  308.                 }
  309.                 Vec3   pos;
  310.                 OBB    obb;
  311.                 string msg;
  312.                 ColorB col;
  313.         };
  314.  
  315.         std::vector<SValidationErrorMarker> m_validationErrorMarkers;
  316.  
  317.         //====================================================================
  318.         // Used during graph generation - should subsequently be empty
  319.         //====================================================================
  320.         CTriangulator*    m_pTriangulator;
  321.         std::vector<Tri*> m_vTriangles;
  322.         VARRAY            m_vVertices;
  323.  
  324.         float             m_dynamicLinkUpdateTimeBump;
  325.         size_t            m_dynamicLinkUpdateTimeBumpDuration;
  326.         size_t            m_dynamicLinkUpdateTimeBumpElapsed;
  327. };
  328.  
  329. #endif // NAVIGATION_H
  330.  
downloadNavigation.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