diff options
author | Tycho <work.tycho+git@gmail.com> | 2014-01-14 21:17:03 +0100 |
---|---|---|
committer | Tycho <work.tycho+git@gmail.com> | 2014-01-14 21:17:03 +0100 |
commit | 292ccdc09e083d6c0af02328651ef3d99cd8edb6 (patch) | |
tree | 3300fbe00f3b8fdca7dccb9a912bf79a1a841f2e /src/World.cpp | |
parent | CMake: Release profile build inherits from Release, not Debug. (diff) | |
download | cuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.tar cuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.tar.gz cuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.tar.bz2 cuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.tar.lz cuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.tar.xz cuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.tar.zst cuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.zip |
Diffstat (limited to 'src/World.cpp')
-rw-r--r-- | src/World.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/World.cpp b/src/World.cpp index 1cf82d641..2b85e4b58 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -690,6 +690,7 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec) TickClients(a_Dt); TickQueuedBlocks(); TickQueuedTasks(); + TickScheduledTasks(); GetSimulatorManager()->Simulate(a_Dt); @@ -861,6 +862,31 @@ void cWorld::TickQueuedTasks(void) } // for itr - m_Tasks[] } +void cWorld::TickScheduledTasks() +{ + ScheduledTaskList Tasks; + // Make a copy of the tasks to avoid deadlocks on accessing m_Tasks + { + cCSLock Lock(m_CSScheduledTasks); + ScheduledTaskList::iterator itr = m_ScheduledTasks.begin(); + while (itr != m_ScheduledTasks.end() && (*itr)->Ticks > 0) + { + Tasks.push_back(m_ScheduledTasks.front()); + m_ScheduledTasks.pop_front(); + } + for(;itr != m_ScheduledTasks.end(); itr++) + { + (*itr)->Ticks--; + } + } + + // Execute and delete each task: + for (ScheduledTaskList::iterator itr = Tasks.begin(), end = Tasks.end(); itr != end; ++itr) + { + (*itr)->Run(*this); + delete *itr; + } // for itr - m_Tasks[] +} @@ -2571,6 +2597,19 @@ void cWorld::QueueTask(cTask * a_Task) m_Tasks.push_back(a_Task); } +void cWorld::ScheduleTask(cScheduledTask * a_Task) +{ + cCSLock Lock(m_CSScheduledTasks); + for(ScheduledTaskList::iterator itr = m_ScheduledTasks.begin(); itr != m_ScheduledTasks.end(); itr++) + { + if((*itr)->Ticks >= a_Task->Ticks) + { + m_ScheduledTasks.insert(itr, a_Task); + return; + } + } + m_ScheduledTasks.push_back(a_Task); +} |