BVB Source Codes

CRYENGINE Show FlowStartNode.cpp Source code

Return Download CRYENGINE: download FlowStartNode.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 "FlowStartNode.h"
  5. #include "CryAction.h"
  6.  
  7. // if this is defined we use the old behaviour.
  8. // means: In Editor switching from Game mode back to Editor
  9. //        the node outputs an 'Output event (which is bogus...)
  10. #define VS2_SAFE_PLAY_USE_OLD_BEHAVIOUR
  11. #undef  VS2_SAFE_PLAY_USE_OLD_BEHAVIOUR  // default: use new behaviour
  12.  
  13. CFlowStartNode::CFlowStartNode(SActivationInfo* pActInfo)
  14. {
  15.         m_refs = 0;
  16.         m_bActivated = true;
  17.         SetActivation(pActInfo, false);
  18. }
  19.  
  20. void CFlowStartNode::AddRef()
  21. {
  22.         ++m_refs;
  23. }
  24.  
  25. void CFlowStartNode::Release()
  26. {
  27.         if (0 == --m_refs)
  28.                 delete this;
  29. }
  30.  
  31. IFlowNodePtr CFlowStartNode::Clone(SActivationInfo* pActInfo)
  32. {
  33.         CFlowStartNode* pClone = new CFlowStartNode(pActInfo);
  34.         pClone->SetActivation(pActInfo, m_bActivated);
  35.         return pClone;
  36. }
  37.  
  38. void CFlowStartNode::GetConfiguration(SFlowNodeConfig& config)
  39. {
  40.         static const SInputPortConfig inputs[] = {
  41.                 InputPortConfig<bool>("InGame",   true, _HELP("Start will Trigger in PureGameMode")),
  42.                 InputPortConfig<bool>("InEditor", true, _HELP("Start will Trigger in EditorGameMode")),
  43.                 { 0 }
  44.         };
  45.         static const SOutputPortConfig outputs[] = {
  46.                 OutputPortConfig<bool>("output"),
  47.                 { 0 }
  48.         };
  49.  
  50.         config.pInputPorts = inputs;
  51.         config.pOutputPorts = outputs;
  52.         config.SetCategory(EFLN_APPROVED);
  53. }
  54.  
  55. bool CFlowStartNode::MayTrigger(SActivationInfo* pActInfo)
  56. {
  57.         const bool isEditor = gEnv->IsEditor();
  58.         const bool canTriggerInGame = *(pActInfo->pInputPorts[0].GetPtr<bool>());
  59.         const bool canTriggerInEditor = *(pActInfo->pInputPorts[1].GetPtr<bool>());
  60.         const bool canTrigger = (isEditor && canTriggerInEditor) || (!isEditor && canTriggerInGame);
  61.         return canTrigger;
  62. }
  63.  
  64. void CFlowStartNode::ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo)
  65. {
  66.         SFlowAddress addr(pActInfo->myID, 0, true);
  67.  
  68. #ifdef VS2_SAFE_PLAY_USE_OLD_BEHAVIOUR
  69.         switch (event)
  70.         {
  71.         case eFE_Update:
  72.                 {
  73.                         if (!CCryAction::GetCryAction()->IsGameStarted())
  74.                                 return;
  75.  
  76.                         pActInfo->pGraph->ActivatePort(addr, true);
  77.                         SetActivation(pActInfo, true);
  78.                 }
  79.                 break;
  80.         case eFE_Initialize:
  81.                 pActInfo->pGraph->ActivatePort(addr, false);
  82.                 SetActivation(pActInfo, false);
  83.                 break;
  84.         }
  85. #else   // new behaviour
  86.         switch (event)
  87.         {
  88.         case eFE_Update:
  89.                 {
  90.                         // when we're in pure game mode
  91.                         if (!gEnv->IsEditor())
  92.                         {
  93.                                 if (!CCryAction::GetCryAction()->IsGameStarted())
  94.                                         return; // not yet started
  95.                         }
  96.                         // else: in editor mode or game has been started
  97.                         // in editor mode we regard the game as initialized as soon as
  98.                         // we receive the first update...
  99.                         if (MayTrigger(pActInfo))
  100.                                 pActInfo->pGraph->ActivatePort(addr, true);
  101.                         SetActivation(pActInfo, true);
  102.                 }
  103.                 break;
  104.         case eFE_Initialize:
  105.                 if (MayTrigger(pActInfo))
  106.                         pActInfo->pGraph->ActivatePort(addr, false);
  107.                 if (!gEnv->IsEditor())
  108.                 {
  109.                         //check whether this Start node is in a deactivated entity (and should not trigger)
  110.                         //this is necessary for deactivated layers, because the flowgraphs are reset and should not run
  111.                         bool bSkipActivation = false;
  112.                         EntityId graphEntity = pActInfo->pGraph->GetGraphEntity(0);
  113.                         IEntity* pEntity = gEnv->pEntitySystem->GetEntity(graphEntity);
  114.                         if (pEntity && gEnv->pEntitySystem->ShouldSerializedEntity(pEntity) == false)
  115.                                 bSkipActivation = true;
  116.  
  117.                         if (bSkipActivation)
  118.                         {
  119.                                 pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false);
  120.                         }
  121.                         else
  122.                         {
  123.                                 // we're in pure game mode
  124.                                 SetActivation(pActInfo, false);
  125.                         }
  126.                 }
  127.                 else
  128.                 {
  129.                         // we're in editor mode and we're currently editing,
  130.                         // (-> not in editor/game mode), so we schedule ourself to be updated
  131.                         if (CCryAction::GetCryAction()->IsEditing() == true)
  132.                                 SetActivation(pActInfo, false);
  133.                 }
  134.                 break;
  135.         }
  136. #endif
  137. }
  138.  
  139. bool CFlowStartNode::SerializeXML(SActivationInfo* pActInfo, const XmlNodeRef& root, bool reading)
  140. {
  141.         if (reading)
  142.         {
  143.                 bool activated;
  144.                 if (!root->getAttr("ACTIVATED", activated))
  145.                         return false;
  146.                 SetActivation(pActInfo, activated);
  147.         }
  148.         else
  149.         {
  150.                 root->setAttr("ACTIVATED", m_bActivated);
  151.         }
  152.         return true;
  153. }
  154.  
  155. void CFlowStartNode::Serialize(SActivationInfo* pActInfo, TSerialize ser)
  156. {
  157.         if (ser.IsWriting())
  158.                 ser.Value("activated", m_bActivated);
  159.         else
  160.         {
  161.                 bool activated;
  162.                 ser.Value("activated", activated);
  163.                 SetActivation(pActInfo, activated);
  164.         }
  165. }
  166.  
  167. void CFlowStartNode::SetActivation(SActivationInfo* pActInfo, bool value)
  168. {
  169.         if (value == m_bActivated)
  170.                 return;
  171.  
  172.         m_bActivated = value;
  173.         pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, !m_bActivated);
  174. }
  175.  
downloadFlowStartNode.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