Tidying
This commit is contained in:
@@ -53,6 +53,9 @@ namespace Bloom
|
||||
|
||||
/**
|
||||
* Each event listener is supplied an ID upon registering with the EventManager.
|
||||
*
|
||||
* @TODO: It might be a better idea to use an std::atomic to generate this auto-incremented ID. Like we do
|
||||
* with events.
|
||||
*/
|
||||
size_t id = 0;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ void EventManager::triggerEvent(std::shared_ptr<const Events::Event> event) {
|
||||
auto registerListenersLock = std::unique_lock(this->registerListenerMutex);
|
||||
for(auto const& [listenerId, listener] : this->registeredListeners) {
|
||||
auto registeredEventTypes = listener->getRegisteredEventTypeNames();
|
||||
if (registeredEventTypes.find(event->getName()) != registeredEventTypes.end()) {
|
||||
if (registeredEventTypes.contains(event->getName())) {
|
||||
listener->registerEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
#include "Events/Events.hpp"
|
||||
#include "EventListener.hpp"
|
||||
|
||||
namespace Bloom
|
||||
{
|
||||
/**
|
||||
* The EventManager class provides a method of dispatching events to a set of listeners.
|
||||
* A single instance of this class is created in Application class. That instance is then passed by references to
|
||||
* all other components in Bloom, that require the ability to trigger events.
|
||||
*
|
||||
* @TODO: Should this be a static class? As in, all methods and variables declared static. We seem to be
|
||||
* using it in that way. It would save us from having to pass around that single instance by reference.
|
||||
* Something to consider.
|
||||
*/
|
||||
class EventManager
|
||||
{
|
||||
private:
|
||||
@@ -19,13 +28,31 @@ namespace Bloom
|
||||
|
||||
public:
|
||||
/**
|
||||
* Generates a new registered listener.
|
||||
* Registers an EventListener instance with this manager.
|
||||
*
|
||||
* All EventListener instances must be registered with the EventManager before any events can
|
||||
* be dispatched to them.
|
||||
*
|
||||
* The EventManager possesses partial ownership of the EventListener. This is why we use a shared_ptr here.
|
||||
*
|
||||
* @param listenerName
|
||||
*/
|
||||
void registerListener(std::shared_ptr<EventListener> listener);
|
||||
|
||||
/**
|
||||
* Deregister an EventListener instance.
|
||||
*
|
||||
* @param listenerId
|
||||
* The ID of the EventListener to deregister. See EventListener::getId();
|
||||
*/
|
||||
void deregisterListener(size_t listenerId);
|
||||
|
||||
/**
|
||||
* Dispatches an event to all registered listeners, if they have registered an interest in the event type.
|
||||
* See EventListener::registeredEventTypes for more.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
void triggerEvent(GenericEventPointer event);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user