root/trunk/src/framework/Utilities/EventProcessor.h

Revision 173, 2.6 kB (checked in by yumileroy, 17 years ago)

[svn] * Avoid access to bag item prototype for getting bag size, use related item update field instead as more fast source.
* Better check client inventory pos data received in some client packets to skip invalid cases.
* Removed some unnecessary database queries.
* Make guid lookup for adding ignore async.
* Added two parameter versions of the AsyncQuery? function
* Make queries for adding friends async. - Hunuza
* Replace some PQuery() calls with more simple Query() - Hunuza
* Mark spell as executed instead of deleteable to solve crash.
*** Source mangos.

**Its a big commit. so test with care... or without care.... whatever floats your boat.

Original author: KingPin?
Date: 2008-11-05 20:10:19-06:00

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