From a8bfe3a4c1993b9bbc2defc5f0b667a2348c210e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 25 Sep 2015 18:56:49 +0100 Subject: Prepared ScheduleTask for threading refactor * Llama-ified and condensed Schedule/QueueTask - Removed hackery done with piston animations --- src/World.h | 107 +++--------------------------------------------------------- 1 file changed, 4 insertions(+), 103 deletions(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index 1902296be..44f18df4a 100644 --- a/src/World.h +++ b/src/World.h @@ -96,72 +96,8 @@ public: typedef cCSLock super; public: cLock(cWorld & a_World); - } ; - - - /** A common ancestor for all tasks queued onto the tick thread */ - class cTask - { - public: - cTask(const cTask & other) = default; - virtual ~cTask() {} - virtual void Run(cWorld & a_World) = 0; - - protected: - cTask() {} - } ; - - typedef SharedPtr cTaskPtr; - typedef std::vector cTasks; - - - class cTaskSaveAllChunks : - public cTask - { - protected: - // cTask overrides: - virtual void Run(cWorld & a_World) override; - } ; - - - class cTaskUnloadUnusedChunks : - public cTask - { - protected: - // cTask overrides: - virtual void Run(cWorld & a_World) override; - }; - - - class cTaskSendBlockToAllPlayers : - public cTask - { - public: - cTaskSendBlockToAllPlayers(std::vector & a_SendQueue); - - protected: - // cTask overrides: - virtual void Run(cWorld & a_World) override; - - std::vector m_SendQueue; - }; - - class cTaskLambda : - public cTask - { - - public: - cTaskLambda(std::function a_Func) : - m_func(a_Func) - { } - - protected: - virtual void Run(cWorld & a_World) override; - - std::function m_func; }; - static const char * GetClassStatic(void) // Needed for ManualBindings's ForEach templates { return "cWorld"; @@ -739,13 +675,10 @@ public: void QueueSaveAllChunks(void); // tolua_export /** Queues a task onto the tick thread. The task object will be deleted once the task is finished */ - void QueueTask(cTaskPtr a_Task); // Exported in ManualBindings.cpp + void QueueTask(std::function a_Task); // Exported in ManualBindings.cpp /** Queues a lambda task onto the tick thread, with the specified delay. */ - void ScheduleTask(int a_DelayTicks, std::function a_Func); - - /** Queues a task onto the tick thread, with the specified delay. */ - void ScheduleTask(int a_DelayTicks, cTaskPtr a_Task); + void ScheduleTask(int a_DelayTicks, std::function a_Task); /** Returns the number of chunks loaded */ int GetNumChunks() const; // tolua_export @@ -912,27 +845,6 @@ private: public: cChunkGeneratorCallbacks(cWorld & a_World); } ; - - - /** A container for tasks that have been scheduled for a specific game tick */ - class cScheduledTask - { - public: - Int64 m_TargetTick; - cTaskPtr m_Task; - - /** Creates a new scheduled task; takes ownership of the task object passed to it. */ - cScheduledTask(Int64 a_TargetTick, cTaskPtr a_Task) : - m_TargetTick(a_TargetTick), - m_Task(a_Task) - { - } - - virtual ~cScheduledTask() {} - }; - - typedef std::unique_ptr cScheduledTaskPtr; - typedef std::list cScheduledTasks; AString m_WorldName; @@ -1062,16 +974,8 @@ private: /** Guards the m_Tasks */ cCriticalSection m_CSTasks; - /** Tasks that have been queued onto the tick thread; guarded by m_CSTasks */ - cTasks m_Tasks; - - /** Guards the m_ScheduledTasks */ - cCriticalSection m_CSScheduledTasks; - - /** Tasks that have been queued to be executed on the tick thread at target tick in the future. - Ordered by increasing m_TargetTick. - Guarded by m_CSScheduledTasks */ - cScheduledTasks m_ScheduledTasks; + /** Tasks that have been queued onto the tick thread, possibly to be executed at target tick in the future; guarded by m_CSTasks */ + std::vector>> m_Tasks; /** Guards m_Clients */ cCriticalSection m_CSClients; @@ -1118,9 +1022,6 @@ private: /** Executes all tasks queued onto the tick thread */ void TickQueuedTasks(void); - /** Executes all tasks queued onto the tick thread */ - void TickScheduledTasks(void); - /** Ticks all clients that are in this world */ void TickClients(float a_Dt); -- cgit v1.2.3