summaryrefslogtreecommitdiffstats
path: root/src/World.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-01-15 11:45:25 +0100
committerMattes D <github@xoft.cz>2014-01-15 11:45:25 +0100
commiteb89de4c88ef3c2048af571eaa29726d08148e24 (patch)
tree783438ae17a67c6953c8170fffcdde8dbf944d50 /src/World.cpp
parentMerge pull request #538 from mc-server/minecarts (diff)
parentadded cWorld::ScheduleTask Function (diff)
downloadcuberite-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.cpp39
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);
+}