diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2016-11-09 12:46:38 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2016-11-09 13:09:49 +0000 |
commit | 2ed4034aa51292a8bb8e770213f0021a3f1c9408 (patch) | |
tree | 24fada7a26b3366faa5646d4d2c3fcde0273cf58 /svx | |
parent | 287b35c43771d3258ed877607e29882b3730201b (diff) |
Revert "Revert "convert sdr::animation::EventList to o3tl::sorted_vector""
This reverts commit 0e0e3ea312dc09de6726318c3579671fec7de7ee.
and fixes the call to o3tl::sorted_vector::erase that causes a crash.
Change-Id: Ic8ef07eb045a63dc8eaaa33886895f1d8f73098c
Reviewed-on: https://gerrit.libreoffice.org/30715
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/sdr/animation/scheduler.cxx | 184 |
1 files changed, 43 insertions, 141 deletions
diff --git a/svx/source/sdr/animation/scheduler.cxx b/svx/source/sdr/animation/scheduler.cxx index 38412725baf9..9936dfdb4be6 100644 --- a/svx/source/sdr/animation/scheduler.cxx +++ b/svx/source/sdr/animation/scheduler.cxx @@ -28,9 +28,7 @@ namespace sdr { namespace animation { - Event::Event() - : mnTime(0), - mpNext(nullptr) + Event::Event() : mnTime(0) { } @@ -39,15 +37,6 @@ namespace sdr } - void Event::SetNext(Event* pNew) - { - if(pNew != mpNext) - { - mpNext = pNew; - } - } - - void Event::SetTime(sal_uInt32 nNew) { if(mnTime != nNew) @@ -55,93 +44,13 @@ namespace sdr mnTime = nNew; } } - } // end of namespace animation -} // end of namespace sdr - - -// eventlist class -namespace sdr -{ - namespace animation - { - EventList::EventList() - : mpHead(nullptr) + bool CompareEvent::operator()(Event* const& lhs, Event* const& rhs) const { + return lhs->GetTime() < rhs->GetTime(); } - EventList::~EventList() - { - while(mpHead) - { - Event* pNext = mpHead->GetNext(); - mpHead->SetNext(nullptr); - mpHead = pNext; - } - } - - void EventList::Insert(Event* pNew) - { - if(pNew) - { - Event* pCurrent = mpHead; - Event* pPrev = nullptr; - - while(pCurrent && pCurrent->GetTime() < pNew->GetTime()) - { - pPrev = pCurrent; - pCurrent = pCurrent->GetNext(); - } - - if(pPrev) - { - pNew->SetNext(pPrev->GetNext()); - pPrev->SetNext(pNew); - } - else - { - pNew->SetNext(mpHead); - mpHead = pNew; - } - } - } - - void EventList::Remove(Event* pOld) - { - if(pOld && mpHead) - { - Event* pCurrent = mpHead; - Event* pPrev = nullptr; - - while(pCurrent && pCurrent != pOld) - { - pPrev = pCurrent; - pCurrent = pCurrent->GetNext(); - } - - if(pPrev) - { - pPrev->SetNext(pOld->GetNext()); - } - else - { - mpHead = pOld->GetNext(); - } - - pOld->SetNext(nullptr); - } - } - - } // end of namespace animation -} // end of namespace sdr - - -// scheduler class -namespace sdr -{ - namespace animation - { Scheduler::Scheduler() : mnTime(0L), mnDeltaTime(0L), @@ -169,38 +78,36 @@ namespace sdr void Scheduler::triggerEvents() { - Event* pNextEvent = maList.GetFirst(); + if (maList.empty()) + return; - if(pNextEvent) - { - // copy events which need to be executed to a vector. Remove them from - // the scheduler - ::std::vector< Event* > EventPointerVector; + // copy events which need to be executed to a vector. Remove them from + // the scheduler + ::std::vector< Event* > aToBeExecutedList; - while(pNextEvent && pNextEvent->GetTime() <= mnTime) - { - maList.Remove(pNextEvent); - EventPointerVector.push_back(pNextEvent); - pNextEvent = maList.GetFirst(); - } + while(!maList.empty() && maList[0]->GetTime() <= mnTime) + { + Event* pNextEvent = maList.front(); + maList.erase(maList.begin()); + aToBeExecutedList.push_back(pNextEvent); + } - // execute events from the vector - ::std::vector< Event* >::const_iterator aEnd = EventPointerVector.end(); - for(::std::vector< Event* >::iterator aCandidate = EventPointerVector.begin(); - aCandidate != aEnd; ++aCandidate) - { - // trigger event. This may re-insert the event to the scheduler again - (*aCandidate)->Trigger(mnTime); - } + // execute events from the vector + ::std::vector< Event* >::const_iterator aEnd = aToBeExecutedList.end(); + for(::std::vector< Event* >::iterator aCandidate = aToBeExecutedList.begin(); + aCandidate != aEnd; ++aCandidate) + { + // trigger event. This may re-insert the event to the scheduler again + (*aCandidate)->Trigger(mnTime); } } void Scheduler::checkTimeout() { // re-start or stop timer according to event list - if(!IsPaused() && maList.GetFirst()) + if(!IsPaused() && !maList.empty()) { - mnDeltaTime = maList.GetFirst()->GetTime() - mnTime; + mnDeltaTime = maList.front()->GetTime() - mnTime; if(0L != mnDeltaTime) { @@ -222,43 +129,38 @@ namespace sdr Stop(); mnTime = nTime; - // get event pointer - Event* pEvent = maList.GetFirst(); + if (maList.empty()) + return; - if(pEvent) + // reset event time points + for (auto & rEvent : maList) { - // retet event time points - while(pEvent) - { - pEvent->SetTime(nTime); - pEvent = pEvent->GetNext(); - } - - if(!IsPaused()) - { - // without delta time, init events by triggering them. This will invalidate - // painted objects and add them to the scheduler again - mnDeltaTime = 0L; - triggerEvents(); - checkTimeout(); - } + rEvent->SetTime(nTime); } + + if(!IsPaused()) + { + // without delta time, init events by triggering them. This will invalidate + // painted objects and add them to the scheduler again + mnDeltaTime = 0L; + triggerEvents(); + checkTimeout(); + } } void Scheduler::InsertEvent(Event* pNew) { - if(pNew) - { - maList.Insert(pNew); - checkTimeout(); - } + maList.insert(pNew); + checkTimeout(); } void Scheduler::RemoveEvent(Event* pOld) { - if(pOld && maList.GetFirst()) + if(!maList.empty()) { - maList.Remove(pOld); + auto it = maList.find(pOld); + if (it != maList.end()) + maList.erase(it); checkTimeout(); } } |