From 292ccdc09e083d6c0af02328651ef3d99cd8edb6 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 14 Jan 2014 12:17:03 -0800 Subject: added cWorld::ScheduleTask Function ScheduleTask schedules a SceduledTask object to be run x ticks in the future. In is exported to lua, fixes #150 --- src/World.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index b61708d03..6ddb3ec86 100644 --- a/src/World.h +++ b/src/World.h @@ -82,7 +82,18 @@ public: virtual void Run(cWorld & a_World) = 0; } ; + /// A common ancestor for all scheduled tasks queued onto the tick thread + class cScheduledTask + { + public: + cScheduledTask(const int a_Ticks) : Ticks(a_Ticks) {}; + virtual ~cScheduledTask() {}; + virtual void Run(cWorld & a_World) = 0; + int Ticks; + }; + typedef std::vector cTasks; + typedef std::list ScheduledTaskList; class cTaskSaveAllChunks : public cTask @@ -533,6 +544,9 @@ public: /// Queues a task onto the tick thread. The task object will be deleted once the task is finished void QueueTask(cTask * a_Task); // Exported in ManualBindings.cpp + + // Queues a task onto the tick thread. The task object will be deleted once the task is finished + void ScheduleTask(cScheduledTask * a_Task); /// Returns the number of chunks loaded int GetNumChunks() const; // tolua_export @@ -745,9 +759,16 @@ private: /// Guards the m_Tasks cCriticalSection m_CSTasks; + /// Guards the m_ScheduledTasks + cCriticalSection m_CSScheduledTasks; + /// Tasks that have been queued onto the tick thread; guarded by m_CSTasks cTasks m_Tasks; + /// Tasks that have been queued to be executed on the tick thread at some number of ticks in + /// the future; guarded by m_CSScheduledTasks + ScheduledTaskList m_ScheduledTasks; + /// Guards m_Clients cCriticalSection m_CSClients; @@ -775,6 +796,9 @@ 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