Kaydet (Commit) 0e0e3ea3 authored tarafından Caolán McNamara's avatar Caolán McNamara

Revert "convert sdr::animation::EventList to o3tl::sorted_vector"

This reverts commit c0c69ccd.

because soffice --headless --convert-to odp ooo75571-1.odp crashes
after this change
üst d115a235
...@@ -23,24 +23,31 @@ ...@@ -23,24 +23,31 @@
#include <sal/types.h> #include <sal/types.h>
#include <vcl/timer.hxx> #include <vcl/timer.hxx>
#include <svx/svxdllapi.h> #include <svx/svxdllapi.h>
#include <o3tl/sorted_vector.hxx>
// event class
namespace sdr namespace sdr
{ {
namespace animation namespace animation
{ {
class SVX_DLLPUBLIC Event class SVX_DLLPUBLIC Event
{ {
// time of event in ms // time of event in ms
sal_uInt32 mnTime; sal_uInt32 mnTime;
// pointer for linked list sorted by mnTime
Event* mpNext;
public: public:
// constructor/destructor // constructor/destructor
SAL_DLLPRIVATE explicit Event(); SAL_DLLPRIVATE explicit Event();
virtual ~Event(); virtual ~Event();
// access to mpNext
SAL_DLLPRIVATE Event* GetNext() const { return mpNext; }
SAL_DLLPRIVATE void SetNext(Event* pNew);
// get/set time // get/set time
SAL_DLLPRIVATE sal_uInt32 GetTime() const { return mnTime; } SAL_DLLPRIVATE sal_uInt32 GetTime() const { return mnTime; }
void SetTime(sal_uInt32 nNew); void SetTime(sal_uInt32 nNew);
...@@ -48,12 +55,43 @@ namespace sdr ...@@ -48,12 +55,43 @@ namespace sdr
// execute event // execute event
virtual void Trigger(sal_uInt32 nTime) = 0; virtual void Trigger(sal_uInt32 nTime) = 0;
}; };
} // end of namespace animation
} // end of namespace sdr
struct CompareEvent // eventlist class
namespace sdr
{
namespace animation
{
class SVX_DLLPUBLIC EventList
{ {
bool operator()(Event* const& lhs, Event* const& rhs) const; // pointer to first entry
Event* mpHead;
public:
// constructor/destructor
SAL_DLLPRIVATE EventList();
virtual ~EventList();
// insert/remove time dependent
SAL_DLLPRIVATE void Insert(Event* pNew);
SAL_DLLPRIVATE void Remove(Event* pOld);
// get first
SAL_DLLPRIVATE Event* GetFirst() { return mpHead; }
}; };
} // end of namespace animation
} // end of namespace sdr
// scheduler class
namespace sdr
{
namespace animation
{
class SVX_DLLPUBLIC Scheduler : public Timer class SVX_DLLPUBLIC Scheduler : public Timer
{ {
// time in ms // time in ms
...@@ -63,7 +101,7 @@ namespace sdr ...@@ -63,7 +101,7 @@ namespace sdr
sal_uInt32 mnDeltaTime; sal_uInt32 mnDeltaTime;
// list of events // list of events
o3tl::sorted_vector<Event*, CompareEvent> maList; EventList maList;
// Flag which remembers if this timer is paused. Default // Flag which remembers if this timer is paused. Default
// is false. // is false.
...@@ -97,7 +135,6 @@ namespace sdr ...@@ -97,7 +135,6 @@ namespace sdr
SAL_DLLPRIVATE bool IsPaused() const { return mbIsPaused; } SAL_DLLPRIVATE bool IsPaused() const { return mbIsPaused; }
SAL_DLLPRIVATE void SetPaused(bool bNew); SAL_DLLPRIVATE void SetPaused(bool bNew);
}; };
} // end of namespace animation } // end of namespace animation
} // end of namespace sdr } // end of namespace sdr
......
...@@ -28,7 +28,9 @@ namespace sdr ...@@ -28,7 +28,9 @@ namespace sdr
{ {
namespace animation namespace animation
{ {
Event::Event() : mnTime(0) Event::Event()
: mnTime(0),
mpNext(nullptr)
{ {
} }
...@@ -37,6 +39,15 @@ namespace sdr ...@@ -37,6 +39,15 @@ namespace sdr
} }
void Event::SetNext(Event* pNew)
{
if(pNew != mpNext)
{
mpNext = pNew;
}
}
void Event::SetTime(sal_uInt32 nNew) void Event::SetTime(sal_uInt32 nNew)
{ {
if(mnTime != nNew) if(mnTime != nNew)
...@@ -44,13 +55,93 @@ namespace sdr ...@@ -44,13 +55,93 @@ namespace sdr
mnTime = nNew; mnTime = nNew;
} }
} }
} // end of namespace animation
} // end of namespace sdr
// eventlist class
bool CompareEvent::operator()(Event* const& lhs, Event* const& rhs) const namespace sdr
{
namespace animation
{
EventList::EventList()
: mpHead(nullptr)
{ {
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() Scheduler::Scheduler()
: mnTime(0L), : mnTime(0L),
mnDeltaTime(0L), mnDeltaTime(0L),
...@@ -78,36 +169,38 @@ namespace sdr ...@@ -78,36 +169,38 @@ namespace sdr
void Scheduler::triggerEvents() void Scheduler::triggerEvents()
{ {
if (maList.empty()) Event* pNextEvent = maList.GetFirst();
return;
// copy events which need to be executed to a vector. Remove them from if(pNextEvent)
// the scheduler
::std::vector< Event* > aToBeExecutedList;
while(!maList.empty() && maList[0]->GetTime() <= mnTime)
{ {
Event* pNextEvent = maList.front(); // copy events which need to be executed to a vector. Remove them from
maList.erase(maList.begin()); // the scheduler
aToBeExecutedList.push_back(pNextEvent); ::std::vector< Event* > EventPointerVector;
}
// execute events from the vector while(pNextEvent && pNextEvent->GetTime() <= mnTime)
::std::vector< Event* >::const_iterator aEnd = aToBeExecutedList.end(); {
for(::std::vector< Event* >::iterator aCandidate = aToBeExecutedList.begin(); maList.Remove(pNextEvent);
aCandidate != aEnd; ++aCandidate) EventPointerVector.push_back(pNextEvent);
{ pNextEvent = maList.GetFirst();
// 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 = 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);
}
} }
} }
void Scheduler::checkTimeout() void Scheduler::checkTimeout()
{ {
// re-start or stop timer according to event list // re-start or stop timer according to event list
if(!IsPaused() && !maList.empty()) if(!IsPaused() && maList.GetFirst())
{ {
mnDeltaTime = maList.front()->GetTime() - mnTime; mnDeltaTime = maList.GetFirst()->GetTime() - mnTime;
if(0L != mnDeltaTime) if(0L != mnDeltaTime)
{ {
...@@ -129,36 +222,43 @@ namespace sdr ...@@ -129,36 +222,43 @@ namespace sdr
Stop(); Stop();
mnTime = nTime; mnTime = nTime;
if (maList.empty()) // get event pointer
return; Event* pEvent = maList.GetFirst();
// reset event time points if(pEvent)
for (auto & rEvent : maList)
{ {
rEvent->SetTime(nTime); // retet event time points
} while(pEvent)
{
pEvent->SetTime(nTime);
pEvent = pEvent->GetNext();
}
if(!IsPaused()) if(!IsPaused())
{ {
// without delta time, init events by triggering them. This will invalidate // without delta time, init events by triggering them. This will invalidate
// painted objects and add them to the scheduler again // painted objects and add them to the scheduler again
mnDeltaTime = 0L; mnDeltaTime = 0L;
triggerEvents(); triggerEvents();
checkTimeout(); checkTimeout();
} }
}
} }
void Scheduler::InsertEvent(Event* pNew) void Scheduler::InsertEvent(Event* pNew)
{ {
maList.insert(pNew); if(pNew)
checkTimeout(); {
maList.Insert(pNew);
checkTimeout();
}
} }
void Scheduler::RemoveEvent(Event* pOld) void Scheduler::RemoveEvent(Event* pOld)
{ {
if(!maList.empty()) if(pOld && maList.GetFirst())
{ {
maList.erase(maList.find(pOld)); maList.Remove(pOld);
checkTimeout(); checkTimeout();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment