guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::event::EventManager< EventType > Class Template Reference

Base class that gives a system the input events of one type, one event per frame. More...

#include <headers/guillaume/event/event_manager.hpp>

Inheritance diagram for guillaume::event::EventManager< EventType >:

Public Member Functions

 EventManager (EventBus &eventBus)
 Subscribe to a bus; events of type EventType published after this call are queued.
virtual ~EventManager (void)=default
 Virtual destructor.
bool hasPendingEvents (void) const
 Tell whether at least one event is queued, waiting for consumeNextEvent().

Protected Member Functions

void consumeNextEvent (void)
 Take the oldest queued event and make it the last event.
std::shared_ptr< EventType > getLastEvent (void)
 Get the event taken by the most recent consumeNextEvent() that found one.

Detailed Description

template<utility::event::InheritFromEvent EventType>
class guillaume::event::EventManager< EventType >

Base class that gives a system the input events of one type, one event per frame.

The input systems (systems::MouseButton, systems::MouseMotion, the hand systems, ...) derive from both ecs::SystemFiller and EventManager. The manager subscribes to the bus and queues the events as the engine polls them. The system then:

class Clicks:
public ecs::SystemFiller<components::Bound>,
public event::EventManager<utility::event::MouseButtonEvent>
{
public:
Clicks(event::EventBus &eventBus)
, event::EventManager<utility::event::MouseButtonEvent>(
eventBus)
{
}
void prepare(void) override
{
}
void update(const ecs::Entity::Identifier &identifier) override
{
auto event = getLastEvent();
if (!event) {
return;
}
// test the event against the entity
}
};
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
The base class to derive a system from: a System whose signature is the list of component types given...
SystemFiller(Phase phase)
Create the system and set its signature from ComponentTypes.
virtual void prepare(void)
Called once per pass, before the first update().
Definition system.hpp:330
virtual void update(const ecs::Entity::Identifier &entityIdentifier)=0
Apply the system's rule to one entity. Implemented by each system.
Hands each engine event to the listeners subscribed to its type.
Definition event_bus.hpp:67
Base class that gives a system the input events of one type, one event per frame.
void consumeNextEvent(void)
Take the oldest queued event and make it the last event.
EventManager(EventBus &eventBus)
Subscribe to a bus; events of type EventType published after this call are queued.
std::shared_ptr< EventType > getLastEvent(void)
Get the event taken by the most recent consumeNextEvent() that found one.
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Definition component.hpp:28
Phase
The four steps of a frame. Every system belongs to one of them.
Delivery of engine events to the systems that subscribed to them.
Definition event_bus.hpp:34

Things to watch out for:

  • One call to consumeNextEvent() takes one event. When several events of the type arrive in the same frame, the others wait for the next frames.
  • The last event is kept when the queue is empty: getLastEvent() returns the same event again on the following frames, until a new one arrives.
  • To listen to several event types, derive from several EventManager instantiations.
Template Parameters
EventTypeThe exact event type to receive.
See also
EventSubscriber
EventBus

Definition at line 90 of file event_manager.hpp.

Constructor & Destructor Documentation

◆ EventManager()

template<utility::event::InheritFromEvent EventType>
guillaume::event::EventManager< EventType >::EventManager ( EventBus & eventBus)

Subscribe to a bus; events of type EventType published after this call are queued.

Parameters
eventBusThe bus to subscribe to, normally the application's. It must outlive the manager's use.

Member Function Documentation

◆ consumeNextEvent()

template<utility::event::InheritFromEvent EventType>
void guillaume::event::EventManager< EventType >::consumeNextEvent ( void )
protected

Take the oldest queued event and make it the last event.

When no event is queued, nothing changes: the last event stays the one of a previous call. Call it once per frame, in ecs::System::prepare.

◆ getLastEvent()

template<utility::event::InheritFromEvent EventType>
std::shared_ptr< EventType > guillaume::event::EventManager< EventType >::getLastEvent ( void )
protected

Get the event taken by the most recent consumeNextEvent() that found one.

The event is not removed: every call returns the same event until consumeNextEvent() replaces it.

Returns
The last event, or nullptr when no event was ever consumed.

◆ hasPendingEvents()

template<utility::event::InheritFromEvent EventType>
bool guillaume::event::EventManager< EventType >::hasPendingEvents ( void ) const

Tell whether at least one event is queued, waiting for consumeNextEvent().

Returns
True when the queue is not empty. The last event does not count.

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