105#define REFLECT_FIELD(Type, FieldName) \
106 refl.fields.push_back({ \
108 Engine::DeduceFieldType<std::decay_t<decltype(std::declval<Type>().FieldName)>>::value, \
109 offsetof(Type, FieldName) \
124#define REGISTER_COMPONENT_EXPAND(Type, MenuPath, Counter) \
126 struct AutoRegisterComp_##Counter { \
127 AutoRegisterComp_##Counter() { \
128 Engine::ComponentReflection refl; \
130 size_t scopePos = refl.name.rfind("::"); \
131 if (scopePos != std::string::npos) refl.name = refl.name.substr(scopePos + 2); \
132 if (refl.name.size() > 9 && refl.name.rfind("Component") == refl.name.size() - 9) { \
133 refl.name = refl.name.substr(0, refl.name.size() - 9); \
136 std::string _path = MenuPath; \
137 size_t _slash = _path.rfind('/'); \
138 if (_slash != std::string::npos) { \
139 refl.category = _path.substr(0, _slash); \
140 refl.displayName = _path.substr(_slash + 1); \
142 refl.category = _path; \
143 refl.displayName = ""; \
145 refl.add = [](Registry& reg, Entity e) { reg.emplace<Type>(e, Type{}); }; \
146 refl.has = [](Registry& reg, Entity e) { return reg.has<Type>(e); }; \
147 refl.remove = [](Registry& reg, Entity e) { reg.remove<Type>(e); }; \
148 refl.get = [](Registry& reg, Entity e) { return static_cast<void*>(reg.get<Type>(e)); }; \
149 Engine::ComponentReflectionRegistry::getInstance().registerComponent(refl); \
152 static AutoRegisterComp_##Counter global_autoRegComp_##Counter; \
155#define REGISTER_COMPONENT_CONCAT(Type, MenuPath, Counter) REGISTER_COMPONENT_EXPAND(Type, MenuPath, Counter)
156#define REGISTER_COMPONENT(Type, MenuPath) REGISTER_COMPONENT_CONCAT(Type, MenuPath, __COUNTER__)
158#define REFLECT_COMPONENT_EXPAND(Type, MenuPath, Counter, InitFunc) \
160 struct AutoRegisterComp_##Counter { \
161 AutoRegisterComp_##Counter() { \
162 Engine::ComponentReflection refl; \
164 size_t scopePos = refl.name.rfind("::"); \
165 if (scopePos != std::string::npos) refl.name = refl.name.substr(scopePos + 2); \
166 if (refl.name.size() > 9 && refl.name.rfind("Component") == refl.name.size() - 9) { \
167 refl.name = refl.name.substr(0, refl.name.size() - 9); \
169 std::string _path = MenuPath; \
170 size_t _slash = _path.rfind('/'); \
171 if (_slash != std::string::npos) { \
172 refl.category = _path.substr(0, _slash); \
173 refl.displayName = _path.substr(_slash + 1); \
175 refl.category = _path; \
176 refl.displayName = ""; \
178 refl.add = [](Registry& reg, Entity e) { reg.emplace<Type>(e, Type{}); }; \
179 refl.has = [](Registry& reg, Entity e) { return reg.has<Type>(e); }; \
180 refl.remove = [](Registry& reg, Entity e) { reg.remove<Type>(e); }; \
181 refl.get = [](Registry& reg, Entity e) { return static_cast<void*>(reg.get<Type>(e)); }; \
182 auto init = InitFunc; \
184 Engine::ComponentReflectionRegistry::getInstance().registerComponent(refl); \
187 static AutoRegisterComp_##Counter global_autoRegComp_##Counter; \
190#define REFLECT_COMPONENT_CONCAT(Type, MenuPath, Counter, InitFunc) REFLECT_COMPONENT_EXPAND(Type, MenuPath, Counter, InitFunc)
191#define REFLECT_COMPONENT(Type, MenuPath, InitFunc) REFLECT_COMPONENT_CONCAT(Type, MenuPath, __COUNTER__, InitFunc)
#define ENGINE_API
Definition EngineAPI.hpp:10
RigidBodyType
Definition RigidBody.hpp:8
static ComponentReflectionRegistry & getInstance()
Definition ComponentReflection.cpp:6
ComponentReflectionRegistry()=default
const std::vector< ComponentReflection > & getReflections() const
Definition ComponentReflection.cpp:52
void registerComponent(const ComponentReflection &refl)
Definition ComponentReflection.cpp:13
std::vector< ComponentReflection > reflections
Definition ComponentReflection.hpp:78
Lightweight identifier representing a game object in the Entity Component System.
Definition Entity.hpp:11
Coordinates entities and components, providing creation, removal, lookup, and views.
Definition Registry.hpp:30
Definition Application.hpp:16
FieldType
Supported field types for component reflection.
Definition ComponentReflection.hpp:16
@ Vec3
Definition ComponentReflection.hpp:20
@ Int
Definition ComponentReflection.hpp:18
@ Entity
Definition ComponentReflection.hpp:22
@ RigidBodyType
Definition ComponentReflection.hpp:21
@ Float
Definition ComponentReflection.hpp:17
@ String
Definition ComponentReflection.hpp:23
@ Bool
Definition ComponentReflection.hpp:19
@ Vec4
Definition ComponentReflection.hpp:25
@ Vec2
Definition ComponentReflection.hpp:24
Standard library namespace.
Reflection metadata for a single field inside a component.
Definition ComponentReflection.hpp:33
FieldType type
Definition ComponentReflection.hpp:35
size_t offset
Definition ComponentReflection.hpp:36
std::string name
Definition ComponentReflection.hpp:34
Reflection metadata and ECS callbacks for a component.
Definition ComponentReflection.hpp:48
std::vector< ComponentField > fields
Definition ComponentReflection.hpp:56
std::string name
Internal component name (derived from type, e.g. "SpriteRenderer").
Definition ComponentReflection.hpp:50
std::function< void *(Registry &, Entity)> get
Definition ComponentReflection.hpp:62
std::function< void(Registry &, Entity)> remove
Definition ComponentReflection.hpp:61
std::function< void(Registry &, Entity)> add
Definition ComponentReflection.hpp:59
std::string displayName
Human-readable label inside the category submenu (e.g. "Sprite Renderer"). If empty the editor derive...
Definition ComponentReflection.hpp:55
std::string category
Top-level menu group shown in "Add Component" (e.g. "Rendering & Lights").
Definition ComponentReflection.hpp:52
std::function< bool(Registry &, Entity)> has
Definition ComponentReflection.hpp:60
static constexpr FieldType value
Definition ComponentReflection.hpp:99
static constexpr FieldType value
Definition ComponentReflection.hpp:100
static constexpr FieldType value
Definition ComponentReflection.hpp:96
static constexpr FieldType value
Definition ComponentReflection.hpp:93
static constexpr FieldType value
Definition ComponentReflection.hpp:91
static constexpr FieldType value
Definition ComponentReflection.hpp:90
static constexpr FieldType value
Definition ComponentReflection.hpp:94
static constexpr FieldType value
Definition ComponentReflection.hpp:95
static constexpr FieldType value
Definition ComponentReflection.hpp:97
static constexpr FieldType value
Definition ComponentReflection.hpp:92
static constexpr FieldType value
Definition ComponentReflection.hpp:98
Definition ComponentReflection.hpp:89
Compatibility layer that wraps a glm::quat but behaves like a glm::vec3 for Euler angles.
Definition Transform.hpp:15