diff options
author | Naios <naios-dev@live.de> | 2016-07-03 00:06:49 +0200 |
---|---|---|
committer | Naios <naios-dev@live.de> | 2016-07-05 00:19:45 +0200 |
commit | 80fe552894a42b0be45fcc0fa0d55a7551e0149f (patch) | |
tree | 529fb1221d3bc3fd8a2614238421747cc6c49fe0 /src/common/Utilities/EventProcessor.h | |
parent | 1a891f3a5edf173adcd304aa4bfc6828b63fb507 (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.h')
-rw-r--r-- | src/common/Utilities/EventProcessor.h | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/src/common/Utilities/EventProcessor.h b/src/common/Utilities/EventProcessor.h index e10558e6a21..57f3065f323 100644 --- a/src/common/Utilities/EventProcessor.h +++ b/src/common/Utilities/EventProcessor.h @@ -20,20 +20,27 @@ #define __EVENTPROCESSOR_H #include "Define.h" - #include <map> +class EventProcessor; + // Note. All times are in milliseconds here. class TC_COMMON_API BasicEvent { + friend class EventProcessor; + + enum class AbortState : uint8 + { + STATE_RUNNING, + STATE_ABORT_SCHEDULED, + STATE_ABORTED + }; + public: BasicEvent() - { - to_Abort = false; - m_addTime = 0; - m_execTime = 0; - } + : m_abortState(AbortState::STATE_RUNNING), m_addTime(0), m_execTime(0) { } + virtual ~BasicEvent() { } // override destructor to perform some actions on event removal // this method executes when the event is triggered @@ -45,8 +52,16 @@ class TC_COMMON_API BasicEvent virtual void Abort(uint64 /*e_time*/) { } // this method executes when the event is aborted - bool to_Abort; // set by externals when the event is aborted, aborted events don't execute - // and get Abort call when deleted + // Aborts the event at the next update tick + void ScheduleAbort(); + + private: + void SetAborted(); + bool IsRunning() const { return (m_abortState == AbortState::STATE_RUNNING); } + bool IsAbortScheduled() const { return (m_abortState == AbortState::STATE_ABORT_SCHEDULED); } + bool IsAborted() const { return (m_abortState == AbortState::STATE_ABORTED); } + + AbortState m_abortState; // set by externals when the event is aborted, aborted events don't execute // these can be used for time offset control uint64 m_addTime; // time when the event was added to queue, filled by event handler @@ -58,16 +73,17 @@ typedef std::multimap<uint64, BasicEvent*> EventList; class TC_COMMON_API EventProcessor { public: - EventProcessor(); + EventProcessor() : m_time(0) { } ~EventProcessor(); void Update(uint32 p_time); void KillAllEvents(bool force); void AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime = true); uint64 CalculateTime(uint64 t_offset) const; + protected: uint64 m_time; EventList m_events; - bool m_aborting; }; + #endif |