BVB Source Codes

CRYENGINE Show MovementPlanner.h Source code

Return Download CRYENGINE: download MovementPlanner.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #pragma once
  4.  
  5. #ifndef MovementPlanner_h
  6.         #define MovementPlanner_h
  7.  
  8.         #include "MovementPlan.h"
  9.         #include <CryAISystem/MovementRequest.h>
  10.  
  11. struct MovementActor;
  12. struct MovementUpdateContext;
  13.  
  14. namespace Movement
  15. {
  16. // The planner takes a movement request and tries to come up with
  17. // a plan to satisfy it. It will also execute the plan and report
  18. // when it has been satisfied.
  19. struct IPlanner
  20. {
  21.         class Status
  22.         {
  23.         public:
  24.                 Status()
  25.                         : m_requestId()
  26.                         , m_requestSatisfied(false)
  27.                         , m_pathfinderFailed(false)
  28.                         , m_movingAlongPathFailed(false)
  29.                         , m_reachedMaxNumberOfReplansAllowed(false)
  30.                 {}
  31.  
  32.                 void SetRequestSatisfied(const MovementRequestID& requestId)
  33.                 {
  34.                         m_requestSatisfied = true;
  35.                         m_requestId = requestId;
  36.                 }
  37.                 void SetPathfinderFailed(const MovementRequestID& requestId)
  38.                 {
  39.                         m_pathfinderFailed = true;
  40.                         m_requestId = requestId;
  41.                 }
  42.                 void SetMovingAlongPathFailed(const MovementRequestID& requestId)
  43.                 {
  44.                         m_movingAlongPathFailed = true;
  45.                         m_requestId = requestId;
  46.                 }
  47.                 void SetReachedMaxAllowedReplans(const MovementRequestID& requestId)
  48.                 {
  49.                         m_reachedMaxNumberOfReplansAllowed = true;
  50.                         m_requestId = requestId;
  51.                 }
  52.  
  53.                 bool                     HasRequestBeenSatisfied() const                    { return m_requestSatisfied; }
  54.                 bool                     HasPathfinderFailed() const                        { return m_pathfinderFailed; }
  55.                 bool                     HasMovingAlongPathFailed() const                   { return m_movingAlongPathFailed; }
  56.                 bool                     HasReachedTheMaximumNumberOfReplansAllowed() const { return m_reachedMaxNumberOfReplansAllowed; }
  57.  
  58.                 const MovementRequestID& GetRequestId() const                               { return m_requestId; }
  59.  
  60.         private:
  61.                 MovementRequestID m_requestId;
  62.                 bool              m_requestSatisfied;
  63.                 bool              m_pathfinderFailed;
  64.                 bool              m_movingAlongPathFailed;
  65.                 bool              m_reachedMaxNumberOfReplansAllowed;
  66.         };
  67.  
  68.         virtual ~IPlanner() {}
  69.  
  70.         // The controller will be updated and kept alive while this is true.
  71.         virtual bool IsUpdateNeeded() const = 0;
  72.  
  73.         // Called when the movement system has some work for the planner.
  74.         // Only called when 'IsReadyForNewRequest' returns true.
  75.         virtual void StartWorkingOnRequest(const MovementRequestID& requestId, const MovementRequest& request, const MovementUpdateContext& context) = 0;
  76.  
  77.         // The movement system calls this when the actor is no longer
  78.         // interested in satisfying the request the planner is working on.
  79.         // Note: This doesn't mean that the actor wants to stop! The planner
  80.         // may continue executing the plan until a new request comes in.
  81.         virtual void CancelCurrentRequest(MovementActor& actor) = 0;
  82.  
  83.         // Do some work and report back the 'Status' of the current request.
  84.         virtual Status Update(const MovementUpdateContext& context) = 0;
  85.  
  86.         // Checked before 'StartWorkingOnRequest' is called. The planner might
  87.         // be in the middle of something and mustn't be disturbed right now.
  88.         virtual bool IsReadyForNewRequest() const = 0;
  89.  
  90.         // Fill in the 'status' object and explain what's currently
  91.         // being worked on. It's very handy for debugging.
  92.         virtual void GetStatus(MovementRequestStatus& status) const = 0;
  93. };
  94.  
  95. // This generic movement planner will be able to these satisfy requests:
  96. // - Move to position in open space
  97. // - Move to cover
  98. // - Move along path
  99. // It will take care of leaving the cover before moving to a position.
  100. class GenericPlanner : public IPlanner
  101. {
  102. public:
  103.         explicit GenericPlanner(NavigationAgentTypeID navigationAgentTypeID);
  104.         ~GenericPlanner();
  105.         virtual bool   IsUpdateNeeded() const override;
  106.         virtual void   StartWorkingOnRequest(const MovementRequestID& requestId, const MovementRequest& request, const MovementUpdateContext& context) override;
  107.         virtual void   CancelCurrentRequest(MovementActor& actor) override;
  108.         virtual Status Update(const MovementUpdateContext& context) override;
  109.         virtual bool   IsReadyForNewRequest() const override;
  110.         virtual void   GetStatus(MovementRequestStatus& status) const override;
  111.  
  112. private:
  113.         void CheckOnPathfinder(const MovementUpdateContext& context, OUT Status& status);
  114.         void ExecuteCurrentPlan(const MovementUpdateContext& context, OUT Status& status);
  115.         void ProducePlan(const MovementUpdateContext& context);
  116.         void ProduceMoveToPlan(const MovementUpdateContext& context);
  117.         void ProduceStopPlan(const MovementUpdateContext& context);
  118.         bool CanReplan(const MovementRequest& request) const;
  119.         void StartWorkingOnRequest_Internal(const MovementRequestID& requestId, const MovementRequest& request, const MovementUpdateContext& context);
  120.         void OnNavigationMeshChanged(NavigationAgentTypeID navigationAgentTypeID, NavigationMeshID meshID, uint32 tileID);
  121.         void CheckForNeedToPathReplanningDueToNavMeshChanges(const MovementUpdateContext& context);
  122.  
  123. private:
  124.         /// Tiles that were affected by NavMesh changes
  125.         struct MeshIDAndTileID
  126.         {
  127.                 const NavigationMeshID meshID;
  128.                 const MNM::TileID      tileID;
  129.  
  130.                 explicit MeshIDAndTileID(NavigationMeshID _meshID, const MNM::TileID _tileID) : meshID(_meshID), tileID(_tileID) {}
  131.                 bool operator==(const MeshIDAndTileID& rhs) const { return (this->tileID == rhs.tileID) && (this->meshID == rhs.meshID); }
  132.         };
  133.  
  134.         // Reasons for potential path-replanning
  135.         struct SPendingPathReplanning
  136.         {
  137.                 bool bNavMeshChanged;              // the NavMesh changed and some (or all) of its changes affect the path we're currently moving along
  138.                 bool bSuddenNonInterruptibleBlock; // the pathfinder returned a path after a previously interruptible block suddenly became non-interruptible (can happen when the UseSmartObject transitions from its internal "Prepare" state to "Traverse")
  139.  
  140.                 SPendingPathReplanning()
  141.                 {
  142.                         Clear();
  143.                 }
  144.  
  145.                 void Clear()
  146.                 {
  147.                         bNavMeshChanged = bSuddenNonInterruptibleBlock = false;
  148.                 }
  149.  
  150.                 bool IsPending() const
  151.                 {
  152.                         return bNavMeshChanged || bSuddenNonInterruptibleBlock;
  153.                 }
  154.         };
  155.  
  156.         const NavigationAgentTypeID  m_navigationAgentTypeID;
  157.         std::vector<MeshIDAndTileID> m_queuedNavMeshChanges;
  158.         SPendingPathReplanning       m_pendingPathReplanning;   // dirty-flag to automatically re-path as soon as the possibly existing plan allows for it again
  159.         Plan                         m_plan;
  160.         MovementRequestID            m_requestId;
  161.         MovementRequest              m_request;
  162.         uint8                        m_replanningAfterFailCount;
  163.         bool                         m_pathfinderRequestQueued;
  164.         const static uint8           s_maxAllowedReplanning = 3;
  165. };
  166. }
  167.  
  168. #endif // MovementPlanner_h
  169.  
downloadMovementPlanner.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