Tramway SDK v0.1.1
Public Types | Static Public Member Functions | Public Attributes | List of all members
tram::Message Struct Reference

Message data. More...

#include <framework/message.h>

Public Types

enum  Type : message_t {
  NONE , PING , MOVE_PICK_UP , OPEN ,
  CLOSE , LOCK , UNLOCK , TOGGLE ,
  KILL , TRIGGER , START , STOP ,
  ACTIVATE , ACTIVATE_ONCE , SELECT , SET_PROGRESS ,
  SET_ANIMATION , SET_FLAG_ON , SET_FLAG_OFF , LAST_MESSAGE
}
 

Static Public Member Functions

static message_t Register (const char *name)
 Registers a new message type. More...
 
static message_t GetType (name_t name)
 Finds a message type from a name. More...
 
static name_t GetName (message_t type)
 Gets a nessage type name. More...
 
static message_t GetLast ()
 Returns the last message_t plus one. More...
 
static void Send (const Message &message)
 Sends a message. More...
 
static void Send (const Message &message, float delay)
 Semds a message into the future. More...
 
static void Dispatch ()
 Dispatches sent messsages. More...
 
static void * AllocateData (size_t ammount)
 Allocates space for message data. More...
 
template<typename T >
static T * AllocateData ()
 
template<typename T >
static T * AllocateData (const T &data)
 
static void SetInterceptCallback (void(const Message &))
 

Public Attributes

message_t type
 Type of the message. More...
 
id_t sender
 ID of the Entity that sent the message. More...
 
id_t receiver
 ID of the Entity that will receive the message. More...
 
union {
   void *   data = nullptr
 
   int32_t   data_int
 
   value_t *   data_value
 
}; 
 

Detailed Description

Message data.

Fill in the struct fields and then use Message::Send() to send it out to listeners.

Member Enumeration Documentation

◆ Type

Enumerator
NONE 
PING 
MOVE_PICK_UP 
OPEN 
CLOSE 
LOCK 
UNLOCK 
TOGGLE 
KILL 
TRIGGER 
START 
STOP 
ACTIVATE 
ACTIVATE_ONCE 
SELECT 
SET_PROGRESS 
SET_ANIMATION 
SET_FLAG_ON 
SET_FLAG_OFF 
LAST_MESSAGE 

Member Function Documentation

◆ AllocateData() [1/3]

template<typename T >
static T * tram::Message::AllocateData ( )
inlinestatic

◆ AllocateData() [2/3]

template<typename T >
static T * tram::Message::AllocateData ( const T &  data)
inlinestatic

◆ AllocateData() [3/3]

void * tram::Message::AllocateData ( size_t  ammount)
static

Allocates space for message data.

This allocation is useful for storing the additional data (Message::data pointer), for messages, since all allocated space will be cleared once all messages have been dispatched. This only applies to messages that are sent without a time delay, if you're sending messages with a delay, then you'll need to allocate memory for their data yourself.

Note
Remember to only use POD data types.

◆ Dispatch()

void tram::Message::Dispatch ( )
static

Dispatches sent messsages.

Dispatches the messages that have been sent using the Message::Send() function.

◆ GetLast()

message_t tram::Message::GetLast ( )
static

Returns the last message_t plus one.

Useful for iterating over all registered messages, i.e. in a while (++message < Message::GetLast()); or a similar loop.

◆ GetName()

name_t tram::Message::GetName ( message_t  type)
static

Gets a nessage type name.

◆ GetType()

message_t tram::Message::GetType ( name_t  name)
static

Finds a message type from a name.

◆ Register()

message_t tram::Message::Register ( const char *  name)
static

Registers a new message type.

Returns
Unique message type number.

◆ Send() [1/2]

void tram::Message::Send ( const Message message)
static

Sends a message.

Message will be delivered to the Entity with the ID number specified in the Message::receiver field, by calling its Entity::MessageHandler() method.

◆ Send() [2/2]

void tram::Message::Send ( const Message message,
float  delay 
)
static

Semds a message into the future.

Same as Message::Send(), but the actual sending will be delayed until specified ammount of ticks have passed.

Parameters
messageMessage to be sent.
whenHow many ticks need to pass until the message will be sent out, i.e. if you want to send a message out in 1 secons, set this parameter to 60.

◆ SetInterceptCallback()

void tram::Message::SetInterceptCallback ( void(const Message &)  )
static

Member Data Documentation

◆ 

union { ... } tram::Message::@40

◆ data

tram::Message::data = nullptr

Pointer to arbitrary data.

Can be set to a nullptr. Some message types have specific data, e.g. structs or other types that they need their data pointers to be pointing to. For your own message types, you can use this pointer for whatever purpose you want. If uncertain, set this to a nullptr.

◆ data_int

tram::Message::data_int

Arbitrary data integer.

◆ data_value

tram::Message::data_value

◆ receiver

tram::Message::receiver

ID of the Entity that will receive the message.

Set to the ID of an Entity.

◆ sender

tram::Message::sender

ID of the Entity that sent the message.

Either set to the ID of an Entity, or can be set to zero.

◆ type

tram::Message::type

Type of the message.


The documentation for this struct was generated from the following files: