![]() |
vkmEngine 1.0.0
A C++ game engine · vkmengine.com
|
Listener list plus deferred-event queue for a single event type. More...
#include <bus.h>
Public Member Functions | |
| ListenerId | subscribe (std::function< void(const EventT &)> cb) |
| Append a listener and return its new id. | |
| bool | remove (ListenerId id) |
Erase the listener with id. | |
| void | emit (const EventT &event) |
Dispatch event to every current listener synchronously. | |
| void | enqueue (EventT event) |
Buffer event for delivery on the next flush(). | |
| void | takeQueue () override |
| Swap the queue aside so what a listener enqueues cannot join it. | |
| void | deliver () override |
| Deliver the batch takeQueue set aside to every current listener. | |
| bool | hasListeners () const override |
| Whether any live listener remains, mid-dispatch removals aside. | |
Listener list plus deferred-event queue for a single event type.
Driven only through EventBus.
|
inline |
Append a listener and return its new id.
Mid-dispatch, the entry joins once the outermost dispatch unwinds: appending could reallocate the list and destroy the std::function whose operator() is on the stack.
| cb | Called with each event of this type delivered from now on. |
|
inline |
Erase the listener with id.
Callable from a listener, on itself too. Mid-dispatch the entry is only marked dead, reaped by admitPending: erasing would shift the index walk and skip a listener, and clearing the std::function would free the captures of the callback still running. An entry still in m_pending is erased outright, since nothing walks it.
| id | What subscribe() returned. |
|
inline |
Dispatch event to every current listener synchronously.
| event | Passed to each listener. |
|
inline |
Buffer event for delivery on the next flush().
| event | Event to queue; moved in. |
|
inlineoverridevirtual |
Swap the queue aside so what a listener enqueues cannot join it.
Swaps with a retained member, so a steady frame allocates nothing.
Implements Vkm::Engine::IBus.
|
inlineoverridevirtual |
Deliver the batch takeQueue set aside to every current listener.
An event a listener enqueues now fires on the next flush, whatever its type.
Implements Vkm::Engine::IBus.
|
inlineoverridevirtual |
Whether any live listener remains, mid-dispatch removals aside.
Implements Vkm::Engine::IBus.