You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.0 KiB

13 years ago
#include "dispatcher.h"
#include "engine.h"
13 years ago
Dispatcher g_dispatcher;
void Dispatcher::cleanup()
{
while(!m_scheduledTaskList.empty()) {
ScheduledTask *task = m_scheduledTaskList.top();
m_scheduledTaskList.pop();
delete task;
}
}
void Dispatcher::poll()
13 years ago
{
while(!m_taskList.empty()) {
m_taskList.front()();
m_taskList.pop_front();
}
while(!m_scheduledTaskList.empty()) {
ScheduledTask *task = m_scheduledTaskList.top();
13 years ago
if(g_engine.getCurrentFrameTicks() < task->ticks)
13 years ago
break;
m_scheduledTaskList.pop();
13 years ago
task->callback();
delete task;
}
}
void Dispatcher::scheduleTask(const boost::function<void()>& callback, int delay)
13 years ago
{
m_scheduledTaskList.push(new ScheduledTask(g_engine.getCurrentFrameTicks() + delay, callback));
13 years ago
}
void Dispatcher::addTask(const boost::function<void()>& callback, bool pushFront)
13 years ago
{
if(pushFront)
m_taskList.push_front(callback);
else
m_taskList.push_back(callback);
13 years ago
}