diff options
author | madmaxoft <github@xoft.cz> | 2014-01-19 23:49:19 +0100 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-01-19 23:49:19 +0100 |
commit | 41618bf242e66744431a1d28e0409f543fb240e4 (patch) | |
tree | 0b5cfe41e67468f495c2c01707d7379f3a241bb5 /src/World.cpp | |
parent | cLuaState can now check function params. (diff) | |
download | cuberite-41618bf242e66744431a1d28e0409f543fb240e4.tar cuberite-41618bf242e66744431a1d28e0409f543fb240e4.tar.gz cuberite-41618bf242e66744431a1d28e0409f543fb240e4.tar.bz2 cuberite-41618bf242e66744431a1d28e0409f543fb240e4.tar.lz cuberite-41618bf242e66744431a1d28e0409f543fb240e4.tar.xz cuberite-41618bf242e66744431a1d28e0409f543fb240e4.tar.zst cuberite-41618bf242e66744431a1d28e0409f543fb240e4.zip |
Diffstat (limited to 'src/World.cpp')
-rw-r--r-- | src/World.cpp | 32 |
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)); } |