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 ++++ map/change_viewport_task.cpp | 5 +++++ map/change_viewport_task.hpp | 2 ++ map/move_screen_task.cpp | 5 +++++ map/move_screen_task.hpp | 2 ++ map/render_policy.cpp | 4 ++-- map/rotate_screen_task.cpp | 5 +++++ map/rotate_screen_task.hpp | 2 ++ 11 files changed, 82 insertions(+), 11 deletions(-) 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); }; } diff --git a/map/change_viewport_task.cpp b/map/change_viewport_task.cpp index 624e070595..9d6cf7d5eb 100644 --- a/map/change_viewport_task.cpp +++ b/map/change_viewport_task.cpp @@ -24,3 +24,8 @@ void ChangeViewportTask::OnEnd(double ts) anim::AnyRectInterpolation::OnEnd(ts); m_framework->GetNavigator().SetFromRect(m_outRect); } + +bool ChangeViewportTask::IsVisual() const +{ + return true; +} diff --git a/map/change_viewport_task.hpp b/map/change_viewport_task.hpp index 6f662169dd..73f15061d7 100644 --- a/map/change_viewport_task.hpp +++ b/map/change_viewport_task.hpp @@ -20,4 +20,6 @@ public: void OnStep(double ts); void OnEnd(double ts); + + bool IsVisual() const; }; diff --git a/map/move_screen_task.cpp b/map/move_screen_task.cpp index 2a292f1cf3..bbe41a35b0 100644 --- a/map/move_screen_task.cpp +++ b/map/move_screen_task.cpp @@ -24,3 +24,8 @@ void MoveScreenTask::OnEnd(double ts) anim::SegmentInterpolation::OnEnd(ts); m_framework->GetNavigator().SetOrg(m_outPt); } + +bool MoveScreenTask::IsVisual() const +{ + return true; +} diff --git a/map/move_screen_task.hpp b/map/move_screen_task.hpp index 7de6bc0c73..bf33a4d206 100644 --- a/map/move_screen_task.hpp +++ b/map/move_screen_task.hpp @@ -20,4 +20,6 @@ public: void OnStep(double ts); void OnEnd(double ts); + + bool IsVisual() const; }; diff --git a/map/render_policy.cpp b/map/render_policy.cpp index b182e8a442..4a078fa4a1 100644 --- a/map/render_policy.cpp +++ b/map/render_policy.cpp @@ -120,9 +120,9 @@ bool RenderPolicy::NeedRedraw() const bool RenderPolicy::IsAnimating() const { - return (m_controller->HasTasks() + return (m_controller->HasVisualTasks() || (m_controller->LockCount() > 0) - || (m_controller->IsPreWarmed())); + || (m_controller->IsVisuallyPreWarmed())); } bool RenderPolicy::IsTiling() const diff --git a/map/rotate_screen_task.cpp b/map/rotate_screen_task.cpp index 9ede02683e..e8518114e1 100644 --- a/map/rotate_screen_task.cpp +++ b/map/rotate_screen_task.cpp @@ -24,3 +24,8 @@ void RotateScreenTask::OnEnd(double ts) anim::AngleInterpolation::OnEnd(ts); m_framework->GetNavigator().SetAngle(m_outAngle); } + +bool RotateScreenTask::IsVisual() const +{ + return true; +} diff --git a/map/rotate_screen_task.hpp b/map/rotate_screen_task.hpp index 9865f2ed43..f7e17ee29a 100644 --- a/map/rotate_screen_task.hpp +++ b/map/rotate_screen_task.hpp @@ -20,4 +20,6 @@ public: void OnStep(double ts); void OnEnd(double ts); + + bool IsVisual() const; }; -- cgit v1.2.3