Skip to main content

ComponentReflector Class Template

Generates and registers ComponentOps for a component type. More...

Declaration

template <typename TEntityManager> class helios::ecs::ComponentReflector<TEntityManager> { ... }

Public Member Typedefs Index

template <typename TEntityManager>
usingHandle_type = TEntityManager::Handle_type

Public Static Functions Index

template <typename T>
static voidregisterType ()

Registers a component type with the reflection system. More...

Description

Generates and registers ComponentOps for a component type.

ComponentReflector uses compile-time trait detection to generate appropriate function pointers for each lifecycle hook that a component type implements. This enables zero-overhead conditional invocation at runtime.

Definition at line 73 of file ComponentReflector.ixx.

Public Member Typedefs

Handle_type

template <typename TEntityManager>
using helios::ecs::ComponentReflector< TEntityManager >::Handle_type = TEntityManager::Handle_type

Definition at line 75 of file ComponentReflector.ixx.

75 using Handle_type = TEntityManager::Handle_type;

Public Static Functions

registerType()

template <typename T>
void helios::ecs::ComponentReflector< TEntityManager >::registerType ()
inline static

Registers a component type with the reflection system.

Generates ComponentOps function pointers based on which lifecycle hooks the type implements. Uses if constexpr for zero-overhead when hooks are not present.

Template Parameters
T

The component type to register. Must be copy-constructible for cloning support.

Definition at line 88 of file ComponentReflector.ixx.

88 static void registerType() {
89 ComponentOps ops{
90
91 .onAcquire = [](void *ptr) {
92 if constexpr (HasOnAcquire<T>) {
93 static_cast<T *>(ptr)->onAcquire();
94 }
95 },
96
97 .onRelease = [](void *ptr) {
98 if constexpr (HasOnRelease<T>) {
99 static_cast<T *>(ptr)->onRelease();
100 }
101 },
102
103 .onRemove = [](void *ptr) -> bool {
104 if constexpr (HasOnRemove<T>) {
105 return static_cast<T *>(ptr)->onRemove();
106 }
107 return true;
108 },
109
110 .clone = [](void *managerRaw, const void *sourceRaw, const void *targetRaw) -> void * {
111 auto *manager = static_cast<TEntityManager *>(managerRaw);
112 const auto *source = static_cast<const T *>(sourceRaw);
113 const auto *target = static_cast<const Handle_type *>(targetRaw);
114
115 T *cmp = nullptr;
116 if constexpr (std::is_copy_constructible_v<T>) {
117 cmp = manager->template emplace<T>(*target, *source);
118 } else {
119 return nullptr;
120 }
121
122 if (!cmp) {
123 return nullptr;
124 }
125
126 if constexpr (HasClone<T>) {
127 cmp->onClone(*source);
128 }
129
130 return cmp;
131 },
132
133 .onActivate = [](void *ptr) {
134 if constexpr (HasActivatable<T>) {
135 static_cast<T *>(ptr)->onActivate();
136 }
137 },
138
139 .onDeactivate = [](void *ptr) {
140 if constexpr (HasActivatable<T>) {
141 static_cast<T *>(ptr)->onDeactivate();
142 }
143 },
144
145
146 };
147
148 const auto typeId = ComponentTypeId<Handle_type>::template id<T>();
149
151 }

References helios::ecs::types::ComponentOps::onAcquire and helios::ecs::ComponentOpsRegistry< THandle >::setOps.


The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.