summaryrefslogtreecommitdiffstats
path: root/src/World.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/World.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/World.cpp b/src/World.cpp
index 6520702c7..5e9f4a38a 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -865,13 +865,17 @@ void cWorld::TickQueuedTasks(void)
} // for itr - m_Tasks[]
}
-void cWorld::TickScheduledTasks()
+
+
+
+
+void cWorld::TickScheduledTasks(void)
{
- ScheduledTaskList Tasks;
// Make a copy of the tasks to avoid deadlocks on accessing m_Tasks
+ cScheduledTasks Tasks;
{
cCSLock Lock(m_CSScheduledTasks);
- while (!m_ScheduledTasks.empty() && m_ScheduledTasks.front()->Ticks < m_WorldAge)
+ while (!m_ScheduledTasks.empty() && (m_ScheduledTasks.front()->m_TargetTick < m_WorldAge))
{
Tasks.push_back(m_ScheduledTasks.front());
m_ScheduledTasks.pop_front();
@@ -879,9 +883,9 @@ void cWorld::TickScheduledTasks()
}
// Execute and delete each task:
- for (ScheduledTaskList::iterator itr = Tasks.begin(), end = Tasks.end(); itr != end; ++itr)
+ for (cScheduledTasks::iterator itr = Tasks.begin(), end = Tasks.end(); itr != end; ++itr)
{
- (*itr)->Run(*this);
+ (*itr)->m_Task->Run(*this);
delete *itr;
} // for itr - m_Tasks[]
}
@@ -2627,19 +2631,25 @@ void cWorld::QueueTask(cTask * a_Task)
m_Tasks.push_back(a_Task);
}
-void cWorld::ScheduleTask(cScheduledTask * a_Task)
+
+
+
+
+void cWorld::ScheduleTask(int a_DelayTicks, cTask * a_Task)
{
- a_Task->Ticks = a_Task->Ticks + m_WorldAge;
+ Int64 TargetTick = a_DelayTicks + m_WorldAge;
+
+ // Insert the task into the list of scheduled tasks, ordered by its target tick
cCSLock Lock(m_CSScheduledTasks);
- for(ScheduledTaskList::iterator itr = m_ScheduledTasks.begin(); itr != m_ScheduledTasks.end(); itr++)
+ for (cScheduledTasks::iterator itr = m_ScheduledTasks.begin(), end = m_ScheduledTasks.end(); itr != end; ++itr)
{
- if((*itr)->Ticks >= a_Task->Ticks)
+ if ((*itr)->m_TargetTick >= TargetTick)
{
- m_ScheduledTasks.insert(itr, a_Task);
+ m_ScheduledTasks.insert(itr, new cScheduledTask(TargetTick, a_Task));
return;
}
}
- m_ScheduledTasks.push_back(a_Task);
+ m_ScheduledTasks.push_back(new cScheduledTask(TargetTick, a_Task));
}