TrinityCore
EventMap.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef _EVENT_MAP_H_
19#define _EVENT_MAP_H_
20
21#include "Define.h"
22#include "Duration.h"
23#include <map>
24#include <queue>
25
27{
39 typedef std::multimap<TimePoint, uint32> EventStore;
40 typedef std::map<uint32 /*event data*/, std::queue<Milliseconds>> EventSeriesStore;
41
42public:
43 EventMap() : _time(TimePoint::min()), _phase(0), _lastEvent(0) { }
44
49 void Reset();
50
56 void Update(uint32 time)
57 {
58 Update(Milliseconds(time));
59 }
60
67 {
68 _time += time;
69 }
70
76 {
77 return _phase;
78 }
79
84 bool Empty() const
85 {
86 return _eventMap.empty();
87 }
88
94 void SetPhase(uint8 phase);
95
101 void AddPhase(uint8 phase)
102 {
103 if (phase && phase <= 8)
104 _phase |= uint8(1 << (phase - 1));
105 }
106
112 void RemovePhase(uint8 phase)
113 {
114 if (phase && phase <= 8)
115 _phase &= uint8(~(1 << (phase - 1)));
116 }
117
126 void ScheduleEvent(uint32 eventId, Milliseconds time, uint32 group = 0, uint8 phase = 0);
127
137 void ScheduleEvent(uint32 eventId, Milliseconds minTime, Milliseconds maxTime, uint32 group = 0, uint8 phase = 0);
138
147 void RescheduleEvent(uint32 eventId, Milliseconds time, uint32 group = 0, uint8 phase = 0);
148
158 void RescheduleEvent(uint32 eventId, Milliseconds minTime, Milliseconds maxTime, uint32 group = 0, uint8 phase = 0);
159
165 void Repeat(Milliseconds time);
166
173 void Repeat(Milliseconds minTime, Milliseconds maxTime);
174
180 uint32 ExecuteEvent();
181
187 void DelayEvents(Milliseconds delay);
188
195 void DelayEvents(Milliseconds delay, uint32 group);
196
202 void CancelEvent(uint32 eventId);
203
209 void CancelEventGroup(uint32 group);
210
217 bool IsInPhase(uint8 phase) const
218 {
219 return phase <= 8 && (!phase || _phase & (1 << (phase - 1)));
220 }
221
228 Milliseconds GetTimeUntilEvent(uint32 eventId) const;
229
235 void ScheduleNextFromSeries(uint32 eventData);
236
245 void ScheduleEventSeries(uint32 eventId, uint8 group, uint8 phase, std::initializer_list<Milliseconds> const& timeSeries);
246
253 void ScheduleEventSeries(uint32 eventId, std::initializer_list<Milliseconds> const& series);
254
255private:
267
277
286
292
298};
299
300#endif // _EVENT_MAP_H_
uint8_t uint8
Definition: Define.h:144
#define TC_COMMON_API
Definition: Define.h:99
uint32_t uint32
Definition: Define.h:142
std::chrono::steady_clock::time_point TimePoint
time_point shorthand typedefs
Definition: Duration.h:41
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition: Duration.h:29
void AddPhase(uint8 phase)
Definition: EventMap.h:101
EventMap()
Definition: EventMap.h:43
std::map< uint32, std::queue< Milliseconds > > EventSeriesStore
Definition: EventMap.h:40
uint8 _phase
Definition: EventMap.h:276
TimePoint _time
Definition: EventMap.h:266
void Update(uint32 time)
Definition: EventMap.h:56
bool Empty() const
Definition: EventMap.h:84
EventStore _eventMap
Definition: EventMap.h:285
EventSeriesStore _timerSeries
Definition: EventMap.h:297
bool IsInPhase(uint8 phase) const
Definition: EventMap.h:217
uint8 GetPhaseMask() const
Definition: EventMap.h:75
std::multimap< TimePoint, uint32 > EventStore
Definition: EventMap.h:39
void RemovePhase(uint8 phase)
Definition: EventMap.h:112
uint32 _lastEvent
Definition: EventMap.h:291
void Update(Milliseconds time)
Definition: EventMap.h:66
void Update(VignetteData &vignette, WorldObject const *owner)
Definition: Vignette.cpp:93