!I integrate from //ce/main...
[CRYENGINE.git] / Code / CryEngine / CryAction / ActionFilter.cpp
blob40b6123ad22ecaa610a37b625b0063e2d911a11c
1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 /*************************************************************************
4 -------------------------------------------------------------------------
5 $Id$
6 $DateTime$
8 -------------------------------------------------------------------------
9 History:
10 - 8:9:2004 10:33 : Created by Márcio Martins
12 *************************************************************************/
13 #include "StdAfx.h"
14 #include "ActionFilter.h"
15 #include "ActionMapManager.h"
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)
27 //------------------------------------------------------------------------
28 CActionFilter::~CActionFilter()
32 //------------------------------------------------------------------------
33 void CActionFilter::Filter(const ActionId& action)
35 m_filterActions.insert(action);
38 //------------------------------------------------------------------------
39 void CActionFilter::Enable(bool enable)
41 m_enabled = enable;
43 // auto-release all actions which
44 if (m_enabled && m_type == eAFT_ActionFail)
46 TFilterActions::const_iterator it = m_filterActions.begin();
47 TFilterActions::const_iterator end = m_filterActions.end();
48 for (; it != end; ++it)
50 m_pActionMapManager->ReleaseActionIfActive(*it);
53 else if (!m_enabled)
55 // Reset analog key states
56 if (!gEnv->IsDedicated())
57 CRY_ASSERT(m_pInput); // don't assert on dedicated servers OR clients
59 if (m_pInput)
61 m_pInput->ClearAnalogKeyState();
64 if (m_pActionMapManager)
66 m_pActionMapManager->RemoveAllRefireData();
70 if (m_pActionMapManager)
72 m_pActionMapManager->BroadcastActionMapEvent(SActionMapEvent(SActionMapEvent::eActionMapManagerEvent_FilterStatusChanged, (UINT_PTR)enable, (UINT_PTR)GetName()));
75 //------------------------------------------------------------------------
76 bool CActionFilter::ActionFiltered(const ActionId& action)
78 // never filter anything out when disabled
79 if (!m_enabled)
80 return false;
82 TFilterActions::const_iterator it = m_filterActions.find(action);
84 if ((m_type == eAFT_ActionPass) == (it == m_filterActions.end()))
86 static ICVar* pDebugVar = gEnv->pConsole->GetCVar("i_debug");
87 if (pDebugVar && pDebugVar->GetIVal() != 0)
89 CryLog("Action %s is filtered by %s", action.c_str(), m_name.c_str());
91 return true;
93 else
95 return false;
99 //------------------------------------------------------------------------
100 bool CActionFilter::SerializeXML(const XmlNodeRef& root, bool bLoading)
102 if (bLoading)
104 // loading
105 const XmlNodeRef& child = root;
106 if (strcmp(child->getTag(), "actionfilter") != 0)
107 return false;
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;
115 m_type = actionFilterType;
117 int nFilters = child->getChildCount();
118 for (int f = 0; f < nFilters; ++f)
120 XmlNodeRef filter = child->getChild(f);
121 Filter(CCryName(filter->getAttr("name")));
124 else
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())
134 XmlNodeRef filterChild = filterRoot->newChild("filter");
135 filterChild->setAttr("name", iter->c_str());
136 ++iter;
139 return true;
142 void CActionFilter::GetMemoryUsage(ICrySizer* s) const
144 s->AddObject(m_filterActions);