SDEngine
Game Engine
Loading...
Searching...
No Matches
component_registration.hpp
Go to the documentation of this file.
1
37#pragma once
38
39#include "SD/core/types.hpp"
41
42namespace sd {
43template<typename... Ts>
45
46template<typename T>
47struct ComponentTraits;
48
49template<typename T>
51 static void serialize(const T& component, Serializer& s) = delete;
52 static void deserialize(T& component, Serializer& s) = delete;
53};
54
55namespace detail {
61
62 static usize next() { return m_counter++; }
63
64private:
65 static inline usize m_counter = 0;
66};
67
68} // namespace detail
69
70template<typename T>
72 static constexpr bool s_is_registered = false;
73};
74
80#define REGISTER_SD_COMPONENT(Type) \
81 template<> \
82 struct ComponentTraits<Type> { \
83 static constexpr bool s_is_registered = true; \
84 static constexpr const char* name = "SD_" #Type; \
85 static inline const usize id = detail::ComponentIdGenerator::next(); \
86 };
87
92#define REGISTER_COMPONENT(Type) \
93 template<> \
94 struct ComponentTraits<Type> { \
95 static constexpr bool s_is_registered = true; \
96 static constexpr const char* name = #Type; \
97 static inline const usize id = detail::ComponentIdGenerator::next(); \
98 };
99
102 const char* name;
103 void* data;
104};
105
106template<typename T>
107concept SerializableComponent = requires(T& t, Serializer& s) {
110};
111
112} // namespace sd
Definition serialization.hpp:36
Definition component_registration.hpp:107
Definition Application.hpp:28
Definition component_registration.hpp:100
const char * name
Definition component_registration.hpp:102
void * data
Definition component_registration.hpp:103
usize id
Definition component_registration.hpp:101
Definition component_registration.hpp:44
Definition component_registration.hpp:50
static void deserialize(T &component, Serializer &s)=delete
static void serialize(const T &component, Serializer &s)=delete
Definition component_registration.hpp:71
static constexpr bool s_is_registered
Definition component_registration.hpp:72
Definition component_registration.hpp:56
static usize next()
Definition component_registration.hpp:62
ComponentIdGenerator & operator=(const ComponentIdGenerator &)=delete
static usize m_counter
Definition component_registration.hpp:65
ComponentIdGenerator(const ComponentIdGenerator &)=delete
constexpr T g_type_max
Definition types.hpp:21
std::size_t usize
Definition types.hpp:18