1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 /*************************************************************************
4 -------------------------------------------------------------------------
8 -------------------------------------------------------------------------
10 - 8:9:2004 10:33 : Created by Márcio Martins
12 *************************************************************************/
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
),
27 //------------------------------------------------------------------------
28 CActionFilter::~CActionFilter()
32 //------------------------------------------------------------------------
33 void CActionFilter::Filter(const ActionId
& action
)
35 m_filterActions
.insert(action
);
38 //------------------------------------------------------------------------
39 void CActionFilter::Enable(bool 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
);
55 // Reset analog key states
56 if (!gEnv
->IsDedicated())
57 CRY_ASSERT(m_pInput
); // don't assert on dedicated servers OR clients
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
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());
99 //------------------------------------------------------------------------
100 bool CActionFilter::SerializeXML(const XmlNodeRef
& root
, bool bLoading
)
105 const XmlNodeRef
& child
= root
;
106 if (strcmp(child
->getTag(), "actionfilter") != 0)
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")));
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());
142 void CActionFilter::GetMemoryUsage(ICrySizer
* s
) const
144 s
->AddObject(m_filterActions
);