@@ -19,7 +19,6 @@ CEvents::CEvents()
1919{
2020 m_bWasEventCancelled = false ;
2121 m_bEventCancelled = false ;
22- m_pCurrentContext = nullptr ;
2322}
2423
2524bool CEvents::AddEvent (const char * szName, const char * szArguments, CLuaMain* pLuaMain, bool bAllowRemoteTrigger)
@@ -132,8 +131,8 @@ void CEvents::PreEventPulse(CEventContext* pContext)
132131 assert (pContext);
133132
134133 m_CancelledList.push_back (m_bEventCancelled);
134+ m_ContextStack.push_back (pContext);
135135
136- m_pCurrentContext = pContext;
137136 pContext->Reset ();
138137
139138 m_bEventCancelled = false ;
@@ -144,13 +143,13 @@ void CEvents::PreEventPulse(CEventContext* pContext)
144143void CEvents::PostEventPulse (CEventContext* pContext)
145144{
146145 assert (pContext);
147- assert (m_pCurrentContext == pContext);
146+ assert (!m_ContextStack.empty ());
147+ assert (m_ContextStack.back () == pContext);
148148
149149 m_bWasEventCancelled = pContext->IsCancelled ();
150150 m_bEventCancelled = m_CancelledList.back () ? true : false ;
151151 m_CancelledList.pop_back ();
152-
153- m_pCurrentContext = nullptr ;
152+ m_ContextStack.pop_back ();
154153}
155154
156155void CEvents::CancelEvent (bool bCancelled)
@@ -164,12 +163,13 @@ void CEvents::CancelEvent(bool bCancelled, const char* szReason)
164163 m_bEventCancelled = bCancelled;
165164
166165 // Also update context if it exists
167- if (m_pCurrentContext )
166+ if (!m_ContextStack. empty () )
168167 {
168+ CEventContext* pCurrentContext = m_ContextStack.back ();
169169 if (bCancelled)
170- m_pCurrentContext ->Cancel (szReason);
170+ pCurrentContext ->Cancel (szReason);
171171 else
172- m_pCurrentContext ->Reset ();
172+ pCurrentContext ->Reset ();
173173 }
174174
175175 if (szReason)
@@ -178,16 +178,16 @@ void CEvents::CancelEvent(bool bCancelled, const char* szReason)
178178
179179bool CEvents::WasEventCancelled ()
180180{
181- if (m_pCurrentContext )
182- return m_pCurrentContext ->IsCancelled ();
181+ if (!m_ContextStack. empty () )
182+ return m_ContextStack. back () ->IsCancelled ();
183183
184184 return m_bEventCancelled || m_bWasEventCancelled;
185185}
186186
187187const char * CEvents::GetLastError ()
188188{
189- if (m_pCurrentContext )
190- return m_pCurrentContext ->GetCancelReason ().c_str ();
189+ if (!m_ContextStack. empty () )
190+ return m_ContextStack. back () ->GetCancelReason ().c_str ();
191191
192192 return m_strLastError;
193193}
0 commit comments