Open 3D Engine AzCore API Reference
24.09
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
|
#include <EBus.h>
Inherits AZ::BusInternal::EBusImpl< AZ::EBus< Interface, Interface >, BusInternal::EBusImplTraits< Interface, Interface >, BusTraits::BusIdType >.
Public Types | |
using | ImplTraits = BusInternal::EBusImplTraits< Interface, BusTraits > |
using | BaseImpl = BusInternal::EBusImpl< AZ::EBus< Interface, BusTraits >, BusInternal::EBusImplTraits< Interface, BusTraits >, typename BusTraits::BusIdType > |
using | Traits = typename ImplTraits::Traits |
using | ThisType = AZ::EBus< Interface, Traits > |
using | AllocatorType = typename ImplTraits::AllocatorType |
using | InterfaceType = typename ImplTraits::InterfaceType |
using | Events = typename ImplTraits::Events |
using | BusIdType = typename ImplTraits::BusIdType |
using | BusIdOrderCompare = typename ImplTraits::BusIdOrderCompare |
using | MutexType = typename ImplTraits::MutexType |
using | BusesContainer = typename ImplTraits::BusesContainer |
using | EventQueueMutexType = typename ImplTraits::EventQueueMutexType |
using | BusPtr = typename ImplTraits::BusPtr |
using | HandlerNode = typename ImplTraits::HandlerNode |
using | QueuePolicy = EBusQueuePolicy< Traits::EnableEventQueue, ThisType, EventQueueMutexType > |
using | ConnectionPolicy = typename Traits::template ConnectionPolicy< ThisType > |
using | CallstackEntry = AZ::Internal::CallstackEntry< Interface, Traits > |
using | Router = AZ::Internal::EBusRouter< ThisType > |
using | NestedVersionRouter = AZ::Internal::EBusNestedVersionRouter< ThisType > |
using | RouterPolicy = typename Traits::template RouterPolicy< ThisType > |
using | RouterProcessingState = typename RouterPolicy::EventProcessingState |
template<typename DispatchMutex > | |
using | DispatchLockGuardTemplate = typename ImplTraits::template DispatchLockGuard< DispatchMutex > |
template<typename ContextMutexType > | |
using | ConnectLockGuardTemplate = typename ImplTraits::template ConnectLockGuard< ContextMutexType > |
template<typename ContextMutexType > | |
using | BindLockGuardTemplate = typename ImplTraits::template BindLockGuard< ContextMutexType > |
template<typename ContextMutexType > | |
using | CallstackTrackerLockGuardTemplate = typename ImplTraits::template CallstackTrackerLockGuard< ContextMutexType > |
using | StoragePolicy = typename Traits::template StoragePolicy< Context > |
using | ConnectLockGuard = typename Context::ConnectLockGuard |
Static Public Member Functions | |
static size_t | GetTotalNumOfEventHandlers () |
static bool | HasHandlers () |
static bool | HasHandlers (const BusIdType &id) |
static bool | HasHandlers (const BusPtr &ptr) |
static const BusIdType * | GetCurrentBusId () |
static bool | HasReentrantEBusUseThisThread (const BusIdType *busId=GetCurrentBusId()) |
static const char * | GetName () |
static Context * | GetContext (bool trackCallstack=true) |
static Context & | GetOrCreateContext (bool trackCallstack=true) |
static bool | IsInDispatch (Context *context=GetContext(false)) |
static bool | IsInDispatchThisThread (Context *context=GetContext(false)) |
Static Public Attributes | |
static const bool | EnableEventQueue = ImplTraits::EnableEventQueue |
static const bool | HasId = Traits::AddressPolicy != EBusAddressPolicy::Single |
Event buses (EBuses) are a general-purpose communication system that Open 3D Engine uses to dispatch notifications and receive requests.
Interface | A class whose virtual functions define the events dispatched or received by the EBus. |
Traits | A class that inherits from EBusTraits and configures the EBus. This parameter may be left unspecified if the Interface class inherits from EBusTraits. |
EBuses are configurable and support many different use cases. For more information about EBuses, see Event Bus and Components and EBuses: Best Practices in the Open 3D Engine Developer Guide.
Components commonly use EBuses in two ways: to dispatch events or to handle requests. A bus that dispatches events is a notification bus. A bus that receives requests is a request bus. Some components provide one type of bus, and some components provide both types. Some components do not provide an EBus at all. You use the EBus class for both EBus types, but you configure the EBuses differently. The following sections show how to set up and configure notification buses, event handlers, and request buses.
Notification buses dispatch events. The events are received by handlers, which implement a function to handle the event. Handlers first connect to the bus. When the bus dispatches an event, the handler's function executes. This section shows how to set up a notification bus to dispatch an event and a handler to receive the event.
To set up a bus to dispatch events, do the following:
AddressPolicy
, which defines how many addresses the EBus contains, HandlerPolicy
, which describes how many handlers can connect to each address, and BusIdType
, which is the type of ID that is used to address the EBus if addresses are used. For example, notification buses often need to have multiple addresses, with the addresses identified by entity ID. To do so, they override the default AddressPolicy
with EBusAddressPolicy::ById and set the BusIdType
to EntityId.QueueBroadcast()
or QueueEvent()
. To flush the event queue, use ExecuteQueuedEvents()
.To enable a handler class to handle the events dispatched by a notification bus, do the following:
<BusName>::Handler
. For example, a class that needs to handle tick requests should derive from TickRequestBus::Handler.OnTick()
.<BusName>:Handler::BusConnect()
to connect to the bus and <BusName>:Handler::BusDisconnect()
to disconnect from the bus. If the handler class is a component, connect to the bus in Activate()
and disconnect from the bus in Deactivate()
. Non-components typically connect in the constructor and disconnect in the destructor.A request bus receives and handles requests. Typically, only one class handles requests for a request bus.
The first several steps for setting up a request bus are similar to setting up a notification bus. After that you also need to implement the handlers for handling the requests. To set up a request bus, do the following:
AddressPolicy
, which defines how many addresses the EBus contains, and HandlerPolicy
, which describes how many handlers can connect to each address. For example, because there is typically only one handler class for each request bus, request buses typically override the default handler policy with EBusHandlerPolicy::Single.using AZ::EBus< Interface, BusTraits >::AllocatorType = typename ImplTraits::AllocatorType |
Allocator used by the EBus. The default setting is AZStd::allocator, which uses AZ::SystemAllocator.
using AZ::EBus< Interface, BusTraits >::BaseImpl = BusInternal::EBusImpl<AZ::EBus<Interface, BusTraits>, BusInternal::EBusImplTraits<Interface, BusTraits>, typename BusTraits::BusIdType> |
Represents an EBus with certain broadcast, event, and routing functionality.
using AZ::EBus< Interface, BusTraits >::BindLockGuardTemplate = typename ImplTraits::template BindLockGuard<ContextMutexType> |
Template Lock Guard class that wraps around the Mutex the EBus uses for Bus Bind calls.
using AZ::EBus< Interface, BusTraits >::BusesContainer = typename ImplTraits::BusesContainer |
Contains all of the addresses on the EBus.
using AZ::EBus< Interface, BusTraits >::BusIdOrderCompare = typename ImplTraits::BusIdOrderCompare |
Sorting function for EBus address IDs. Used only when the address policy is AZ::EBusAddressPolicy::ByIdAndOrdered. If an event is dispatched without an ID, this function determines the order in which each address receives the event.
The following example shows a sorting function that meets these requirements.
using AZ::EBus< Interface, BusTraits >::BusIdType = typename ImplTraits::BusIdType |
The type of ID that is used to address the EBus. Used only when the address policy is AZ::EBusAddressPolicy::ById or AZ::EBusAddressPolicy::ByIdAndOrdered. The type must support AZStd::hash<ID>
and bool operator==(const ID&, const ID&)
.
using AZ::EBus< Interface, BusTraits >::BusPtr = typename ImplTraits::BusPtr |
Pointer to an address on the bus.
using AZ::EBus< Interface, BusTraits >::CallstackEntry = AZ::Internal::CallstackEntry<Interface, Traits> |
Used to manually create a callstack entry for a call (often used by ConnectionPolicy)
using AZ::EBus< Interface, BusTraits >::CallstackTrackerLockGuardTemplate = typename ImplTraits::template CallstackTrackerLockGuard<ContextMutexType> |
Template Lock Guard class that wraps around the Mutex the EBus uses for Bus callstack tracking.
using AZ::EBus< Interface, BusTraits >::ConnectionPolicy = typename Traits::template ConnectionPolicy<ThisType> |
Enables custom logic to run when a handler connects to or disconnects from the EBus. For example, you can make a handler execute an event immediately upon connecting to the EBus. For available settings, see AZ::EBusConnectionPolicy. By default, no extra logic is run.
using AZ::EBus< Interface, BusTraits >::ConnectLockGuardTemplate = typename ImplTraits::template ConnectLockGuard<ContextMutexType> |
Template Lock Guard class that wraps around the Mutex the EBus uses for Bus Connects / Disconnects.
using AZ::EBus< Interface, BusTraits >::DispatchLockGuardTemplate = typename ImplTraits::template DispatchLockGuard<DispatchMutex> |
using AZ::EBus< Interface, BusTraits >::EventQueueMutexType = typename ImplTraits::EventQueueMutexType |
Locking primitive that is used when executing events in the event queue.
using AZ::EBus< Interface, BusTraits >::Events = typename ImplTraits::Events |
The events that are defined by the EBus interface.
using AZ::EBus< Interface, BusTraits >::HandlerNode = typename ImplTraits::HandlerNode |
Pointer to a handler node.
using AZ::EBus< Interface, BusTraits >::ImplTraits = BusInternal::EBusImplTraits<Interface, BusTraits> |
Contains data about EBusTraits.
using AZ::EBus< Interface, BusTraits >::InterfaceType = typename ImplTraits::InterfaceType |
The class that defines the interface of the EBus.
using AZ::EBus< Interface, BusTraits >::MutexType = typename ImplTraits::MutexType |
Locking primitive that is used when connecting handlers to the EBus or executing events. By default, all access is assumed to be single threaded and no locking occurs. For multithreaded access, specify a mutex of the following type.
using AZ::EBus< Interface, BusTraits >::NestedVersionRouter = AZ::Internal::EBusNestedVersionRouter<ThisType> |
Class that implements an EBus version router.
using AZ::EBus< Interface, BusTraits >::QueuePolicy = EBusQueuePolicy<Traits::EnableEventQueue, ThisType, EventQueueMutexType> |
Policy for the function queue.
using AZ::EBus< Interface, BusTraits >::Router = AZ::Internal::EBusRouter<ThisType> |
Class that implements EBus routing functionality.
using AZ::EBus< Interface, BusTraits >::RouterPolicy = typename Traits::template RouterPolicy<ThisType> |
Controls the flow of EBus events. Enables an event to be forwarded, and possibly stopped, before reaching the normal event handlers. Use cases for routing include tracing, debugging, and versioning an EBus. The default EBusRouterPolicy
forwards the event to each connected EBusRouterNode
before sending the event to the normal handlers. Each node can stop the event or let it continue.
using AZ::EBus< Interface, BusTraits >::RouterProcessingState = typename RouterPolicy::EventProcessingState |
State that indicates whether to continue routing the event, skip all handlers but notify other routers, or stop processing the event.
using AZ::EBus< Interface, BusTraits >::StoragePolicy = typename Traits::template StoragePolicy<Context> |
Specifies where EBus data is stored. This drives how many instances of this EBus exist at runtime. Available storage policies include the following:
using AZ::EBus< Interface, BusTraits >::ThisType = AZ::EBus<Interface, Traits> |
The type of EBus, which is defined by the interface and the EBusTraits.
using AZ::EBus< Interface, BusTraits >::Traits = typename ImplTraits::Traits |
Alias for EBusTraits.
|
static |
Returns the global bus data (if it was created). Depending on the storage policy, there might be one or multiple instances of the bus data.
|
static |
Gets the ID of the address that is currently receiving an event. You can use this function while handling an event to determine which ID the event concerns. This is especially useful for handlers that connect to multiple address IDs.
|
static |
Returns the global bus data. Creates it if it wasn't already created. Depending on the storage policy, there might be one or multiple instances of the bus data.
|
inlinestatic |
Returns whether handlers are connected to this specific address.
|
inlinestatic |
Returns whether handlers are connected to the specific cached address.
|
static |
Checks to see if an EBus with a given Bus ID appears twice in the callstack. This can be used to detect infinite recursive loops and other reentrancy problems. This method only checks EBus and ID, not the specific EBus event, so two different nested event calls on the same EBus and ID will still return true.
busId | The bus ID to check for reentrancy on this thread. |
|
static |
Returns whether the EBus context is in the middle of a dispatch on the current thread
|
static |
Specifies whether the EBus supports an event queue. You can use the event queue to execute events at a later time. To execute the queued events, you must call <BusName>::ExecuteQueuedEvents()
. By default, the event queue is disabled.
|
static |
True if the EBus supports more than one address. Otherwise, false.