6#include <unordered_map>
30 std::unordered_map<std::string, EventMetadata>
Callers;
32 std::unordered_map<ListenerID, std::shared_ptr<ListenerAction>>
Listeners;
88 const char*
File =
nullptr;
92 const char*
Key =
nullptr;
128 const char* file =
nullptr,
int line = 0);
167 if (mEventRegistry.contains(
id)) {
168 return &mEventRegistry.at(
id);
179 return this->mEventRegistry;
197 std::unordered_map<EventID, EventRegistration> mEventRegistry;
201 std::vector<DispatchContext> mDispatchStack;
EventPriority
Priority levels that control listener dispatch order within an event.
Definition EventTypes.h:19
@ EVENT_PRIORITY_NORMAL
Default priority for most listeners.
Definition EventTypes.h:21
int32_t EventID
Numeric identifier for an event. -1 is uninitialized, IDs < -1 are internally registered,...
Definition EventTypes.h:8
void(* EventCallback)(IEvent *)
Callback signature for event listeners. The argument is the event payload cast to IEvent*.
Definition EventTypes.h:39
int64_t ListenerID
Numeric identifier for a registered listener; used to unregister later.
Definition EventTypes.h:10
void MarkInitialized()
Marks this component as initialized without going through Init().
Tickable event bus that dispatches listeners through Tick(EventID).
Definition Events.h:74
void UnregisterListener(EventID id, ListenerID listenerId)
Removes a previously registered listener from an event.
EventID RegisterEvent(const char *name=nullptr)
Allocates a new internally managed EventID.
ListenerID RegisterListener(EventID id, EventCallback callback, EventPriority priority=EVENT_PRIORITY_NORMAL, const char *file=nullptr, int line=0)
Registers a callback listener for an event.
EventRegistration * GetEventRegistration(EventID id)
Returns the registration record for an EventID, if present.
Definition Events.h:166
std::unordered_map< EventID, EventRegistration > & GetEventRegistrations()
Returns the complete event registry map.
Definition Events.h:178
void CallEvent(EventID id, IEvent *event, const char *file=nullptr, int line=0, const char *key=nullptr)
Dispatches an event by pushing dispatch state and ticking its EventID.
void RemoveEvent(EventID id)
Removes an event and all listeners currently registered to it.
const DispatchContext * GetActiveDispatchContext() const
Returns the current top-of-stack dispatch context.
Events()
Constructs and self-initializes the global event bus component.
Definition Events.h:101
Combines Tickable and Component, auto-registering with a Context.
Definition TickableComponent.h:42
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
Base event payload struct.
Definition EventTypes.h:33
Tracks registration state for a single EventID.
Definition Events.h:22
uint64_t NextListenerSequence
Registration-order sequence used to preserve stable listener ordering.
Definition Events.h:28
const char * Name
Optional human-readable name for this event.
Definition Events.h:24
std::unordered_map< ListenerID, std::shared_ptr< ListenerAction > > Listeners
Active listeners for this event keyed by ListenerID.
Definition Events.h:32
ListenerID NextListenerID
Monotonically increasing listener identifier counter for this event.
Definition Events.h:26
std::unordered_map< std::string, EventMetadata > Callers
Diagnostic map of event call sites keyed by file:line string.
Definition Events.h:30
Active payload and call-site data for a single in-flight dispatch.
Definition Events.h:82
const char * Key
Optional deduplication key used for caller diagnostics.
Definition Events.h:92
IEvent * Event
Event payload supplied by the caller.
Definition Events.h:86
EventID ID
EventID currently being dispatched.
Definition Events.h:84
int Line
Source line that initiated the dispatch, when provided.
Definition Events.h:90
Raw file buffer as read from an archive or the filesystem.
Definition File.h:56