Updated Copyright year to 2013
[getmangos.git] / src / framework / Utilities / EventProcessor.h
blob1ad470b981c76c244f97cf720fb332d988fdd26a
1 /*
2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef __EVENTPROCESSOR_H
20 #define __EVENTPROCESSOR_H
22 #include "Platform/Define.h"
24 #include <map>
26 // Note. All times are in milliseconds here.
28 class BasicEvent
30 public:
32 BasicEvent()
33 : to_Abort(false)
37 virtual ~BasicEvent() // override destructor to perform some actions on event removal
41 // this method executes when the event is triggered
42 // return false if event does not want to be deleted
43 // e_time is execution time, p_time is update interval
44 virtual bool Execute(uint64 /*e_time*/, uint32 /*p_time*/) { return true; }
46 virtual bool IsDeletable() const { return true; } // this event can be safely deleted
48 virtual void Abort(uint64 /*e_time*/) {} // this method executes when the event is aborted
50 bool to_Abort; // set by externals when the event is aborted, aborted events don't execute
51 // and get Abort call when deleted
53 // these can be used for time offset control
54 uint64 m_addTime; // time when the event was added to queue, filled by event handler
55 uint64 m_execTime; // planned time of next execution, filled by event handler
58 typedef std::multimap<uint64, BasicEvent*> EventList;
60 class EventProcessor
62 public:
64 EventProcessor();
65 ~EventProcessor();
67 void Update(uint32 p_time);
68 void KillAllEvents(bool force);
69 void AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime = true);
70 uint64 CalculateTime(uint64 t_offset);
72 protected:
74 uint64 m_time;
75 EventList m_events;
76 bool m_aborting;
79 #endif