14template <typename T, if_t< is_flecs_constructible<T>::value > = 0>
15inline void set(world_t *world, flecs::entity_t entity, T&& value, flecs::id_t
id) {
16 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
19 dst = FLECS_MOV(value);
25template <typename T, if_t< is_flecs_constructible<T>::value > = 0>
26inline void set(world_t *world, flecs::entity_t entity,
const T& value, flecs::id_t
id) {
27 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
36template <typename T, if_not_t< is_flecs_constructible<T>::value > = 0>
37inline void set(world_t *world, flecs::entity_t entity, T&& value, flecs::id_t
id) {
38 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
40 T& dst = *
static_cast<remove_reference_t<T>*
>(
ecs_get_mut_id(world, entity,
id));
42 dst = FLECS_MOV(value);
48template <typename T, if_not_t< is_flecs_constructible<T>::value > = 0>
49inline void set(world_t *world, flecs::entity_t entity,
const T& value, flecs::id_t
id) {
50 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
59template <
typename T,
typename ... Args, if_t<
60 std::is_constructible<actual_type_t<T>, Args...>::value ||
61 std::is_default_constructible<actual_type_t<T>>::value > = 0>
62inline void emplace(world_t *world, flecs::entity_t entity, flecs::id_t
id, Args&&... args) {
63 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
66 FLECS_PLACEMENT_NEW(&dst, T{FLECS_FWD(args)...});
72template <
typename T,
typename A>
73inline void set(world_t *world, entity_t entity, A&& value) {
74 id_t
id = _::cpp_type<T>::id(world);
75 flecs::set(world, entity, FLECS_FWD(value),
id);
79template <
typename T,
typename A>
80inline void set(world_t *world, entity_t entity,
const A& value) {
81 id_t
id = _::cpp_type<T>::id(world);
82 flecs::set(world, entity, value,
id);
96 return ECS_GENERATION(e);
118 , m_owned( true ) { init_builtin_components(); }
124 explicit world(
int argc,
char *argv[])
126 , m_owned( true ) { init_builtin_components(); }
132 , m_owned( false ) { }
139 m_world = obj.m_world;
140 m_owned = obj.m_owned;
141 obj.m_world =
nullptr;
146 operator world_t*()
const {
return m_world; }
155 m_world = obj.m_world;
156 m_owned = obj.m_owned;
157 obj.m_world =
nullptr;
166 if (m_owned && m_world) {
174 ecs_assert(this->m_owned, ECS_INVALID_OPERATION, NULL);
338 ecs_poly_is(m_world, ecs_stage_t),
339 ECS_INVALID_PARAMETER, NULL);
340 return ecs_poly_is(m_world, ecs_stage_t);
412 result.m_owned =
true;
425 m_world ?
const_cast<flecs::world_t*
>(
ecs_get_world(m_world)) :
nullptr);
461 void dim(int32_t entity_count)
const {
462 ecs_dim(m_world, entity_count);
505 template <
typename T>
522 template <typename T, if_t< !is_callable<T>::value > = 0>
523 void set(
const T& value)
const {
529 template <typename T, if_t< !is_callable<T>::value > = 0>
530 void set(T&& value)
const {
537 template <
typename First,
typename Second,
typename P = flecs::pair<First, Second>,
538 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
539 void set(
const A& value)
const {
545 template <
typename First,
typename Second,
typename P = flecs::pair<First, Second>,
546 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
547 void set(A&& value)
const {
553 template <
typename First,
typename Second>
554 void set(Second second,
const First& value)
const;
558 template <
typename First,
typename Second>
559 void set(Second second, First&& value)
const;
563 template <typename Func, if_t< is_callable<Func>::value > = 0 >
564 void set(
const Func& func)
const;
566 template <
typename T,
typename ... Args>
567 void emplace(Args&&... args)
const {
569 flecs::emplace<T>(m_world, component_id, component_id,
575 template <
typename T>
580 template <
typename T>
585 template <
typename T>
590 template <
typename T>
591 const T*
get()
const;
595 template <
typename First,
typename Second,
typename P = flecs::pair<First, Second>,
596 typename A = actual_type_t<P>>
597 const A*
get()
const;
601 template <
typename First,
typename Second>
602 const First*
get(Second second)
const;
606 template <typename Func, if_t< is_callable<Func>::value > = 0 >
607 void get(
const Func& func)
const;
611 template <
typename T>
619 template <
typename First,
typename Second>
627 template <
typename First>
628 bool has(flecs::id_t second)
const;
635 bool has(flecs::id_t first, flecs::id_t second)
const;
639 template <
typename T>
647 template <
typename First,
typename Second>
655 template <
typename First>
656 void add(flecs::entity_t second)
const;
663 void add(flecs::entity_t first, flecs::entity_t second)
const;
667 template <
typename T>
675 template <
typename First,
typename Second>
683 template <
typename First>
684 void remove(flecs::entity_t second)
const;
691 void remove(flecs::entity_t first, flecs::entity_t second)
const;
697 template <
typename Func>
702 template <
typename T>
713 template<
typename First>
743 template <
typename T>
764 int count(flecs::id_t component_id)
const {
773 int count(flecs::entity_t first, flecs::entity_t second)
const {
781 template <
typename T>
791 template <
typename First>
792 int count(flecs::entity_t second)
const {
801 template <
typename First,
typename Second>
810 template <
typename Func>
811 void with(id_t with_id,
const Func& func)
const {
819 template <
typename T,
typename Func>
820 void with(
const Func& func)
const {
826 template <
typename First,
typename Second,
typename Func>
827 void with(
const Func& func)
const {
833 template <
typename First,
typename Func>
834 void with(id_t second,
const Func& func)
const {
840 template <
typename Func>
841 void with(id_t first, id_t second,
const Func& func)
const {
842 with(ecs_pair(first, second), func);
848 template <
typename Func>
849 void scope(id_t parent,
const Func& func)
const {
857 template <
typename T,
typename Func>
858 void scope(
const Func& func)
const {
868 template <
typename T>
882 template <
typename T>
888 template <
typename First,
typename Second>
904 template <
typename T>
910 template <
typename First,
typename Second>
918 template <
typename Func>
919 void defer(
const Func& func)
const {
1010# ifdef FLECS_PIPELINE
1013# ifdef FLECS_SNAPSHOT
1037# ifdef FLECS_METRICS
1038# include "mixins/metrics/mixin.inl"
1041# include "mixins/alerts/mixin.inl"
1045 void init_builtin_components();
1057 flecs::entity_t s) :
world(
nullptr)
1069 m_prev_scope = obj.m_prev_scope;
1070 m_world = obj.m_world;
1071 m_owned = obj.m_owned;
1074 flecs::entity_t m_prev_scope;
ecs_entity_t ecs_set_with(ecs_world_t *world, ecs_id_t id)
Set current with id.
void ecs_remove_all(ecs_world_t *world, ecs_id_t id)
Remove all instances of the specified id.
#define ecs_assert(condition, error_code,...)
Assert.
bool ecs_defer_end(ecs_world_t *world)
End block of operations to defer.
void ecs_defer_resume(ecs_world_t *world)
Resume deferring.
bool ecs_defer_begin(ecs_world_t *world)
Defer operations until end of frame.
void ecs_defer_suspend(ecs_world_t *world)
Suspend deferring but do not flush queue.
bool ecs_is_deferred(const ecs_world_t *world)
Test if deferring is enabled for current stage.
bool ecs_stage_is_async(ecs_world_t *stage)
Test whether provided stage is asynchronous.
void ecs_merge(ecs_world_t *world)
Merge world or stage.
void ecs_async_stage_free(ecs_world_t *stage)
Free asynchronous stage.
void ecs_set_automerge(ecs_world_t *world, bool automerge)
Enable/disable automerging for world or stage.
ecs_world_t * ecs_async_stage_new(ecs_world_t *world)
Create asynchronous stage.
bool ecs_stage_is_readonly(const ecs_world_t *world)
Test whether the current world is readonly.
int32_t ecs_get_stage_count(const ecs_world_t *world)
Get number of configured stages.
bool ecs_readonly_begin(ecs_world_t *world)
Begin readonly mode.
ecs_world_t * ecs_get_stage(const ecs_world_t *world, int32_t stage_id)
Get stage-specific world pointer.
void ecs_set_stage_count(ecs_world_t *world, int32_t stages)
Configure world to have N stages.
void ecs_readonly_end(ecs_world_t *world)
End readonly mode.
int32_t ecs_get_stage_id(const ecs_world_t *world)
Get current stage id.
ecs_id_t ecs_entity_t
An entity identifier.
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
void ecs_delete_with(ecs_world_t *world, ecs_id_t id)
Delete all entities with the specified id.
int32_t ecs_count_id(const ecs_world_t *world, ecs_id_t entity)
Count entities that have the specified id.
void(* ecs_fini_action_t)(ecs_world_t *world, void *ctx)
Action callback on world exit.
void * ecs_emplace_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Emplace a component.
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Signal that a component has been modified.
void * ecs_get_mut_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get a mutable pointer to a component.
ecs_id_t ecs_strip_generation(ecs_entity_t e)
Remove generation from entity id.
bool ecs_is_valid(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is valid.
bool ecs_exists(const ecs_world_t *world, ecs_entity_t entity)
Test whether an entity exists.
bool ecs_is_alive(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is alive.
#define ecs_ftime_t
Customizable precision for scalar time values.
ecs_entity_t * ecs_set_lookup_path(ecs_world_t *world, const ecs_entity_t *lookup_path)
Set search path for lookup operations.
ecs_entity_t ecs_set_scope(ecs_world_t *world, ecs_entity_t scope)
Set the current scope.
void ecs_atfini(ecs_world_t *world, ecs_fini_action_t action, void *ctx)
Register action to be executed when world is destroyed.
int ecs_fini(ecs_world_t *world)
Delete a world.
ecs_world_t * ecs_init(void)
Create a new world.
ecs_world_t * ecs_init_w_args(int argc, char *argv[])
Create a new world with arguments.
float ecs_frame_begin(ecs_world_t *world, float delta_time)
Begin frame.
void ecs_run_post_frame(ecs_world_t *world, ecs_fini_action_t action, void *ctx)
Register action to be executed once after frame.
bool ecs_should_quit(const ecs_world_t *world)
Return whether a quit has been signaled.
void ecs_quit(ecs_world_t *world)
Signal exit This operation signals that the application should quit.
void ecs_frame_end(ecs_world_t *world)
End frame.
void ecs_set_context(ecs_world_t *world, void *ctx)
Set a world context.
void ecs_dim(ecs_world_t *world, int32_t entity_count)
Dimension the world for a specified number of entities.
void ecs_set_entity_range(ecs_world_t *world, ecs_entity_t id_start, ecs_entity_t id_end)
Set a range for issueing new entity ids.
const ecs_world_info_t * ecs_get_world_info(const ecs_world_t *world)
Get world info.
const ecs_world_t * ecs_get_world(const ecs_poly_t *poly)
Get world from poly.
void * ecs_get_context(const ecs_world_t *world)
Get the world context.
bool ecs_enable_range_check(ecs_world_t *world, bool enable)
Enable/disable range limits.
Type that contains information about the world.
Class that wraps around a flecs::id_t.
bool is_stage() const
Test if is a stage.
void delete_with() const
Delete all entities with specified component.
void set_automerge(bool automerge) const
Enable/disable automerging for world or stage.
void remove_all(id_t the_id) const
Remove all instances of specified id.
void merge() const
Merge world or stage.
void delete_with(id_t the_id) const
Delete all entities with specified id.
const flecs::world_info_t * get_info() const
Get the world info.
flecs::entity get_scope() const
Get current scope.
T * get_mut() const
Get mut singleton component.
void remove() const
Remove singleton component.
void set(A &&value) const
Set singleton pair.
void quit() const
Signal application should quit.
flecs::entity get_alive(flecs::entity_t e) const
Get alive entity for id.
void set_entity_range(entity_t min, entity_t max) const
Set entity range.
void readonly_end() const
End staging.
void with(const Func &func) const
All entities created in function are created with pair.
int count() const
Count entities matching a component.
flecs::entity target(int32_t index=0) const
Get target for a given pair from a singleton entity.
const T * get() const
Get singleton component.
void defer(const Func &func) const
Defer all operations called in function.
bool should_quit() const
Test if quit() has been called.
bool is_alive(flecs::entity_t e) const
Check if entity id exists in the world.
void * get_context() const
Get world context.
world_t * c_ptr() const
Obtain pointer to C world object.
bool defer_begin() const
Defer operations until end of frame.
void reset()
Deletes and recreates the world.
flecs::entity lookup(const char *name) const
Lookup entity by name.
flecs::entity_t * set_lookup_path(const flecs::entity_t *search_path) const
Set search path.
void defer_suspend() const
Suspend deferring operations.
void set(const A &value) const
Set singleton pair.
bool is_valid(flecs::entity_t e) const
Check if entity id is valid.
flecs::world async_stage() const
Create asynchronous stage.
bool is_deferred() const
Test whether deferring is enabled.
world & operator=(const world &obj)=delete
Not allowed to copy a world.
int32_t get_stage_id() const
Get current stage id.
void scope(const Func &func) const
Same as scope(parent, func), but with T as parent.
bool readonly_begin() const
Begin staging.
void defer_resume() const
Resume deferring operations.
flecs::entity set_scope() const
Same as set_scope but with type.
void dim(int32_t entity_count) const
Preallocate memory for number of entities.
void set_stage_count(int32_t stages) const
Configure world to have N stages.
void with(id_t with_id, const Func &func) const
All entities created in function are created with id.
void set_context(void *ctx) const
Set world context.
world(const world &obj)=delete
Not allowed to copy a world.
int count() const
Count entities matching a pair.
void remove_all() const
Remove all instances of specified pair.
bool defer_end() const
End block of operations to defer.
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
world(world_t *w)
Create world from C world.
void children(Func &&f) const
Iterate entities in root of world Accepts a callback with the following signature: void(*)(flecs::ent...
flecs::world get_world() const
Get actual world.
void atfini(ecs_fini_action_t action, void *ctx) const
Register action to be executed when world is destroyed.
flecs::entity ensure(flecs::entity_t e) const
Ensures that entity with provided generation is alive.
void scope(id_t parent, const Func &func) const
All entities created in function are created in scope.
void with(const Func &func) const
All entities created in function are created with type.
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
void modified() const
Mark singleton component as modified.
int count(flecs::entity_t second) const
Count entities matching a pair.
ecs_ftime_t frame_begin(float delta_time=0) const
Begin frame.
flecs::entity use(const char *alias=nullptr) const
Create alias for component.
bool is_readonly() const
Test whether the current world object is readonly.
void add() const
Add singleton component.
void set(const T &value) const
Set singleton component.
void with(id_t first, id_t second, const Func &func) const
All entities created in function are created with pair.
void enable_range_check(bool enabled) const
Enforce that operations cannot modify entities outside of range.
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
void set(T &&value) const
Set singleton component.
bool has() const
Test if world has singleton component.
bool exists(flecs::entity_t e) const
Check if entity id exists in the world.
void frame_end() const
End frame.
int32_t get_stage_count() const
Get number of configured stages.
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
void delete_with() const
Delete all entities with specified pair.
flecs::entity singleton() const
Get singleton entity for type.
void with(id_t second, const Func &func) const
All entities created in function are created with pair.
world(int argc, char *argv[])
Create world with command line arguments.
int count(flecs::id_t component_id) const
Count entities matching a component.
void remove_all() const
Remove all instances of specified component.
ref< T > get_ref() const
Get ref singleton component.
System module world mixin.
flecs::id_t strip_generation(flecs::entity_t e)
Return id without generation.
uint32_t get_generation(flecs::entity_t e)
Return entity generation.