Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
component.inl
1
3template <typename Func>
4component& opaque(const Func& type_support) {
5 flecs::world world(world_);
6 auto ts = type_support(world);
7 ts.desc.entity = _::type<T>::id(world_);
8 ecs_opaque_init(world_, &ts.desc);
9 return *this;
10}
11
12flecs::opaque<T> opaque(flecs::entity_t as_type) {
13 return flecs::opaque<T>(world_).as_type(as_type);
14}
15
16flecs::opaque<T> opaque(flecs::entity as_type) {
17 return this->opaque(as_type.id());
18}
19
21 return this->opaque(as_type.id());
22}
23
25template <typename ElemType>
26flecs::opaque<T, ElemType> opaque(flecs::id_t as_type) {
27 return flecs::opaque<T, ElemType>(world_).as_type(as_type);
28}
29
31component<T>& constant(const char *name, T value) {
32 using U = typename std::underlying_type<T>::type;
33
34 ecs_add_id(world_, id_, _::type<flecs::Enum>::id(world_));
35
36 ecs_entity_desc_t desc = {};
37 desc.name = name;
38 desc.parent = id_;
39 ecs_entity_t eid = ecs_entity_init(world_, &desc);
40 ecs_assert(eid != 0, ECS_INTERNAL_ERROR, NULL);
41
42 flecs::id_t pair = ecs_pair(flecs::Constant, _::type<U>::id(world_));
43 U *ptr = static_cast<U*>(ecs_ensure_id(world_, eid, pair));
44 *ptr = static_cast<U>(value);
45 ecs_modified_id(world_, eid, pair);
46
47 return *this;
48}
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_opaque_init(ecs_world_t *world, const ecs_opaque_desc_t *desc)
Create a new opaque type.
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:346
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_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Signal that a component has been modified.
Used with ecs_entity_init().
Definition flecs.h:976
const char * name
Name of the entity.
Definition flecs.h:983
ecs_entity_t parent
Parent entity.
Definition flecs.h:981
entity_t id() const
Get entity id.
Entity.
Definition entity.hpp:30
Type safe interface for opaque types.
Definition opaque.hpp:32
opaque & as_type(flecs::id_t func)
Type that describes the type kind/structure of the opaque type.
Definition opaque.hpp:40
Untyped component class.
The world.
Definition world.hpp:137