TrinityCore
Loading...
Searching...
No Matches
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 <vector>
25
27{
39 typedef std::multimap<TimePoint, uint32> EventStore;
40 typedef std::map<uint32 /*event data*/, std::vector<Milliseconds>> EventSeriesStore;
41
42public:
43 EventMap() : _time(TimePoint::min()), _phase(0), _lastEvent(0) { }
44 EventMap(EventMap const& other);
45 EventMap(EventMap&& other) noexcept = default;
46 EventMap& operator=(EventMap const& other);
47 EventMap& operator=(EventMap&& other) noexcept = default;
49
54 void Reset();
55
61 void Update(uint32 time)
62 {
63 Update(Milliseconds(time));
64 }
65
72 {
73 _time += time;
74 }
75
81 {
82 return _phase;
83 }
84
89 bool Empty() const
90 {
91 return _eventMap.empty();
92 }
93
99 void SetPhase(uint8 phase);
100
106 void AddPhase(uint8 phase)
107 {
108 if (phase && phase <= 8)
109 _phase |= uint8(1 << (phase - 1));
110 }
111
117 void RemovePhase(uint8 phase)
118 {
119 if (phase && phase <= 8)
120 _phase &= uint8(~(1 << (phase - 1)));
121 }
122
131 void ScheduleEvent(uint32 eventId, Milliseconds time, uint32 group = 0, uint8 phase = 0);
132
142 void ScheduleEvent(uint32 eventId, Milliseconds minTime, Milliseconds maxTime, uint32 group = 0, uint8 phase = 0);
143
152 void RescheduleEvent(uint32 eventId, Milliseconds time, uint32 group = 0, uint8 phase = 0);
153
163 void RescheduleEvent(uint32 eventId, Milliseconds minTime, Milliseconds maxTime, uint32 group = 0, uint8 phase = 0);
164
170 void Repeat(Milliseconds time);
171
178 void Repeat(Milliseconds minTime, Milliseconds maxTime);
179
185 uint32 ExecuteEvent();
186
192 void DelayEvents(Milliseconds delay);
193
200 void DelayEvents(Milliseconds delay, uint32 group);
201
207 void CancelEvent(uint32 eventId);
208
214 void CancelEventGroup(uint32 group);
215
222 bool IsInPhase(uint8 phase) const
223 {
224 return phase <= 8 && (!phase || _phase & (1 << (phase - 1)));
225 }
226
233 Milliseconds GetTimeUntilEvent(uint32 eventId) const;
234
240 void ScheduleNextFromSeries(uint32 eventData);
241
250 void ScheduleEventSeries(uint32 eventId, uint8 group, uint8 phase, std::initializer_list<Milliseconds> timeSeries);
251
258 void ScheduleEventSeries(uint32 eventId, std::initializer_list<Milliseconds> series);
259
260private:
272
282
291
297
303};
304
305#endif // _EVENT_MAP_H_
uint8_t uint8
Definition Define.h:156
#define TC_COMMON_API
Definition Define.h:99
uint32_t uint32
Definition Define.h:154
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition Duration.h:24
std::chrono::steady_clock::time_point TimePoint
time_point shorthand typedefs
Definition Duration.h:40
void AddPhase(uint8 phase)
Definition EventMap.h:106
std::map< uint32, std::vector< Milliseconds > > EventSeriesStore
Definition EventMap.h:40
EventMap & operator=(EventMap &&other) noexcept=default
EventMap()
Definition EventMap.h:43
uint8 _phase
Definition EventMap.h:281
TimePoint _time
Definition EventMap.h:271
void Update(uint32 time)
Definition EventMap.h:61
bool Empty() const
Definition EventMap.h:89
EventMap & operator=(EventMap const &other)
EventStore _eventMap
Definition EventMap.h:290
EventSeriesStore _timerSeries
Definition EventMap.h:302
bool IsInPhase(uint8 phase) const
Definition EventMap.h:222
uint8 GetPhaseMask() const
Definition EventMap.h:80
std::multimap< TimePoint, uint32 > EventStore
Definition EventMap.h:39
void RemovePhase(uint8 phase)
Definition EventMap.h:117
uint32 _lastEvent
Definition EventMap.h:296
void Update(Milliseconds time)
Definition EventMap.h:71
EventMap(EventMap &&other) noexcept=default
EventMap(EventMap const &other)