Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::core::EventQueue Class Reference

Deferred event queue dispatched by priority at a chosen point in the tick. More...

#include <aegis2d/core/event_queue.hpp>

Public Member Functions

template<typename Event >
void push (const Event &event, int priority=0)
 Queues an event for deferred dispatch.
 
void dispatch (EventBus &bus)
 Dispatches all queued events in priority order and clears the queue.
 
std::size_t size () const noexcept
 Number of events currently in the queue.
 
void clear () noexcept
 Discards all queued events without dispatching them.
 

Detailed Description

Deferred event queue dispatched by priority at a chosen point in the tick.

Events are pushed at any point during a tick, then dispatched all at once in priority order by calling dispatch(). Higher numeric priorities are dispatched first; events with the same priority are dispatched in push() order (stable).

Use EventQueue when the dispatch order across event types matters, or when handlers must not run mid-tick. Use EventBus when reactions are immediate (audio, effects, cross-module callbacks) and do not need ordering between event types.

EventQueue queue;
queue.push(WaveCleared{}, 5); // lower priority
queue.push(EnemyDestroyed{.id = 1}, 10); // dispatched first
queue.dispatch(events); // calls EventBus handlers in that order
Deferred event queue dispatched by priority at a chosen point in the tick.
Definition event_queue.hpp:30
void push(const Event &event, int priority=0)
Queues an event for deferred dispatch.
Definition event_queue.hpp:36
void dispatch(EventBus &bus)
Dispatches all queued events in priority order and clears the queue.
Definition event_queue.hpp:44

Member Function Documentation

◆ clear()

void aegis2d::core::EventQueue::clear ( )
inlinenoexcept

Discards all queued events without dispatching them.

◆ dispatch()

void aegis2d::core::EventQueue::dispatch ( EventBus &  bus)
inline

Dispatches all queued events in priority order and clears the queue.

Events with equal priority are dispatched in push() order (stable sort). Handlers subscribed on bus are called in the usual subscription order.

Parameters
busBus to publish each event on.

◆ push()

template<typename Event >
void aegis2d::core::EventQueue::push ( const Event &  event,
int  priority = 0 
)
inline

Queues an event for deferred dispatch.

Parameters
eventEvent to queue; copied into the queue.
priorityDispatch order: higher values are dispatched before lower ones.

◆ size()

std::size_t aegis2d::core::EventQueue::size ( ) const
inlinenoexcept

Number of events currently in the queue.

Returns
Events pushed since the last dispatch() or clear().

The documentation for this class was generated from the following file: