Nebula
|
#include <message.h>
Messages are the main communications channel between entities.
Messages aren't exclusive to entities however; any method or function can be used as a callback from a message which means you can hook into a message from anywhere. This can be useful for debugging, tools, managers etc.
A property can register a message callback by using the __RegisterMsg macro.
Messages should be generated using Nebula's IDLC. If that's not preferred, you can implement a message by deriving from the Game::Message class and overriding the GetName, GetFourCC, Send and Defer methods. This class uses curiously recurring template patterns and you need to provide the template with the subclass as the first template argument. The rest of the template arguments are the callbacks parameters.
Classes | |
struct | MessageQueueId |
Public Types | |
using | Delegate = Util::Delegate<void(TYPES...)> |
Type definition for this message's delegate. | |
using | MessageQueue = typename Util::ArrayAllocator<Util::Tuple<UnqualifiedType<TYPES> ...>> |
Type definition for this message's queues. | |
Public Member Functions | |
Message () | |
~Message () | |
Message (const Message< MSG, TYPES... > &)=delete | |
void | operator= (const Message< MSG, TYPES... > &)=delete |
Static Public Member Functions | |
static MessageListener | Register (Delegate &&callback) |
Register a listener to this message. Returns an ID for the listener so that we can associate it. | |
static void | Deregister (MessageListener listener) |
Deregister a listener. | |
static void | Send (TYPES ... values) |
Send a message. | |
static MessageQueueId | AllocateMessageQueue () |
Creates a new message queue for deferred dispatching. | |
static void | Defer (MessageQueueId qid, TYPES ... values) |
Add a message to a message queue. | |
static void | DispatchMessageQueue (MessageQueueId id) |
Dispatch all messages in a message queue. | |
static void | DeAllocateMessageQueue (MessageQueueId id) |
Deallocate a message queue. All messages in the queue will be destroyed. | |
static bool | IsMessageQueueValid (MessageQueueId id) |
Check whether a message queue is still valid. | |
static void | Distribute (TYPES ...) |
Send a network distributed message. | |
static void | DeregisterAll () |
Deregisters all listeners at once. | |
static bool | IsValid (MessageListenerId listener) |
Returns whether a MessageListenerId is still registered or not. | |
static MessageQueue & | GetMessageQueue (MessageQueueId id) |
Returns a message queue by id Can be used to manually dispatch queues. | |
Static Protected Member Functions | |
static Message< MSG, TYPES... > * | Instance () |
Protected Attributes | |
friend | MSG |
Util::HashTable< MessageListenerId, IndexT > | listenerMap |
Internal singleton instance. | |
Util::ArrayAllocator< MessageListenerId, Delegate > | callbacks |
contains the callback and the listener it's attached to. | |
Ids::IdGenerationPool | messageQueueIdPool |
id generation pool for the deferred messages queues. | |
Util::Array< MessageQueue > | messageQueues |
Deferred messages. | |
MessageQueue | distributedMessages |
Contains the arguments of a recieved distributed message. | |
Util::StringAtom | name |
Util::FourCC | fourcc |
Ids::IdGenerationPool | listenerPool |
Private Member Functions | |
template<std::size_t... Is> | |
void | send_expander (MessageQueue &data, const IndexT cid, const SizeT index, std::index_sequence< Is... >) |
void | send_expander (MessageQueue &data, const IndexT cid, const SizeT index) |
using Game::Message< MSG, TYPES >::Delegate = Util::Delegate<void(TYPES...)> |
Type definition for this message's delegate.
using Game::Message< MSG, TYPES >::MessageQueue = typename Util::ArrayAllocator<Util::Tuple<UnqualifiedType<TYPES> ...>> |
Type definition for this message's queues.
|
inline |
|
inline |
|
delete |
|
inlinestatic |
Creates a new message queue for deferred dispatching.
|
inlinestatic |
Deallocate a message queue. All messages in the queue will be destroyed.
|
inlinestatic |
Add a message to a message queue.
|
inlinestatic |
Deregister a listener.
|
inlinestatic |
Deregisters all listeners at once.
|
inlinestatic |
Dispatch all messages in a message queue.
|
inlinestatic |
Send a network distributed message.
|
inlinestatic |
Returns a message queue by id Can be used to manually dispatch queues.
|
inlinestaticprotected |
|
inlinestatic |
Check whether a message queue is still valid.
|
inlinestatic |
Returns whether a MessageListenerId is still registered or not.
|
delete |
|
inlinestatic |
Register a listener to this message. Returns an ID for the listener so that we can associate it.
|
inlinestatic |
Send a message.
|
inlineprivate |
|
inlineprivate |
|
protected |
contains the callback and the listener it's attached to.
|
protected |
Contains the arguments of a recieved distributed message.
|
protected |
|
protected |
Internal singleton instance.
Registry between component and index in list.
|
protected |
|
protected |
id generation pool for the deferred messages queues.
|
protected |
Deferred messages.
|
protected |
|
protected |