BVB Source Codes

CRYENGINE Show MovementBlock_UseExactPositioningBase.cpp Source code

Return Download CRYENGINE: download MovementBlock_UseExactPositioningBase.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "MovementBlock_UseExactPositioningBase.h"
  5. #include "MovementActor.h"
  6. #include <CryAISystem/MovementUpdateContext.h>
  7. #include "PipeUser.h"
  8. #include "AIBubblesSystem/AIBubblesSystem.h"
  9.  
  10. namespace Movement
  11. {
  12. namespace MovementBlocks
  13. {
  14. UseExactPositioningBase::UseExactPositioningBase(
  15.   const CNavPath& path,
  16.   const MovementStyle& style)
  17.         : m_path(path)
  18.         , m_style(style)
  19.         , m_state(Prepare)
  20.         , m_accumulatedPathFollowerFailureTime(0.0f)
  21. {
  22.  
  23. }
  24.  
  25. void UseExactPositioningBase::Begin(IMovementActor& actor)
  26. {
  27.         m_accumulatedPathFollowerFailureTime = 0.0f;
  28.         actor.GetAdapter().SetActorStyle(m_style, m_path);
  29.         m_stuckDetector.Reset();
  30. }
  31.  
  32. void UseExactPositioningBase::End(IMovementActor& actor)
  33. {
  34.         actor.GetAdapter().ClearMovementState();
  35. }
  36.  
  37. Movement::Block::Status UseExactPositioningBase::Update(const MovementUpdateContext& context)
  38. {
  39.         if (m_state == Prepare)
  40.         {
  41.                 return UpdatePrepare(context);
  42.         }
  43.         else
  44.         {
  45.                 assert(m_state == Traverse);
  46.                 return UpdateTraverse(context);
  47.         }
  48. }
  49.  
  50. Movement::Block::Status UseExactPositioningBase::UpdatePrepare(const MovementUpdateContext& context)
  51. {
  52.         // Switch to the smart object state when the time is right
  53.         const EActorTargetPhase targetPhase = context.actor.GetAdapter().GetActorPhase();
  54.  
  55.         // eATP_None
  56.         //              No request sent yet
  57.         // eATP_Waiting
  58.         //              AIProxy has sent the request to controller (should be the frame after we request it)
  59.         //              Controller will start behaving differently near the target and when it
  60.         //              is near enough it will queue an action. When that happens we go to:
  61.         // eATP_Starting
  62.         //              Action has been queued
  63.         //              Wait now for the controller to say the action entered and notified us
  64.         //              about the finish point
  65.         // eATP_Started,
  66.         //              Action has entered (and we got notified about the finish point)
  67.         //              Wait..for next frame...for some reason...
  68.         // eATP_Playing,
  69.         //              We're at least one frame after the action has entered
  70.         // eATP_StartedAndFinished:
  71.         // eATP_Finished:
  72.         //              LOOPING: the loop has started
  73.         //              ONESHOT: the action has finished
  74.         //              (eATP_StartedAndFinished means the Playing state has been skipped)
  75.         // eATP_Error:
  76.         //              Jonas finds this unacceptable ;)
  77.  
  78.         if (targetPhase == eATP_Error)
  79.         {
  80.                 HandleExactPositioningError(context);
  81.                 return Movement::Block::Finished;
  82.         }
  83.  
  84.         if (targetPhase == eATP_Starting || targetPhase == eATP_Started)
  85.         {
  86.                 // Done preparing, traverse it
  87.                 context.actor.GetAdapter().ClearMovementState();
  88.                 m_state = Traverse;
  89.                 OnTraverseStarted(context);
  90.                 return Movement::Block::Running;
  91.         }
  92.  
  93.         if (targetPhase == eATP_None)
  94.         {
  95.                 const TryRequestingExactPositioningResult result = TryRequestingExactPositioning(context);
  96.  
  97.                 switch (result)
  98.                 {
  99.                 case RequestSucceeded:
  100.                         {
  101.                                 // Enforce to use the current path.
  102.                                 context.actor.GetCallbacks().getPathFunction()->GetParams().inhibitPathRegeneration = true;
  103.                         }
  104.                         break;
  105.                 case RequestDelayed_ContinuePathFollowing:
  106.                         break;
  107.                 case RequestDelayed_SkipPathFollowing:
  108.                         return Running;
  109.                 case RequestFailed_FinishImmediately:
  110.                         return Finished;
  111.                 case RequestFailed_CancelImmediately:
  112.                         // Reset movement to prevent actor moving on spot
  113.                         context.actor.GetAdapter().ClearMovementState();
  114.                         return CantBeFinished;
  115.                 }
  116.         }
  117.  
  118.         assert((targetPhase == eATP_None) || (targetPhase == eATP_Waiting));
  119.  
  120.         PathFollowResult result;
  121.         const bool targetReachable = Movement::Helpers::UpdatePathFollowing(result, context, m_style);
  122.  
  123.         m_stuckDetector.Update(context);
  124.  
  125.         if (m_stuckDetector.IsAgentStuck())
  126.         {
  127.                 return Movement::Block::CantBeFinished;
  128.         }
  129.  
  130.         if (!targetReachable)
  131.         {
  132.                 // Track how much time we spent in this FollowPath block
  133.                 // without being able to reach the movement target.
  134.                 m_accumulatedPathFollowerFailureTime += context.updateTime;
  135.  
  136.                 // If it keeps on failing we don't expect to recover.
  137.                 // We report back that we can't be finished and the planner
  138.                 // will attempt to re-plan for the current situation.
  139.                 if (m_accumulatedPathFollowerFailureTime > 3.0f)
  140.                 {
  141.                         return Movement::Block::CantBeFinished;
  142.                 }
  143.         }
  144.  
  145.         return Movement::Block::Running;
  146. }
  147.  
  148. Movement::Block::Status UseExactPositioningBase::UpdateTraverse(const MovementUpdateContext& context)
  149. {
  150.         EActorTargetPhase phase = context.actor.GetAdapter().GetActorPhase();
  151.  
  152.         if (phase == eATP_None || phase == eATP_StartedAndFinished)
  153.         {
  154.                 return Finished;
  155.         }
  156.  
  157.         return Running;
  158. }
  159. }
  160. }
  161.  
downloadMovementBlock_UseExactPositioningBase.cpp 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