core/EventManager.cpp
changeset 684 6e46bb7aaf70
parent 653 ef60870067ff
child 687 d9779d053851
     1.1 --- a/core/EventManager.cpp	Thu Apr 12 02:16:09 2007 +0000
     1.2 +++ b/core/EventManager.cpp	Thu Apr 12 07:51:05 2007 +0000
     1.3 @@ -25,7 +25,7 @@
     1.4  const ParamType GAMEEVENT_PARAMS[] = {Param_Cell, Param_String, Param_Cell};
     1.5  typedef List<EventHook *> EventHookList;
     1.6  
     1.7 -EventManager::EventManager() : m_EventType(0), m_NotifyPlugins(true), m_EventCopy(NULL)
     1.8 +EventManager::EventManager() : m_EventType(0), m_NotifyPlugins(true)
     1.9  {
    1.10  	/* Create an event lookup trie */
    1.11  	m_EventHooks = sm_trie_create();
    1.12 @@ -322,6 +322,7 @@
    1.13  {
    1.14  	EventHook *pHook;
    1.15  	IChangeableForward *pForward;
    1.16 +	const char *name;
    1.17  	cell_t res = Pl_Continue;
    1.18  
    1.19  	if (!m_NotifyPlugins)
    1.20 @@ -330,9 +331,11 @@
    1.21  	}
    1.22  	
    1.23  	/* Get the event name, we're going to need this for passing to post hooks */
    1.24 -	m_EventName = pEvent->GetName();
    1.25 +	name = pEvent->GetName();
    1.26  
    1.27 -	if (sm_trie_retrieve(m_EventHooks, m_EventName, reinterpret_cast<void **>(&pHook)))
    1.28 +	m_EventNames.push(name);
    1.29 +
    1.30 +	if (sm_trie_retrieve(m_EventHooks, name, reinterpret_cast<void **>(&pHook)))
    1.31  	{
    1.32  		pForward = pHook->pPreHook;
    1.33  
    1.34 @@ -342,7 +345,7 @@
    1.35  
    1.36  			Handle_t hndl = g_HandleSys.CreateHandle(m_EventType, &info, NULL, g_pCoreIdent, NULL);
    1.37  			pForward->PushCell(hndl);
    1.38 -			pForward->PushString(m_EventName);
    1.39 +			pForward->PushString(name);
    1.40  			pForward->PushCell(bDontBroadcast);
    1.41  			pForward->Execute(&res, NULL);
    1.42  
    1.43 @@ -352,7 +355,7 @@
    1.44  
    1.45  		if (pHook->postCopy)
    1.46  		{
    1.47 -			m_EventCopy = gameevents->DuplicateEvent(pEvent);
    1.48 +			pHook->pEventCopy = gameevents->DuplicateEvent(pEvent);
    1.49  		}
    1.50  
    1.51  		if (res)
    1.52 @@ -368,8 +371,10 @@
    1.53  /* IGameEventManager2::FireEvent post hook */
    1.54  bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast)
    1.55  {
    1.56 +	IGameEvent *pEventCopy;
    1.57  	EventHook *pHook;
    1.58  	IChangeableForward *pForward;
    1.59 +	const char *name;
    1.60  	Handle_t hndl = 0;
    1.61  
    1.62  	if (!m_NotifyPlugins)
    1.63 @@ -380,7 +385,9 @@
    1.64  		RETURN_META_VALUE(MRES_IGNORED, true);
    1.65  	}
    1.66  
    1.67 -	if (sm_trie_retrieve(m_EventHooks, m_EventName, reinterpret_cast<void **>(&pHook)))
    1.68 +	name = m_EventNames.front();
    1.69 +
    1.70 +	if (sm_trie_retrieve(m_EventHooks, name, reinterpret_cast<void **>(&pHook)))
    1.71  	{
    1.72  		pForward = pHook->pPostHook;
    1.73  
    1.74 @@ -388,14 +395,17 @@
    1.75  		{
    1.76  			if (pHook->postCopy)
    1.77  			{
    1.78 -				EventInfo info = {m_EventCopy, false};
    1.79 +				pEventCopy = pHook->pEventCopy;
    1.80 +
    1.81 +				EventInfo info = {pEventCopy, false};
    1.82  				hndl = g_HandleSys.CreateHandle(m_EventType, &info, NULL, g_pCoreIdent, NULL);
    1.83 +
    1.84  				pForward->PushCell(hndl);
    1.85  			} else {
    1.86  				pForward->PushCell(BAD_HANDLE);
    1.87  			}
    1.88  
    1.89 -			pForward->PushString(m_EventName);
    1.90 +			pForward->PushString(name);
    1.91  			pForward->PushCell(bDontBroadcast);
    1.92  			pForward->Execute(NULL);
    1.93  
    1.94 @@ -406,11 +416,13 @@
    1.95  				g_HandleSys.FreeHandle(hndl, &sec);
    1.96  
    1.97  				/* Free event structure */
    1.98 -				gameevents->FreeEvent(m_EventCopy);
    1.99 -				m_EventCopy = NULL;
   1.100 +				gameevents->FreeEvent(pEventCopy);
   1.101 +				pHook->pEventCopy = NULL;
   1.102  			}
   1.103  		}
   1.104  	}
   1.105  
   1.106 +	m_EventNames.pop();
   1.107 +
   1.108  	RETURN_META_VALUE(MRES_IGNORED, true);
   1.109  }