BVB Source Codes

CRYENGINE Show SequenceManager.cpp Source code

Return Download CRYENGINE: download SequenceManager.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 "SequenceManager.h"
  5. #include "SequenceAgent.h"
  6. #include "SequenceFlowNodes.h"
  7. #include "AIBubblesSystem/AIBubblesSystem.h"
  8.  
  9. namespace AIActionSequence
  10. {
  11.  
  12. void SequenceManager::Reset()
  13. {
  14.         m_registeredSequences.clear();
  15.         m_sequenceIdCounter = 1;
  16. }
  17.  
  18. bool SequenceManager::RegisterSequence(EntityId entityId, TFlowNodeId startNodeId, SequenceProperties sequenceProperties, IFlowGraph* flowGraph)
  19. {
  20.         SequenceId newSequenceId = GenerateUniqueSequenceId();
  21.         Sequence sequence(entityId, newSequenceId, startNodeId, sequenceProperties, flowGraph);
  22.  
  23.         SequenceAgent agent(entityId);
  24.         if (!agent.ValidateAgent())
  25.                 return false;
  26.  
  27.         if (!sequence.TraverseAndValidateSequence())
  28.                 return false;
  29.  
  30.         m_registeredSequences.insert(std::pair<SequenceId, Sequence>(newSequenceId, sequence));
  31.         return true;
  32. }
  33.  
  34. void SequenceManager::UnregisterSequence(SequenceId sequenceId)
  35. {
  36.         m_registeredSequences.erase(sequenceId);
  37. }
  38.  
  39. void SequenceManager::StartSequence(SequenceId sequenceId)
  40. {
  41.         Sequence* sequence = GetSequence(sequenceId);
  42.         if (!sequence)
  43.         {
  44.                 CRY_ASSERT_MESSAGE(false, "Could not access sequence.");
  45.                 return;
  46.         }
  47.  
  48.         CancelActiveSequencesForThisEntity(sequence->GetEntityId());
  49.         sequence->Start();
  50. }
  51.  
  52. void SequenceManager::CancelSequence(SequenceId sequenceId)
  53. {
  54.         Sequence* sequence = GetSequence(sequenceId);
  55.         if (!sequence)
  56.         {
  57.                 CRY_ASSERT_MESSAGE(false, "Could not access sequence.");
  58.                 return;
  59.         }
  60.  
  61.         if (sequence->IsActive())
  62.         {
  63.                 sequence->Cancel();
  64.         }
  65. }
  66.  
  67. bool SequenceManager::IsSequenceActive(SequenceId sequenceId)
  68. {
  69.         Sequence* sequence = GetSequence(sequenceId);
  70.         if (!sequence)
  71.                 return false;
  72.  
  73.         return sequence->IsActive();
  74. }
  75.  
  76. void SequenceManager::SequenceBehaviorReady(EntityId entityId)
  77. {
  78.         SequenceMap::iterator sequenceIterator = m_registeredSequences.begin();
  79.         SequenceMap::iterator sequenceIteratorEnd = m_registeredSequences.end();
  80.         for (; sequenceIterator != sequenceIteratorEnd; ++sequenceIterator)
  81.         {
  82.                 Sequence& sequence = sequenceIterator->second;
  83.                 if (sequence.IsActive() && sequence.GetEntityId() == entityId)
  84.                 {
  85.                         sequence.SequenceBehaviorReady();
  86.                         return;
  87.                 }
  88.         }
  89.  
  90.         CRY_ASSERT_MESSAGE(false, "Entity not registered with any sequence.");
  91. }
  92.  
  93. void SequenceManager::SequenceInterruptibleBehaviorLeft(EntityId entityId)
  94. {
  95.         SequenceMap::iterator sequenceIterator = m_registeredSequences.begin();
  96.         SequenceMap::iterator sequenceIteratorEnd = m_registeredSequences.end();
  97.         for (; sequenceIterator != sequenceIteratorEnd; ++sequenceIterator)
  98.         {
  99.                 Sequence& sequence = sequenceIterator->second;
  100.                 if (sequence.IsActive() && sequence.IsInterruptible() && sequence.GetEntityId() == entityId)
  101.                 {
  102.                         sequence.SequenceInterruptibleBehaviorLeft();
  103.                 }
  104.         }
  105. }
  106.  
  107. void SequenceManager::SequenceNonInterruptibleBehaviorLeft(EntityId entityId)
  108. {
  109.         SequenceMap::iterator sequenceIterator = m_registeredSequences.begin();
  110.         SequenceMap::iterator sequenceIteratorEnd = m_registeredSequences.end();
  111.         for (; sequenceIterator != sequenceIteratorEnd; ++sequenceIterator)
  112.         {
  113.                 Sequence& sequence = sequenceIterator->second;
  114.                 if (sequence.IsActive() && !sequence.IsInterruptible() && sequence.GetEntityId() == entityId)
  115.                 {
  116.                         AIQueueBubbleMessage("AI Sequence Error", entityId, "The sequence behavior has unexpectedly been deselected and the sequence has been canceled.", eBNS_LogWarning | eBNS_Balloon);
  117.                         sequence.Cancel();
  118.                 }
  119.         }
  120. }
  121.  
  122. void SequenceManager::AgentDisabled(EntityId entityId)
  123. {
  124.         SequenceMap::iterator sequenceIterator = m_registeredSequences.begin();
  125.         SequenceMap::iterator sequenceIteratorEnd = m_registeredSequences.end();
  126.         for (; sequenceIterator != sequenceIteratorEnd; ++sequenceIterator)
  127.         {
  128.                 Sequence& sequence = sequenceIterator->second;
  129.                 if (sequence.IsActive() && sequence.GetEntityId() == entityId)
  130.                 {
  131.                         sequence.Cancel();
  132.                 }
  133.         }
  134. }
  135.  
  136. void SequenceManager::RequestActionStart(SequenceId sequenceId, TFlowNodeId actionNodeId)
  137. {
  138.         Sequence* sequence = GetSequence(sequenceId);
  139.         if (!sequence)
  140.         {
  141.                 CRY_ASSERT_MESSAGE(false, "Could not access sequence.");
  142.                 return;
  143.         }
  144.  
  145.         sequence->RequestActionStart(actionNodeId);
  146. }
  147.  
  148. void SequenceManager::ActionCompleted(SequenceId sequenceId)
  149. {
  150.         Sequence* sequence = GetSequence(sequenceId);
  151.         if (!sequence)
  152.         {
  153.                 CRY_ASSERT_MESSAGE(false, "Could not access sequence.");
  154.                 return;
  155.         }
  156.  
  157.         sequence->ActionComplete();
  158. }
  159.  
  160. void SequenceManager::SetBookmark(SequenceId sequenceId, TFlowNodeId bookmarkNodeId)
  161. {
  162.         Sequence* sequence = GetSequence(sequenceId);
  163.         if (!sequence)
  164.         {
  165.                 CRY_ASSERT_MESSAGE(false, "Could not access sequence.");
  166.                 return;
  167.         }
  168.  
  169.         sequence->SetBookmark(bookmarkNodeId);
  170. }
  171.  
  172. SequenceId SequenceManager::GenerateUniqueSequenceId()
  173. {
  174.         return m_sequenceIdCounter++;
  175. }
  176.  
  177. Sequence* SequenceManager::GetSequence(SequenceId sequenceId)
  178. {
  179.         SequenceMap::iterator sequenceIterator = m_registeredSequences.find(sequenceId);
  180.         if (sequenceIterator == m_registeredSequences.end())
  181.         {
  182.                 return 0;
  183.         }
  184.  
  185.         return &sequenceIterator->second;
  186. }
  187.  
  188. void SequenceManager::CancelActiveSequencesForThisEntity(EntityId entityId)
  189. {
  190.         SequenceMap::iterator sequenceIterator = m_registeredSequences.begin();
  191.         SequenceMap::iterator sequenceIteratorEnd = m_registeredSequences.end();
  192.         for (; sequenceIterator != sequenceIteratorEnd; ++sequenceIterator)
  193.         {
  194.                 Sequence& sequence = sequenceIterator->second;
  195.                 if (sequence.IsActive() && sequence.GetEntityId() == entityId)
  196.                 {
  197.                         sequence.Cancel();
  198.                 }
  199.         }
  200. }
  201.  
  202. } // namespace AIActionSequence
  203.  
downloadSequenceManager.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