BVB Source Codes

CRYENGINE Show FlowModuleNodes.h Source code

Return Download CRYENGINE: download FlowModuleNodes.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*
  4.  * Utility nodes and Node types for modules: Start, Return and Call.
  5.  * These nodes are generated by factories with the following convention:
  6.  *  Module:[Call|Start|Return]_<ModuleName>
  7.  */
  8.  
  9. #pragma once
  10.  
  11. #include <CryFlowGraph/IFlowGraphModuleManager.h>
  12. #include <CryFlowGraph/IFlowBaseNode.h>
  13.  
  14. class CFlowGraphModule;
  15. struct SModuleInstance;
  16.  
  17. //////////////////////////////////////////////////////////////////////////
  18. //
  19. //      Dynamically generated nodes based on a module's inputs/outputs
  20. //
  21. //////////////////////////////////////////////////////////////////////////
  22.  
  23. //////////////////////////////////////////////////////////////////////////
  24. // Start node factory
  25. //////////////////////////////////////////////////////////////////////////
  26.  
  27. class CFlowModuleStartNodeFactory : public IFlowNodeFactory
  28. {
  29. public:
  30.         CFlowModuleStartNodeFactory(CFlowGraphModule* pModule);
  31.         ~CFlowModuleStartNodeFactory();
  32.  
  33.         virtual void         AddRef() override  { m_nRefCount++; }
  34.         virtual void         Release() override { if (0 == --m_nRefCount) delete this; }
  35.         virtual IFlowNodePtr Create(IFlowNode::SActivationInfo*) override;
  36.  
  37.         virtual void         GetMemoryUsage(ICrySizer* s) const override
  38.         {
  39.                 SIZER_SUBCOMPONENT_NAME(s, "CFlowModuleStartNodeFactory");
  40.                 s->AddObject(this, sizeof(*this));
  41.                 s->AddObject(m_outputs);
  42.         }
  43.  
  44.         void         GetConfiguration(SFlowNodeConfig&);
  45.  
  46.         void         Reset() override;
  47.  
  48.         virtual bool AllowOverride() const override { return true; }
  49.  
  50. private:
  51.         friend class CFlowModuleStartNode;
  52.         CFlowGraphModule* const        m_pModule;
  53.  
  54.         TModuleId                      m_moduleId;
  55.         int                            m_nRefCount;
  56.         std::vector<SOutputPortConfig> m_outputs;
  57. };
  58.  
  59. //////////////////////////////////////////////////////////////////////////
  60. // Start node inside the module.
  61. // Dynamically generated by a factory with ports from the Module's interface
  62. //////////////////////////////////////////////////////////////////////////
  63.  
  64. class CFlowModuleStartNode : public CFlowBaseNode<eNCT_Instanced>
  65. {
  66. public:
  67.         CFlowModuleStartNode(CFlowModuleStartNodeFactory* pFactory, SActivationInfo* pActInfo);
  68.         virtual ~CFlowModuleStartNode() {}
  69.  
  70.         virtual IFlowNodePtr Clone(SActivationInfo* pActInfo);
  71.         virtual void         GetMemoryUsage(ICrySizer* s) const { s->Add(*this); }
  72.  
  73.         virtual void         GetConfiguration(SFlowNodeConfig&);
  74.         virtual void         ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo);
  75.  
  76.         void                 OnUpdateAllInputs(TModuleParams const* params);
  77.         void                 OnUpdateSingleInput(size_t idx, const TFlowInputData& value);
  78.         void OnCancel();
  79.  
  80. private:
  81.         void Serialize(SActivationInfo* pActInfo, TSerialize ser) {}
  82.  
  83.         enum EOutputPorts
  84.         {
  85.                 eOP_EntityId,
  86.                 eOP_Start,
  87.                 eOP_Update,
  88.                 eOP_Cancel,
  89.                 eOP_Param1,
  90.                 // ...
  91.         };
  92.         SActivationInfo                    m_actInfo;
  93.  
  94.         CFlowModuleStartNodeFactory* const m_pFactory;   //! Reference to the factory that generated this node (has ports info)
  95.         CFlowGraphModule* const            m_pModule;    //! Reference to the Module type for this node
  96.         EntityId                           m_entityId;   //! Entity that this instance is associated with, may be invalid
  97.         TModuleInstanceId                  m_instanceId; //! ID of the module instance that this node is associated it
  98.                                                          // Changes at runtime and might be invalid (start nodes are cloned)
  99.  
  100.         bool m_bStarted;
  101. };
  102.  
  103. //////////////////////////////////////////////////////////////////////////
  104. // Return node factory
  105. //////////////////////////////////////////////////////////////////////////
  106.  
  107. class CFlowModuleReturnNodeFactory : public IFlowNodeFactory
  108. {
  109. public:
  110.         CFlowModuleReturnNodeFactory(CFlowGraphModule* pModule);
  111.         ~CFlowModuleReturnNodeFactory();
  112.  
  113.         virtual void         AddRef() override  { m_nRefCount++; }
  114.         virtual void         Release() override { if (0 == --m_nRefCount) delete this; }
  115.         virtual IFlowNodePtr Create(IFlowNode::SActivationInfo*) override;
  116.  
  117.         virtual void         GetMemoryUsage(ICrySizer* s) const override
  118.         {
  119.                 SIZER_SUBCOMPONENT_NAME(s, "CFlowModuleReturnNodeFactory");
  120.                 s->AddObject(this, sizeof(*this));
  121.                 s->AddObject(m_inputs);
  122.         }
  123.  
  124.         void         GetConfiguration(SFlowNodeConfig&);
  125.  
  126.         void         Reset() override;
  127.  
  128.         virtual bool AllowOverride() const override { return true; }
  129.  
  130. private:
  131.         friend class CFlowModuleReturnNode;
  132.         CFlowGraphModule* const       m_pModule;
  133.  
  134.         TModuleId                     m_moduleId;
  135.         int                           m_nRefCount;
  136.         std::vector<SInputPortConfig> m_inputs;
  137. };
  138.  
  139. //////////////////////////////////////////////////////////////////////////
  140. // Return (end) node inside the module.
  141. // Dynamically generated by a factory with ports from the Module's interface
  142. //////////////////////////////////////////////////////////////////////////
  143.  
  144. class CFlowModuleReturnNode : public CFlowBaseNode<eNCT_Instanced>
  145. {
  146. public:
  147.         CFlowModuleReturnNode(CFlowModuleReturnNodeFactory* pFactory, SActivationInfo* pActInfo);
  148.         virtual ~CFlowModuleReturnNode() {}
  149.  
  150.         virtual IFlowNodePtr Clone(SActivationInfo* pActInfo);
  151.         virtual void         GetMemoryUsage(ICrySizer* s) const { s->Add(*this); }
  152.  
  153.         virtual void         GetConfiguration(SFlowNodeConfig&);
  154.         virtual void         ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo);
  155.  
  156.         void                 OnFinished(bool success);
  157.  
  158. private:
  159.         void Serialize(SActivationInfo* pActInfo, TSerialize ser) {}
  160.  
  161.         enum EInputPorts
  162.         {
  163.                 eIP_Success = 0,
  164.                 eIP_Cancel,
  165.                 eIP_Param1,
  166.                 // ...
  167.         };
  168.         SActivationInfo                     m_actInfo;
  169.  
  170.         CFlowModuleReturnNodeFactory* const m_pFactory;   //! Reference to the factory that generated this node (has ports info)
  171.         CFlowGraphModule* const             m_pModule;    //! Reference to the Module type for this node
  172.         EntityId                            m_entityId;   //! Entity that this instance is associated with, may be invalid
  173.         TModuleInstanceId                   m_instanceId; //! ID of the module instance that this node is associated it
  174.                                                           // Changes at runtime and might be invalid (return nodes are cloned)
  175.         bool                                m_bFinished;
  176. };
  177.  
  178. //////////////////////////////////////////////////////////////////////////
  179. // Call module node factory
  180. //////////////////////////////////////////////////////////////////////////
  181.  
  182. class CFlowModuleCallNodeFactory : public IFlowNodeFactory
  183. {
  184. public:
  185.         CFlowModuleCallNodeFactory(CFlowGraphModule* pModule);
  186.         ~CFlowModuleCallNodeFactory();
  187.  
  188.         virtual void         AddRef() override  { m_nRefCount++; }
  189.         virtual void         Release() override { if (0 == --m_nRefCount) delete this; }
  190.         virtual IFlowNodePtr Create(IFlowNode::SActivationInfo*) override;
  191.  
  192.         virtual void         GetMemoryUsage(ICrySizer* s) const override
  193.         {
  194.                 SIZER_SUBCOMPONENT_NAME(s, "CFlowModuleCallNodeFactory");
  195.                 s->AddObject(this, sizeof(*this));
  196.                 s->AddObject(m_outputs);
  197.         }
  198.  
  199.         void         GetConfiguration(SFlowNodeConfig&);
  200.  
  201.         void         Reset() override;
  202.  
  203.         virtual bool AllowOverride() const override { return true; }
  204.  
  205. private:
  206.         friend class CFlowModuleCallNode;
  207.         CFlowGraphModule* const        m_pModule;
  208.  
  209.         int                            m_nRefCount;
  210.         std::vector<SInputPortConfig>  m_inputs;
  211.         std::vector<SOutputPortConfig> m_outputs;
  212. };
  213.  
  214. //////////////////////////////////////////////////////////////////////////
  215. // Call Node - the external interface for the module to be called from other graphs
  216. // Dynamically generated by a factory with ports from the Module's interface
  217. //////////////////////////////////////////////////////////////////////////
  218.  
  219. class CFlowModuleCallNode : public CFlowBaseNode<eNCT_Instanced>
  220. {
  221. public:
  222.         CFlowModuleCallNode(CFlowModuleCallNodeFactory* pFactory, SActivationInfo* pActInfo);
  223.         virtual ~CFlowModuleCallNode();
  224.  
  225.         virtual IFlowNodePtr Clone(SActivationInfo* pActInfo);
  226.         virtual void         GetMemoryUsage(ICrySizer* s) const { s->Add(*this); }
  227.  
  228.         virtual void         GetConfiguration(SFlowNodeConfig&);
  229.         virtual void         ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo);
  230.  
  231.         void                 OnInstanceStarted(TModuleInstanceId instanceId);
  232.         void                 OnInstanceFinished(bool bSuccess, const TModuleParams& params);
  233.         void                 OnInstanceOutput(size_t paramIdx, const TFlowInputData& value);
  234.  
  235.         uint                 GetId() const { return m_callNodeId; }
  236.  
  237. private:
  238.         void Serialize(SActivationInfo* pActInfo, TSerialize ser) {}
  239.  
  240.         enum EInputPort
  241.         {
  242.                 eIP_Call = 0,
  243.                 eIP_Cancel,
  244.                 eIP_IsGlobalController,
  245.                 eIP_InstanceId,
  246.                 eIP_ContInput,
  247.                 eIP_ContOutput,
  248.                 eIP_Param1,
  249.                 // ...
  250.         };
  251.         enum EOutputPort
  252.         {
  253.                 eOP_OnCall = 0,
  254.                 eOP_Success,
  255.                 eOP_Canceled,
  256.                 eOP_Param1,
  257.                 // ...
  258.         };
  259.         SActivationInfo                   m_actInfo;
  260.  
  261.         CFlowModuleCallNodeFactory* const m_pFactory;   //! Reference to the factory that generated this node (has ports info)
  262.         CFlowGraphModule* const           m_pModule;    //! Reference to the Module type for this node
  263.         TModuleId                         m_moduleId;   //! Id of the module type, to check in case the module was deleted
  264.         EntityId                          m_entityId;   //! Entity that this instance is associated with, may be 0 (invalid)
  265.         TModuleInstanceId                 m_instanceId; //! ID of the module instance that this node is associated it
  266.                                                         // Changes at runtime and might be invalid (call nodes exist without an instance before being activated)
  267.         bool                              m_bIsGlobal;
  268.         bool                              m_bEntityChanged;
  269.  
  270.         const uint                        m_callNodeId;     //! Unique identifier for Call nodes
  271.         static uint                       s_nextCallNodeId; //! Static ID generator for Call node IDs
  272. };
  273.  
  274. //////////////////////////////////////////////////////////////////////////
  275. //
  276. //      Utility nodes for use with Modules
  277. //
  278. //////////////////////////////////////////////////////////////////////////
  279.  
  280. //////////////////////////////////////////////////////////////////////////
  281. // helper class to bind user id to a module instance id (e.g. to map entity id to a module id)
  282. //////////////////////////////////////////////////////////////////////////
  283. class CFlowModuleUserIdNode : public CFlowBaseNode<eNCT_Singleton>
  284. {
  285. public:
  286.         CFlowModuleUserIdNode(SActivationInfo* pActInfo) {}
  287.         virtual ~CFlowModuleUserIdNode() {}
  288.  
  289.         virtual void GetMemoryUsage(ICrySizer* s) const { s->Add(*this); }
  290.         virtual void GetConfiguration(SFlowNodeConfig& config);
  291.         virtual void ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo);
  292.  
  293. private:
  294.         enum EInputPorts
  295.         {
  296.                 eIP_Get = 0,
  297.                 eIP_Set,
  298.                 eIP_UserId,
  299.                 eIP_ModuleName,
  300.                 eIP_ModuleInstanceId,
  301.         };
  302.         enum EOutputPorts
  303.         {
  304.                 eOP_ModuleInstanceId = 0,
  305.         };
  306.  
  307.         typedef std::unordered_map<string, std::map<int, TModuleInstanceId>, stl::hash_strcmp<string>> TInstanceUserIDs;
  308.         static TInstanceUserIDs s_ids;
  309. };
  310.  
  311. //////////////////////////////////////////////////////////////////////////
  312. // helper node to get the count of running instances of a module
  313. //////////////////////////////////////////////////////////////////////////
  314. class CFlowModuleCountListener : public CFlowBaseNode<eNCT_Instanced>, IFlowGraphModuleListener
  315. {
  316. public:
  317.         CFlowModuleCountListener(SActivationInfo* pActInfo);
  318.         virtual ~CFlowModuleCountListener();
  319.  
  320.         virtual IFlowNodePtr Clone(SActivationInfo* pActInfo);
  321.         virtual void         GetMemoryUsage(ICrySizer* s) const { s->Add(*this); }
  322.         virtual void         GetConfiguration(SFlowNodeConfig& config);
  323.         virtual void         ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo);
  324.  
  325.         //IFlowGraphModuleListener
  326.         virtual void OnModuleInstanceCreated(IFlowGraphModule* pModule, TModuleInstanceId instanceID);
  327.         virtual void OnModuleInstanceDestroyed(IFlowGraphModule* pModule, TModuleInstanceId instanceID);
  328.         virtual void OnPostModuleDestroyed()                                                     {}
  329.         virtual void OnModuleDestroyed(IFlowGraphModule* pModule)                                {}
  330.         virtual void OnRootGraphChanged(IFlowGraphModule* module, ERootGraphChangeReason reason) {}
  331.         virtual void OnScannedForModules()                                                       {}
  332.         //~IFlowGraphModuleListener
  333.  
  334. private:
  335.         enum EInputPorts
  336.         {
  337.                 eIP_ModuleName,
  338.         };
  339.         enum EOutputPorts
  340.         {
  341.                 eOP_InstanceCount,
  342.         };
  343.         SActivationInfo m_actInfo;
  344.         string          m_sModuleName;
  345. };
  346.  
downloadFlowModuleNodes.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