From 7ea55eff17c28cb688f314e0904c160cba4c8952 Mon Sep 17 00:00:00 2001 From: rachytski Date: Fri, 28 Sep 2012 21:12:14 +0300 Subject: [PATCH] keeping anim::Controller pre-warmed for 5 cycles to allow new animations to start without interrupting rendering process. --- anim/controller.cpp | 15 +++++++++++++++ anim/controller.hpp | 9 +++++++++ map/render_policy.cpp | 10 ++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/anim/controller.cpp b/anim/controller.cpp index 9e246da4c2..3f217cf48c 100644 --- a/anim/controller.cpp +++ b/anim/controller.cpp @@ -10,6 +10,8 @@ namespace anim Controller::Controller() { m_LockCount = 0; + m_IdleThreshold = 5; + m_IdleFrames = 0; } Controller::~Controller() @@ -19,6 +21,7 @@ namespace anim void Controller::AddTask(shared_ptr const & task) { m_tasks.PushBack(task); + m_IdleFrames = m_IdleThreshold; } void Controller::CopyAndClearTasks(TTasks & from, TTasks & to) @@ -56,8 +59,12 @@ namespace anim TTasks l; + bool hasTasks = !m_tasksList.empty(); + for (TTasks::const_iterator it = m_tasksList.begin(); it != m_tasksList.end(); ++it) { + m_IdleFrames = m_IdleThreshold; + shared_ptr const & task = *it; if (task->State() == Task::EStarted) task->OnStart(ts); @@ -75,6 +82,14 @@ namespace anim } } + if (!hasTasks && m_IdleFrames > 0) + m_IdleFrames -= 1; + m_tasks.ProcessList(bind(&Controller::CopyAndClearTasks, ref(l), _1)); } + + bool Controller::IsPreWarmed() const + { + return m_IdleFrames > 0; + } } diff --git a/anim/controller.hpp b/anim/controller.hpp index b93b19b71e..ff8a66e863 100644 --- a/anim/controller.hpp +++ b/anim/controller.hpp @@ -22,6 +22,8 @@ namespace anim TTasks m_tasksList; int m_LockCount; + int m_IdleThreshold; + int m_IdleFrames; static void CopyAndClearTasks(list > & from, list > & to); @@ -44,5 +46,12 @@ namespace anim int LockCount(); // Perform single animation step void PerformStep(); + // When the last animation is finished, Controller continues + // to be considered animating something for some frames to allow + // animations that are likely to happen in the next few frames to + // 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; }; } diff --git a/map/render_policy.cpp b/map/render_policy.cpp index 7cc8513412..b182e8a442 100644 --- a/map/render_policy.cpp +++ b/map/render_policy.cpp @@ -99,12 +99,13 @@ void RenderPolicy::StopRotate(double a, double) void RenderPolicy::BeginFrame(shared_ptr const & e, ScreenBase const & s) { - /// processing animations at the beginning of the frame - m_controller->PerformStep(); } void RenderPolicy::EndFrame(shared_ptr const & e, ScreenBase const & s) -{} +{ + /// processing animations at the end of the frame + m_controller->PerformStep(); +} bool RenderPolicy::DoSupportRotation() const { @@ -120,7 +121,8 @@ bool RenderPolicy::NeedRedraw() const bool RenderPolicy::IsAnimating() const { return (m_controller->HasTasks() - || (m_controller->LockCount() > 0)); + || (m_controller->LockCount() > 0) + || (m_controller->IsPreWarmed())); } bool RenderPolicy::IsTiling() const