|
Engine²
Open-source game engine written in C++.
|
Thread-safe event manager for registering, queuing, and dispatching events. More...
#include <EventManager.hpp>
Classes | |
| struct | DirectCallbackSchedulerTag |
Public Types | |
| using | EventTypeID = size_t |
| Type identifier for event types. | |
| using | EventCallbackID = size_t |
| Unique identifier for registered event callbacks. | |
Public Member Functions | |
| EventManager ()=default | |
| Default constructor. | |
| ~EventManager () | |
| EventManager (const EventManager &)=delete | |
| EventManager & | operator= (const EventManager &)=delete |
| EventManager (EventManager &&other) noexcept | |
| Move constructor. | |
| EventManager & | operator= (EventManager &&other) noexcept |
| Move assignment operator. | |
| template<typename TEvent, typename TScheduler = DirectCallbackSchedulerTag, typename TCallBack> | |
| EventCallbackID | RegisterCallback (TCallBack &&callback) |
| template<typename TEvent> | |
| void | PushEvent (const TEvent &event) |
| Queue an event for processing. | |
| template<typename TScheduler> | |
| void | ProcessEvents (void) |
| Process all queued events for a specific scheduler. | |
| template<typename TEvent, typename TScheduler = DirectCallbackSchedulerTag> | |
| void | UnregisterCallback (EventCallbackID callbackID) |
| Unregister a previously registered callback. | |
Private Member Functions | |
| template<typename TEvent, typename TCallBack, typename TScheduler> | |
| EventCallbackID | _RegisterCallbackImpl (TCallBack &&callback) |
Static Private Member Functions | |
| static EventCallbackID | _GenerateRandomID () |
| template<typename TEvent> | |
| static EventTypeID | _GetId (void) |
Private Attributes | |
| std::unordered_map< std::type_index, std::unordered_map< EventTypeID, std::shared_ptr< Utils::IEventContainer > > > | _eventCallbacks |
| std::unordered_map< std::type_index, std::queue< std::pair< EventTypeID, std::any > > > | _eventQueue |
| std::mutex | _queueMutex |
| std::mutex | _callbacksMutex |
Thread-safe event manager for registering, queuing, and dispatching events.
Manages event callbacks and event queues per scheduler type. Events are queued when pushed and processed during the corresponding scheduler execution. All operations are thread-safe.
| using Event::Resource::EventManager::EventCallbackID = size_t |
Unique identifier for registered event callbacks.
| using Event::Resource::EventManager::EventTypeID = size_t |
Type identifier for event types.
|
default |
Default constructor.
|
inline |
|
delete |
|
inlinenoexcept |
Move constructor.
| other | The EventManager to move from. |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlineprivate |
|
delete |
|
inlinenoexcept |
Move assignment operator.
| other | The EventManager to move from. |
|
inline |
Process all queued events for a specific scheduler.
Dequeues and triggers all callbacks registered for the given scheduler type. This method is typically called by the scheduler during its execution phase.
| TScheduler | The scheduler type whose events should be processed. |
| core | Reference to the engine core. |
|
inline |
Queue an event for processing.
The event is added to the queue for each scheduler that has registered callbacks for this event type. Events are processed during the corresponding scheduler execution.
| TEvent | The event type. |
| event | The event instance to queue. |
|
inline |
@brief Register a callback for an event type on a specific scheduler. @tparam TEvent The event type to listen for. @tparam TScheduler The scheduler type on which to process this event. @tparam TCallBack The callback type (auto-deduced).
| callback | The callback function with signature void(const TEvent&). |
|
inline |
Unregister a previously registered callback.
Removes the callback identified by the given ID for the specified event type and scheduler. Logs a warning if the callback or event type is not found.
| TEvent | The event type the callback was registered for. |
| TScheduler | The scheduler type (defaults to Immediate call tag). |
| callbackID | The unique identifier returned by RegisterCallback. |
|
private |
|
private |
|
private |
|
private |