From 6ba4033ea8e74a72dd71f5e5fab940729d1db33d Mon Sep 17 00:00:00 2001 From: ExMix Date: Fri, 26 Sep 2014 13:50:44 +0300 Subject: [PATCH] [core] remove PreWermend Idle --- anim/controller.cpp | 100 ++++++++++-------------------------------- anim/controller.hpp | 26 +++-------- map/render_policy.cpp | 3 +- 3 files changed, 29 insertions(+), 100 deletions(-) diff --git a/anim/controller.cpp b/anim/controller.cpp index ff3fd2a877..a38eab816a 100644 --- a/anim/controller.cpp +++ b/anim/controller.cpp @@ -18,39 +18,13 @@ namespace anim m_controller->Unlock(); } - Controller::Controller() - { - m_LockCount = 0; - m_IdleThreshold = 5; - m_IdleFrames = 0; - } - - Controller::~Controller() - { - } - - void Controller::AddTaskImpl(list > & l, shared_ptr const & task) - { - l.push_back(task); - task->SetController(this); - 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) - { - to.clear(); - swap(from, to); - } - - void Controller::MergeTasks(TTasks & from, TTasks & to) - { - copy(from.begin(), from.end(), back_inserter(to)); + m_tasks.ProcessList([this, &task](TTasks & taskList) + { + taskList.push_back(task); + task->SetController(this); + }); } bool Controller::HasTasks() @@ -58,26 +32,9 @@ 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; + return m_hasVisualTasks; } void Controller::Lock() @@ -98,31 +55,20 @@ namespace anim void Controller::PerformStep() { - m_tasks.ProcessList(bind(&Controller::CopyAndClearTasks, _1, ref(m_tasksList))); + m_tasks.ProcessList([this](TTasks & from) + { + m_tasksList.clear(); + swap(from, m_tasksList); + }); double ts = GetCurrentTime(); - TTasks l; + TTasks resultList; - 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) + for (TTaskPtr const & task : m_tasksList) { - shared_ptr const & task = *it; - task->Lock(); - if (task->IsVisual()) - m_IdleFrames = m_IdleThreshold; - if (task->IsReady()) { task->Start(); @@ -132,7 +78,7 @@ namespace anim task->OnStep(ts); if (task->IsRunning()) - l.push_back(task); + resultList.push_back(task); else { if (task->IsCancelled()) @@ -144,15 +90,15 @@ namespace anim task->Unlock(); } - if (!hasVisualTasks && m_IdleFrames > 0) - m_IdleFrames -= 1; - - m_tasks.ProcessList(bind(&Controller::MergeTasks, ref(l), _1)); - } - - bool Controller::IsVisuallyPreWarmed() const - { - return m_IdleFrames > 0; + m_hasVisualTasks = false; + m_tasks.ProcessList([this, &resultList](TTasks & to) + { + for_each(resultList.begin(), resultList.end(), [this, &to](shared_ptr task) + { + m_hasVisualTasks |= task->IsVisual(); + to.push_back(task); + }); + }); } double Controller::GetCurrentTime() const diff --git a/anim/controller.hpp b/anim/controller.hpp index 37ea774387..1cde757b04 100644 --- a/anim/controller.hpp +++ b/anim/controller.hpp @@ -14,21 +14,16 @@ namespace anim { private: + typedef shared_ptr TTaskPtr; // Container for tasks - typedef list > TTasks; + typedef list TTasks; - ThreadedList > m_tasks; + ThreadedList m_tasks; // Task for the current step. TTasks m_tasksList; - int m_LockCount; - 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); + int m_LockCount = 0; + bool m_hasVisualTasks = false; public: @@ -39,10 +34,6 @@ namespace anim ~Guard(); }; - // Constructor - Controller(); - // Destructor - ~Controller(); // Adding animation task to the controller void AddTask(shared_ptr const & task); // Do we have animation tasks, which are currently running? @@ -59,13 +50,6 @@ 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 IsVisuallyPreWarmed() const; // Getting current simulation time double GetCurrentTime() const; }; diff --git a/map/render_policy.cpp b/map/render_policy.cpp index f2449f4900..2044bce1ef 100644 --- a/map/render_policy.cpp +++ b/map/render_policy.cpp @@ -141,8 +141,7 @@ bool RenderPolicy::NeedRedraw() const bool RenderPolicy::IsAnimating() const { return (m_controller->HasVisualTasks() - || (m_controller->LockCount() > 0) - || (m_controller->IsVisuallyPreWarmed())); + || (m_controller->LockCount() > 0)); } bool RenderPolicy::IsTiling() const