Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
untyped_component.inl
Go to the documentation of this file.
1
13private:
14
16untyped_component& internal_member(
17 flecs::entity_t type_id,
18 flecs::entity_t unit,
19 const char *name,
20 int32_t count = 0,
21 size_t offset = 0,
22 bool use_offset = false)
23{
24 ecs_entity_desc_t desc = {};
25 desc.name = name;
26 desc.parent = id_;
27 ecs_entity_t eid = ecs_entity_init(world_, &desc);
28 ecs_assert(eid != 0, ECS_INTERNAL_ERROR, NULL);
29
30 flecs::entity e(world_, eid);
31
32 Member m = {};
33 m.type = type_id;
34 m.unit = unit;
35 m.count = count;
36 m.offset = static_cast<int32_t>(offset);
37 m.use_offset = use_offset;
38 e.set<Member>(m);
39
40 return *this;
41}
42
43public:
44
47 flecs::entity_t type_id,
48 flecs::entity_t unit,
49 const char *name,
50 int32_t count = 0)
51{
52 return internal_member(type_id, unit, name, count, 0, false);
53}
54
57 flecs::entity_t type_id,
58 flecs::entity_t unit,
59 const char *name,
60 int32_t count,
61 size_t offset)
62{
63 return internal_member(type_id, unit, name, count, offset, true);
64}
65
68 flecs::entity_t type_id,
69 const char* name,
70 int32_t count = 0)
71{
72 return member(type_id, 0, name, count);
73}
74
77 flecs::entity_t type_id,
78 const char* name,
79 int32_t count,
80 size_t offset)
81{
82 return member(type_id, 0, name, count, offset);
83}
84
86template <typename MemberType>
88 const char *name,
89 int32_t count = 0)
90{
91 flecs::entity_t type_id = _::type<MemberType>::id(world_);
92 return member(type_id, name, count);
93}
94
96template <typename MemberType>
98 const char *name,
99 int32_t count,
100 size_t offset)
101{
102 flecs::entity_t type_id = _::type<MemberType>::id(world_);
103 return member(type_id, name, count, offset);
104}
105
107template <typename MemberType>
109 flecs::entity_t unit,
110 const char *name,
111 int32_t count = 0)
112{
113 flecs::entity_t type_id = _::type<MemberType>::id(world_);
114 return member(type_id, unit, name, count);
115}
116
118template <typename MemberType>
120 flecs::entity_t unit,
121 const char *name,
122 int32_t count,
123 size_t offset)
124{
125 flecs::entity_t type_id = _::type<MemberType>::id(world_);
126 return member(type_id, unit, name, count, offset);
127}
128
130template <typename MemberType, typename UnitType>
132 const char *name,
133 int32_t count = 0)
134{
135 flecs::entity_t type_id = _::type<MemberType>::id(world_);
136 flecs::entity_t unit_id = _::type<UnitType>::id(world_);
137 return member(type_id, unit_id, name, count);
138}
139
141template <typename MemberType, typename UnitType>
143 const char *name,
144 int32_t count,
145 size_t offset)
146{
147 flecs::entity_t type_id = _::type<MemberType>::id(world_);
148 flecs::entity_t unit_id = _::type<UnitType>::id(world_);
149 return member(type_id, unit_id, name, count, offset);
150}
151
153template <typename MemberType, typename ComponentType,
154 typename RealType = typename std::remove_extent<MemberType>::type>
156 const char* name,
157 const MemberType ComponentType::* ptr)
158{
159 flecs::entity_t type_id = _::type<RealType>::id(world_);
160 size_t offset = reinterpret_cast<size_t>(&(static_cast<ComponentType*>(nullptr)->*ptr));
161 return member(type_id, name, std::extent<MemberType>::value, offset);
162}
163
165template <typename MemberType, typename ComponentType,
166 typename RealType = typename std::remove_extent<MemberType>::type>
168 flecs::entity_t unit,
169 const char* name,
170 const MemberType ComponentType::* ptr)
171{
172 flecs::entity_t type_id = _::type<RealType>::id(world_);
173 size_t offset = reinterpret_cast<size_t>(&(static_cast<ComponentType*>(nullptr)->*ptr));
174 return member(type_id, unit, name, std::extent<MemberType>::value, offset);
175}
176
178template <typename UnitType, typename MemberType, typename ComponentType,
179 typename RealType = typename std::remove_extent<MemberType>::type>
181 const char* name,
182 const MemberType ComponentType::* ptr)
183{
184 flecs::entity_t type_id = _::type<RealType>::id(world_);
185 flecs::entity_t unit_id = _::type<UnitType>::id(world_);
186 size_t offset = reinterpret_cast<size_t>(&(static_cast<ComponentType*>(nullptr)->*ptr));
187 return member(type_id, unit_id, name, std::extent<MemberType>::value, offset);
188}
189
192 const char *name,
193 int32_t value)
194{
195 ecs_add_id(world_, id_, _::type<flecs::Enum>::id(world_));
196
197 ecs_entity_desc_t desc = {};
198 desc.name = name;
199 desc.parent = id_;
200 ecs_entity_t eid = ecs_entity_init(world_, &desc);
201 ecs_assert(eid != 0, ECS_INTERNAL_ERROR, NULL);
202
203 ecs_set_id(world_, eid,
204 ecs_pair(flecs::Constant, flecs::I32), sizeof(int32_t),
205 &value);
206
207 return *this;
208}
209
212 const char *name,
213 uint32_t value)
214{
215 ecs_add_id(world_, id_, _::type<flecs::Bitmask>::id(world_));
216
217 ecs_entity_desc_t desc = {};
218 desc.name = name;
219 desc.parent = id_;
220 ecs_entity_t eid = ecs_entity_init(world_, &desc);
221 ecs_assert(eid != 0, ECS_INTERNAL_ERROR, NULL);
222
223 ecs_set_id(world_, eid,
224 ecs_pair(flecs::Constant, flecs::U32), sizeof(uint32_t),
225 &value);
226
227 return *this;
228}
229
231template <typename Elem>
233 int32_t elem_count)
234{
235 ecs_array_desc_t desc = {};
236 desc.entity = id_;
237 desc.type = _::type<Elem>::id(world_);
238 desc.count = elem_count;
239 ecs_array_init(world_, &desc);
240 return *this;
241}
242
245 double min,
246 double max)
247{
248 const flecs::member_t *m = ecs_cpp_last_member(world_, id_);
249 if (!m) {
250 return *this;
251 }
252
253 flecs::world w(world_);
254 flecs::entity me = w.entity(m->member);
255
256 // Don't use C++ ensure because Unreal defines a macro called ensure
257 flecs::MemberRanges *mr = static_cast<flecs::MemberRanges*>(
259 mr->value.min = min;
260 mr->value.max = max;
262 return *this;
263}
264
267 double min,
268 double max)
269{
270 const flecs::member_t *m = ecs_cpp_last_member(world_, id_);
271 if (!m) {
272 return *this;
273 }
274
275 flecs::world w(world_);
276 flecs::entity me = w.entity(m->member);
277
278 // Don't use C++ ensure because Unreal defines a macro called ensure
279 flecs::MemberRanges *mr = static_cast<flecs::MemberRanges*>(
281 mr->warning.min = min;
282 mr->warning.max = max;
284 return *this;
285}
286
289 double min,
290 double max)
291{
292 const flecs::member_t *m = ecs_cpp_last_member(world_, id_);
293 if (!m) {
294 return *this;
295 }
296
297 flecs::world w(world_);
298 flecs::entity me = w.entity(m->member);
299
300 // Don't use C++ ensure because Unreal defines a macro called ensure
302 w, me, w.id<flecs::MemberRanges>()));
303 mr->error.min = min;
304 mr->error.max = max;
306 return *this;
307}
308
flecs::entity_t type_id()
Get id currently assigned to component.
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Add a (component) id to an entity.
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:352
FLECS_API ecs_entity_t ecs_array_init(ecs_world_t *world, const ecs_array_desc_t *desc)
Create a new array type.
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:347
untyped_component & member(const char *name, int32_t count, size_t offset)
Add member with unit.
untyped_component & member(const char *name, int32_t count=0)
Add member.
untyped_component & member(flecs::entity_t unit, const char *name, int32_t count, size_t offset)
Add member with unit.
untyped_component & constant(const char *name, int32_t value)
Add constant.
untyped_component & member(const char *name, int32_t count=0)
Add member with unit.
untyped_component & member(flecs::entity_t type_id, flecs::entity_t unit, const char *name, int32_t count=0)
Add member with unit.
untyped_component & member(flecs::entity_t unit, const char *name, const MemberType ComponentType::*ptr)
Add member with unit using pointer-to-member.
untyped_component & warning_range(double min, double max)
Add member warning range.
untyped_component & member(flecs::entity_t unit, const char *name, int32_t count=0)
Add member with unit.
untyped_component & member(flecs::entity_t type_id, flecs::entity_t unit, const char *name, int32_t count, size_t offset)
Add member with unit, count and offset.
untyped_component & member(flecs::entity_t type_id, const char *name, int32_t count, size_t offset)
Add member with count and offset.
untyped_component & array(int32_t elem_count)
Register array metadata for component.
untyped_component & range(double min, double max)
Add member value range.
untyped_component & member(const char *name, const MemberType ComponentType::*ptr)
Add member using pointer-to-member.
untyped_component & member(flecs::entity_t type_id, const char *name, int32_t count=0)
Add member.
untyped_component & member(const char *name, const MemberType ComponentType::*ptr)
Add member with unit using pointer-to-member.
untyped_component & bit(const char *name, uint32_t value)
Add bitmask constant.
untyped_component & member(const char *name, int32_t count, size_t offset)
Add member.
untyped_component & error_range(double min, double max)
Add member error range.
flecs::entity entity(Args &&... args) const
Create an entity.
flecs::id id(E value) const
Convert enum constant to entity.
ecs_entity_t ecs_entity_init(ecs_world_t *world, const ecs_entity_desc_t *desc)
Find or create an entity.
void * ecs_ensure_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get a mutable pointer to a component.
void ecs_set_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id, size_t size, const void *ptr)
Set the value of a component.
Component added to member entities to express valid value ranges.
Definition meta.h:215
ecs_member_value_range_t warning
Member value warning range.
Definition meta.h:217
ecs_member_value_range_t value
Member value range.
Definition meta.h:216
ecs_member_value_range_t error
Member value error range.
Definition meta.h:218
ecs_entity_t type
Member type.
Definition meta.h:201
Used with ecs_array_init().
Definition meta.h:996
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:997
ecs_entity_t type
Element type.
Definition meta.h:998
int32_t count
Number of elements.
Definition meta.h:999
Used with ecs_entity_init().
Definition flecs.h:938
const char * name
Name of the entity.
Definition flecs.h:945
ecs_entity_t parent
Parent entity.
Definition flecs.h:943
Element type of members vector in EcsStruct.
Definition meta.h:222
ecs_entity_t member
Should not be set by ecs_struct_desc_t.
Definition meta.h:261
double min
Min member value.
Definition meta.h:210
double max
Max member value.
Definition meta.h:211
Entity.
Definition entity.hpp:30
void modified() const
Signal that component was modified.
Definition entity.hpp:186
Untyped component class.
The world.
Definition world.hpp:137