#ifndef _EVENTMANAGER_H_
#define _EVENTMANAGER_H_

#include "TSingleton.h"

#include "IEvent.h"
#include "IEventListener.h"
#include "HashString.h"

#include <vector>
#include <queue>

class EventManager : public TSingleton<EventManager>
{
	public:
	EventManager();
	~EventManager();

	void ProcessQueue(unsigned int totalTime = 0);

	void AddEventListener(const HashString &eventType, IEventListener* pListener);
	void RemoveEventListener(const HashString &eventType, IEventListener* pListener);
	void RemoveEventListenerFromAll(IEventListener* pListener);

	void TriggerEvent(IEvent* pEvent);
	void QueueEvent(IEvent* pEvent);

	protected:
	struct EventListenerSet
	{
		HashString EventType;
		std::vector<IEventListener*> EventListeners;
	};

	EventListenerSet* GetListenerSet(const HashString &eventType);

	std::vector<EventListenerSet*> m_vEventListenerSets;
	std::queue<IEvent*> m_qEventQueue;
};

#endif
