Instead mark spell as delatable mark it as executed and referenced from Unit current...
[auctionmangos.git] / src / framework / Utilities / EventProcessor.cpp
blob2bcf6a46a7d6e7a6ea5f3ebc04c75b6dc4859529
1 /*
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()
23 m_time = 0;
24 m_aborting = false;
27 EventProcessor::~EventProcessor()
29 KillAllEvents(true);
32 void EventProcessor::Update(uint32 p_time)
34 // update time
35 m_time += p_time;
37 // main event loop
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;
43 m_events.erase(i);
45 if (!Event->to_Abort)
47 if (Event->Execute(m_time, p_time))
49 // completely destroy event if it is not re-added
50 delete Event;
53 else
55 Event->Abort(m_time);
56 delete Event;
61 void EventProcessor::KillAllEvents(bool force)
63 // prevent event insertions
64 m_aborting = true;
66 // first, abort all existing events
67 for (EventList::iterator i = m_events.begin(); i != m_events.end();)
69 EventList::iterator i_old = i;
70 ++i;
72 i_old->second->to_Abort = true;
73 i_old->second->Abort(m_time);
74 if(force || i_old->second->IsDeletable())
76 delete i_old->second;
78 if(!force) // need per-element cleanup
79 m_events.erase (i_old);
83 // fast clear event list (in force case)
84 if(force)
85 m_events.clear();
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);