Design Patterns:
The system uses a broadcast messaging pattern where events are routed to multiple handlers based on their target domain. The EventBus (from dependencies) maintains a mapping of domains to handler lists and delivers each event to all subscribed handlers in order.
Event Flow:
- A system creates an event via
EventFactory.CreateEvent(domain, verb) - The event is populated with parameters using
event.Params.Set(key, value) - The event is raised via
eventBus.Raise(event) EventBusextracts theTargetDomainfrom the event- All handlers subscribed to that domain receive the event
Key Concepts:
- Domain: An enum value identifying which system should handle the event (UI, Audio, VFX, etc.)
- Verb: An integer representing the specific action or command within a domain, defined by the feature's contracts
- Params: A type-safe parameter container holding event payload data using
ParamKey<T>instances - IEvent: A marker interface that all event types must implement to be recognized by the routing system
Connection to Dependencies:
EventBusis the actual router; it is obtained from the globalServiceLocatorParamsis used internally byEventto store its payloadDomainandParamKey<T>come from the Contracts system and provide the typing and routing identifiersIEventReceiveris implemented by handler classes that listen for events
Thread Safety:
The EventBus documentation notes that Subscribe and Raise are called from the main thread, so no additional synchronization is required within EventSystem itself.