BVB Source Codes

CRYENGINE Show ActionFilter.cpp Source code

Return Download CRYENGINE: download ActionFilter.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.  
  8.    -------------------------------------------------------------------------
  9.    History:
  10.    - 8:9:2004   10:33 : Created by M谩rcio Martins
  11.  
  12. *************************************************************************/
  13. #include "StdAfx.h"
  14. #include "ActionFilter.h"
  15. #include "ActionMapManager.h"
  16.  
  17. //------------------------------------------------------------------------
  18. CActionFilter::CActionFilter(CActionMapManager* pActionMapManager, IInput* pInput, const char* name, EActionFilterType type)
  19.         : m_pActionMapManager(pActionMapManager),
  20.         m_pInput(pInput),
  21.         m_enabled(false),
  22.         m_type(type),
  23.         m_name(name)
  24. {
  25. }
  26.  
  27. //------------------------------------------------------------------------
  28. CActionFilter::~CActionFilter()
  29. {
  30. }
  31.  
  32. //------------------------------------------------------------------------
  33. void CActionFilter::Filter(const ActionId& action)
  34. {
  35.         m_filterActions.insert(action);
  36. }
  37.  
  38. //------------------------------------------------------------------------
  39. void CActionFilter::Enable(bool enable)
  40. {
  41.         m_enabled = enable;
  42.  
  43.         // auto-release all actions which
  44.         if (m_enabled && m_type == eAFT_ActionFail)
  45.         {
  46.                 TFilterActions::const_iterator it = m_filterActions.begin();
  47.                 TFilterActions::const_iterator end = m_filterActions.end();
  48.                 for (; it != end; ++it)
  49.                 {
  50.                         m_pActionMapManager->ReleaseActionIfActive(*it);
  51.                 }
  52.         }
  53.         else if (!m_enabled)
  54.         {
  55.                 // Reset analog key states
  56.                 if (!gEnv->IsDedicated())
  57.                         CRY_ASSERT(m_pInput); // don't assert on dedicated servers OR clients
  58.  
  59.                 if (m_pInput)
  60.                 {
  61.                         m_pInput->ClearAnalogKeyState();
  62.                 }
  63.  
  64.                 if (m_pActionMapManager)
  65.                 {
  66.                         m_pActionMapManager->RemoveAllRefireData();
  67.                 }
  68.         }
  69.  
  70.         if (m_pActionMapManager)
  71.         {
  72.                 m_pActionMapManager->BroadcastActionMapEvent(SActionMapEvent(SActionMapEvent::eActionMapManagerEvent_FilterStatusChanged, (UINT_PTR)enable, (UINT_PTR)GetName()));
  73.         }
  74. };
  75. //------------------------------------------------------------------------
  76. bool CActionFilter::ActionFiltered(const ActionId& action)
  77. {
  78.         // never filter anything out when disabled
  79.         if (!m_enabled)
  80.                 return false;
  81.  
  82.         TFilterActions::const_iterator it = m_filterActions.find(action);
  83.  
  84.         if ((m_type == eAFT_ActionPass) == (it == m_filterActions.end()))
  85.         {
  86.                 static ICVar* pDebugVar = gEnv->pConsole->GetCVar("i_debug");
  87.                 if (pDebugVar && pDebugVar->GetIVal() != 0)
  88.                 {
  89.                         CryLog("Action %s is filtered by %s", action.c_str(), m_name.c_str());
  90.                 }
  91.                 return true;
  92.         }
  93.         else
  94.         {
  95.                 return false;
  96.         }
  97. }
  98.  
  99. //------------------------------------------------------------------------
  100. bool CActionFilter::SerializeXML(const XmlNodeRef& root, bool bLoading)
  101. {
  102.         if (bLoading)
  103.         {
  104.                 // loading
  105.                 const XmlNodeRef& child = root;
  106.                 if (strcmp(child->getTag(), "actionfilter") != 0)
  107.                         return false;
  108.  
  109.                 EActionFilterType actionFilterType = eAFT_ActionFail;
  110.                 if (!strcmp(child->getAttr("type"), "actionFail"))
  111.                         actionFilterType = eAFT_ActionFail;
  112.                 if (!strcmp(child->getAttr("type"), "actionPass"))
  113.                         actionFilterType = eAFT_ActionPass;
  114.  
  115.                 m_type = actionFilterType;
  116.  
  117.                 int nFilters = child->getChildCount();
  118.                 for (int f = 0; f < nFilters; ++f)
  119.                 {
  120.                         XmlNodeRef filter = child->getChild(f);
  121.                         Filter(CCryName(filter->getAttr("name")));
  122.                 }
  123.         }
  124.         else
  125.         {
  126.                 // saving
  127.                 XmlNodeRef filterRoot = root->newChild("actionfilter");
  128.                 filterRoot->setAttr("name", m_name);
  129.                 filterRoot->setAttr("type", m_type == eAFT_ActionPass ? "actionPass" : "actionFail");
  130.                 filterRoot->setAttr("version", m_pActionMapManager->GetVersion());
  131.                 TFilterActions::const_iterator iter = m_filterActions.begin();
  132.                 while (iter != m_filterActions.end())
  133.                 {
  134.                         XmlNodeRef filterChild = filterRoot->newChild("filter");
  135.                         filterChild->setAttr("name", iter->c_str());
  136.                         ++iter;
  137.                 }
  138.         }
  139.         return true;
  140. }
  141.  
  142. void CActionFilter::GetMemoryUsage(ICrySizer* s) const
  143. {
  144.         s->AddObject(m_filterActions);
  145. }
  146.  
downloadActionFilter.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