diff options
-rw-r--r-- | src/World.cpp | 10 | ||||
-rw-r--r-- | src/World.h | 3 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/World.cpp b/src/World.cpp index edf27050d..e4c03699f 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -875,10 +875,6 @@ void cWorld::TickScheduledTasks() Tasks.push_back(m_ScheduledTasks.front()); m_ScheduledTasks.pop_front(); } - for(;itr != m_ScheduledTasks.end(); itr++) - { - (*itr)->Ticks--; - } } // Execute and delete each task: @@ -887,6 +883,9 @@ void cWorld::TickScheduledTasks() (*itr)->Run(*this); delete *itr; } // for itr - m_Tasks[] + + // Increment TickID + m_TickID = (m_TickID+1) &0xFFFF; } @@ -2623,10 +2622,11 @@ void cWorld::QueueTask(cTask * a_Task) void cWorld::ScheduleTask(cScheduledTask * a_Task) { + a_Task->Ticks = (a_Task->Ticks + m_TickID) & 0xFFFF; cCSLock Lock(m_CSScheduledTasks); for(ScheduledTaskList::iterator itr = m_ScheduledTasks.begin(); itr != m_ScheduledTasks.end(); itr++) { - if((*itr)->Ticks >= a_Task->Ticks) + if((*itr)->Ticks >= a_Task->Ticks && (a_Task->Ticks > m_TickID || (*itr)->Ticks < m_TickID)) { m_ScheduledTasks.insert(itr, a_Task); return; diff --git a/src/World.h b/src/World.h index 1ecf41507..2fd7319cf 100644 --- a/src/World.h +++ b/src/World.h @@ -772,6 +772,9 @@ private: /// the future; guarded by m_CSScheduledTasks ScheduledTaskList m_ScheduledTasks; + /// Current Tick number for sceduled tasks + int m_TickID; + /// Guards m_Clients cCriticalSection m_CSClients; |