14template <
typename Self>
17 using entity_view::entity_view;
27 "cannot default construct type: add T::T() or use emplace<T>()");
41 template <typename E, if_t< is_enum<E>::value > = 0>
44 const auto& et = enum_type<E>(this->m_world);
45 flecs::entity_t
second = et.entity(value);
47 ecs_assert(
second, ECS_INVALID_PARAMETER,
"Component was not found in reflection data.");
68 ecs_add_pair(this->m_world, this->m_id,
first,
second);
78 template<
typename First,
typename Second>
89 template<typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
92 "cannot default construct type: add T::T() or use emplace<T>()");
103 template<typename First, typename Second, if_t< is_enum<Second>::value > = 0>
104 Self&
add(Second constant) {
106 "cannot default construct type: add T::T() or use emplace<T>()");
107 const auto& et = enum_type<Second>(this->m_world);
108 return this->add<First>(et.entity(constant));
117 template<
typename Second>
130 return this->
add(component);
132 return this->
remove(component);
142 template <
typename T>
145 return this->add<T>();
147 return this->remove<T>();
180 template <
typename First>
192 template <
typename First,
typename Second>
203 template <typename E, if_t< is_enum<E>::value > = 0>
205 const auto& et = enum_type<E>(this->m_world);
206 return this->add_if<E>(cond, et.entity(constant));
221 template <
typename T>
231 return this->
add(flecs::ChildOf,
second);
239 return this->
add(flecs::DependsOn,
second);
246 template <typename E, if_t<is_enum<E>::value> = 0>
249 const auto& et = enum_type<E>(this->m_world);
266 ECS_INVALID_PARAMETER,
"add ChildOf pair before using slot()");
276 template <
typename T>
285 template <
typename T>
294 template <
typename T>
303 template <typename T, if_not_t< is_enum<T>::value > = 0>
314 template <typename E, if_t< is_enum<E>::value > = 0>
317 return this->
remove(first, flecs::Wildcard);
336 ecs_remove_pair(this->m_world, this->m_id,
first,
second);
346 template<
typename First,
typename Second>
357 template<typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
368 template<
typename Second>
379 template<typename First, typename Second, if_t< is_enum<Second>::value > = 0>
381 const auto& et = enum_type<Second>(this->m_world);
382 flecs::entity_t
second = et.entity(constant);
383 return this->remove<First>(
second);
393 Self&
override(flecs::id_t
id) {
412 template <
typename T>
423 template <
typename First>
434 template <
typename First,
typename Second>
444 template <
typename T>
447 return this->set<T>(val);
455 template <
typename T>
458 return this->set<T>(FLECS_FWD(val));
467 template <
typename First>
469 this->override<First>(
second);
470 return this->set<First>(
second, val);
479 template <
typename First>
481 this->override<First>(
second);
482 return this->set<First>(
second, FLECS_FWD(val));
491 template <
typename First,
typename Second,
typename P = pair<First, Second>,
492 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
494 this->override<First, Second>();
495 return this->set<First, Second>(val);
504 template <
typename First,
typename Second,
typename P = pair<First, Second>,
505 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
507 this->override<First, Second>();
508 return this->set<First, Second>(FLECS_FWD(val));
516 template <
typename T,
typename ... Args>
520 flecs::emplace<T>(this->m_world, this->m_id,
532 template <
typename First,
typename Second,
typename P = pair<First, Second>,
533 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0,
536 this->override<First, Second>();
538 flecs::emplace<A>(this->m_world, this->m_id,
571 Self&
enable(flecs::id_t
id,
bool toggle =
true) {
602 template<
typename First>
613 template<
typename First,
typename Second>
625 return this->
enable(
id,
false);
654 template<
typename First>
665 template<
typename First,
typename Second>
670 Self& set_ptr(entity_t comp,
size_t size,
const void *ptr) {
671 ecs_set_id(this->m_world, this->m_id, comp, size, ptr);
675 Self& set_ptr(entity_t comp,
const void *ptr) {
680 ecs_assert(cptr != NULL, ECS_INVALID_PARAMETER, NULL);
682 return set_ptr(comp, cptr->
size, ptr);
685 template<
typename T, if_t<
686 !is_callable<T>::value && is_actual<T>::value> = 0 >
687 Self& set(T&& value) {
688 flecs::set<T>(this->m_world, this->m_id, FLECS_FWD(value));
692 template<
typename T, if_t<
693 !is_callable<T>::value && is_actual<T>::value > = 0>
694 Self& set(
const T& value) {
695 flecs::set<T>(this->m_world, this->m_id, value);
699 template<
typename T,
typename A = actual_type_t<T>, if_not_t<
700 is_callable<T>::value || is_actual<T>::value > = 0>
701 Self& set(A&& value) {
702 flecs::set<T>(this->m_world, this->m_id, FLECS_FWD(value));
706 template<
typename T,
typename A = actual_type_t<T>, if_not_t<
707 is_callable<T>::value || is_actual<T>::value > = 0>
708 Self& set(
const A& value) {
709 flecs::set<T>(this->m_world, this->m_id, value);
721 template <
typename First,
typename Second,
typename P = pair<First, Second>,
722 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
724 flecs::set<P>(this->m_world, this->m_id, FLECS_FWD(value));
736 template <
typename First,
typename Second,
typename P = pair<First, Second>,
737 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
738 Self&
set(
const A& value) {
739 flecs::set<P>(this->m_world, this->m_id, value);
751 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
754 flecs::set(this->m_world, this->m_id, value,
767 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
770 flecs::set(this->m_world, this->m_id, FLECS_FWD(value),
783 template <typename First, typename Second, if_t< is_enum<Second>::value > = 0>
784 Self&
set(Second constant,
const First& value) {
785 const auto& et = enum_type<Second>(this->m_world);
786 flecs::entity_t
second = et.entity(constant);
787 return set<First>(
second, value);
798 template <
typename Second>
801 flecs::set(this->m_world, this->m_id, value,
814 template <
typename Second>
817 flecs::set(this->m_world, this->m_id, FLECS_FWD(value),
822 template <
typename First,
typename Second>
824 flecs::set<pair_object<First, Second>>(this->m_world, this->m_id, value);
843 template <typename Func, if_t< is_callable<Func>::value > = 0>
844 Self& set(
const Func& func);
867 template<
typename T,
typename ... Args,
typename A = actual_type_t<T>>
869 flecs::emplace<A>(this->m_world, this->m_id,
874 template <
typename First,
typename Second,
typename ... Args,
typename P =
pair<First, Second>,
875 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
876 Self&
emplace(Args&&... args) {
877 flecs::emplace<A>(this->m_world, this->m_id,
884 template <
typename First,
typename ... Args>
885 Self& emplace_first(flecs::entity_t
second, Args&&... args) {
886 flecs::emplace<First>(this->m_world, this->m_id,
887 ecs_pair(_::cpp_type<First>::id(this->m_world),
second),
892 template <
typename Second,
typename ... Args>
893 Self& emplace_second(flecs::entity_t
first, Args&&... args) {
894 flecs::emplace<Second>(this->m_world, this->m_id,
895 ecs_pair(
first, _::cpp_type<Second>::id(this->m_world)),
905 template <
typename Func>
919 template <
typename First,
typename Func>
931 template <
typename Func>
934 ecs_pair(
first, this->m_id));
941 template <
typename Func>
956 Self& set_name(
const char *
name) {
963 Self& set_alias(
const char *
name) {
984 return *
static_cast<Self*
>(
this);
Doc entity builder mixin.
ecs_entity_t ecs_set_with(ecs_world_t *world, ecs_id_t id)
Set current with id.
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Add a (component) id to an entity.
void ecs_remove_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Remove a (component) id from an entity.
#define ecs_assert(condition, error_code,...)
Assert.
#define ecs_check(condition, error_code,...)
Check.
ecs_id_t ecs_entity_t
An entity identifier.
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
void ecs_enable_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id, bool enable)
Enable or disable component.
void ecs_enable(ecs_world_t *world, ecs_entity_t entity, bool enabled)
Enable or disable entity.
ecs_entity_t ecs_get_target(const ecs_world_t *world, ecs_entity_t entity, ecs_entity_t rel, int32_t index)
Get the target of a relationship.
bool ecs_has_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Test if an entity has an id.
ecs_entity_t 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.
const ecs_id_t ECS_OVERRIDE
Automatically override component when it is inherited.
void ecs_set_alias(ecs_world_t *world, ecs_entity_t entity, const char *alias)
Set alias for entity.
ecs_entity_t ecs_set_name(ecs_world_t *world, ecs_entity_t entity, const char *name)
Set the name of an entity.
ecs_entity_t ecs_set_scope(ecs_world_t *world, ecs_entity_t scope)
Set the current scope.
ecs_size_t size
Component size.
Self & add(Second constant)
Add a pair.
Self & child_of(entity_t second)
Shortcut for add(ChildOf, entity).
Self & set(Second constant, const First &value)
Set a pair for an entity.
Self & child_of()
Shortcut for add(ChildOf, entity).
Self & enable(flecs::id_t first, flecs::id_t second)
Enable a pair.
Self & disable(flecs::id_t id)
Disable an id.
Self & with(entity_t first, const Func &func)
Entities created in function will have (first, this).
Self & add_if(bool cond)
Conditional add.
Self & depends_on()
Shortcut for add(DependsOn, entity).
Self & add_second(flecs::entity_t first)
Add a pair.
Self & with(const Func &func)
Entities created in function will have the current entity.
Self & set_override(T &&val)
Set component, mark component for auto-overriding.
Self & scope(const Func &func)
The function will be ran with the scope set to the current entity.
Self & add()
Add a component to an entity.
Self & add_if(bool cond, flecs::entity_t second)
Conditional add.
Self & set_second(entity_t first, Second &&value)
Set a pair for an entity.
Self & depends_on(entity_t second)
Shortcut for add(DependsOn, entity).
Self & enable()
Enable a component.
scoped_world scope() const
Return world scoped to entity.
Self & set(A &&value)
Set a pair for an entity.
Self & set(Second second, const First &value)
Set a pair for an entity.
Self & disable(flecs::id_t first, flecs::id_t second)
Disable a pair.
Self & add(entity_t first, entity_t second)
Add a pair.
Self & enable()
Enable an entity.
Self & is_a(entity_t second)
Shortcut for add(IsA, entity).
Self & add(Second second)
Add a pair.
Self & add(id_t component)
Add an entity to an entity.
Self & disable()
Disable an entity.
Self & disable()
Disable a pair.
Self & set_override(flecs::entity_t second, First &&val)
Set pair, mark component for auto-overriding.
Self & remove(Second constant)
Remove a pair.
Self & with(const Func &func)
Entities created in function will have (First, this).
Self & add_if(bool cond, flecs::id_t component)
Conditional add.
Self & remove(Second second)
Remove a pair.
Self & enable(flecs::id_t second)
Enable a pair.
Self & remove()
Remove a component from an entity.
Self & disable(flecs::id_t second)
Disable a pair.
Self & depends_on(E second)
Shortcut for add(DependsOn, entity).
Self & set_override(const T &val)
Set component, mark component for auto-overriding.
Self & emplace_override(Args &&... args)
Emplace component, mark component for auto-overriding.
Self & set(Second second, First &&value)
Set a pair for an entity.
Self & add_if(bool cond)
Conditional add.
Self & remove(entity_t first, entity_t second)
Remove a pair.
Self & disable()
Disable a component.
Self & slot_of(entity_t second)
Shortcut for add(SlotOf, entity).
Self & set_override(flecs::entity_t second, const First &val)
Set pair, mark component for auto-overriding.
Self & enable()
Enable a pair.
Self & add_if(bool cond, flecs::entity_t first, flecs::entity_t second)
Conditional add.
Self & set_second(entity_t first, const Second &value)
Set a pair for an entity.
Self & enable(flecs::id_t id, bool toggle=true)
Enable an id.
Self & emplace_override(Args &&... args)
Emplace pair, mark pair for auto-overriding.
Self & set_override(const A &val)
Set component, mark component for auto-overriding.
Self & set(const A &value)
Set a pair for an entity.
Self & remove_second(flecs::entity_t first)
Removes a pair.
Self & slot()
Shortcut for add(SlotOf, target(ChildOf)).
Self & is_a()
Shortcut for add(IsA, entity).
Self & slot_of()
Shortcut for add(SlotOf, entity).
Self & add(E value)
Add pair for enum constant.
Self & set_override(A &&val)
Set component, mark component for auto-overriding.
Self & add_if(bool cond, E constant)
Conditional add.
Self & remove(entity_t entity)
Remove an entity from an entity.
Self & emplace(Args &&... args)
Emplace component.
flecs::string_view name() const
Return the entity name.
entity_t id() const
Get entity id.
flecs::entity target(int32_t index=0) const
Get target for a given pair.
flecs::entity second() const
Get second element from a pair.
flecs::entity first() const
Get first element from a pair.
Type that represents a pair.