mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user