From 0e4f41bfb531d6b49caa8ee8fc8de7216774108b Mon Sep 17 00:00:00 2001 From: rachytski Date: Thu, 11 Oct 2012 18:34:13 +0300 Subject: dividing anim::Task's into visual/non-visual and taking it into account in RenderPolicy::NeedRedraw. --- anim/controller.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- anim/controller.hpp | 6 +++++- anim/task.cpp | 5 +++++ anim/task.hpp | 4 ++++ 4 files changed, 59 insertions(+), 9 deletions(-) (limited to 'anim') diff --git a/anim/controller.cpp b/anim/controller.cpp index 2482a21370..94495666c2 100644 --- a/anim/controller.cpp +++ b/anim/controller.cpp @@ -18,11 +18,17 @@ namespace anim { } - void Controller::AddTask(shared_ptr const & task) + void Controller::AddTaskImpl(list > & l, shared_ptr const & task) { + l.push_back(task); task->SetController(this); - m_tasks.PushBack(task); - m_IdleFrames = m_IdleThreshold; + if (task->IsVisual()) + m_IdleFrames = m_IdleThreshold; + } + + void Controller::AddTask(shared_ptr const & task) + { + m_tasks.ProcessList(bind(&Controller::AddTaskImpl, this, _1, task)); } void Controller::CopyAndClearTasks(TTasks & from, TTasks & to) @@ -41,6 +47,28 @@ namespace anim return !m_tasks.Empty(); } + void Controller::HasVisualTasksImpl(list > &l, bool *res) const + { + *res = false; + for (list >::const_iterator it = l.begin(); + it != l.end(); + ++it) + { + if ((*it)->IsVisual()) + { + *res = true; + break; + } + } + } + + bool Controller::HasVisualTasks() + { + bool res; + m_tasks.ProcessList(bind(&Controller::HasVisualTasksImpl, this, _1, &res)); + return res; + } + void Controller::Lock() { ++m_LockCount; @@ -65,16 +93,25 @@ namespace anim TTasks l; - bool hasTasks = !m_tasksList.empty(); + bool hasVisualTasks = false; + for (list >::const_iterator it = m_tasksList.begin(); + it != m_tasksList.end(); + ++it) + if ((*it)->IsVisual()) + { + hasVisualTasks = true; + break; + } for (TTasks::const_iterator it = m_tasksList.begin(); it != m_tasksList.end(); ++it) { - m_IdleFrames = m_IdleThreshold; - shared_ptr const & task = *it; task->Lock(); + if (task->IsVisual()) + m_IdleFrames = m_IdleThreshold; + if (task->IsReady()) { task->Start(); @@ -96,13 +133,13 @@ namespace anim task->Unlock(); } - if (!hasTasks && m_IdleFrames > 0) + if (!hasVisualTasks && m_IdleFrames > 0) m_IdleFrames -= 1; m_tasks.ProcessList(bind(&Controller::MergeTasks, ref(l), _1)); } - bool Controller::IsPreWarmed() const + bool Controller::IsVisuallyPreWarmed() const { return m_IdleFrames > 0; } diff --git a/anim/controller.hpp b/anim/controller.hpp index 398f191a4d..a26f5e2721 100644 --- a/anim/controller.hpp +++ b/anim/controller.hpp @@ -25,6 +25,8 @@ namespace anim int m_IdleThreshold; int m_IdleFrames; + void AddTaskImpl(list > & l, shared_ptr const & task); + void HasVisualTasksImpl(list > & l, bool * res) const; static void CopyAndClearTasks(list > & from, list > & to); static void MergeTasks(list > & from, list > & to); @@ -37,6 +39,8 @@ namespace anim void AddTask(shared_ptr const & task); // Do we have animation tasks, which are currently running? bool HasTasks(); + // Do we have visual animation tasks, which are currently running? + bool HasVisualTasks(); // Lock/Unlock controller. Locked controller // is considered to be in "transition" mode from one task to another // and this situation is taken into account into RenderPolicy when @@ -53,7 +57,7 @@ namespace anim // catch the Controller up and animate everything smoothly without // interrupting rendering process, which might had happened in these // "frames-in-the-middle". - bool IsPreWarmed() const; + bool IsVisuallyPreWarmed() const; // Getting current simulation time double GetCurrentTime() const; }; diff --git a/anim/task.cpp b/anim/task.cpp index 92a5c4b04e..72bbdb2cfa 100644 --- a/anim/task.cpp +++ b/anim/task.cpp @@ -97,6 +97,11 @@ namespace anim return State() == EReady; } + bool Task::IsVisual() const + { + return false; + } + void Task::AddCallback(EState state, TCallback const & cb) { m_Callbacks[state].push_back(cb); diff --git a/anim/task.hpp b/anim/task.hpp index 8cea0054dd..470d22b1e9 100644 --- a/anim/task.hpp +++ b/anim/task.hpp @@ -69,6 +69,10 @@ namespace anim void Lock(); void Unlock(); + /// is this animation task animate something, + /// which is directly changing visual appearance. + virtual bool IsVisual() const; + void AddCallback(EState state, TCallback const & cb); }; } -- cgit v1.2.3