Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/anim
diff options
context:
space:
mode:
authorrachytski <siarhei.rachytski@gmail.com>2012-08-17 19:10:48 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:42:09 +0300
commitb79d29f3f35f04d0a5709904d2b2f96eb061e800 (patch)
tree7d467e6a6d92c0f441cd774690d76851b572a3e3 /anim
parent4ba8227713116acf6b0820687019041b6d063566 (diff)
refactored anim::Controller and moved it into RenderPolicy.
Diffstat (limited to 'anim')
-rw-r--r--anim/anim.pro2
-rw-r--r--anim/controller.cpp84
-rw-r--r--anim/controller.hpp30
-rw-r--r--anim/task.hpp34
4 files changed, 82 insertions, 68 deletions
diff --git a/anim/anim.pro b/anim/anim.pro
index 0e328c422f..a7954cbf5a 100644
--- a/anim/anim.pro
+++ b/anim/anim.pro
@@ -15,5 +15,7 @@ HEADERS += \
SOURCES += \
controller.cpp \
+ task.cpp
+
diff --git a/anim/controller.cpp b/anim/controller.cpp
index 6737105e85..a68955d216 100644
--- a/anim/controller.cpp
+++ b/anim/controller.cpp
@@ -8,20 +8,16 @@ namespace anim
{
Controller::Controller()
{
- m_animStep = 10;
- m_thread.Create(this);
+ m_LockCount = 0;
}
Controller::~Controller()
{
- m_tasks.Cancel();
- m_newTasks.Cancel();
- m_thread.Cancel();
}
void Controller::AddTask(shared_ptr<Task> const & task)
{
- m_newTasks.PushBack(task);
+ m_tasks.PushBack(task);
}
void Controller::CopyTasks(TTasks & from, TTasks & to)
@@ -30,54 +26,50 @@ namespace anim
swap(from, to);
}
- void Controller::Do()
+ bool Controller::HasTasks()
{
- while (true)
- {
- // making synchronized copy of tasks to process
- // them without intervention from other threads.
- m_newTasks.ProcessList(bind(&Controller::CopyTasks, this, _1, ref(m_newTasksList)));
- m_tasks.ProcessList(bind(&Controller::CopyTasks, this, _1, ref(m_tasksList)));
+ return !m_tasks.Empty();
+ }
+
+ void Controller::Lock()
+ {
+ ++m_LockCount;
+ }
- // checking for thread cancellation
- if (m_newTasks.IsCancelled()
- || m_tasks.IsCancelled()
- || IsCancelled())
- break;
+ void Controller::Unlock()
+ {
+ --m_LockCount;
+ }
- // current animation step timestamp
- double timeStamp = my::Timer::LocalTime();
+ int Controller::LockCount()
+ {
+ if (m_LockCount < 0)
+ LOG(LWARNING, ("Lock/Unlock is unbalanced! LockCount < 0!"));
- // starting new tasks and adding them to the pool.
- // they we'll be processed in the next animation step
- for (TTasks::const_iterator it = m_newTasksList.begin();
- it != m_newTasksList.end();
- ++it)
- {
- shared_ptr<Task> task = *it;
- task->OnStart(timeStamp);
- m_tasks.PushBack(task);
- }
+ return m_LockCount;
+ }
- m_newTasksList.clear();
+ void Controller::PerformStep()
+ {
+ m_tasks.ProcessList(bind(&Controller::CopyTasks, this, _1, ref(m_tasksList)));
- // processing current tasks
- for (TTasks::const_iterator it = m_tasksList.begin();
- it != m_tasksList.end();
- ++it)
- {
- shared_ptr<Task> task = *it;
- task->OnStep(timeStamp);
- if (!task->IsFinished())
- m_tasks.PushBack(task);
- else
- task->OnEnd(timeStamp);
- }
+ double ts = my::Timer::LocalTime();
- m_tasksList.clear();
+ TTasks l;
- // sleeping till the next animation step.
- threads::Sleep(m_animStep);
+ for (TTasks::const_iterator it = m_tasksList.begin(); it != m_tasksList.end(); ++it)
+ {
+ shared_ptr<Task> const & task = *it;
+ if (task->State() == Task::EWaitStart)
+ task->OnStart(ts);
+ if (task->State() == Task::EInProgress)
+ task->OnStep(ts);
+ if (task->State() == Task::EWaitEnd)
+ task->OnEnd(ts);
+ else
+ l.push_back(task);
}
+
+ m_tasks.ProcessList(bind(&Controller::CopyTasks, this, ref(l), _1));
}
}
diff --git a/anim/controller.hpp b/anim/controller.hpp
index bf77e7766e..a46c9032c9 100644
--- a/anim/controller.hpp
+++ b/anim/controller.hpp
@@ -10,11 +10,7 @@ namespace anim
class Task;
// Animation controller class.
- // - Creates and manages the separate thread.
- // - Using ThreadedList to manage the list of active commands.
- // - CPU efficient, which means that when there are no commands
- // the thread is sleeping and doesn't consume CPU
- class Controller : public threads::IRoutine
+ class Controller
{
private:
@@ -25,17 +21,7 @@ namespace anim
// Task for the current step.
TTasks m_tasksList;
- ThreadedList<shared_ptr<Task> > m_newTasks;
- // Added, but not started tasks.
- // They'll be started in the next animation step.
- TTasks m_newTasksList;
-
- // Animation thread.
- threads::Thread m_thread;
- // Animation step in miliseconds.
- unsigned m_animStep;
- // MainLoop method
- void Do();
+ int m_LockCount;
void CopyTasks(list<shared_ptr<Task> > & from, list<shared_ptr<Task> > & to);
@@ -46,5 +32,17 @@ namespace anim
~Controller();
// Adding animation task to the controller
void AddTask(shared_ptr<Task> const & task);
+ // Do we have animation tasks, which are currently running?
+ bool HasTasks();
+ // 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
+ // checking for "need redraw" status.
+ void Lock();
+ void Unlock();
+ // Getting current lock count
+ int LockCount();
+ // Perform single animation step
+ void PerformStep();
};
}
diff --git a/anim/task.hpp b/anim/task.hpp
index 16adf3231c..3853b27fce 100644
--- a/anim/task.hpp
+++ b/anim/task.hpp
@@ -6,12 +6,34 @@ namespace anim
class Task
{
public:
- virtual void OnStart(double ts) = 0;
- virtual void OnStep(double ts) = 0;
- virtual void OnEnd(double ts) = 0;
- virtual bool IsFinished() = 0;
- virtual void Finish() = 0;
- virtual ~Task() {};
+ enum EState
+ {
+ EWaitStart,
+ EInProgress,
+ EWaitEnd
+ };
+
+ private:
+
+ EState m_State;
+
+ protected:
+
+ void SetState(EState state);
+
+ public:
+
+ Task();
+ virtual ~Task();
+
+ EState State() const;
+
+ virtual void OnStart(double ts);
+ virtual void OnStep(double ts);
+ virtual void OnEnd(double ts);
+
+ void Finish();
+ bool IsFinished() const;
};
}