BVB Source Codes

CRYENGINE Show FlowEntityNode.h Source code

Return Download CRYENGINE: download FlowEntityNode.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #pragma once
  4.  
  5. #include <CryFlowGraph/IFlowBaseNode.h>
  6.  
  7. //////////////////////////////////////////////////////////////////////////
  8. class CFlowEntityClass : public IFlowNodeFactory
  9. {
  10. public:
  11.         CFlowEntityClass(IEntityClass* pEntityClass);
  12.         ~CFlowEntityClass();
  13.         virtual void         AddRef()  { m_nRefCount++; }
  14.         virtual void         Release() { if (0 == --m_nRefCount) delete this; }
  15.         virtual IFlowNodePtr Create(IFlowNode::SActivationInfo*);
  16.  
  17.         virtual void         GetMemoryUsage(ICrySizer* s) const
  18.         {
  19.                 SIZER_SUBCOMPONENT_NAME(s, "CFlowEntityClass");
  20.                 s->AddObject(this, sizeof(*this));
  21.                 s->AddObject(m_inputs);
  22.                 s->AddObject(m_outputs);
  23.         }
  24.  
  25.         void        GetConfiguration(SFlowNodeConfig&);
  26.  
  27.         const char* CopyStr(const char* src);
  28.         void        FreeStr(const char* src);
  29.  
  30.         size_t      GetNumOutputs() { return m_outputs.size() - 1; }
  31.  
  32.         void        Reset();
  33.  
  34. private:
  35.         void GetInputsOutputs(IEntityClass* pEntityClass);
  36.         friend class CFlowEntityNode;
  37.  
  38.         int                            m_nRefCount;
  39.         //string m_classname;
  40.         IEntityClass*                  m_pEntityClass;
  41.         std::vector<SInputPortConfig>  m_inputs;
  42.         std::vector<SOutputPortConfig> m_outputs;
  43. };
  44.  
  45. //////////////////////////////////////////////////////////////////////////
  46. class CFlowEntityNodeBase : public CFlowBaseNode<eNCT_Instanced>, public IEntityEventListener
  47. {
  48. public:
  49.         CFlowEntityNodeBase()
  50.         {
  51.                 m_entityId = 0;
  52.                 m_event = ENTITY_EVENT_LAST;
  53.         };
  54.         ~CFlowEntityNodeBase()
  55.         {
  56.                 UnregisterEvent(m_event);
  57.         }
  58.  
  59.         // deliberately don't implement Clone(), make sure derived classes do.
  60.  
  61.         virtual void ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo)
  62.         {
  63.                 if (event != eFE_SetEntityId)
  64.                         return;
  65.  
  66.                 EntityId newEntityId = GetEntityId(pActInfo);
  67.  
  68.                 if (m_entityId && newEntityId)
  69.                         UnregisterEvent(m_event);
  70.  
  71.                 if (newEntityId)
  72.                 {
  73.                         m_entityId = newEntityId;
  74.                         RegisterEvent(m_event);
  75.                 }
  76.         }
  77.  
  78.         // Return entity of this node.
  79.         ILINE IEntity* GetEntity() const
  80.         {
  81.                 return gEnv->pEntitySystem->GetEntity(m_entityId);
  82.         }
  83.  
  84.         // Return entityId of this node
  85.         EntityId GetEntityId(SActivationInfo* pActInfo) const
  86.         {
  87.                 assert(pActInfo);
  88.  
  89.                 EntityId entityId = 0;
  90.  
  91.                 if (pActInfo->pEntity)
  92.                 {
  93.                         entityId = pActInfo->pEntity->GetId();
  94.                 }
  95.  
  96.                 return entityId;
  97.         }
  98.  
  99.         void RegisterEvent(EEntityEvent event)
  100.         {
  101.                 if (event != ENTITY_EVENT_LAST)
  102.                 {
  103.                         gEnv->pEntitySystem->AddEntityEventListener(m_entityId, event, this);
  104.                         gEnv->pEntitySystem->AddEntityEventListener(m_entityId, ENTITY_EVENT_DONE, this);
  105.                 }
  106.         }
  107.         void UnregisterEvent(EEntityEvent event)
  108.         {
  109.                 if (m_entityId && event != ENTITY_EVENT_LAST)
  110.                 {
  111.                         IEntitySystem* pEntitySystem = gEnv->pEntitySystem;
  112.                         if (pEntitySystem)
  113.                         {
  114.                                 pEntitySystem->RemoveEntityEventListener(m_entityId, event, this);
  115.                                 pEntitySystem->RemoveEntityEventListener(m_entityId, ENTITY_EVENT_DONE, this);
  116.                         }
  117.                 }
  118.         }
  119.  
  120.         virtual void GetMemoryUsage(ICrySizer* s) const
  121.         {
  122.                 s->Add(*this);
  123.         }
  124.  
  125. protected:
  126.         EEntityEvent m_event; // This member must be set in derived class constructor.
  127.         EntityId     m_entityId;
  128. };
  129.  
  130. //////////////////////////////////////////////////////////////////////////
  131. // Flow node for entity.
  132. //////////////////////////////////////////////////////////////////////////
  133. class CFlowEntityNode : public CFlowEntityNodeBase
  134. {
  135. public:
  136.         CFlowEntityNode(CFlowEntityClass* pClass, SActivationInfo* pActInfo);
  137.         virtual IFlowNodePtr Clone(SActivationInfo* pActInfo);
  138.         virtual void         GetConfiguration(SFlowNodeConfig&);
  139.         virtual void         ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo);
  140.         virtual bool         SerializeXML(SActivationInfo*, const XmlNodeRef&, bool);
  141.  
  142.         //////////////////////////////////////////////////////////////////////////
  143.         // IEntityEventListener
  144.         virtual void OnEntityEvent(IEntity* pEntity, SEntityEvent& event);
  145.         //////////////////////////////////////////////////////////////////////////
  146.  
  147.         virtual void GetMemoryUsage(ICrySizer* s) const
  148.         {
  149.                 s->Add(*this);
  150.         }
  151.  
  152. protected:
  153.         void Serialize(SActivationInfo* pActInfo, TSerialize ser);
  154.         void SendEventToEntity(SActivationInfo* pActInfo, IEntity* pEntity);
  155.  
  156.         IFlowGraph*                  m_pGraph;
  157.         TFlowNodeId                  m_nodeID;
  158.         _smart_ptr<CFlowEntityClass> m_pClass;
  159.         int                          m_lastInitializeFrameId;
  160. };
  161.  
downloadFlowEntityNode.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