TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
EventMap Class Reference

#include <EventMap.h>

Public Member Functions

 EventMap ()
 
Reset

Removes all scheduled events and resets time and phase.

void Reset ()
 
Update

Updates the timer of the event map.

Parameters
timeValue in ms to be added to time.
void Update (uint32 time)
 
GetTimer
Returns
Current timer in ms value.
uint32 GetTimer () const
 
GetPhaseMask
Returns
Active phases as mask.
uint8 GetPhaseMask () const
 
Empty
Returns
True, if there are no events scheduled.
bool Empty () const
 
SetPhase

Sets the phase of the map (absolute).

Parameters
phasePhase which should be set. Values: 1 - 8. 0 resets phase.
void SetPhase (uint8 phase)
 
AddPhase

Activates the given phase (bitwise).

Parameters
phasePhase which should be activated. Values: 1 - 8
void AddPhase (uint8 phase)
 
RemovePhase

Deactivates the given phase (bitwise).

Parameters
phasePhase which should be deactivated. Values: 1 - 8.
void RemovePhase (uint8 phase)
 
ScheduleEvent

Creates new event entry in map.

Parameters
eventIdThe id of the new event.
timeThe time in milliseconds until the event occurs.
groupThe group which the event is associated to. Has to be between 1 and 8. 0 means it has no group.
phaseThe phase in which the event can occur. Has to be between 1 and 8. 0 means it can occur in all phases.
void ScheduleEvent (uint32 eventId, Milliseconds const &time, uint32 group=0, uint8 phase=0)
 
void ScheduleEvent (uint32 eventId, uint32 time, uint32 group=0, uint8 phase=0)
 
RescheduleEvent

Cancels the given event and reschedules it.

Parameters
eventIdThe id of the event.
timeThe time in milliseconds until the event occurs.
groupThe group which the event is associated to. Has to be between 1 and 8. 0 means it has no group.
phaseThe phase in which the event can occur. Has to be between 1 and 8. 0 means it can occur in all phases.
void RescheduleEvent (uint32 eventId, Milliseconds const &time, uint32 group=0, uint8 phase=0)
 
void RescheduleEvent (uint32 eventId, uint32 time, uint32 group=0, uint8 phase=0)
 
RepeatEvent

Repeats the mostly recently executed event, Equivalent to Repeat(urand(minTime, maxTime).

Parameters
minTimeMinimum time until the event occurs.
maxTimeMaximum time until the event occurs.
void Repeat (Milliseconds const &time)
 
void Repeat (uint32 time)
 
void Repeat (Milliseconds const &minTime, Milliseconds const &maxTime)
 
void Repeat (uint32 minTime, uint32 maxTime)
 
ExecuteEvent

Returns the next event to execute and removes it from map.

Returns
Id of the event to execute.
uint32 ExecuteEvent ()
 
DelayEvents

Delay all events of the same group.

Parameters
delayAmount of delay.
groupGroup of the events.
void DelayEvents (Milliseconds const &delay)
 
void DelayEvents (uint32 delay)
 
void DelayEvents (Milliseconds const &delay, uint32 group)
 
void DelayEvents (uint32 delay, uint32 group)
 
CancelEvent

Cancels all events of the specified id.

Parameters
eventIdEvent id to cancel.
void CancelEvent (uint32 eventId)
 
CancelEventGroup

Cancel events belonging to specified group.

Parameters
groupGroup to cancel.
void CancelEventGroup (uint32 group)
 
GetNextEventTime
Returns
Time of next event.
uint32 GetNextEventTime (uint32 eventId) const
 
uint32 GetNextEventTime () const
 
IsInPhase

Returns whether event map is in specified phase or not.

Parameters
phaseWanted phase.
Returns
True, if phase of event map contains specified phase.
bool IsInPhase (uint8 phase) const
 
GetTimeUntilEvent

Returns time in milliseconds until next event.

Parameters
eventIdof the event.
Returns
Time of next event.
uint32 GetTimeUntilEvent (uint32 eventId) const
 

Private Types

typedef std::multimap< uint32,
uint32
EventStore
 

Private Attributes

_time

Internal timer.

This does not represent the real date/time value. It's more like a stopwatch: It can run, it can be stopped, it can be resetted and so on. Events occur when this timer has reached their time value. Its value is changed in the Update method.

uint32 _time
 
_phase

Phase mask of the event map.

Contains the phases the event map is in. Multiple phases from 1 to 8 can be set with SetPhase or AddPhase. RemovePhase deactives a phase.

uint8 _phase
 
_eventMap

Internal event storage map. Contains the scheduled events.

See typedef at the beginning of the class for more details.

EventStore _eventMap
 
_lastEvent

Stores information on the most recently executed event

uint32 _lastEvent
 

Member Typedef Documentation

typedef std::multimap<uint32, uint32> EventMap::EventStore
private

Internal storage type. Key: Time as uint32 when the event should occur. Value: The event data as uint32.

Structure of event data:

  • Bit 0 - 15: Event Id.
  • Bit 16 - 23: Group
  • Bit 24 - 31: Phase
  • Pattern: 0xPPGGEEEE

Constructor & Destructor Documentation

EventMap::EventMap ( )
inline
41 : _time(0), _phase(0), _lastEvent(0) { }
uint8 _phase
Definition: EventMap.h:324
uint32 _time
Definition: EventMap.h:314
uint32 _lastEvent
Definition: EventMap.h:339

Member Function Documentation

void EventMap::AddPhase ( uint8  phase)
inline
99  {
100  if (phase && phase <= 8)
101  _phase |= uint8(1 << (phase - 1));
102  }
uint8 _phase
Definition: EventMap.h:324
uint8_t uint8
Definition: g3dmath.h:164
void EventMap::CancelEvent ( uint32  eventId)
90 {
91  if (Empty())
92  return;
93 
94  for (EventStore::iterator itr = _eventMap.begin(); itr != _eventMap.end();)
95  {
96  if (eventId == (itr->second & 0x0000FFFF))
97  _eventMap.erase(itr++);
98  else
99  ++itr;
100  }
101 }
bool Empty() const
Definition: EventMap.h:81
EventStore _eventMap
Definition: EventMap.h:333

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void EventMap::CancelEventGroup ( uint32  group)
104 {
105  if (!group || group > 8 || Empty())
106  return;
107 
108  for (EventStore::iterator itr = _eventMap.begin(); itr != _eventMap.end();)
109  {
110  if (itr->second & (1 << (group + 15)))
111  _eventMap.erase(itr++);
112  else
113  ++itr;
114  }
115 }
bool Empty() const
Definition: EventMap.h:81
EventStore _eventMap
Definition: EventMap.h:333

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void EventMap::DelayEvents ( Milliseconds const delay)
inline
220  {
221  DelayEvents(uint32(delay.count()));
222  }
uint32_t uint32
Definition: g3dmath.h:168
void DelayEvents(Milliseconds const &delay)
Definition: EventMap.h:219

+ Here is the caller graph for this function:

void EventMap::DelayEvents ( uint32  delay)
inline
230  {
231  _time = delay < _time ? _time - delay : 0;
232  }
uint32 _time
Definition: EventMap.h:314
void EventMap::DelayEvents ( Milliseconds const delay,
uint32  group 
)
inline
241  {
242  DelayEvents(uint32(delay.count()), group);
243  }
uint32_t uint32
Definition: g3dmath.h:168
void DelayEvents(Milliseconds const &delay)
Definition: EventMap.h:219
void EventMap::DelayEvents ( uint32  delay,
uint32  group 
)
69 {
70  if (!group || group > 8 || Empty())
71  return;
72 
73  EventStore delayed;
74 
75  for (EventStore::iterator itr = _eventMap.begin(); itr != _eventMap.end();)
76  {
77  if (itr->second & (1 << (group + 15)))
78  {
79  delayed.insert(EventStore::value_type(itr->first + delay, itr->second));
80  _eventMap.erase(itr++);
81  }
82  else
83  ++itr;
84  }
85 
86  _eventMap.insert(delayed.begin(), delayed.end());
87 }
std::multimap< uint32, uint32 > EventStore
Definition: EventMap.h:38
bool Empty() const
Definition: EventMap.h:81
EventStore _eventMap
Definition: EventMap.h:333

+ Here is the call graph for this function:

bool EventMap::Empty ( ) const
inline
82  {
83  return _eventMap.empty();
84  }
EventStore _eventMap
Definition: EventMap.h:333

+ Here is the caller graph for this function:

uint32 EventMap::ExecuteEvent ( )
47 {
48  while (!Empty())
49  {
50  EventStore::iterator itr = _eventMap.begin();
51 
52  if (itr->first > _time)
53  return 0;
54  else if (_phase && (itr->second & 0xFF000000) && !((itr->second >> 24) & _phase))
55  _eventMap.erase(itr);
56  else
57  {
58  uint32 eventId = (itr->second & 0x0000FFFF);
59  _lastEvent = itr->second; // include phase/group
60  _eventMap.erase(itr);
61  return eventId;
62  }
63  }
64 
65  return 0;
66 }
uint8 _phase
Definition: EventMap.h:324
bool Empty() const
Definition: EventMap.h:81
uint32 _time
Definition: EventMap.h:314
uint32_t uint32
Definition: Define.h:150
uint32 _lastEvent
Definition: EventMap.h:339
EventStore _eventMap
Definition: EventMap.h:333

+ Here is the call graph for this function:

uint32 EventMap::GetNextEventTime ( uint32  eventId) const
118 {
119  if (Empty())
120  return 0;
121 
122  for (EventStore::const_iterator itr = _eventMap.begin(); itr != _eventMap.end(); ++itr)
123  if (eventId == (itr->second & 0x0000FFFF))
124  return itr->first;
125 
126  return 0;
127 }
bool Empty() const
Definition: EventMap.h:81
EventStore _eventMap
Definition: EventMap.h:333

+ Here is the call graph for this function:

uint32 EventMap::GetNextEventTime ( ) const
inline
280  {
281  return Empty() ? 0 : _eventMap.begin()->first;
282  }
bool Empty() const
Definition: EventMap.h:81
EventStore _eventMap
Definition: EventMap.h:333
uint8 EventMap::GetPhaseMask ( ) const
inline
73  {
74  return _phase;
75  }
uint8 _phase
Definition: EventMap.h:324

+ Here is the caller graph for this function:

uint32 EventMap::GetTimer ( ) const
inline
64  {
65  return _time;
66  }
uint32 _time
Definition: EventMap.h:314
uint32 EventMap::GetTimeUntilEvent ( uint32  eventId) const
130 {
131  for (EventStore::const_iterator itr = _eventMap.begin(); itr != _eventMap.end(); ++itr)
132  if (eventId == (itr->second & 0x0000FFFF))
133  return itr->first - _time;
134 
136 }
T max(const T &x, const T &y)
Definition: g3dmath.h:320
uint32 _time
Definition: EventMap.h:314
EventStore _eventMap
Definition: EventMap.h:333

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool EventMap::IsInPhase ( uint8  phase) const
inline
291  {
292  return phase <= 8 && (!phase || _phase & (1 << (phase - 1)));
293  }
uint8 _phase
Definition: EventMap.h:324
void EventMap::RemovePhase ( uint8  phase)
inline
110  {
111  if (phase && phase <= 8)
112  _phase &= uint8(~(1 << (phase - 1)));
113  }
uint8 _phase
Definition: EventMap.h:324
uint8_t uint8
Definition: g3dmath.h:164
void EventMap::Repeat ( Milliseconds const time)
inline
171  {
172  Repeat(uint32(time.count()));
173  }
void Repeat(Milliseconds const &time)
Definition: EventMap.h:170
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the caller graph for this function:

void EventMap::Repeat ( uint32  time)
inline
181  {
182  _eventMap.insert(EventStore::value_type(_time + time, _lastEvent));
183  }
uint32 _time
Definition: EventMap.h:314
uint32 _lastEvent
Definition: EventMap.h:339
EventStore _eventMap
Definition: EventMap.h:333
void EventMap::Repeat ( Milliseconds const minTime,
Milliseconds const maxTime 
)
inline
192  {
193  Repeat(uint32(minTime.count()), uint32(maxTime.count()));
194  }
void Repeat(Milliseconds const &time)
Definition: EventMap.h:170
uint32_t uint32
Definition: g3dmath.h:168
void EventMap::Repeat ( uint32  minTime,
uint32  maxTime 
)
inline
203  {
204  Repeat(urand(minTime, maxTime));
205  }
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
void Repeat(Milliseconds const &time)
Definition: EventMap.h:170

+ Here is the call graph for this function:

void EventMap::RescheduleEvent ( uint32  eventId,
Milliseconds const time,
uint32  group = 0,
uint8  phase = 0 
)
inline
147  {
148  RescheduleEvent(eventId, uint32(time.count()), group, phase);
149  }
void RescheduleEvent(uint32 eventId, Milliseconds const &time, uint32 group=0, uint8 phase=0)
Definition: EventMap.h:146
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the caller graph for this function:

void EventMap::RescheduleEvent ( uint32  eventId,
uint32  time,
uint32  group = 0,
uint8  phase = 0 
)
inline
160  {
161  CancelEvent(eventId);
162  ScheduleEvent(eventId, time, group, phase);
163  }
void CancelEvent(uint32 eventId)
Definition: EventMap.cpp:89
void ScheduleEvent(uint32 eventId, Milliseconds const &time, uint32 group=0, uint8 phase=0)
Definition: EventMap.h:123
void EventMap::Reset ( )
21 {
22  _eventMap.clear();
23  _time = 0;
24  _phase = 0;
25 }
uint8 _phase
Definition: EventMap.h:324
uint32 _time
Definition: EventMap.h:314
EventStore _eventMap
Definition: EventMap.h:333
void EventMap::ScheduleEvent ( uint32  eventId,
Milliseconds const time,
uint32  group = 0,
uint8  phase = 0 
)
inline
124  {
125  ScheduleEvent(eventId, uint32(time.count()), group, phase);
126  }
void ScheduleEvent(uint32 eventId, Milliseconds const &time, uint32 group=0, uint8 phase=0)
Definition: EventMap.h:123
uint32_t uint32
Definition: g3dmath.h:168
void EventMap::ScheduleEvent ( uint32  eventId,
uint32  time,
uint32  group = 0,
uint8  phase = 0 
)
36 {
37  if (group && group <= 8)
38  eventId |= (1 << (group + 15));
39 
40  if (phase && phase <= 8)
41  eventId |= (1 << (phase + 23));
42 
43  _eventMap.insert(EventStore::value_type(_time + time, eventId));
44 }
uint32 _time
Definition: EventMap.h:314
EventStore _eventMap
Definition: EventMap.h:333
void EventMap::SetPhase ( uint8  phase)
28 {
29  if (!phase)
30  _phase = 0;
31  else if (phase <= 8)
32  _phase = uint8(1 << (phase - 1));
33 }
uint8 _phase
Definition: EventMap.h:324
uint8_t uint8
Definition: g3dmath.h:164
void EventMap::Update ( uint32  time)
inline
55  {
56  _time += time;
57  }
uint32 _time
Definition: EventMap.h:314

Member Data Documentation

EventStore EventMap::_eventMap
private
uint32 EventMap::_lastEvent
private
uint8 EventMap::_phase
private
uint32 EventMap::_time
private

The documentation for this class was generated from the following files: