Tramway SDK
message.h
Go to the documentation of this file.
1// Tramway Drifting and Dungeon Exploration Simulator SDK Runtime
2
3#ifndef TRAM_SDK_FRAMEWORK_MESSAGE_H
4#define TRAM_SDK_FRAMEWORK_MESSAGE_H
5
6#include <framework/uid.h>
7
8namespace tram {
9
10typedef uint32_t message_t;
11typedef uint32_t id_t;
12
13struct Value;
14typedef Value value_t;
15
16struct Message {
17 enum Type : message_t {
38 };
39
40 static message_t Register(const char* name);
41 static message_t GetType(name_t name);
43 static message_t GetLast();
44
45 static void Send(const Message& message);
46 static void Send(const Message& message, float delay);
47 static void Dispatch();
48 static void* AllocateData(size_t ammount);
49 template <typename T> static T* AllocateData() { return (T*)AllocateData(sizeof(T)); }
50 template <typename T> static T* AllocateData(const T& data) { T* ptr = (T*)AllocateData(sizeof(T)); *ptr = data; return ptr; }
51 static void SetInterceptCallback(void(const Message&));
52
56
57 union {
58 void* data = nullptr;
59 int32_t data_int;
61 };
62};
63
64}
65
66#endif // TRAM_SDK_FRAMEWORK_MESSAGE_H
Generic, type-safe union.
Definition: value.h:18
Serialization, i.e.
uint32_t id_t
Definition: core.h:10
uint32_t message_t
Definition: message.h:10
Value value_t
Definition: event.h:21
Message data.
Definition: message.h:16
message_t type
Type of the message.
Definition: message.h:53
static message_t GetLast()
Returns the last message_t plus one.
Definition: message.cpp:147
id_t receiver
ID of the Entity that will receive the message.
Definition: message.h:55
id_t sender
ID of the Entity that sent the message.
Definition: message.h:54
static message_t Register(const char *name)
Registers a new message type.
Definition: message.cpp:96
static void Send(const Message &message)
Sends a message.
Definition: message.cpp:180
static T * AllocateData()
Definition: message.h:49
static void Dispatch()
Dispatches sent messsages.
Definition: message.cpp:153
int32_t data_int
Arbitrary data integer.
Definition: message.h:59
static T * AllocateData(const T &data)
Definition: message.h:50
static message_t GetType(name_t name)
Finds a message type from a name.
Definition: message.cpp:120
Type
Definition: message.h:17
@ STOP
Definition: message.h:29
@ ACTIVATE
Definition: message.h:30
@ SELECT
Definition: message.h:32
@ UNLOCK
Definition: message.h:24
@ KILL
Definition: message.h:26
@ SET_FLAG_ON
Definition: message.h:35
@ SET_ANIMATION
Definition: message.h:34
@ TRIGGER
Definition: message.h:27
@ NONE
Definition: message.h:18
@ SET_PROGRESS
Definition: message.h:33
@ CLOSE
Definition: message.h:22
@ PING
Definition: message.h:19
@ SET_FLAG_OFF
Definition: message.h:36
@ TOGGLE
Definition: message.h:25
@ LAST_MESSAGE
Definition: message.h:37
@ ACTIVATE_ONCE
Definition: message.h:31
@ MOVE_PICK_UP
Definition: message.h:20
@ OPEN
Definition: message.h:21
@ START
Definition: message.h:28
@ LOCK
Definition: message.h:23
static name_t GetName(message_t type)
Gets a nessage type name.
Definition: message.cpp:136
static void SetInterceptCallback(void(const Message &))
Definition: message.cpp:217
value_t * data_value
Pointer to a value_t.
Definition: message.h:60
void * data
Pointer to arbitrary data.
Definition: message.h:58
Interned string type.
Definition: uid.h:10