31 lines
649 B
C++
31 lines
649 B
C++
#include "Delegate.hpp"
|
|
|
|
Delegate::Delegate(Node *parent) : Node(parent) {}
|
|
|
|
void Delegate::add_subscriber(subscriber s, SDL_EventType type)
|
|
{
|
|
if (subscribers.count(type) == 0)
|
|
{
|
|
subscribers[type] = {};
|
|
}
|
|
subscribers[type].push_back(s);
|
|
}
|
|
|
|
void Delegate::dispatch()
|
|
{
|
|
SDL_Event event;
|
|
while (SDL_PollEvent(&event))
|
|
{
|
|
for (auto iter = subscribers.begin(); iter != subscribers.end(); iter++)
|
|
{
|
|
if (event.type == iter->first)
|
|
{
|
|
for (subscriber s : iter->second)
|
|
{
|
|
s(event);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|