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

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

Loading...
Searching...
No Matches
component.inl
Go to the documentation of this file.
1
5
7template <typename Func>
8component& opaque(const Func& type_support) {
9 flecs::world world(world_);
10 auto ts = type_support(world);
11 ts.desc.entity = _::type<T>::id(world_);
12 ecs_opaque_init(world_, &ts.desc);
13 return *this;
14}
15
17 flecs::opaque<T> opaque(flecs::entity_t as_type) {
18 return flecs::opaque<T>(world_).as_type(as_type);
19}
20
22 flecs::opaque<T> opaque(flecs::entity as_type) {
23 return this->opaque(as_type.id());
24}
25
27 flecs::opaque<T> opaque(flecs::untyped_component as_type) {
28 return this->opaque(as_type.id());
29}
30
32template <typename ElemType>
33 flecs::opaque<T, ElemType> opaque(flecs::id_t as_type) {
34 return flecs::opaque<T, ElemType>(world_).as_type(as_type);
35}
36
38component<T>& constant(const char *name, T value) {
39 using U = typename std::underlying_type<T>::type;
40
41 ecs_add_id(world_, id_, _::type<flecs::Enum>::id(world_));
42
43 ecs_entity_desc_t desc = {};
44 desc.name = name;
45 desc.parent = id_;
46 ecs_entity_t eid = ecs_entity_init(world_, &desc);
47 ecs_assert(eid != 0, ECS_INTERNAL_ERROR, NULL);
48
49 flecs::id_t pair = ecs_pair(flecs::Constant, _::type<U>::id(world_));
50 U *ptr = static_cast<U*>(ecs_ensure_id(world_, eid, pair, sizeof(U)));
51 *ptr = static_cast<U>(value);
52 ecs_modified_id(world_, eid, pair);
53
54 // If we're not using automatic enum reflection, manually set static data.
55 #ifdef FLECS_CPP_NO_ENUM_REFLECTION
56 auto et = enum_type<T>(world_);
57 et.register_constant(world_, static_cast<U>(value), eid);
58 #endif
59
60 return *this;
61}
opaque
component & opaque(const Func &type_support)
Register an opaque type interface.
Definition component.inl:8
constant
component< T > & constant(const char *name, T value)
Add a constant.
Definition component.inl:38
ecs_add_id
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Add a (component) ID to an entity.
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:473
ECS_INTERNAL_ERROR
#define ECS_INTERNAL_ERROR
Internal error code.
Definition log.h:671
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
flecs::id_t
ecs_id_t id_t
ID type.
Definition c_types.hpp:20
flecs::entity_t
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
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_modified_id
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Signal that a component has been modified.
ecs_ensure_id
void * ecs_ensure_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component, size_t size)
Ensure an entity has a component and return a pointer.
ecs_entity_desc_t
Used with ecs_entity_init().
Definition flecs.h:1042
ecs_entity_desc_t::name
const char * name
Name of the entity.
Definition flecs.h:1049
ecs_entity_desc_t::parent
ecs_entity_t parent
Parent entity.
Definition flecs.h:1047
flecs::entity_view::id
entity_t id() const
Get entity ID.
Definition entity_view.hpp:53
flecs::entity
Entity.
Definition entity.hpp:30
flecs::opaque
Type-safe interface for opaque types.
Definition opaque.hpp:39
flecs::opaque::as_type
opaque & as_type(flecs::id_t func)
Set the type that describes the kind/structure of the opaque type.
Definition opaque.hpp:47
flecs::untyped_component
Untyped component class.
Definition component.hpp:263
flecs::world
The world.
Definition world.hpp:246