TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
EventProcessor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __EVENTPROCESSOR_H
20 #define __EVENTPROCESSOR_H
21 
22 #include "Define.h"
23 
24 #include <map>
25 
26 // Note. All times are in milliseconds here.
27 
29 {
30  public:
32  {
33  to_Abort = false;
34  m_addTime = 0;
35  m_execTime = 0;
36  }
37  virtual ~BasicEvent() { } // override destructor to perform some actions on event removal
38 
39  // this method executes when the event is triggered
40  // return false if event does not want to be deleted
41  // e_time is execution time, p_time is update interval
42  virtual bool Execute(uint64 /*e_time*/, uint32 /*p_time*/) { return true; }
43 
44  virtual bool IsDeletable() const { return true; } // this event can be safely deleted
45 
46  virtual void Abort(uint64 /*e_time*/) { } // this method executes when the event is aborted
47 
48  bool to_Abort; // set by externals when the event is aborted, aborted events don't execute
49  // and get Abort call when deleted
50 
51  // these can be used for time offset control
52  uint64 m_addTime; // time when the event was added to queue, filled by event handler
53  uint64 m_execTime; // planned time of next execution, filled by event handler
54 };
55 
56 typedef std::multimap<uint64, BasicEvent*> EventList;
57 
59 {
60  public:
62  ~EventProcessor();
63 
64  void Update(uint32 p_time);
65  void KillAllEvents(bool force);
66  void AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime = true);
67  uint64 CalculateTime(uint64 t_offset) const;
68  protected:
71  bool m_aborting;
72 };
73 #endif
bool to_Abort
Definition: EventProcessor.h:48
virtual ~BasicEvent()
Definition: EventProcessor.h:37
BasicEvent()
Definition: EventProcessor.h:31
virtual void Abort(uint64)
Definition: EventProcessor.h:46
std::multimap< uint64, BasicEvent * > EventList
Definition: EventProcessor.h:56
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
uint64 m_addTime
Definition: EventProcessor.h:52
#define TC_COMMON_API
Definition: Define.h:116
virtual bool Execute(uint64, uint32)
Definition: EventProcessor.h:42
Definition: EventProcessor.h:28
EventList m_events
Definition: EventProcessor.h:70
bool m_aborting
Definition: EventProcessor.h:71
uint64 m_time
Definition: EventProcessor.h:69
Definition: EventProcessor.h:58
uint64 m_execTime
Definition: EventProcessor.h:53
virtual bool IsDeletable() const
Definition: EventProcessor.h:44
void Update(uint32 diff)
Definition: WeatherMgr.cpp:150