BVB Source Codes

CRYENGINE Show GoalOpTrace.h Source code

Return Download CRYENGINE: download GoalOpTrace.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef __GOALOP_TRACE_H_
  4. #define __GOALOP_TRACE_H_
  5.  
  6. #if _MSC_VER > 1000
  7.         #pragma once
  8. #endif
  9.  
  10. #include "GoalOp.h"
  11.  
  12. #include <limits>
  13.  
  14. // Observes a characters progression along a path and
  15. // signals when it stopped progressing. It's stuck.
  16. class StuckDetector
  17. {
  18. public:
  19.         enum Status
  20.         {
  21.                 UserIsStuck,
  22.                 UserIsMovingOnFine
  23.         };
  24.  
  25.         StuckDetector()
  26.         {
  27.                 Reset();
  28.         }
  29.  
  30.         void Reset()
  31.         {
  32.                 m_closest = std::numeric_limits<float>::max();
  33.                 m_lastProgress = gEnv->pTimer->GetCurrTime();
  34.         }
  35.  
  36.         Status Update(const float distToEnd)
  37.         {
  38.                 const float now = gEnv->pTimer->GetCurrTime();
  39.  
  40.                 if (distToEnd + 0.05f < m_closest)
  41.                 {
  42.                         m_closest = distToEnd;
  43.                         m_lastProgress = now;
  44.                 }
  45.                 else
  46.                 {
  47.                         const float timeWithoutProgress = now - m_lastProgress;
  48.  
  49.                         if (timeWithoutProgress > 2.0f)
  50.                         {
  51.                                 return StuckDetector::UserIsStuck;
  52.                         }
  53.                 }
  54.  
  55.                 return StuckDetector::UserIsMovingOnFine;
  56.         }
  57.  
  58. private:
  59.         float m_closest;
  60.         float m_lastProgress;
  61. };
  62.  
  63. ////////////////////////////////////////////////////////////
  64. //
  65. //                              TRACE - makes agent follow generated path... does nothing if no path generated
  66. //
  67. ////////////////////////////////////////////////////////////
  68.  
  69. class COPTrace : public CGoalOp
  70. {
  71. public:
  72.         COPTrace(
  73.           bool bExactFollow,
  74.           float fEndAccuracy = 1.f,
  75.           bool bForceReturnPartialPath = false,
  76.           bool bStopOnAnimationStart = false,
  77.           ETraceEndMode eTraceEndMode = eTEM_FixedDistance
  78.           );
  79.         COPTrace(const XmlNodeRef& node);
  80.         COPTrace(const COPTrace& rhs);
  81.         virtual ~COPTrace();
  82.  
  83.         virtual void          Reset(CPipeUser* pPipeUser);
  84.         virtual void          Serialize(TSerialize ser);
  85.         virtual EGoalOpResult Execute(CPipeUser* pPipeUser);
  86.         virtual bool          IsPathRegenerationInhibited() const { return m_inhibitPathRegen || m_passingStraightNavSO; }
  87.         virtual void          DebugDraw(CPipeUser* pPipeUser) const;
  88.  
  89.         bool                  ExecuteTrace(CPipeUser* pPipeUser, bool bFullUpdate);
  90.  
  91.         void                  SetControlSpeed(bool bValue) { m_bControlSpeed = bValue; }
  92.  
  93.         //////////////////////////////////////////////////////////////////////////
  94.         enum EManeuver { eMV_None, eMV_Back, eMV_Fwd };
  95.         enum EManeuverDir { eMVD_Clockwise, eMVD_AntiClockwise };
  96.         enum TraceResult { StillTracing, TraceDone };
  97.  
  98.         EManeuver     m_Maneuver;
  99.         EManeuverDir  m_ManeuverDir;
  100.         ETraceEndMode m_eTraceEndMode;
  101.  
  102.         /// we aim to stop within m_fAccuracy of the target minus m_fStickDistance (normally do better than this)
  103.         float m_fEndAccuracy;
  104.         /// finish tracing after this duration
  105.         /// fDuration is used to make us stop gracefully after a certain time
  106.         //  float m_fDuration;
  107.  
  108.         bool m_passingStraightNavSO;
  109.  
  110. private:
  111.         bool        ExecutePreamble(CPipeUser* pPipeUser);
  112.         bool        ExecutePostamble(CPipeUser* pPipeUser, bool& reachedEnd, bool fullUpdate, bool twoD);
  113.  
  114.         bool        ExecutePathFollower(CPipeUser* pPipeUser, bool fullUpdate, IPathFollower* pPathFollower);
  115.         bool        Execute2D(CPipeUser* pPipeUser, bool fullUpdate);
  116.         bool        Execute3D(CPipeUser* pPipeUser, bool fullUpdate);
  117.  
  118.         void        ExecuteManeuver(CPipeUser* pPipeUser, const Vec3& pathDir);
  119.         /// returns true when landing is completed
  120.         bool        ExecuteLanding(CPipeUser* pPipeUser, const Vec3& pathEnd);
  121.  
  122.         inline void ExecuteTraceDebugDraw(CPipeUser* pPipeUser);
  123.  
  124.         inline bool HandleAnimationPhase(CPipeUser* pPipeUser, bool bFullUpdate, bool* pbForceRegeneratePath, bool* pbExactPositioning, bool* pbTraceFinished);
  125.         inline bool HandlePathResult(CPipeUser* pPipeUser, bool* pbReturnValue);
  126.         inline bool IsVehicleAndDriverIsFallen(CPipeUser* pPipeUser);
  127.         inline void RegeneratePath(CPipeUser* pPipeUser, bool* pbForceRegeneratePath);
  128.         void        StopMovement(CPipeUser* pPipeUser);
  129.         inline void TriggerExactPositioning(CPipeUser* pPipeUser, bool* pbForceRegeneratePath, bool* pbExactPositioning);
  130.         void        Teleport(CPipeUser& pipeUser, const Vec3& teleportDestination);
  131.  
  132. private:
  133.         static PathFollowResult::TPredictedStates s_tmpPredictedStates;
  134.         static int                                s_instanceCount;
  135.  
  136. private:
  137.         //////////////////////////////////////////////////////////////////////////
  138.         bool       m_bBlock_ExecuteTrace_untilFullUpdateThenReset; // set when we should follow the path no more
  139.  
  140.         float      m_ManeuverDist;
  141.         CTimeValue m_ManeuverTime;
  142.         /// For things like helicopters that land then this gets set to some offset used at the end of the
  143.         /// path. Then at the path end the descent is gradually controlled - path only finishes when the
  144.         /// agent touches ground
  145.         float               m_landHeight;
  146.         /// Specifies how high we should be above the path at the current point
  147.         float               m_workingLandingHeightOffset;
  148.         // The ground position and facing direction
  149.         Vec3                m_landingPos;
  150.         Vec3                m_landingDir;
  151.  
  152.         bool                m_bExactFollow; /// Don't know what bExactFollow means!
  153.         /// bForceReturnPartialPath is used when we regen the path internally
  154.         bool                m_bForceReturnPartialPath;
  155.         Vec3                m_lastPosition;
  156.         CTimeValue          m_prevFrameStartTime;
  157.         float               m_TimeStep;
  158.         CWeakRef<CPipeUser> m_refPipeUser;  // The destructor needs to know the most recent pipe user
  159.         int                 m_looseAttentionId;
  160.         /// keep track of how long we've been tracing a path for - however, this is more of a time
  161.         /// since the last "event" - it can get reset when we regenerate the path etc
  162.         float m_fTotalTracingTime;
  163.         bool  m_inhibitPathRegen;
  164.  
  165.         bool  m_bWaitingForPathResult;
  166.         bool  m_bWaitingForBusySmartObject; // Indicates movement is paused waiting for a busy smart object to become available
  167.  
  168.         bool  m_earlyPathRegen;
  169.         bool  m_bControlSpeed; // indicates whether this goalop will control/modify PIpeUser's speed
  170.  
  171.         /// How far we've moved since the very start
  172.         float m_fTravelDist;
  173.         float m_accumulatedFailureTime;
  174.  
  175.         enum ETraceActorTgtRequest
  176.         {
  177.                 eTATR_None,      // no request
  178.                 eTATR_NavSO,     // navigational smart object
  179.                 eTATR_EndOfPath, // end of path exact positioning
  180.         };
  181.  
  182.         /// flag indicating the the trace requested exact positioning.
  183.         ETraceActorTgtRequest m_actorTargetRequester;
  184.         ETraceActorTgtRequest m_pendingActorTargetRequester;
  185.         CStrongRef<CAIObject> m_refNavTarget;
  186.  
  187.         StuckDetector         m_stuckDetector;
  188.  
  189.         /// bStopOnAnimationStart would make trace finish once the exact positioning animation at the end of path is started
  190.         bool m_stopOnAnimationStart;
  191. };
  192.  
  193. #endif  // #ifndef __GOALOP_TRACE_H_
  194.  
downloadGoalOpTrace.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