Nebula
Loading...
Searching...
No Matches
Game::Message< MSG, TYPES > Class Template Reference

#include <message.h>

Detailed Description

template<class MSG, class ... TYPES>
class Game::Message< MSG, TYPES >
Deprecated

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 MessageQueueGetMessageQueue (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, IndexTlistenerMap
 Internal singleton instance.
 
Util::ArrayAllocator< MessageListenerId, Delegatecallbacks
 contains the callback and the listener it's attached to.
 
Ids::IdGenerationPool messageQueueIdPool
 id generation pool for the deferred messages queues.
 
Util::Array< MessageQueuemessageQueues
 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)
 

Member Typedef Documentation

◆ Delegate

template<class MSG , class ... TYPES>
using Game::Message< MSG, TYPES >::Delegate = Util::Delegate<void(TYPES...)>

Type definition for this message's delegate.

◆ MessageQueue

template<class MSG , class ... TYPES>
using Game::Message< MSG, TYPES >::MessageQueue = typename Util::ArrayAllocator<Util::Tuple<UnqualifiedType<TYPES> ...>>

Type definition for this message's queues.

Constructor & Destructor Documentation

◆ Message() [1/2]

template<typename MSG , class ... TYPES>
Game::Message< MSG, TYPES >::Message ( )
inline

◆ ~Message()

template<typename MSG , class ... TYPES>
Game::Message< MSG, TYPES >::~Message ( )
inline

◆ Message() [2/2]

template<class MSG , class ... TYPES>
Game::Message< MSG, TYPES >::Message ( const Message< MSG, TYPES... > & )
delete

Member Function Documentation

◆ AllocateMessageQueue()

template<typename MSG , class ... TYPES>
Message< MSG, TYPES... >::MessageQueueId Game::Message< MSG, TYPES >::AllocateMessageQueue ( )
inlinestatic

Creates a new message queue for deferred dispatching.

◆ DeAllocateMessageQueue()

template<typename MSG , class ... TYPES>
void Game::Message< MSG, TYPES >::DeAllocateMessageQueue ( MessageQueueId id)
inlinestatic

Deallocate a message queue. All messages in the queue will be destroyed.

◆ Defer()

template<typename MSG , class ... TYPES>
void Game::Message< MSG, TYPES >::Defer ( MessageQueueId qid,
TYPES ... values )
inlinestatic

Add a message to a message queue.

◆ Deregister()

template<typename MSG , class ... TYPES>
void Game::Message< MSG, TYPES >::Deregister ( MessageListener listener)
inlinestatic

Deregister a listener.

◆ DeregisterAll()

template<typename MSG , class ... TYPES>
void Game::Message< MSG, TYPES >::DeregisterAll ( )
inlinestatic

Deregisters all listeners at once.

◆ DispatchMessageQueue()

template<typename MSG , class ... TYPES>
void Game::Message< MSG, TYPES >::DispatchMessageQueue ( MessageQueueId id)
inlinestatic

Dispatch all messages in a message queue.

◆ Distribute()

template<typename MSG , class ... TYPES>
void Game::Message< MSG, TYPES >::Distribute ( TYPES ... )
inlinestatic

Send a network distributed message.

Todo
Implement networked messages.

◆ GetMessageQueue()

template<typename MSG , class ... TYPES>
Message< MSG, TYPES... >::MessageQueue & Game::Message< MSG, TYPES >::GetMessageQueue ( MessageQueueId id)
inlinestatic

Returns a message queue by id Can be used to manually dispatch queues.

◆ Instance()

template<class MSG , class ... TYPES>
static Message< MSG, TYPES... > * Game::Message< MSG, TYPES >::Instance ( )
inlinestaticprotected

◆ IsMessageQueueValid()

template<typename MSG , class ... TYPES>
bool Game::Message< MSG, TYPES >::IsMessageQueueValid ( MessageQueueId id)
inlinestatic

Check whether a message queue is still valid.

◆ IsValid()

template<typename MSG , class ... TYPES>
bool Game::Message< MSG, TYPES >::IsValid ( MessageListenerId listener)
inlinestatic

Returns whether a MessageListenerId is still registered or not.

◆ operator=()

template<class MSG , class ... TYPES>
void Game::Message< MSG, TYPES >::operator= ( const Message< MSG, TYPES... > & )
delete

◆ Register()

template<typename MSG , class ... TYPES>
MessageListener Game::Message< MSG, TYPES >::Register ( Delegate && callback)
inlinestatic

Register a listener to this message. Returns an ID for the listener so that we can associate it.

◆ Send()

template<typename MSG , class ... TYPES>
void Game::Message< MSG, TYPES >::Send ( TYPES ... values)
inlinestatic

Send a message.

◆ send_expander() [1/2]

template<class MSG , class ... TYPES>
void Game::Message< MSG, TYPES >::send_expander ( MessageQueue & data,
const IndexT cid,
const SizeT index )
inlineprivate

◆ send_expander() [2/2]

template<class MSG , class ... TYPES>
template<std::size_t... Is>
void Game::Message< MSG, TYPES >::send_expander ( MessageQueue & data,
const IndexT cid,
const SizeT index,
std::index_sequence< Is... >  )
inlineprivate

Member Data Documentation

◆ callbacks

template<class MSG , class ... TYPES>
Util::ArrayAllocator< MessageListenerId, Delegate > Game::Message< MSG, TYPES >::callbacks
protected

contains the callback and the listener it's attached to.

◆ distributedMessages

template<class MSG , class ... TYPES>
MessageQueue Game::Message< MSG, TYPES >::distributedMessages
protected

Contains the arguments of a recieved distributed message.

Todo
This should be updated by some NetworkMessageManager-y object.

◆ fourcc

template<class MSG , class ... TYPES>
Util::FourCC Game::Message< MSG, TYPES >::fourcc
protected

◆ listenerMap

template<class MSG , class ... TYPES>
Util::HashTable<MessageListenerId, IndexT> Game::Message< MSG, TYPES >::listenerMap
protected

Internal singleton instance.

Registry between component and index in list.

◆ listenerPool

template<class MSG , class ... TYPES>
Ids::IdGenerationPool Game::Message< MSG, TYPES >::listenerPool
protected

◆ messageQueueIdPool

template<class MSG , class ... TYPES>
Ids::IdGenerationPool Game::Message< MSG, TYPES >::messageQueueIdPool
protected

id generation pool for the deferred messages queues.

◆ messageQueues

template<class MSG , class ... TYPES>
Util::Array<MessageQueue> Game::Message< MSG, TYPES >::messageQueues
protected

Deferred messages.

◆ MSG

template<class MSG , class ... TYPES>
friend Game::Message< MSG, TYPES >::MSG
protected

◆ name

template<class MSG , class ... TYPES>
Util::StringAtom Game::Message< MSG, TYPES >::name
protected

The documentation for this class was generated from the following file: