BVB Source Codes

CRYENGINE Show OffMeshNavigationManager.h Source code

Return Download CRYENGINE: download OffMeshNavigationManager.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef __OFFMESH_NAVIGATION_MANAGER_H__
  4. #define __OFFMESH_NAVIGATION_MANAGER_H__
  5.  
  6. #pragma once
  7.  
  8. #include <CryAISystem/INavigationSystem.h>
  9. #include <CryAISystem/IOffMeshNavigationManager.h>
  10. #include "../MNM/OffGridLinks.h"
  11.  
  12. class CSmartObject;
  13. class CSmartObjectClass;
  14.  
  15. //////////////////////////////////////////////////////////////////////////
  16. /// OffMesh Navigation Manager
  17. /// Keeps track of off-mesh navigation objects associated to each navigation mesh
  18. /// and all the smart-objects which can generate off-mesh connections
  19. ///
  20. /// Interfaces also with the Navigation System, to update the right objects
  21. /// when meshes are created, updated or deleted
  22. //////////////////////////////////////////////////////////////////////////
  23. class OffMeshNavigationManager : public IOffMeshNavigationManager
  24. {
  25. private:
  26.         struct SLinkInfo
  27.         {
  28.                 SLinkInfo() {}
  29.                 SLinkInfo(NavigationMeshID _meshId, MNM::TriangleID _startTriangleID, MNM::TriangleID _endTriangleID, MNM::OffMeshLinkPtr _offMeshLink)
  30.                         : meshID(_meshId)
  31.                         , startTriangleID(_startTriangleID)
  32.                         , endTriangleID(_endTriangleID)
  33.                         , offMeshLink(_offMeshLink)
  34.                 {}
  35.  
  36.                 bool operator==(const NavigationMeshID _meshID) const
  37.                 {
  38.                         return (meshID == _meshID);
  39.                 }
  40.  
  41.                 NavigationMeshID    meshID;
  42.                 MNM::TriangleID     startTriangleID;
  43.                 MNM::TriangleID     endTriangleID;
  44.                 MNM::OffMeshLinkPtr offMeshLink;
  45.         };
  46.  
  47.         struct SObjectMeshInfo
  48.         {
  49.                 SObjectMeshInfo(NavigationMeshID _meshId)
  50.                         : meshID(_meshId)
  51.                 {
  52.  
  53.                 }
  54.  
  55.                 bool operator==(const NavigationMeshID _meshID)
  56.                 {
  57.                         return (meshID == _meshID);
  58.                 }
  59.  
  60.                 typedef std::vector<MNM::TriangleID> TTriangleList;
  61.                 TTriangleList    triangleList;
  62.                 NavigationMeshID meshID;
  63.         };
  64.         typedef std::vector<SObjectMeshInfo> TObjectInfo;
  65.  
  66. public:
  67. #if DEBUG_MNM_ENABLED
  68.         struct ProfileMemoryStats
  69.         {
  70.                 ProfileMemoryStats()
  71.                         : linkInfoSize(0)
  72.                         , totalSize(0)
  73.                 {
  74.                 }
  75.  
  76.                 size_t linkInfoSize;      // SLinkInfo
  77.                 size_t totalSize;         // currently redundant, but good for easier extension in the future
  78.         };
  79. #endif
  80.  
  81. public:
  82.         OffMeshNavigationManager(const int offMeshMapSize);
  83.  
  84.         const MNM::OffMeshNavigation& GetOffMeshNavigationForMesh(const NavigationMeshID& meshID) const;
  85.  
  86.         //Note: Try to kill this one, outside should never manipulate this
  87.         // Needs to make a lot of code in SmartObjects const correct first...
  88.         MNM::OffMeshNavigation& GetOffMeshNavigationForMesh(const NavigationMeshID& meshID);
  89.  
  90.         void                    RegisterSmartObject(CSmartObject* pSmartObject, CSmartObjectClass* pSmartObjectClass);
  91.         void                    UnregisterSmartObjectForAllClasses(CSmartObject* pSmartObject);
  92.  
  93.         void                    RefreshConnections(const NavigationMeshID meshID, const MNM::TileID tileID);
  94.         void                    Clear();
  95.         void                    Enable();
  96.  
  97.         void                    OnNavigationMeshCreated(const NavigationMeshID& meshID);
  98.         void                    OnNavigationMeshDestroyed(const NavigationMeshID& meshID);
  99.         void                    OnNavigationLoadedComplete();
  100.  
  101.         bool                    IsObjectLinkedWithNavigationMesh(const EntityId objectId) const;
  102.  
  103.         // IOffMeshNavigationManager
  104.         virtual void                    QueueCustomLinkAddition(const MNM::LinkAdditionRequest& request) override;
  105.         virtual void                    QueueCustomLinkRemoval(const MNM::LinkRemovalRequest& request) override;
  106.         virtual MNM::OffMeshLink*       GetOffMeshLink(const MNM::OffMeshLinkID& linkID) override;
  107.         virtual const MNM::OffMeshLink* GetOffMeshLink(const MNM::OffMeshLinkID& linkID) const override;
  108.         virtual void                    RegisterListener(IOffMeshNavigationListener* pListener, const char* listenerName) override;
  109.         virtual void                    UnregisterListener(IOffMeshNavigationListener* pListener) override;
  110.         virtual void                    RemoveAllQueuedAdditionRequestForEntity(const EntityId requestOwner) override;
  111.         // ~IOffMeshNavigationManager
  112.  
  113.         void ProcessQueuedRequests();
  114.  
  115. #if DEBUG_MNM_ENABLED
  116.         void               UpdateEditorDebugHelpers();
  117.         ProfileMemoryStats GetMemoryStats(ICrySizer* pSizer, const NavigationMeshID meshID) const;
  118. #else
  119.         void               UpdateEditorDebugHelpers() {};
  120. #endif
  121.  
  122. private:
  123.         bool       AddCustomLink(const NavigationMeshID& meshID, MNM::OffMeshLinkPtr& pLinkData, MNM::OffMeshLinkID& linkID, const bool bCloneLinkData);
  124.         void       RemoveCustomLink(const MNM::OffMeshLinkID& linkID);
  125.  
  126.         bool       IsLinkRemovalRequested(const MNM::OffMeshLinkID& linkID) const;
  127.  
  128.         void       UnregisterSmartObject(CSmartObject* pSmartObject, const string& smartObjectClassName);
  129.  
  130.         bool       ObjectRegistered(const EntityId objectId, const string& smartObjectClassName) const;
  131.         ILINE bool CanRegisterObject() const { return m_objectRegistrationEnabled; };
  132.  
  133.         void       NotifyAllListenerAboutLinkAddition(const MNM::OffMeshLinkID& linkID);
  134.         void       NotifyAllListenerAboutLinkDeletion(const MNM::OffMeshLinkID& linkID);
  135.  
  136.         // For every navigation mesh, there will be always an off-mesh navigation object
  137.         typedef id_map<uint32, MNM::OffMeshNavigation> TOffMeshMap;
  138.         TOffMeshMap            m_offMeshMap;
  139.  
  140.         MNM::OffMeshNavigation m_emptyOffMeshNavigation;
  141.  
  142.         // Tracking of objects registered
  143.         // All registered objects are stored here, and some additional data
  144.         // like to witch mesh they belong (only one), or bound triangles/tiles
  145.         struct OffMeshLinkIDList
  146.         {
  147.                 typedef std::vector<MNM::OffMeshLinkID> TLinkIDList;
  148.  
  149.                 TLinkIDList&       GetLinkIDList()       { return offMeshLinkIDList; }
  150.                 const TLinkIDList& GetLinkIDList() const { return offMeshLinkIDList; }
  151.  
  152.                 void               OnLinkAdditionRequestForSmartObjectServiced(const MNM::SOffMeshOperationCallbackData& callbackData)
  153.                 {
  154.                         if (callbackData.operationSucceeded)
  155.                         {
  156.                                 assert(callbackData.linkID != MNM::Constants::eOffMeshLinks_InvalidOffMeshLinkID);
  157.                                 offMeshLinkIDList.push_back(callbackData.linkID);
  158.                         }
  159.                 }
  160.                 void               OnLinkRepairRequestForSmartObjectServiced(const MNM::SOffMeshOperationCallbackData& callbackData)
  161.                 {
  162.                         if (!callbackData.operationSucceeded)
  163.                         {
  164.                                 auto it = std::find(offMeshLinkIDList.begin(), offMeshLinkIDList.end(), callbackData.linkID);
  165.                                 assert(it != offMeshLinkIDList.end());
  166.                                 if (it != offMeshLinkIDList.end())
  167.                                 {
  168.                                         offMeshLinkIDList.erase(it);
  169.                                 }
  170.                         }
  171.                 }
  172.  
  173.         private:
  174.                 TLinkIDList offMeshLinkIDList;
  175.         };
  176.  
  177.         typedef stl::STLPoolAllocator<std::pair<const uint32, OffMeshLinkIDList>, stl::PoolAllocatorSynchronizationSinglethreaded> TSOClassInfoAllocator;
  178.         typedef std::map<uint32, OffMeshLinkIDList, std::less<uint32>, TSOClassInfoAllocator>             TSOClassInfo;
  179.         typedef std::map<EntityId, TSOClassInfo>                                                          TRegisteredObjects;
  180.  
  181.         OffMeshLinkIDList* GetClassInfoFromLinkInfo(const SLinkInfo& linkInfo);
  182.  
  183.         TRegisteredObjects m_registeredObjects;
  184.  
  185.         // List of registered links
  186.         typedef std::map<MNM::OffMeshLinkID, SLinkInfo> TLinkInfoMap;
  187.         TLinkInfoMap m_links;
  188.  
  189.         bool         m_objectRegistrationEnabled;
  190.  
  191.         typedef std::list<MNM::OffMeshOperationRequestBase> Operations; // it's a list to safely allow queuing further operations from their callbacks while the queue is being processed
  192.         Operations m_operations;
  193.  
  194.         typedef CListenerSet<IOffMeshNavigationListener*> Listeners;
  195.         Listeners m_listeners;
  196. };
  197.  
  198. #endif  //__OFFMESH_NAVIGATION_MANAGER_H__
  199.  
downloadOffMeshNavigationManager.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