xyginext  0.2.0
Second generation of xygine game creation framework
Classes | Public Types | Public Member Functions | Public Attributes | Friends | List of all members
xy::Message Class Referencefinal

Message class. More...

#include <Message.hpp>

Classes

struct  AudioEvent
 Events raised by the AudioSystem. More...
 
struct  SceneEvent
 Events raised by the Scecne class. More...
 
struct  StateEvent
 Events raised by the StateStack. More...
 
struct  WindowEvent
 Events raised by the RenderWindow. More...
 

Public Types

enum  Type {
  AudioMessage = 0, UIMessage, WindowMessage, SceneMessage,
  StateMessage, Count
}
 
using ID = sf::Int32
 

Public Member Functions

template<typename T >
const T & getData () const
 

Public Attributes

ID id = -1
 

Friends

class MessageBus
 

Detailed Description

Message class.

The message class contains an ID used to identify the type of data contained in the message, and the message data itself. xygine uses some internal messaging types, so custom messages should have their IDs start at Message::Type::Count

See also
MessageBus

Member Function Documentation

◆ getData()

template<typename T >
const T& xy::Message::getData ( ) const
inline
    \brief Returns the actual data contained in the message

    Using the ID of the message to determine the data type of the
    message, this function will return a reference to that data.
    It is important to request the correct type of data from the
    message else behaviour will be undefined.

    if(msg.id == Type::PhysicsMessage)
    {
    const PhysicsEvent& data = msg.getData<PhysicsEvent>();

do stuff with data }