14template <
typename Self>
17 using entity_view::entity_view;
25 const Self&
add()
const {
27 "cannot default construct type: add T::T() or use emplace<T>()");
41 template <typename E, if_t< is_enum<E>::value > = 0>
42 const Self&
add(E value)
const {
44 const auto& et = enum_type<E>(this->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->world_, this->id_,
first,
second);
78 template<
typename First,
typename Second>
79 const Self&
add()
const {
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 const Self&
add(Second constant)
const {
106 "cannot default construct type: add T::T() or use emplace<T>()");
107 const auto& et = enum_type<Second>(this->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>
204 const Self&
add_if(
bool cond, E constant)
const {
205 const auto& et = enum_type<E>(this->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>
248 const auto& et = enum_type<E>(this->world_);
265 ECS_INVALID_PARAMETER,
"add ChildOf pair before using slot()");
275 template <
typename T>
284 template <
typename T>
293 template <
typename T>
302 template <typename T, if_not_t< is_enum<T>::value > = 0>
313 template <typename E, if_t< is_enum<E>::value > = 0>
316 return this->
remove(first, flecs::Wildcard);
335 ecs_remove_pair(this->world_, this->id_,
first,
second);
345 template<
typename First,
typename Second>
356 template<typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
367 template<
typename Second>
378 template<typename First, typename Second, if_t< is_enum<Second>::value > = 0>
379 const Self&
remove(Second constant)
const {
380 const auto& et = enum_type<Second>(this->world_);
381 flecs::entity_t
second = et.entity(constant);
382 return this->remove<First>(
second);
411 template <
typename T>
422 template <
typename First>
433 template <
typename First,
typename Second>
444 template <
typename T>
446 this->auto_override<T>();
447 return this->set<T>(val);
456 template <
typename T>
458 this->auto_override<T>();
459 return this->set<T>(FLECS_FWD(val));
469 template <
typename First>
471 this->auto_override<First>(
second);
472 return this->set<First>(
second, val);
482 template <
typename First>
484 this->auto_override<First>(
second);
485 return this->set<First>(
second, FLECS_FWD(val));
495 template <
typename First,
typename Second,
typename P = pair<First, Second>,
496 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
498 this->auto_override<First, Second>();
499 return this->set<First, Second>(val);
509 template <
typename First,
typename Second,
typename P = pair<First, Second>,
510 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
512 this->auto_override<First, Second>();
513 return this->set<First, Second>(FLECS_FWD(val));
522 template <
typename T,
typename ... Args>
524 this->auto_override<T>();
526 flecs::emplace<T>(this->world_, this->id_,
539 template <
typename First,
typename Second,
typename P = pair<First, Second>,
540 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0,
543 this->auto_override<First, Second>();
545 flecs::emplace<A>(this->world_, this->id_,
580 const Self&
enable(flecs::id_t
id,
bool toggle =
true)
const {
611 template<
typename First>
622 template<
typename First,
typename Second>
637 return this->
enable(
id,
false);
666 template<
typename First>
677 template<
typename First,
typename Second>
682 const Self& set_ptr(entity_t comp,
size_t size,
const void *ptr)
const {
683 ecs_set_id(this->world_, this->id_, comp, size, ptr);
687 const Self& set_ptr(entity_t comp,
const void *ptr)
const {
692 ecs_assert(cptr != NULL, ECS_INVALID_PARAMETER, NULL);
694 return set_ptr(comp, cptr->
size, ptr);
697 template<typename T, if_t<is_actual<T>::value> = 0 >
698 const Self& set(T&& value)
const {
699 flecs::set<T>(this->world_, this->id_, FLECS_FWD(value));
703 template<typename T, if_t<is_actual<T>::value > = 0>
704 const Self& set(
const T& value)
const {
705 flecs::set<T>(this->world_, this->id_, value);
709 template<
typename T,
typename A = actual_type_t<T>, if_not_t<
710 is_actual<T>::value > = 0>
711 const Self& set(A&& value)
const {
712 flecs::set<T>(this->world_, this->id_, FLECS_FWD(value));
716 template<
typename T,
typename A = actual_type_t<T>, if_not_t<
717 is_actual<T>::value > = 0>
718 const Self& set(
const A& value)
const {
719 flecs::set<T>(this->world_, this->id_, value);
731 template <
typename First,
typename Second,
typename P = pair<First, Second>,
732 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
733 const Self&
set(A&& value)
const {
734 flecs::set<P>(this->world_, this->id_, FLECS_FWD(value));
746 template <
typename First,
typename Second,
typename P = pair<First, Second>,
747 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
748 const Self&
set(
const A& value)
const {
749 flecs::set<P>(this->world_, this->id_, value);
761 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
762 const Self&
set(Second
second,
const First& value)
const {
764 flecs::set(this->world_, this->id_, value,
777 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
780 flecs::set(this->world_, this->id_, FLECS_FWD(value),
793 template <typename First, typename Second, if_t< is_enum<Second>::value > = 0>
794 const Self&
set(Second constant,
const First& value)
const {
795 const auto& et = enum_type<Second>(this->world_);
796 flecs::entity_t
second = et.entity(constant);
797 return set<First>(
second, value);
808 template <
typename Second>
812 ECS_INVALID_PARAMETER,
"pair is not a component");
814 ECS_INVALID_PARAMETER,
"type of pair is not Second");
815 flecs::set(this->world_, this->id_, value,
828 template <
typename Second>
832 ECS_INVALID_PARAMETER,
"pair is not a component");
834 ECS_INVALID_PARAMETER,
"type of pair is not Second");
835 flecs::set(this->world_, this->id_, FLECS_FWD(value),
840 template <
typename First,
typename Second>
841 const Self&
set_second(
const Second& value)
const {
842 flecs::set<pair_object<First, Second>>(this->world_, this->id_, value);
861 template <
typename Func>
862 const Self&
insert(
const Func& func)
const;
885 template<
typename T,
typename ... Args,
typename A = actual_type_t<T>>
887 flecs::emplace<A>(this->world_, this->id_,
892 template <
typename First,
typename Second,
typename ... Args,
typename P =
pair<First, Second>,
893 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
894 const Self&
emplace(Args&&... args)
const {
895 flecs::emplace<A>(this->world_, this->id_,
902 template <
typename First,
typename ... Args>
903 const Self& emplace_first(flecs::entity_t
second, Args&&... args)
const {
904 auto first = _::type<First>::id(this->world_);
905 flecs::emplace<First>(this->world_, this->id_,
911 template <
typename Second,
typename ... Args>
912 const Self& emplace_second(flecs::entity_t
first, Args&&... args)
const {
913 auto second = _::type<Second>::id(this->world_);
915 ECS_INVALID_PARAMETER,
"pair is not a component");
917 ECS_INVALID_PARAMETER,
"type of pair is not Second");
918 flecs::emplace<Second>(this->world_, this->id_,
929 template <
typename Func>
930 const Self&
with(
const Func& func)
const {
943 template <
typename First,
typename Func>
944 const Self&
with(
const Func& func)
const {
955 template <
typename Func>
956 const Self&
with(entity_t
first,
const Func& func)
const {
958 ecs_pair(
first, this->id_));
965 template <
typename Func>
966 const Self&
scope(
const Func& func)
const {
980 const Self& set_name(
const char *
name)
const {
987 const Self& set_alias(
const char *
name)
const {
1007 const Self& to_base()
const {
1008 return *
static_cast<const 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.
const ecs_type_info_t * ecs_get_type_info(const ecs_world_t *world, ecs_id_t id)
Get the type for an id.
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.
void 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_AUTO_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.
const Self & emplace_auto_override(Args &&... args) const
Emplace pair, mark pair for auto-overriding.
const Self & disable() const
Disable an entity.
const Self & add(E value) const
Add pair for enum constant.
const Self & set(Second constant, const First &value) const
Set a pair for an entity.
const Self & auto_override(flecs::entity_t second) const
Mark pair for auto-overriding.
const Self & enable(flecs::id_t second) const
Enable a pair.
const Self & remove(Second constant) const
Remove a pair.
const Self & remove(entity_t first, entity_t second) const
Remove a pair.
const Self & add_if(bool cond, E constant) const
Conditional add.
const Self & remove(Second second) const
Remove a pair.
const Self & emplace(Args &&... args) const
Emplace component.
const Self & set_auto_override(flecs::entity_t second, const First &val) const
Set pair, mark component for auto-overriding.
const Self & disable(flecs::id_t first, flecs::id_t second) const
Disable a pair.
const Self & emplace_auto_override(Args &&... args) const
Emplace component, mark component for auto-overriding.
const Self & add() const
Add a pair.
const Self & is_a() const
Shortcut for add(IsA, entity).
const Self & enable() const
Enable an entity.
const Self & remove_second(flecs::entity_t first) const
Removes a pair.
const Self & slot_of(entity_t second) const
Shortcut for add(SlotOf, entity).
const Self & auto_override() const
Mark component for auto-overriding.
const Self & enable() const
Enable a component.
scoped_world scope() const
Return world scoped to entity.
const Self & child_of() const
Shortcut for add(ChildOf, entity).
const Self & set(A &&value) const
Set a pair for an entity.
const Self & set_auto_override(A &&val) const
Set component, mark component for auto-overriding.
const Self & enable() const
Enable a pair.
const Self & enable(flecs::id_t first, flecs::id_t second) const
Enable a pair.
const Self & disable(flecs::id_t id) const
Disable an id.
const Self & slot() const
Shortcut for add(SlotOf, target(ChildOf)).
const Self & set(Second second, const First &value) const
Set a pair for an entity.
const Self & add_if(bool cond) const
Conditional add.
const Self & is_a(entity_t second) const
Shortcut for add(IsA, entity).
const Self & add(Second constant) const
Add a pair.
const Self & depends_on(E second) const
Shortcut for add(DependsOn, entity).
const Self & add_if(bool cond, flecs::entity_t first, flecs::entity_t second) const
Conditional add.
const Self & set_second(entity_t first, Second &&value) const
Set a pair for an entity.
const Self & set_auto_override(T &&val) const
Set component, mark component for auto-overriding.
const Self & add_if(bool cond) const
Conditional add.
const Self & remove() const
Remove a component from an entity.
const Self & disable() const
Disable a component.
const Self & add(id_t component) const
Add an entity to an entity.
const Self & add(entity_t first, entity_t second) const
Add a pair.
const Self & with(entity_t first, const Func &func) const
Entities created in function will have (first, this).
const Self & set(Second second, First &&value) const
Set a pair for an entity.
const Self & insert(const Func &func) const
Set 1..N components.
const Self & scope(const Func &func) const
The function will be ran with the scope set to the current entity.
const Self & add_if(bool cond, flecs::entity_t second) const
Conditional add.
const Self & add_second(flecs::entity_t first) const
Add a pair.
const Self & add_if(bool cond, flecs::id_t component) const
Conditional add.
const Self & with(const Func &func) const
Entities created in function will have (First, this).
const Self & disable(flecs::id_t second) const
Disable a pair.
const Self & set_auto_override(const T &val) const
Set component, mark component for auto-overriding.
const Self & remove(entity_t entity) const
Remove an entity from an entity.
const Self & set_auto_override(flecs::entity_t second, First &&val) const
Set pair, mark component for auto-overriding.
const Self & enable(flecs::id_t id, bool toggle=true) const
Enable an id.
const Self & child_of(entity_t second) const
Shortcut for add(ChildOf, entity).
const Self & depends_on(entity_t second) const
Shortcut for add(DependsOn, entity).
const Self & depends_on() const
Shortcut for add(DependsOn, entity).
const Self & auto_override(flecs::id_t id) const
Mark id for auto-overriding.
const Self & set(const A &value) const
Set a pair for an entity.
const Self & disable() const
Disable a pair.
const Self & auto_override(flecs::entity_t first, flecs::entity_t second) const
Mark pair for auto-overriding.
const Self & auto_override() const
Mark pair for auto-overriding.
const Self & slot_of() const
Shortcut for add(SlotOf, entity).
const Self & add() const
Add a component to an entity.
const Self & add(Second second) const
Add a pair.
const Self & set_auto_override(const A &val) const
Set component, mark component for auto-overriding.
const Self & with(const Func &func) const
Entities created in function will have the current entity.
const Self & set_second(entity_t first, const Second &value) const
Set a pair for an entity.
flecs::string_view name() const
Return the entity name.
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.