![]() |
xyginext
0.2.0
Second generation of xygine game creation framework
|
System wide message bus for custom event messaging. More...
#include <MessageBus.hpp>
Public Member Functions | |
MessageBus (const MessageBus &)=delete | |
MessageBus (MessageBus &&)=delete | |
MessageBus & | operator= (const MessageBus &)=delete |
MessageBus & | operator= (MessageBus &&)=delete |
const Message & | poll () |
Read and despatch all messages on the message stack. More... | |
template<typename T > | |
T * | post (Message::ID id) |
Places a message on the message stack, and returns a pointer to the data. More... | |
bool | empty () |
Returns true if there are no messages left on the message bus. | |
std::size_t | pendingMessageCount () const |
Returns the number of messages currently sitting on the message bus. More... | |
void | disable () |
Disables the message bus. Used internally by xygine. | |
System wide message bus for custom event messaging.
The app class contains an instance of the MessageBus which allows events and messages to be broadcast system wide, upon which objects entities and components can decide whether or not to act. Custom message type IDs can be added by extending the ID set starting at Message::Type::Count. EG
enum MyMessageTypes { AlienEvent = Message::Type::Count, GhostEvent, BadgerEvent //etc... };
std::size_t xy::MessageBus::pendingMessageCount | ( | ) | const |
Returns the number of messages currently sitting on the message bus.
Useful for stat logging and debugging.
const Message& xy::MessageBus::poll | ( | ) |
Read and despatch all messages on the message stack.
Used internally by xygine
|
inline |
Places a message on the message stack, and returns a pointer to the data.
The message data can then be filled in via the pointer. Custom message types can be defined via structs, which are then created on the message bus. Structs should contain only trivial data such as PODs and pointers to other objects. ATTEMPING TO PLACE LARGE OBJECTS DIRECTLY ON THE MESSAGE BUS IS ASKING FOR TROUBLE Custom message types should have a unique 32 bit integer ID which can be used to identify the message type when reading messages. Message data has a maximum size of 128 bytes.
id | Unique ID for this message type |