BVB Source Codes

CRYENGINE Show FlowFilters.cpp Source code

Return Download CRYENGINE: download FlowFilters.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:   FlowFilters.h
  5. //  Version:     v1.00
  6. //  Created:     27/03/2006 by AlexL
  7. //  Compilers:   Visual Studio.NET 2003
  8. //  Description: Some Inspector filters
  9. // -------------------------------------------------------------------------
  10. //  History:
  11. //
  12. ////////////////////////////////////////////////////////////////////////////
  13. #include "StdAfx.h"
  14.  
  15. #include "FlowFilters.h"
  16. #include <CryFlowGraph/IFlowSystem.h>
  17. #include <CryAISystem/IAIAction.h>
  18. #include <CryEntitySystem/IEntity.h>
  19. #include <CryEntitySystem/IEntityClass.h>
  20.  
  21. namespace
  22. {
  23. std::map<string, CFlowFilterBase* (*)()>* g_pCreatorMap = NULL;
  24. template<typename T, typename Base> Base* Create() { return new T(); };
  25.  
  26. std::map<string, CFlowFilterBase* (*)()>& GetCreatorMap()
  27. {
  28.         if (!g_pCreatorMap)
  29.         {
  30.                 g_pCreatorMap = new std::map<string, CFlowFilterBase* (*)()>();
  31.                 (*g_pCreatorMap)[CFlowFilterAIAction::GetClassName()] = &Create<CFlowFilterAIAction, CFlowFilterBase>;
  32.                 (*g_pCreatorMap)[CFlowFilterEntity::GetClassName()] = &Create<CFlowFilterEntity, CFlowFilterBase>;
  33.                 (*g_pCreatorMap)[CFlowFilterNode::GetClassName()] = &Create<CFlowFilterNode, CFlowFilterBase>;
  34.         }
  35.         return *g_pCreatorMap;
  36. }
  37. }
  38.  
  39. /* static */ CFlowFilterBase*
  40. CFlowFilterBase::CreateFilter(const char* filterType)
  41. {
  42.         std::map<string, CFlowFilterBase* (*)()>::iterator iter = GetCreatorMap().find(filterType);
  43.         if (iter != GetCreatorMap().end())
  44.                 return ((*iter).second)();
  45.         return 0;
  46. }
  47.  
  48. CFlowFilterEntity::CFlowFilterEntity() : CFlowFilterBase(eFF_Entity), m_entityId(0)
  49. {
  50. }
  51.  
  52. /* virtual */ IFlowGraphInspector::IFilter::EFilterResult
  53. CFlowFilterEntity::Apply(IFlowGraph* pGraph, const SFlowAddress from, const SFlowAddress to)
  54. {
  55.         if (m_entityId == 0 || m_entityId == pGraph->GetGraphEntity(0) || m_entityId == pGraph->GetGraphEntity(1))
  56.                 return eFR_Pass;
  57.  
  58.         return eFR_Block;
  59. }
  60.  
  61. CFlowFilterAIAction::CFlowFilterAIAction() : CFlowFilterBase(eFF_AIAction)
  62. {
  63.         m_userId = 0;
  64.         m_objectId = 0;
  65. }
  66.  
  67. void
  68. CFlowFilterAIAction::SetParams(const string& userClass, const string& objectClass, EntityId userId, EntityId objectId)
  69. {
  70.         m_userClass = userClass;
  71.         m_userId = userId;
  72.         m_objectClass = objectClass;
  73.         m_objectId = objectId;
  74. }
  75.  
  76. void
  77. CFlowFilterAIAction::GetParams(string& userClass, EntityId& userId, string& objectClass, EntityId& objectId) const
  78. {
  79.         userClass = m_userClass;
  80.         userId = m_userId;
  81.         objectClass = m_objectClass;
  82.         objectId = m_objectId;
  83. }
  84.  
  85. /* virtual */ IFlowGraphInspector::IFilter::EFilterResult
  86. CFlowFilterAIAction::Apply(IFlowGraph* pGraph, const SFlowAddress from, const SFlowAddress to)
  87. {
  88.         IAIAction* pAction = pGraph->GetAIAction();
  89.  
  90.         // no AI action
  91.         if (!pAction)
  92.                 return eFR_Block;
  93.  
  94.         // it's an AI action, but not the one we're interested in -> block
  95.         if (m_actionName.empty() == false && m_actionName.compare(pAction->GetName()) != 0)
  96.                 return eFR_Block;
  97.  
  98.         IEntity* pUser = pAction->GetUserEntity();
  99.         // check for specific user entity
  100.         if (m_userId > 0)
  101.         {
  102.                 if (!pUser) return eFR_Block;                     // there is no user at all
  103.                 if (pUser->GetId() != m_userId) return eFR_Block; // user entity does not match
  104.         }
  105.         // otherwise check for the user's class if applicable
  106.         else if (!m_userClass.empty())
  107.         {
  108.                 if (!pUser) return eFR_Block; // no user at all
  109.                 if (m_userClass.compare(pUser->GetClass()->GetName()) != 0) return eFR_Block;
  110.         }
  111.  
  112.         IEntity* pObject = pAction->GetObjectEntity();
  113.         // check for specific object entity
  114.         if (m_objectId > 0)
  115.         {
  116.                 if (!pObject) return eFR_Block;
  117.                 if (pObject->GetId() != m_objectId) return eFR_Block;
  118.         }
  119.         // otherwise check for the object's class if applicable
  120.         else if (!m_objectClass.empty())
  121.         {
  122.                 if (!pObject) return eFR_Block; // no object at all
  123.                 if (m_objectClass.compare(pObject->GetClass()->GetName()) != 0) return eFR_Block;
  124.         }
  125.  
  126.         // it passed all tests and no subfilters -> great
  127.         if (m_filters.empty())
  128.                 return eFR_Pass;
  129.  
  130.         // ask sub-filters: if anyone says yes, so do we (basically ORing the sub-filter results)
  131.         // otherwise we block
  132.         IFilter::EFilterResult res = eFR_Block;
  133.         IFlowGraphInspector::IFilter_AutoArray::iterator iter(m_filters.begin());
  134.         IFlowGraphInspector::IFilter_AutoArray::iterator end(m_filters.end());
  135.         while (iter != end)
  136.         {
  137.                 res = (*iter)->Apply(pGraph, from, to);
  138.                 if (res == eFR_Pass)
  139.                         break;
  140.                 ++iter;
  141.         }
  142.         return res;
  143. }
  144.  
  145. CFlowFilterNode::CFlowFilterNode() : CFlowFilterBase(eFF_Node)
  146. {
  147.         m_nodeId = InvalidFlowNodeId;
  148. }
  149.  
  150. /* virtual */ IFlowGraphInspector::IFilter::EFilterResult
  151. CFlowFilterNode::Apply(IFlowGraph* pGraph, const SFlowAddress from, const SFlowAddress to)
  152. {
  153.         if (from.node == m_nodeId || to.node == m_nodeId)
  154.         {
  155.                 if (m_nodeType.compare(pGraph->GetNodeTypeName(m_nodeId)) != 0) return eFR_Block;
  156.         }
  157.         return eFR_Pass;
  158. }
  159.  
downloadFlowFilters.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