diff options
author | Mattes D <github@xoft.cz> | 2014-01-15 11:45:25 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2014-01-15 11:45:25 +0100 |
commit | eb89de4c88ef3c2048af571eaa29726d08148e24 (patch) | |
tree | 783438ae17a67c6953c8170fffcdde8dbf944d50 /src/World.cpp | |
parent | Merge pull request #538 from mc-server/minecarts (diff) | |
parent | added cWorld::ScheduleTask Function (diff) | |
download | cuberite-eb89de4c88ef3c2048af571eaa29726d08148e24.tar cuberite-eb89de4c88ef3c2048af571eaa29726d08148e24.tar.gz cuberite-eb89de4c88ef3c2048af571eaa29726d08148e24.tar.bz2 cuberite-eb89de4c88ef3c2048af571eaa29726d08148e24.tar.lz cuberite-eb89de4c88ef3c2048af571eaa29726d08148e24.tar.xz cuberite-eb89de4c88ef3c2048af571eaa29726d08148e24.tar.zst cuberite-eb89de4c88ef3c2048af571eaa29726d08148e24.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); +} |