13template <auto Write,
typename T>
15 using A = std::remove_const_t<remove_reference_t<T>>;
17 "operation invalid for empty type");
19 A& dst = *
static_cast<A*
>(res.ptr);
20 if constexpr (std::is_copy_assignable_v<T> || std::is_const_v<remove_reference_t<T>>) {
21 dst = FLECS_FWD(value);
23 dst = FLECS_MOV(value);
26 flecs_defer_end(res.world, res.stage);
28 if (res.call_modified) {
37 _::write_component<ecs_cpp_set>(
world,
entity, FLECS_FWD(value),
id);
45template <
typename T,
typename A>
50template <
typename T,
typename A>
57 _::write_component<ecs_cpp_assign>(
world,
entity, FLECS_FWD(value),
id);
65template <
typename T,
typename A>
70template <
typename T,
typename A>
84template <
typename T,
typename ... Args,
if_t<
85 std::is_constructible<actual_type_t<T>, Args...>::value ||
86 std::is_default_constructible<actual_type_t<T>>::value > = 0>
89 "operation invalid for empty type");
92 FLECS_PLACEMENT_NEW(&dst, T{FLECS_FWD(args)...});
114 return ECS_GENERATION(e);
141 explicit world(
int argc,
char *argv[])
159 flecs_poly_claim(this->
world_);
165 this->
world_ = obj.world_;
166 flecs_poly_claim(this->
world_);
173 obj.world_ =
nullptr;
180 obj.world_ =
nullptr;
189 if (!flecs_poly_release(
world_)) {
220 flecs_poly_release(
world_);
227 "reset would invalidate other handles");
392 "flecs::world instance contains invalid reference to world or stage");
445 flecs_poly_release(as);
537 void dim(int32_t entity_count)
const {
565 template <
typename T>
585 flecs::entity lookup(
const char *name,
const char *sep =
"::",
const char *root_sep =
"::",
bool recursive =
true)
const;
588 void set(A&& value)
const {
589 auto id = _::value_id<T...>(
world_, value);
590 flecs::set(
world_,
id.owner(
world_), FLECS_FWD(value),
id.
id);
593 template <
typename... T,
typename A = _::value_type_t<T...>, if_not_t<is_callable<A>::value> = 0>
594 void set(
const A& value)
const {
595 auto id = _::value_id<T...>(
world_, value);
599 template <
typename First,
typename Second>
600 void set(Second second, First&& value)
const {
601 auto id = _::make_id<First>(
world_, second);
605 template <
typename First,
typename Second>
606 void set(Second second,
const First& value)
const {
607 auto id = _::make_id<First>(
world_, second);
613 template <typename Func, if_t< is_callable<Func>::value > = 0 >
614 void set(
const Func& func)
const;
616 template <
typename T,
typename ... Args>
617 void emplace(Args&&... args)
const {
619 flecs::emplace<T>(
world_, component_id, component_id, FLECS_FWD(args)...);
623 template <
typename... T,
typename... Args>
624 decltype(
auto) ensure(Args... args)
const {
625 auto id = _::make_id<T...>(
world_, args...);
626 return _::get_component<true, true, true>(
world_,
id.owner(
world_),
id);
630 template <
typename T>
631 void modified()
const {
632 auto id = _::make_id<T>(
world_);
634 "operation invalid for empty type");
640 template <
typename T>
644 template <typename Func, if_t<is_callable<Func>::value> = 0>
645 void get(
const Func& func)
const;
647 template <
typename... T,
typename... Args>
648 decltype(
auto) try_get(Args... args)
const {
649 auto id = _::make_id<T...>(
world_, args...);
650 return _::get_component<false, false>(
world_,
id.owner(
world_),
id);
653 template <
typename... T,
typename... Args>
654 decltype(
auto)
get(Args... args)
const {
655 auto id = _::make_id<T...>(
world_, args...);
656 return _::get_component<false, true>(
world_,
id.owner(
world_),
id);
659 template <
typename... T,
typename... Args>
660 decltype(
auto) try_get_mut(Args... args)
const {
661 auto id = _::make_id<T...>(
world_, args...);
662 return _::get_component<true, false>(
world_,
id.owner(
world_),
id);
665 template <
typename... T,
typename... Args>
666 decltype(
auto) get_mut(Args... args)
const {
667 auto id = _::make_id<T...>(
world_, args...);
668 return _::get_component<true, true>(
world_,
id.owner(
world_),
id);
671 template <
typename... T,
typename... Args>
672 bool has(Args... args)
const {
673 auto id = _::make_id<T...>(
world_, args...);
677 template <
typename... T,
typename... Args>
678 void add(Args... args)
const {
679 auto id = _::make_id<T...>(
world_, args...);
683 template <
typename... T,
typename... Args>
684 void remove(Args... args)
const {
685 auto id = _::make_id<T...>(
world_, args...);
696 template <
typename Func>
701 template <
typename T>
713 template<
typename First>
746 template <
typename T>
761 void use(flecs::entity
entity,
const char *alias =
nullptr)
const;
763 template <
typename... T,
typename... Args>
764 int count(Args... args)
const {
771 template <
typename Func>
780 template <
typename T,
typename Func>
781 void scope(
const Func& func)
const {
786 template <
typename... T,
typename... Args>
787 void delete_with(Args... args)
const {
791 template <
typename... T,
typename... Args>
792 void remove_all(Args... args)
const {
804 template <
typename Func>
805 void defer(
const Func& func)
const {
941 template <
typename T>
951 template <
typename... T,
typename... Args>
966# include "mixins/prefab/mixin.inl"
968# ifdef FLECS_ENTITY_RANGES
977# ifdef FLECS_PIPELINE
Entity ranges world mixin.
void ecs_remove_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Remove a component from an entity.
void ecs_remove_all(ecs_world_t *world, ecs_id_t component)
Remove all instances of the specified component.
#define ecs_assert(condition, error_code,...)
Assert.
#define ECS_INVALID_OPERATION
Invalid operation error code.
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
ecs_world_t * ecs_stage_new(ecs_world_t *world)
Create an unmanaged stage.
bool ecs_defer_end(ecs_world_t *world)
End a block of operations to defer.
bool ecs_readonly_begin(ecs_world_t *world, bool multi_threaded)
Begin readonly mode.
void ecs_defer_resume(ecs_world_t *world)
Resume deferring.
bool ecs_defer_begin(ecs_world_t *world)
Defer operations until the end of the 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 the current stage.
void ecs_stage_free(ecs_world_t *stage)
Free an unmanaged stage.
void ecs_merge(ecs_world_t *stage)
Merge a stage.
int32_t ecs_stage_get_id(const ecs_world_t *world)
Get the stage ID.
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 the number of configured stages.
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 the world to have N stages.
void ecs_readonly_end(ecs_world_t *world)
End readonly mode.
bool ecs_is_defer_suspended(const ecs_world_t *world)
Test if deferring is suspended for the current stage.
const ecs_type_info_t * ecs_get_type_info(const ecs_world_t *world, ecs_id_t component)
Get the type info for a component.
struct ecs_stage_t ecs_stage_t
A stage enables modification while iterating and from multiple threads.
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.
flecs::entity entity(Args &&... args) const
Create an entity.
ecs_world_info_t world_info_t
World info type.
ecs_entity_t entity_t
Entity type.
ecs_world_t world_t
World type.
ecs_type_info_t type_info_t
Type info type.
void ecs_delete_with(ecs_world_t *world, ecs_id_t component)
Delete all entities with the specified component.
int32_t ecs_count_id(const ecs_world_t *world, ecs_id_t entity)
Count entities that have the specified ID.
void(*) ecs_ctx_free_t(void *ctx)
Function to clean up context data.
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 component, size_t size, bool *is_new)
Emplace a component.
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Signal that a component has been modified.
ecs_id_t ecs_strip_generation(ecs_entity_t e)
Remove the generation from an entity ID.
bool ecs_is_valid(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is valid.
uint32_t ecs_get_version(ecs_entity_t entity)
Get the generation of an entity.
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.
void ecs_set_version(ecs_world_t *world, ecs_entity_t entity)
Override the generation of an entity.
#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 the 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 an action to be executed when the 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.
void * ecs_get_binding_ctx(const ecs_world_t *world)
Get the world binding context.
void ecs_shrink(ecs_world_t *world)
Free unused memory.
void ecs_dim(ecs_world_t *world, int32_t entity_count)
Dimension the world for a specified number of entities.
const ecs_world_info_t * ecs_get_world_info(const ecs_world_t *world)
Get the world info.
const ecs_world_t * ecs_get_world(const ecs_poly_t *poly)
Get the world from a poly.
void ecs_set_ctx(ecs_world_t *world, void *ctx, ecs_ctx_free_t ctx_free)
Set a world context.
void ecs_exclusive_access_begin(ecs_world_t *world, const char *thread_name)
Begin exclusive thread access.
void ecs_set_binding_ctx(ecs_world_t *world, void *ctx, ecs_ctx_free_t ctx_free)
Set a world binding context.
#define flecs_poly_is(object, type)
Test if a pointer is of the specified type.
void ecs_exclusive_access_end(ecs_world_t *world, bool lock_world)
End exclusive thread access.
void * ecs_get_ctx(const ecs_world_t *world)
Get the world context.
float delta_time
Time passed to or computed by ecs_progress().
bool is_stage() const
Test if this is a stage.
void shrink() const
Free unused memory.
uint32_t get_version(flecs::entity_t e) const
Get the version of the provided entity.
void merge() const
Merge world or stage.
world_t * world_
Pointer to the underlying C world.
const flecs::world_info_t * get_info() const
Get the world info.
flecs::entity get_scope() const
Get current scope.
flecs::entity lookup(const char *name, const char *sep="::", const char *root_sep="::", bool recursive=true) const
Lookup entity by name.
ecs_ftime_t delta_time() const
Get delta_time.
flecs::entity get_alive(flecs::entity_t e) const
Get alive entity for ID.
void readonly_end() const
End readonly mode.
flecs::entity make_alive(flecs::entity_t e) const
Ensure an entity ID is alive.
void exclusive_access_begin(const char *thread_name=nullptr)
Begin exclusive access.
flecs::entity target(int32_t index=0) const
Get target for a given pair from a singleton entity.
void defer(const Func &func) const
Defer all operations called in function.
bool is_alive(flecs::entity_t e) const
Check if entity is alive.
world_t * c_ptr() const
Obtain a pointer to the C world object.
bool defer_begin() const
Defer operations until end of frame.
void reset()
Delete and recreate the world.
flecs::entity_t * set_lookup_path(const flecs::entity_t *search_path) const
Set search path.
void defer_suspend() const
Suspend deferring operations.
void make_owner()
Make the current world object the owner of the world.
bool is_valid(flecs::entity_t e) const
Check if entity ID is valid.
flecs::world async_stage() const
Create an asynchronous stage.
bool is_deferred() const
Test whether deferring is enabled.
void release()
Release the underlying world object.
void * get_binding_ctx() const
Get world binding context.
int32_t get_stage_id() const
Get current stage ID.
void init_builtin_components()
Initialize built-in components.
world(const world &obj)
Copy constructor.
void scope(const Func &func) const
Same as scope(parent, func), but with T as parent.
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 a number of entities.
void set_version(flecs::entity_t e) const
Set the version of an entity to the provided value.
void set_stage_count(int32_t stages) const
Configure world to have N stages.
void * get_ctx() const
Get world context.
bool defer_end() const
End block of operations to defer.
world(world_t *w)
Create a world from a C world.
void children(Func &&f) const
Iterate entities in root of world.
flecs::world get_world() const
Get actual world.
void scope(id_t parent, const Func &func) const
All entities created in the function are created in the scope.
world(world &&obj) noexcept
Move constructor.
world & operator=(const world &obj) noexcept
Copy assignment operator.
flecs::id_t id_if_registered()
Return the component ID if it has been registered.
flecs::entity use(const char *alias=nullptr) const
Create an alias for a component.
bool is_readonly() const
Test whether the current world object is readonly.
bool readonly_begin(bool multi_threaded=false) const
Begin readonly mode.
void get(const Func &func) const
Get a singleton component using a callback.
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
bool exists(flecs::entity_t e) const
Check if entity ID exists in the world.
void set_binding_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world binding context.
void atfini(ecs_fini_action_t action, void *ctx=nullptr) const
Register action to be executed when world is destroyed.
int32_t get_stage_count() const
Get the number of configured stages.
flecs::entity singleton() const
Get singleton entity for type.
void exclusive_access_end(bool lock_world=false)
End exclusive access.
void set_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world context.
bool is_defer_suspended() const
Test whether deferring is suspended.
world(int argc, char *argv[])
Create a world with command-line arguments.
world & operator=(world &&obj) noexcept
Move assignment operator.
ref< T > get_ref() const
Get ref singleton component.
flecs::entity entity(Args &&... args) const
Create an entity.
System module world mixin.
enable_if_t< false==V, int > if_not_t
Convenience enable_if alias for negated conditions.
enable_if_t< V, int > if_t
Convenience enable_if alias using int as default type.
flecs::id_t strip_generation(flecs::entity_t e)
Return the ID without generation.
uint32_t get_generation(flecs::entity_t e)
Return the entity generation.
void emplace(world_t *world, flecs::entity_t entity, flecs::id_t id, Args &&... args)
Emplace a component value, constructing it in place.