From 8d331f2b10cff29ee0571f7056ad353df6a3eabd Mon Sep 17 00:00:00 2001 From: KingPin Date: Wed, 5 Nov 2008 20:10:19 -0600 Subject: [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. --HG-- branch : trunk --- src/framework/Utilities/EventProcessor.cpp | 26 ++++++++++++++++++-------- src/framework/Utilities/EventProcessor.h | 4 +++- 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'src/framework/Utilities') diff --git a/src/framework/Utilities/EventProcessor.cpp b/src/framework/Utilities/EventProcessor.cpp index 225497e6935..0a869481916 100644 --- a/src/framework/Utilities/EventProcessor.cpp +++ b/src/framework/Utilities/EventProcessor.cpp @@ -28,7 +28,7 @@ EventProcessor::EventProcessor() EventProcessor::~EventProcessor() { - KillAllEvents(); + KillAllEvents(true); } void EventProcessor::Update(uint32 p_time) @@ -60,21 +60,31 @@ void EventProcessor::Update(uint32 p_time) } } -void EventProcessor::KillAllEvents() +void EventProcessor::KillAllEvents(bool force) { // prevent event insertions m_aborting = true; // first, abort all existing events - for (EventList::iterator i = m_events.begin(); i != m_events.end(); ++i) + for (EventList::iterator i = m_events.begin(); i != m_events.end();) { - i->second->to_Abort = true; - i->second->Abort(m_time); - delete i->second; + EventList::iterator i_old = i; + ++i; + + i_old->second->to_Abort = true; + i_old->second->Abort(m_time); + if(force || i_old->second->IsDeletable()) + { + delete i_old->second; + + if(!force) // need per-element cleanup + m_events.erase (i_old); + } } - // clear event list - m_events.clear(); + // fast clear event list (in force case) + if(force) + m_events.clear(); } void EventProcessor::AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime) diff --git a/src/framework/Utilities/EventProcessor.h b/src/framework/Utilities/EventProcessor.h index c40e065c87a..09cc243a2b2 100644 --- a/src/framework/Utilities/EventProcessor.h +++ b/src/framework/Utilities/EventProcessor.h @@ -39,6 +39,8 @@ class BasicEvent // return false if event does not want to be deleted // e_time is execution time, p_time is update interval virtual bool Execute(uint64 /*e_time*/, uint32 /*p_time*/) { return true; } + + virtual bool IsDeletable() const { return true; } // this event can be safely deleted virtual void Abort(uint64 /*e_time*/) {} // this method executes when the event is aborted @@ -59,7 +61,7 @@ class EventProcessor ~EventProcessor(); void Update(uint32 p_time); - void KillAllEvents(); + void KillAllEvents(bool force); void AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime = true); uint64 CalculateTime(uint64 t_offset); protected: -- cgit v1.2.3