aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/EventProcessor.cpp
diff options
context:
space:
mode:
authorNaios <naios-dev@live.de>2016-07-03 00:06:49 +0200
committerNaios <naios-dev@live.de>2016-07-05 00:19:45 +0200
commit80fe552894a42b0be45fcc0fa0d55a7551e0149f (patch)
tree529fb1221d3bc3fd8a2614238421747cc6c49fe0 /src/common/Utilities/EventProcessor.cpp
parent1a891f3a5edf173adcd304aa4bfc6828b63fb507 (diff)
Core/EventProcessor: Wait for non deletable events to get deletable.
* Immediate deletion caused issues with the SpellEvent, so we delete it at one of the next update ticks now. * Only affects the unforced cancellation of events. * Ref #16675 (cherry picked from commit 1ad73212dca0cf8a829d15ffdbcc4cd611e64d4e)
Diffstat (limited to 'src/common/Utilities/EventProcessor.cpp')
-rw-r--r--src/common/Utilities/EventProcessor.cpp51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/common/Utilities/EventProcessor.cpp b/src/common/Utilities/EventProcessor.cpp
index be74d58b790..195deeb054b 100644
--- a/src/common/Utilities/EventProcessor.cpp
+++ b/src/common/Utilities/EventProcessor.cpp
@@ -17,11 +17,20 @@
*/
#include "EventProcessor.h"
+#include "Errors.h"
-EventProcessor::EventProcessor()
+void BasicEvent::ScheduleAbort()
{
- m_time = 0;
- m_aborting = false;
+ ASSERT(IsRunning()
+ && "Tried to scheduled the abortion of an event twice!");
+ m_abortState = AbortState::STATE_ABORT_SCHEDULED;
+}
+
+void BasicEvent::SetAborted()
+{
+ ASSERT(!IsAborted()
+ && "Tried to abort an already aborted event!");
+ m_abortState = AbortState::STATE_ABORTED;
}
EventProcessor::~EventProcessor()
@@ -39,37 +48,47 @@ void EventProcessor::Update(uint32 p_time)
while (((i = m_events.begin()) != m_events.end()) && i->first <= m_time)
{
// get and remove event from queue
- BasicEvent* Event = i->second;
+ BasicEvent* event = i->second;
m_events.erase(i);
- if (!Event->to_Abort)
+ if (event->IsRunning())
{
- if (Event->Execute(m_time, p_time))
+ if (event->Execute(m_time, p_time))
{
// completely destroy event if it is not re-added
- delete Event;
+ delete event;
}
+ continue;
+ }
+
+ if (event->IsAbortScheduled())
+ {
+ event->Abort(m_time);
+ // Mark the event as aborted
+ event->SetAborted();
}
- else
+
+ if (event->IsDeletable())
{
- Event->Abort(m_time);
- delete Event;
+ delete event;
+ continue;
}
+
+ // Reschedule non deletable events to be checked at
+ // the next update tick
+ AddEvent(event, CalculateTime(1), false);
}
}
void EventProcessor::KillAllEvents(bool force)
{
- // prevent event insertions
- m_aborting = true;
-
// first, abort all existing events
for (EventList::iterator i = m_events.begin(); i != m_events.end();)
{
EventList::iterator i_old = i;
++i;
- i_old->second->to_Abort = true;
+ i_old->second->SetAborted();
i_old->second->Abort(m_time);
if (force || i_old->second->IsDeletable())
{
@@ -87,7 +106,8 @@ void EventProcessor::KillAllEvents(bool force)
void EventProcessor::AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime)
{
- if (set_addtime) Event->m_addTime = m_time;
+ if (set_addtime)
+ Event->m_addTime = m_time;
Event->m_execTime = e_time;
m_events.insert(std::pair<uint64, BasicEvent*>(e_time, Event));
}
@@ -96,4 +116,3 @@ uint64 EventProcessor::CalculateTime(uint64 t_offset) const
{
return(m_time + t_offset);
}
-