![]() |
vkmEngine 1.0.15
A C++ game engine · vkmengine.com
|
Typed pub/sub for in-engine events. A subscriber registers a callback for one event type; a publisher calls emit() to deliver now or enqueue() to deliver at the next flush().
The bus is engine infrastructure, not a System: the Engine owns one, every FrameContext carries it as ctx.events, and Engine::run calls flush() at the top of the Simulation stage once per tick, and once more per frame for whatever was queued outside a tick. Delivery is per tick so a reaction's delay does not depend on the frame rate.
Any struct is an event - no base class, no registration. The type is the channel: a DamageEvent subscriber sees only DamageEvents.
Use emit for a reaction that belongs in the same tick; enqueue for decoupled flow (UI, asset events, anything latency-tolerant). An event enqueued by a listener during a flush - of any type - is delivered at the next flush: every queue is taken aside before any delivers.
A behavior does not get the bus. Behavior::events() is an EventSender (emit and enqueue only), and it listens through its own tracked subscribe(), which is dropped when the session ends; see Scripting. A listener registered on the bus directly would outlive the gameplay module, and a flush after a script reload would call unmapped code.