BVB Source Codes

CRYENGINE Show FlowPrefabNodes.cpp Source code

Return Download CRYENGINE: download FlowPrefabNodes.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   FlowPrefabNodes.cpp
  5. //  Version:     v1.00
  6. //  Created:     11/6/2012 by Dean Claassen
  7. //  Compilers:   Visual Studio.NET 2010
  8. //  Description: Prefab flownode functionality
  9. // -------------------------------------------------------------------------
  10. //  History:
  11. //
  12. ////////////////////////////////////////////////////////////////////////////
  13.  
  14. #include "StdAfx.h"
  15.  
  16. #include "FlowPrefabNodes.h"
  17.  
  18. #include <CryAction/ICustomEvents.h>
  19. #include "CustomEvents/CustomEventsManager.h"
  20.  
  21. //////////////////////////////////////////////////////////////////////////
  22. // Prefab:EventSource node
  23. // This node is placed inside a prefab flowgraph to create / handle a custom event
  24. //////////////////////////////////////////////////////////////////////////
  25. CFlowNode_PrefabEventSource::~CFlowNode_PrefabEventSource()
  26. {
  27.         if (m_eventId != CUSTOMEVENTID_INVALID)
  28.         {
  29.                 ICustomEventManager* pCustomEventManager = gEnv->pGameFramework->GetICustomEventManager();
  30.                 CRY_ASSERT(pCustomEventManager != NULL);
  31.                 pCustomEventManager->UnregisterEventListener(this, m_eventId);
  32.         }
  33. }
  34.  
  35. void CFlowNode_PrefabEventSource::GetConfiguration(SFlowNodeConfig& config)
  36. {
  37.         static const SInputPortConfig in_ports[] =
  38.         {
  39.                 InputPortConfig<string>("PrefabName",   _HELP("Prefab name")),
  40.                 InputPortConfig<string>("InstanceName", _HELP("Prefab instance name")),
  41.                 InputPortConfig<string>("EventName",    _HELP("Name of event associated to this prefab")),
  42.                 InputPortConfig<int>("EventType",       ePrefabEventType_Out,                             _HELP("Name of event associated to this prefab"), nullptr, _UICONFIG("enum_int:InOut=0,In=1,Out=2") ),
  43.                 InputPortConfig_AnyType("FireEvent",    _HELP("Fires associated event")),
  44.                 InputPortConfig<int>("EventId",         0,                                                _HELP("Event id storage")),
  45.                 InputPortConfig<int>("EventIndex",      -1,                                               _HELP("Event id storage")),
  46.                 { 0 }
  47.         };
  48.  
  49.         static const SOutputPortConfig out_ports[] =
  50.         {
  51.                 OutputPortConfig_AnyType("EventFired", _HELP("Triggered when associated event is fired")),
  52.                 { 0 }
  53.         };
  54.  
  55.         config.pInputPorts = in_ports;
  56.         config.pOutputPorts = out_ports;
  57.         config.sDescription = _HELP("Event node that must be placed inside a prefab for it to be handled in an instance");
  58.         config.SetCategory(EFLN_APPROVED);
  59. }
  60.  
  61. void CFlowNode_PrefabEventSource::ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo)
  62. {
  63.         ICustomEventManager* pCustomEventManager = gEnv->pGameFramework->GetICustomEventManager();
  64.         CRY_ASSERT(pCustomEventManager != NULL);
  65.  
  66.         if (event == eFE_Activate)
  67.         {
  68.                 if (IsPortActive(pActInfo, EIP_FireEvent))
  69.                 {
  70.                         if (m_eventId != CUSTOMEVENTID_INVALID)
  71.                         {
  72.                                 const TFlowInputData& customData = GetPortAny(pActInfo, EIP_FireEvent);
  73.                                 pCustomEventManager->FireEvent(m_eventId, customData);
  74.                         }
  75.  
  76.                         // Output port is activated from event
  77.                 }
  78.         }
  79.         else if (event == eFE_Initialize)
  80.         {
  81.                 m_actInfo = *pActInfo;
  82.  
  83.                 const TCustomEventId eventId = (TCustomEventId)GetPortInt(pActInfo, EIP_EventId);
  84.  
  85.                 if (eventId != CUSTOMEVENTID_INVALID && eventId != m_eventId)
  86.                 {
  87.                         if (m_eventId != CUSTOMEVENTID_INVALID)
  88.                         {
  89.                                 pCustomEventManager->UnregisterEventListener(this, m_eventId);
  90.                         }
  91.                         m_eventId = eventId;
  92.                         pCustomEventManager->RegisterEventListener(this, eventId);
  93.                 }
  94.         }
  95. }
  96.  
  97. void CFlowNode_PrefabEventSource::OnCustomEvent(const TCustomEventId eventId, const TFlowInputData& customData)
  98. {
  99.         if (m_eventId == eventId)
  100.         {
  101.                 ActivateOutput(&m_actInfo, EOP_EventFired, customData);
  102.         }
  103. }
  104.  
  105. //////////////////////////////////////////////////////////////////////////
  106. // Prefab:Instance node
  107. // This node represents a prefab instance (Currently used to handle events specific to a prefab instance)
  108. //////////////////////////////////////////////////////////////////////////
  109. CFlowNode_PrefabInstance::CFlowNode_PrefabInstance(SActivationInfo* pActInfo)
  110. {
  111.         for (int i = 0; i < CUSTOMEVENTS_PREFABS_MAXNPERINSTANCE; ++i)
  112.         {
  113.                 m_eventIds.push_back(CUSTOMEVENTID_INVALID);
  114.         }
  115. }
  116.  
  117. CFlowNode_PrefabInstance::~CFlowNode_PrefabInstance()
  118. {
  119.         ICustomEventManager* pCustomEventManager = gEnv->pGameFramework->GetICustomEventManager();
  120.         CRY_ASSERT(pCustomEventManager != NULL);
  121.  
  122.         for (int i = 0; i < CUSTOMEVENTS_PREFABS_MAXNPERINSTANCE; ++i)
  123.         {
  124.                 TCustomEventId& eventId = m_eventIds[i];
  125.                 if (eventId != CUSTOMEVENTID_INVALID)
  126.                 {
  127.                         pCustomEventManager->UnregisterEventListener(this, eventId);
  128.                         eventId = CUSTOMEVENTID_INVALID;
  129.                 }
  130.         }
  131. }
  132.  
  133. #define PREFAB_INSTANCE_CREATE_INPUT_PORT(ID)                                     \
  134.   InputPortConfig_AnyType("Event" STRINGIFY(ID), _HELP("Event trigger port")),    \
  135.   InputPortConfig<int>("Event" STRINGIFY(ID) "Id", 0, _HELP("Event id storage")), \
  136.   InputPortConfig<string>("Event" STRINGIFY(ID) "Name", _HELP("Event name storage")),
  137.  
  138. #define PREFAB_INSTANCE_CREATE_OUTPUT_PORT(ID) \
  139.   OutputPortConfig_AnyType("Event" STRINGIFY(ID), _HELP("Triggered when associated event is fired")),
  140.  
  141. void CFlowNode_PrefabInstance::GetConfiguration(SFlowNodeConfig& config)
  142. {
  143.         static const SInputPortConfig in_ports[] =
  144.         {
  145.                 InputPortConfig<string>("PrefabName",   _HELP("Prefab name")),
  146.                 InputPortConfig<string>("InstanceName", _HELP("Prefab instance name")),
  147.                 PREFAB_INSTANCE_CREATE_INPUT_PORT(1)
  148.                 PREFAB_INSTANCE_CREATE_INPUT_PORT(2)
  149.                 PREFAB_INSTANCE_CREATE_INPUT_PORT(3)
  150.                 PREFAB_INSTANCE_CREATE_INPUT_PORT(4)
  151.                 PREFAB_INSTANCE_CREATE_INPUT_PORT(5)
  152.                 PREFAB_INSTANCE_CREATE_INPUT_PORT(6)
  153.                 PREFAB_INSTANCE_CREATE_INPUT_PORT(7)
  154.                 PREFAB_INSTANCE_CREATE_INPUT_PORT(8)
  155.                 PREFAB_INSTANCE_CREATE_INPUT_PORT(9)
  156.                 PREFAB_INSTANCE_CREATE_INPUT_PORT(10)
  157.                 PREFAB_INSTANCE_CREATE_INPUT_PORT(11)
  158.                 PREFAB_INSTANCE_CREATE_INPUT_PORT(12)
  159.                 {
  160.                         0
  161.                 }
  162.         };
  163.  
  164.         static const SOutputPortConfig out_ports[] =
  165.         {
  166.                 PREFAB_INSTANCE_CREATE_OUTPUT_PORT(1)
  167.                 PREFAB_INSTANCE_CREATE_OUTPUT_PORT(2)
  168.                 PREFAB_INSTANCE_CREATE_OUTPUT_PORT(3)
  169.                 PREFAB_INSTANCE_CREATE_OUTPUT_PORT(4)
  170.                 PREFAB_INSTANCE_CREATE_OUTPUT_PORT(5)
  171.                 PREFAB_INSTANCE_CREATE_OUTPUT_PORT(6)
  172.                 PREFAB_INSTANCE_CREATE_OUTPUT_PORT(7)
  173.                 PREFAB_INSTANCE_CREATE_OUTPUT_PORT(8)
  174.                 PREFAB_INSTANCE_CREATE_OUTPUT_PORT(9)
  175.                 PREFAB_INSTANCE_CREATE_OUTPUT_PORT(10)
  176.                 PREFAB_INSTANCE_CREATE_OUTPUT_PORT(11)
  177.                 PREFAB_INSTANCE_CREATE_OUTPUT_PORT(12)
  178.                 {
  179.                         0
  180.                 }
  181.         };
  182.  
  183.         config.pInputPorts = in_ports;
  184.         config.pOutputPorts = out_ports;
  185.         config.sDescription = _HELP("Prefab instance node to handle events specific to an instance");
  186.         config.SetCategory(EFLN_APPROVED | EFLN_HIDE_UI);
  187. }
  188.  
  189. #undef PREFAB_INSTANCE_CREATE_INPUT_PORT
  190. #undef PREFAB_INSTANCE_CREATE_OUTPUT_PORT
  191.  
  192. void CFlowNode_PrefabInstance::ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo)
  193. {
  194.         ICustomEventManager* pCustomEventManager = gEnv->pGameFramework->GetICustomEventManager();
  195.         CRY_ASSERT(pCustomEventManager != NULL);
  196.  
  197.         if (event == eFE_Activate)
  198.         {
  199.                 int iCurInputPort = EIP_Event1;
  200.                 for (int i = 0; i < CUSTOMEVENTS_PREFABS_MAXNPERINSTANCE; ++i)
  201.                 {
  202.                         if (IsPortActive(pActInfo, iCurInputPort))
  203.                         {
  204.                                 const TCustomEventId eventId = m_eventIds[i];
  205.                                 if (m_eventIds[i] != CUSTOMEVENTID_INVALID)
  206.                                 {
  207.                                         const TFlowInputData& customData = GetPortAny(pActInfo, iCurInputPort);
  208.                                         pCustomEventManager->FireEvent(eventId, customData);
  209.                                 }
  210.  
  211.                                 // Output port is activated from event
  212.                         }
  213.  
  214.                         iCurInputPort += static_cast<int>(ePrefabInstance_NumInputPortsPerEvent);
  215.                 }
  216.  
  217.         }
  218.         else if (event == eFE_Initialize)
  219.         {
  220.                 m_actInfo = *pActInfo;
  221.  
  222.                 int iCurPort = EIP_Event1Id;
  223.                 for (int i = 0; i < CUSTOMEVENTS_PREFABS_MAXNPERINSTANCE; ++i)
  224.                 {
  225.                         const TCustomEventId eventId = (TCustomEventId)GetPortInt(pActInfo, iCurPort);
  226.  
  227.                         if (eventId != CUSTOMEVENTID_INVALID && eventId != m_eventIds[i])
  228.                         {
  229.                                 if (m_eventIds[i] != CUSTOMEVENTID_INVALID)
  230.                                 {
  231.                                         pCustomEventManager->UnregisterEventListener(this, m_eventIds[i]);
  232.                                 }
  233.                                 m_eventIds[i] = eventId;
  234.                                 pCustomEventManager->RegisterEventListener(this, eventId);
  235.                         }
  236.  
  237.                         iCurPort += static_cast<int>(ePrefabInstance_NumInputPortsPerEvent);
  238.                 }
  239.         }
  240. }
  241.  
  242. void CFlowNode_PrefabInstance::OnCustomEvent(const TCustomEventId eventId, const TFlowInputData& customData)
  243. {
  244.         // Need to determine which output port corresponds to event id
  245.         int iOutputPort = EOP_Event1;
  246.         for (int i = 0; i < CUSTOMEVENTS_PREFABS_MAXNPERINSTANCE; ++i)
  247.         {
  248.                 const TCustomEventId curEventId = m_eventIds[i];
  249.                 if (curEventId == eventId)
  250.                 {
  251.                         ActivateOutput(&m_actInfo, iOutputPort, customData);
  252.                         break;
  253.                 }
  254.  
  255.                 iOutputPort++;
  256.         }
  257. }
  258.  
  259. REGISTER_FLOW_NODE("Prefab:EventSource", CFlowNode_PrefabEventSource)
  260. REGISTER_FLOW_NODE("Prefab:Instance", CFlowNode_PrefabInstance)
  261.  
downloadFlowPrefabNodes.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