daily pastebin goal
29%
SHARE
TWEET

Untitled

Jadda Feb 22nd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Copyright (C) 2008-2014 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.  
  28. class BasicEvent
  29. {
  30.     public:
  31.         BasicEvent()
  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.  
  58. class EventProcessor
  59. {
  60.     public:
  61.         EventProcessor();
  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:
  69.         uint64 m_time;
  70.         EventList m_events;
  71.         bool m_aborting;
  72. };
  73. #endif
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top