2011-08-14 04:09:11 +02:00
|
|
|
#include "eventdispatcher.h"
|
2011-08-15 16:06:15 +02:00
|
|
|
|
|
|
|
#include <framework/platform/platform.h>
|
2011-08-14 04:09:11 +02:00
|
|
|
|
|
|
|
EventDispatcher g_dispatcher;
|
|
|
|
|
|
|
|
void EventDispatcher::init()
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventDispatcher::terminate()
|
|
|
|
{
|
|
|
|
// clean scheduled events
|
|
|
|
while(!m_scheduledEventList.empty())
|
|
|
|
m_scheduledEventList.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventDispatcher::poll()
|
|
|
|
{
|
|
|
|
while(!m_eventList.empty()) {
|
|
|
|
m_eventList.front()();
|
|
|
|
m_eventList.pop_front();
|
|
|
|
}
|
|
|
|
|
|
|
|
while(!m_scheduledEventList.empty()) {
|
|
|
|
if(g_platform.getTicks() < m_scheduledEventList.top().ticks)
|
|
|
|
break;
|
|
|
|
SimpleCallback callback = std::move(m_scheduledEventList.top().callback);
|
|
|
|
m_scheduledEventList.pop();
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventDispatcher::scheduleEvent(const SimpleCallback& callback, int delay)
|
|
|
|
{
|
|
|
|
m_scheduledEventList.push(ScheduledEvent(g_platform.getTicks() + delay, callback));
|
|
|
|
}
|
|
|
|
|
2011-08-28 01:16:23 +02:00
|
|
|
void EventDispatcher::addEvent(const SimpleCallback& callback, bool pushFront /* = false */)
|
2011-08-14 04:09:11 +02:00
|
|
|
{
|
|
|
|
if(pushFront)
|
|
|
|
m_eventList.push_front(callback);
|
|
|
|
else
|
|
|
|
m_eventList.push_back(callback);
|
|
|
|
}
|