Flecs: include/flecs/addons/cpp/mixins/meta/component.inl Source File
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.0 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
component.inl
1
3template <typename Func>
4 component& 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
12 flecs::opaque<T> opaque(flecs::entity_t as_type) {
13 return flecs::opaque<T>(world_).as_type(as_type);
14}
15
16 flecs::opaque<T> opaque(flecs::entity as_type) {
17 return this->opaque(as_type.id());
18}
19
20 flecs::opaque<T> opaque(flecs::untyped_component as_type) {
21 return this->opaque(as_type.id());
22}
23
25template <typename ElemType>
26 flecs::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}
ecs_add_id
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Add a (component) id to an entity.
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:368
ecs_opaque_init
FLECS_API ecs_entity_t ecs_opaque_init(ecs_world_t *world, const ecs_opaque_desc_t *desc)
Create a new opaque type.
ecs_entity_t
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:381
ecs_entity_init
ecs_entity_t ecs_entity_init(ecs_world_t *world, const ecs_entity_desc_t *desc)
Find or create an entity.
ecs_ensure_id
void * ecs_ensure_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get a mutable pointer to a component.
ecs_modified_id
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Signal that a component has been modified.
ecs_entity_desc_t
Used with ecs_entity_init().
Definition flecs.h:1012
ecs_entity_desc_t::name
const char * name
Name of the entity.
Definition flecs.h:1019
ecs_entity_desc_t::parent
ecs_entity_t parent
Parent entity.
Definition flecs.h:1017
flecs::entity_view::id
entity_t id() const
Get entity id.
Definition entity_view.hpp:50
flecs::entity
Entity.
Definition entity.hpp:30
flecs::opaque
Type safe interface for opaque types.
Definition opaque.hpp:41
flecs::opaque::as_type
opaque & as_type(flecs::id_t func)
Type that describes the type kind/structure of the opaque type.
Definition opaque.hpp:49
flecs::untyped_component
Untyped component class.
Definition component.hpp:296
flecs::world
The world.
Definition world.hpp:137
flecs::world::pair
flecs::id pair() const
Get pair id from relationship, object.
flecs::world::component
flecs::component< T > component(Args &&... args) const
Find or register component.