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 && !std::is_same<First, 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>
324 ecs_remove_pair(this->world_, this->id_,
first,
second);
334 template<
typename First,
typename Second>
345 template<typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
356 template<
typename Second>
367 template<typename First, typename Second, if_t< is_enum<Second>::value > = 0>
368 const Self&
remove(Second constant)
const {
369 const auto& et = enum_type<Second>(this->world_);
371 return this->remove<First>(
second);
400 template <
typename T>
411 template <
typename First>
422 template <
typename First,
typename Second>
433 template <
typename T>
435 this->auto_override<T>();
436 return this->set<T>(val);
445 template <
typename T>
447 this->auto_override<T>();
448 return this->set<T>(FLECS_FWD(val));
458 template <
typename First>
460 this->auto_override<First>(
second);
461 return this->set<First>(
second, val);
471 template <
typename First>
473 this->auto_override<First>(
second);
474 return this->set<First>(
second, FLECS_FWD(val));
484 template <
typename First,
typename Second,
typename P = pair<First, Second>,
485 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
487 this->auto_override<First, Second>();
488 return this->set<First, Second>(val);
498 template <
typename First,
typename Second,
typename P = pair<First, Second>,
499 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
501 this->auto_override<First, Second>();
502 return this->set<First, Second>(FLECS_FWD(val));
511 template <
typename T,
typename ... Args>
513 this->auto_override<T>();
515 flecs::emplace<T>(this->world_, this->id_,
528 template <
typename First,
typename Second,
typename P = pair<First, Second>,
529 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0,
532 this->auto_override<First, Second>();
534 flecs::emplace<A>(this->world_, this->id_,
569 const Self&
enable(flecs::id_t
id,
bool toggle =
true)
const {
600 template<
typename First>
611 template<
typename First,
typename Second>
626 return this->
enable(
id,
false);
655 template<
typename First>
666 template<
typename First,
typename Second>
671 const Self& set_ptr(entity_t comp,
size_t size,
const void *ptr)
const {
672 ecs_set_id(this->world_, this->id_, comp, size, ptr);
676 const Self& set_ptr(entity_t comp,
const void *ptr)
const {
681 ecs_assert(cptr != NULL, ECS_INVALID_PARAMETER, NULL);
683 return set_ptr(comp, cptr->
size, ptr);
686 template<typename T, if_t<is_actual<T>::value> = 0 >
687 const Self& set(T&& value)
const {
688 flecs::set<T>(this->world_, this->id_, FLECS_FWD(value));
692 template<typename T, if_t<is_actual<T>::value > = 0>
693 const Self& set(
const T& value)
const {
694 flecs::set<T>(this->world_, this->id_, value);
698 template<
typename T,
typename A = actual_type_t<T>, if_not_t<
699 is_actual<T>::value > = 0>
700 const Self& set(A&& value)
const {
701 flecs::set<T>(this->world_, this->id_, FLECS_FWD(value));
705 template<
typename T,
typename A = actual_type_t<T>, if_not_t<
706 is_actual<T>::value > = 0>
707 const Self& set(
const A& value)
const {
708 flecs::set<T>(this->world_, this->id_, value);
720 template <
typename First,
typename Second,
typename P = pair<First, Second>,
721 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
722 const Self&
set(A&& value)
const {
723 flecs::set<P>(this->world_, this->id_, FLECS_FWD(value));
735 template <
typename First,
typename Second,
typename P = pair<First, Second>,
736 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
737 const Self&
set(
const A& value)
const {
738 flecs::set<P>(this->world_, this->id_, value);
750 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
751 const Self&
set(Second
second,
const First& value)
const {
753 flecs::set(this->world_, this->id_, value,
766 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
769 flecs::set(this->world_, this->id_, FLECS_FWD(value),
782 template <typename First, typename Second, if_t< is_enum<Second>::value > = 0>
783 const Self&
set(Second constant,
const First& value)
const {
784 const auto& et = enum_type<Second>(this->world_);
786 return set<First>(
second, value);
797 template <
typename Second>
801 ECS_INVALID_PARAMETER,
"pair is not a component");
803 ECS_INVALID_PARAMETER,
"type of pair is not Second");
804 flecs::set(this->world_, this->id_, value,
817 template <
typename Second>
821 ECS_INVALID_PARAMETER,
"pair is not a component");
823 ECS_INVALID_PARAMETER,
"type of pair is not Second");
824 flecs::set(this->world_, this->id_, FLECS_FWD(value),
829 template <
typename First,
typename Second>
830 const Self&
set_second(
const Second& value)
const {
831 flecs::set<pair_object<First, Second>>(this->world_, this->id_, value);
850 template <
typename Func>
851 const Self&
insert(
const Func& func)
const;
860 template<
typename T,
typename ... Args,
typename A = actual_type_t<T>>
862 flecs::emplace<A>(this->world_, this->id_,
867 template <
typename First,
typename Second,
typename ... Args,
typename P =
pair<First, Second>,
868 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
869 const Self&
emplace(Args&&... args)
const {
870 flecs::emplace<A>(this->world_, this->id_,
877 template <
typename First,
typename ... Args>
878 const Self& emplace_first(flecs::entity_t
second, Args&&... args)
const {
879 auto first = _::type<First>::id(this->world_);
880 flecs::emplace<First>(this->world_, this->id_,
886 template <
typename Second,
typename ... Args>
887 const Self& emplace_second(flecs::entity_t
first, Args&&... args)
const {
888 auto second = _::type<Second>::id(this->world_);
890 ECS_INVALID_PARAMETER,
"pair is not a component");
892 ECS_INVALID_PARAMETER,
"type of pair is not Second");
893 flecs::emplace<Second>(this->world_, this->id_,
904 template <
typename Func>
905 const Self&
with(
const Func& func)
const {
918 template <
typename First,
typename Func>
919 const Self&
with(
const Func& func)
const {
930 template <
typename Func>
931 const Self&
with(entity_t
first,
const Func& func)
const {
933 ecs_pair(
first, this->id_));
940 template <
typename Func>
941 const Self&
scope(
const Func& func)
const {
955 const Self& set_name(
const char *
name)
const {
962 const Self& set_alias(
const char *
name)
const {
982 const Self& to_base()
const {
983 return *
static_cast<const Self*
>(
this);
component< T > & constant(const char *name, T value)
Add constant.
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 & remove() const
Remove a component from an entity.
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
Removes a pair.
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.