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

47 lines
1.1 KiB
C++
Raw Normal View History

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));
}
void EventDispatcher::addEvent(const SimpleCallback& callback, bool pushFront)
{
if(pushFront)
m_eventList.push_front(callback);
else
m_eventList.push_back(callback);
}