keeping anim::Controller pre-warmed for 5 cycles to allow new animations to start without interrupting rendering process.

This commit is contained in:
rachytski 2012-09-28 21:12:14 +03:00 committed by Alex Zolotarev
parent b307e49a76
commit 7ea55eff17
3 changed files with 30 additions and 4 deletions

View file

@ -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<Task> 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<Task> 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;
}
}

View file

@ -22,6 +22,8 @@ namespace anim
TTasks m_tasksList;
int m_LockCount;
int m_IdleThreshold;
int m_IdleFrames;
static void CopyAndClearTasks(list<shared_ptr<Task> > & from, list<shared_ptr<Task> > & 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;
};
}

View file

@ -99,12 +99,13 @@ void RenderPolicy::StopRotate(double a, double)
void RenderPolicy::BeginFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s)
{
/// processing animations at the beginning of the frame
m_controller->PerformStep();
}
void RenderPolicy::EndFrame(shared_ptr<PaintEvent> 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