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;
|
|
|
|
|
2011-07-12 21:27:37 +02:00
|
|
|
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()) {
|
2011-05-02 06:13:57 +02:00
|
|
|
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;
|
2011-05-02 06:13:57 +02:00
|
|
|
m_scheduledTaskList.pop();
|
2011-04-08 07:10:00 +02:00
|
|
|
task->callback();
|
|
|
|
delete task;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-27 01:13:27 +02:00
|
|
|
void Dispatcher::scheduleTask(const std::function<void()>& callback, int delay)
|
2011-04-08 07:10:00 +02:00
|
|
|
{
|
2011-05-02 06:13:57 +02:00
|
|
|
m_scheduledTaskList.push(new ScheduledTask(g_engine.getCurrentFrameTicks() + delay, callback));
|
2011-04-08 07:10:00 +02:00
|
|
|
}
|
|
|
|
|
2011-07-27 01:13:27 +02:00
|
|
|
void Dispatcher::addTask(const std::function<void()>& callback, bool pushFront)
|
2011-04-08 07:10:00 +02:00
|
|
|
{
|
2011-05-02 06:13:57 +02:00
|
|
|
if(pushFront)
|
|
|
|
m_taskList.push_front(callback);
|
|
|
|
else
|
|
|
|
m_taskList.push_back(callback);
|
2011-04-08 07:10:00 +02:00
|
|
|
}
|