Certainly! Below are the detailed Doxygen comments for the Subscribe, Publish, and Update methods of the EventManager class.
Subscribe
/**
* @brief Subscribes a handler to a specific event type.
*
* Register a callback function to be invoked when an event of type T is published.
* The handler function must accept a shared pointer to the event type as its parameter.
* Subscribing to the same event type multiple times for the same handler will result in
* multiple calls to the handler when the event is published.
*
* @tparam T The type of the event to subscribe to. Must be derived from Event.
* @param handler A std::function that handles events of type T. The function signature
* should be equivalent to void(std::shared_ptr<T>).
*
* Example usage:
* @code
* eventManager.Subscribe<MyEvent>([](std::shared_ptr<MyEvent> event) {
* // Handle the MyEvent here
* });
* @endcode
*
* @note The EventManager makes no guarantees about the order in which multiple handlers for
* the same event type are called.
*
* @see Publish, Event
*/
Publish
/**
* @brief Publishes an event to all subscribed handlers.
*
* Immediately adds the event to a priority queue based on the event's priority. Events are not
* dispatched until `Update` is called. This allows the event system to aggregate events and
* process them in batches, prioritizing certain events over others based on their priority level.
*
* @param event A std::shared_ptr to an event derived from the Event class. The shared pointer
* indicates ownership and lifecycle management of the event.
*
* Example usage:
* @code
* auto event = std::make_shared<MyEvent>(/* constructor arguments */);
* eventManager.Publish(event);
* @endcode
*
* @note Events with higher priority values are processed before those with lower values when
* `Update` is called.
*
* @see Update, Subscribe, Event::GetPriority
*/
Update
/**
* @brief Processes and dispatches all queued events to their respective subscribers.
*
* This function should be called regularly, typically within the main game loop, to ensure
* that events are processed and dispatched in a timely manner. It iterates through the event
* queue, dispatching each event to all subscribers of that event's type, according to the
* event's priority.
*
* Events are dispatched in the order of their priority, with higher priority events being
* dispatched before lower priority ones. This allows for a level of control over the order
* in which events are handled.
*
* Example usage:
* @code
* while (gameIsRunning) {
* // Game loop code...
*
* eventManager.Update();
* }
* @endcode
*
* @note It is the responsibility of the caller to ensure `Update` is called frequently enough
* to meet the game's real-time requirements.
*
* @see Publish, Subscribe
*/
Additional Considerations:
-
Thread Safety: If your game engine is multi-threaded, you might want to highlight if these functions are thread-safe or if any precautions should be taken when calling them from multiple threads.
-
Performance Implications: For methods like Update, especially in a game loop, it might be useful to note any significant performance implications or recommended usage patterns to ensure smooth runtime behavior.
These detailed documentation comments explain how each method operates within the context of the event management system, offering insights into their implementations, expected behaviors, and usage examples to provide a comprehensive understanding for developers working with your game engine.