![]()  | 
  
    Gamedev Framework (gf)
    0.9.0
    
   A C++14 framework for 2D games 
   | 
 
A message manager. More...
#include <gf/MessageManager.h>
Public Member Functions | |
| MessageManager () | |
| Constructor.  More... | |
Registering an handler  | |
| MessageHandlerId | registerHandler (Id type, MessageHandler handler) | 
| Register a message handler for a type of message.  More... | |
| template<typename E > | |
| MessageHandlerId | registerHandler (MessageHandler handler) | 
| Register a message handler for a type of message.  More... | |
| template<typename R , typename T > | |
| MessageHandlerId | registerHandler (Id type, R T::*pm, T *obj) | 
| Register a message handler for a type of message.  More... | |
| template<typename E , typename R , typename T > | |
| MessageHandlerId | registerHandler (R T::*pm, T *obj) | 
| Register a message handler for a type of message.  More... | |
Removing an handler  | |
| void | removeHandler (MessageHandlerId id) | 
| Remove a handler.  More... | |
| void | removeHandlers (ArrayRef< MessageHandlerId > ids) | 
| Remove a list of handlers.  More... | |
Sending a message  | |
| void | sendMessage (Id type, Message *message) | 
| Send a message.  More... | |
| template<typename E > | |
| void | sendMessage (E *message) | 
| Send a message.  More... | |
A message manager.
A message manager is responsible for passing messages synchronously between game entities. It relies on a variant of the observer pattern. Some entities send messages (subclasses of gf::Message identified by their unique message type) to the message manager while some other entities listen to messages of a defined type through a message handler (gf::MessageHandler). As a consequence, there is very low coupling between entities.
Generally, you only need one message manager in a game. It is a good candidate for being a singleton (thanks to gf::Singleton).
| gf::MessageManager::MessageManager | ( | ) | 
Constructor.
| MessageHandlerId gf::MessageManager::registerHandler | ( | Id | type, | 
| MessageHandler | handler | ||
| ) | 
Register a message handler for a type of message.
| type | The type of message | 
| handler | The message handler | 
      
  | 
  inline | 
Register a message handler for a type of message.
| handler | The message handler | 
      
  | 
  inline | 
Register a message handler for a type of message.
| type | The type of message | 
| pm | A pointer to member function that represents the handler | 
| obj | The destination object that receives the message | 
      
  | 
  inline | 
Register a message handler for a type of message.
| pm | A pointer to member function that represents the handler | 
| obj | The destination object that receives the message | 
| void gf::MessageManager::removeHandler | ( | MessageHandlerId | id | ) | 
Remove a handler.
| id | The handler id | 
      
  | 
  inline | 
Remove a list of handlers.
| ids | The list of handler ids | 
Send a message.
The message is sent synchronously i.e. immediately when calling the function. A consequence is that the memory for the message can be allocated on the stack because it only has to live during the function call.
| type | The message type | 
| message | A pointer to the message | 
      
  | 
  inline | 
Send a message.
The message is sent synchronously i.e. immediately when calling the function. A consequence is that the memory for the message can be allocated on the stack because it only has to live during the function call.
| message | A pointer to the message | 
 1.8.13