2 * Copyright (C) 2005-2008 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 #include "EventProcessor.h"
21 EventProcessor::EventProcessor()
27 EventProcessor::~EventProcessor()
32 void EventProcessor::Update(uint32 p_time
)
38 EventList::iterator i
;
39 while (((i
= m_events
.begin()) != m_events
.end()) && i
->first
<= m_time
)
41 // get and remove event from queue
42 BasicEvent
* Event
= i
->second
;
47 if (Event
->Execute(m_time
, p_time
))
49 // completely destroy event if it is not re-added
61 void EventProcessor::KillAllEvents(bool force
)
63 // prevent event insertions
66 // first, abort all existing events
67 for (EventList::iterator i
= m_events
.begin(); i
!= m_events
.end();)
69 EventList::iterator i_old
= i
;
72 i_old
->second
->to_Abort
= true;
73 i_old
->second
->Abort(m_time
);
74 if(force
|| i_old
->second
->IsDeletable())
78 if(!force
) // need per-element cleanup
79 m_events
.erase (i_old
);
83 // fast clear event list (in force case)
88 void EventProcessor::AddEvent(BasicEvent
* Event
, uint64 e_time
, bool set_addtime
)
90 if (set_addtime
) Event
->m_addTime
= m_time
;
91 Event
->m_execTime
= e_time
;
92 m_events
.insert(std::pair
<uint64
, BasicEvent
*>(e_time
, Event
));
95 uint64
EventProcessor::CalculateTime(uint64 t_offset
)
97 return(m_time
+ t_offset
);