tibia-client/src/framework/core/dispatcher.cpp

44 lines
1.0 KiB
C++
Raw Normal View History

2011-07-17 02:13:53 +02:00
#include "dispatcher.h"
#include "engine.h"
2011-04-08 07:10:00 +02:00
Dispatcher g_dispatcher;
void Dispatcher::cleanup()
{
while(!m_scheduledTaskList.empty()) {
ScheduledTask *task = m_scheduledTaskList.top();
m_scheduledTaskList.pop();
delete task;
}
}
2011-04-15 04:13:53 +02:00
void Dispatcher::poll()
2011-04-08 07:10:00 +02:00
{
while(!m_taskList.empty()) {
m_taskList.front()();
m_taskList.pop_front();
}
while(!m_scheduledTaskList.empty()) {
ScheduledTask *task = m_scheduledTaskList.top();
2011-04-17 21:14:24 +02:00
if(g_engine.getCurrentFrameTicks() < task->ticks)
2011-04-08 07:10:00 +02:00
break;
m_scheduledTaskList.pop();
2011-04-08 07:10:00 +02:00
task->callback();
delete task;
}
}
2011-07-13 23:12:36 +02:00
void Dispatcher::scheduleTask(const boost::function<void()>& callback, int delay)
2011-04-08 07:10:00 +02:00
{
m_scheduledTaskList.push(new ScheduledTask(g_engine.getCurrentFrameTicks() + delay, callback));
2011-04-08 07:10:00 +02:00
}
2011-07-13 23:12:36 +02:00
void Dispatcher::addTask(const boost::function<void()>& callback, bool pushFront)
2011-04-08 07:10:00 +02:00
{
if(pushFront)
m_taskList.push_front(callback);
else
m_taskList.push_back(callback);
2011-04-08 07:10:00 +02:00
}