Tramway SDK
message.h
Go to the documentation of this file.
1// TRAMWAY DRIFT AND DUNGEON EXPLORATION SIMULATOR 2022
2// All rights reserved.
3
4#ifndef TRAM_SDK_FRAMEWORK_MESSAGE_H
5#define TRAM_SDK_FRAMEWORK_MESSAGE_H
6
7#include <framework/uid.h>
8
9namespace tram {
10
11typedef uint32_t message_t;
12typedef uint32_t id_t;
13
14struct Value;
15
16struct Message {
17 enum Type : message_t {
36 };
37
38 static message_t Register(const char* name);
39 static message_t GetType(name_t name);
41 static message_t GetLast();
42
43 static void Send(const Message& message);
44 static void Send(const Message& message, float delay);
45 static void Dispatch();
46 static void* AllocateData(size_t ammount);
47 template <typename T> static T* AllocateData() { static_assert(std::is_trivially_destructible_v<T>); return (T*)AllocateData(sizeof(T)); }
48 template <typename T> static T* AllocateData(const T& data) { /*static_assert(std::is_trivially_destructible_v<T>);*/ T* ptr = (T*)AllocateData(sizeof(T)); *ptr = data; return ptr; }
49 static void SetInterceptCallback(void(const Message&));
50
54
55 union {
56 void* data = nullptr;
57 int64_t data_int;
59 };
60};
61
62}
63
64#endif // TRAM_SDK_FRAMEWORK_MESSAGE_H
Generic, type-safe union.
Definition: value.h:18
Definition: api.h:9
uint32_t id_t
Definition: core.h:11
uint32_t message_t
Definition: message.h:11
Definition: message.h:16
static message_t GetLast()
Definition: message.cpp:77
static message_t Register(const char *name)
Registers a new message type.
Definition: message.cpp:51
int64_t data_int
Definition: message.h:57
static void Send(const Message &message)
Sends a message.
Definition: message.cpp:110
message_t type
Definition: message.h:51
Value * data_value
Definition: message.h:58
void * data
Definition: message.h:56
static T * AllocateData()
Definition: message.h:47
static void Dispatch()
Dispatches sent messsages.
Definition: message.cpp:83
id_t sender
Definition: message.h:52
id_t receiver
Definition: message.h:53
static T * AllocateData(const T &data)
Definition: message.h:48
static message_t GetType(name_t name)
Finds a message type from a name.
Definition: message.cpp:57
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_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
@ TOGGLE
Definition: message.h:25
@ LAST_MESSAGE
Definition: message.h:35
@ 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:73
static void SetInterceptCallback(void(const Message &))
Definition: message.cpp:139
Definition: uid.h:11