7template <
typename Func>
8component&
opaque(
const Func& type_support) {
10 auto ts = type_support(world);
11 ts.desc.entity = _::type<T>::id(world_);
32template <
typename ElemType>
38component<T>&
constant(
const char *name, T value) {
39 using U =
typename std::underlying_type<T>::type;
41 ecs_add_id(world_, id_, _::type<flecs::Enum>::id(world_));
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);
55 #ifdef FLECS_CPP_NO_ENUM_REFLECTION
56 auto et = enum_type<T>(world_);
57 et.register_constant(world_,
static_cast<U
>(value), eid);
component & opaque(const Func &type_support)
Register an opaque type interface.
component< T > & constant(const char *name, T value)
Add a constant.
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Add a (component) ID to an entity.
#define ecs_assert(condition, error_code,...)
Assert.
#define ECS_INTERNAL_ERROR
Internal error code.
ecs_id_t ecs_entity_t
An entity identifier.
ecs_entity_t entity_t
Entity type.
ecs_entity_t ecs_entity_init(ecs_world_t *world, const ecs_entity_desc_t *desc)
Find or create an entity.
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Signal that a component has been modified.
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.
Used with ecs_entity_init().
const char * name
Name of the entity.
ecs_entity_t parent
Parent entity.
entity_t id() const
Get entity ID.
Type-safe interface for opaque types.
opaque & as_type(flecs::id_t func)
Set the type that describes the kind/structure of the opaque type.