#pragma once #include "../std/shared_ptr.hpp" #include "../base/thread.hpp" #include "../base/threaded_list.hpp" namespace anim { class Task; // Animation controller class. class Controller { private: // Container for tasks typedef list > TTasks; 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); public: struct Guard { Controller * m_controller; Guard(Controller * controller); ~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? 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 // checking for "need redraw" status. void Lock(); void Unlock(); // Getting current lock count 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; }; }