Switch EventManager off KTrie (bug 5884 part 13, r=ds).
This commit is contained in:
parent
80eba57e6b
commit
d5177fdc74
@ -57,14 +57,10 @@ public:
|
|||||||
|
|
||||||
EventManager::EventManager() : m_EventType(0)
|
EventManager::EventManager() : m_EventType(0)
|
||||||
{
|
{
|
||||||
/* Create an event lookup trie */
|
|
||||||
m_EventHooks = sm_trie_create();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EventManager::~EventManager()
|
EventManager::~EventManager()
|
||||||
{
|
{
|
||||||
sm_trie_destroy(m_EventHooks);
|
|
||||||
|
|
||||||
/* Free memory used by EventInfo structs if any */
|
/* Free memory used by EventInfo structs if any */
|
||||||
CStack<EventInfo *>::iterator iter;
|
CStack<EventInfo *>::iterator iter;
|
||||||
for (iter = m_FreeEvents.begin(); iter != m_FreeEvents.end(); iter++)
|
for (iter = m_FreeEvents.begin(); iter != m_FreeEvents.end(); iter++)
|
||||||
@ -183,7 +179,7 @@ EventHookError EventManager::HookEvent(const char *name, IPluginFunction *pFunct
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If a hook structure does not exist... */
|
/* If a hook structure does not exist... */
|
||||||
if (!sm_trie_retrieve(m_EventHooks, name, (void **)&pHook))
|
if (!m_EventHooks.retrieve(name, &pHook))
|
||||||
{
|
{
|
||||||
EventHookList *pHookList;
|
EventHookList *pHookList;
|
||||||
IPlugin *plugin = scripts->FindPluginByContext(pFunction->GetParentContext()->GetContext());
|
IPlugin *plugin = scripts->FindPluginByContext(pFunction->GetParentContext()->GetContext());
|
||||||
@ -221,7 +217,7 @@ EventHookError EventManager::HookEvent(const char *name, IPluginFunction *pFunct
|
|||||||
|
|
||||||
/* Add hook structure to hook lists */
|
/* Add hook structure to hook lists */
|
||||||
pHookList->push_back(pHook);
|
pHookList->push_back(pHook);
|
||||||
sm_trie_insert(m_EventHooks, name, pHook);
|
m_EventHooks.insert(name, pHook);
|
||||||
|
|
||||||
return EventHookErr_Okay;
|
return EventHookErr_Okay;
|
||||||
}
|
}
|
||||||
@ -267,7 +263,7 @@ EventHookError EventManager::UnhookEvent(const char *name, IPluginFunction *pFun
|
|||||||
IChangeableForward **pEventForward;
|
IChangeableForward **pEventForward;
|
||||||
|
|
||||||
/* If hook does not exist at all */
|
/* If hook does not exist at all */
|
||||||
if (!sm_trie_retrieve(m_EventHooks, name, (void **)&pHook))
|
if (!m_EventHooks.retrieve(name, &pHook))
|
||||||
{
|
{
|
||||||
return EventHookErr_NotActive;
|
return EventHookErr_NotActive;
|
||||||
}
|
}
|
||||||
@ -317,7 +313,7 @@ EventHookError EventManager::UnhookEvent(const char *name, IPluginFunction *pFun
|
|||||||
pHookList->remove(pHook);
|
pHookList->remove(pHook);
|
||||||
|
|
||||||
/* Delete entry in trie */
|
/* Delete entry in trie */
|
||||||
sm_trie_delete(m_EventHooks, name);
|
m_EventHooks.remove(name);
|
||||||
|
|
||||||
/* Free the cached name */
|
/* Free the cached name */
|
||||||
delete pHook->name;
|
delete pHook->name;
|
||||||
@ -396,7 +392,7 @@ bool EventManager::OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast)
|
|||||||
|
|
||||||
name = pEvent->GetName();
|
name = pEvent->GetName();
|
||||||
|
|
||||||
if (sm_trie_retrieve(m_EventHooks, name, reinterpret_cast<void **>(&pHook)))
|
if (m_EventHooks.retrieve(name, &pHook))
|
||||||
{
|
{
|
||||||
/* Push the event onto the event stack. The reference count is increased to make sure
|
/* Push the event onto the event stack. The reference count is increased to make sure
|
||||||
* the structure is not garbage collected in between now and the post hook.
|
* the structure is not garbage collected in between now and the post hook.
|
||||||
@ -503,7 +499,7 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast)
|
|||||||
{
|
{
|
||||||
assert(pHook->pPostHook == NULL);
|
assert(pHook->pPostHook == NULL);
|
||||||
assert(pHook->pPreHook == NULL);
|
assert(pHook->pPreHook == NULL);
|
||||||
sm_trie_delete(m_EventHooks, pHook->name);
|
m_EventHooks.remove(pHook->name);
|
||||||
delete pHook->name;
|
delete pHook->name;
|
||||||
delete pHook;
|
delete pHook;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 :
|
* vim: set ts=4 sw=4 tw=99 noet :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
|
||||||
@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
#include "sm_globals.h"
|
#include "sm_globals.h"
|
||||||
#include "sourcemm_api.h"
|
#include "sourcemm_api.h"
|
||||||
#include "sm_trie.h"
|
#include <sm_namehashset.h>
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
#include <sh_stack.h>
|
#include <sh_stack.h>
|
||||||
#include <IHandleSys.h>
|
#include <IHandleSys.h>
|
||||||
@ -70,6 +70,11 @@ struct EventHook
|
|||||||
bool postCopy;
|
bool postCopy;
|
||||||
unsigned int refCount;
|
unsigned int refCount;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
|
static inline bool matches(const char *name, const EventHook *hook)
|
||||||
|
{
|
||||||
|
return strcmp(name, hook->name) == 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum EventHookMode
|
enum EventHookMode
|
||||||
@ -127,7 +132,7 @@ private: // IGameEventManager2 hooks
|
|||||||
bool OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast);
|
bool OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast);
|
||||||
private:
|
private:
|
||||||
HandleType_t m_EventType;
|
HandleType_t m_EventType;
|
||||||
Trie *m_EventHooks;
|
NameHashSet<EventHook *> m_EventHooks;
|
||||||
CStack<EventInfo *> m_FreeEvents;
|
CStack<EventInfo *> m_FreeEvents;
|
||||||
CStack<EventHook *> m_EventStack;
|
CStack<EventHook *> m_EventStack;
|
||||||
CStack<IGameEvent *> m_EventCopies;
|
CStack<IGameEvent *> m_EventCopies;
|
||||||
|
Loading…
Reference in New Issue
Block a user