24 "operation invalid for empty type");
26 ecs_cpp_get_mut_t res = ecs_cpp_set(
world,
entity,
id, &value,
sizeof(T));
28 T& dst = *
static_cast<remove_reference_t<T>*
>(res.ptr);
29 if constexpr (std::is_copy_assignable_v<T>) {
30 dst = FLECS_FWD(value);
32 dst = FLECS_MOV(value);
36 flecs_defer_end(res.world, res.stage);
39 if (res.call_modified) {
55 "operation invalid for empty type");
57 ecs_cpp_get_mut_t res = ecs_cpp_set(
world,
entity,
id, &value,
sizeof(T));
59 T& dst = *
static_cast<remove_reference_t<T>*
>(res.ptr);
63 flecs_defer_end(res.world, res.stage);
66 if (res.call_modified) {
79template <
typename T,
typename A>
93template <
typename T,
typename A>
113 ecs_cpp_get_mut_t res = ecs_cpp_assign(
116 T& dst = *
static_cast<remove_reference_t<T>*
>(res.ptr);
117 if constexpr (std::is_copy_assignable_v<T>) {
118 dst = FLECS_FWD(value);
120 dst = FLECS_MOV(value);
124 flecs_defer_end(res.world, res.stage);
127 if (res.call_modified) {
146 ecs_cpp_get_mut_t res = ecs_cpp_assign(
149 T& dst = *
static_cast<remove_reference_t<T>*
>(res.ptr);
153 flecs_defer_end(res.world, res.stage);
156 if (res.call_modified) {
169template <
typename T,
typename A>
183template <
typename T,
typename A>
199template <
typename T,
typename ... Args, if_t<
200 std::is_constructible<actual_type_t<T>, Args...>::value ||
201 std::is_default_constructible<actual_type_t<T>>::value > = 0>
204 "operation invalid for empty type");
207 FLECS_PLACEMENT_NEW(&dst, T{FLECS_FWD(args)...});
229 return ECS_GENERATION(e);
258 explicit world(
int argc,
char *argv[])
276 flecs_poly_claim(this->
world_);
282 this->
world_ = obj.world_;
283 flecs_poly_claim(this->
world_);
290 obj.world_ =
nullptr;
297 obj.world_ =
nullptr;
306 if (!flecs_poly_release(
world_)) {
337 flecs_poly_release(
world_);
344 "reset would invalidate other handles");
560 "flecs::world instance contains invalid reference to world or stage");
613 flecs_poly_release(as);
705 void dim(int32_t entity_count)
const {
759 template <
typename T>
779 flecs::entity lookup(
const char *name,
const char *sep =
"::",
const char *root_sep =
"::",
bool recursive =
true)
const;
783 template <typename T, if_t< !is_callable<T>::value > = 0>
784 void set(
const T& value)
const {
790 template <typename T, if_t< !is_callable<T>::value > = 0>
791 void set(T&& value)
const {
798 template <
typename First,
typename Second,
typename P = flecs::pair<First, Second>,
799 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
800 void set(
const A& value)
const {
806 template <
typename First,
typename Second,
typename P = flecs::pair<First, Second>,
807 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
808 void set(A&& value)
const {
814 template <
typename First,
typename Second>
815 void set(Second second,
const First& value)
const;
819 template <
typename First,
typename Second>
820 void set(Second second, First&& value)
const;
824 template <typename Func, if_t< is_callable<Func>::value > = 0 >
825 void set(
const Func& func)
const;
827 template <
typename T,
typename ... Args>
828 void emplace(Args&&... args)
const {
830 flecs::emplace<T>(
world_, component_id, component_id, FLECS_FWD(args)...);
836 template <
typename T>
842 template <
typename T>
847 template <
typename T>
863 template <
typename T>
868 template <
typename First,
typename Second,
typename P = flecs::pair<First, Second>,
869 typename A = actual_type_t<P>>
874 template <
typename First,
typename Second>
875 const First*
try_get(Second second)
const;
888 template <
typename T>
889 const T&
get()
const;
893 template <
typename First,
typename Second,
typename P = flecs::pair<First, Second>,
894 typename A = actual_type_t<P>>
895 const A&
get()
const;
899 template <
typename First,
typename Second>
900 const First&
get(Second second)
const;
904 template <typename Func, if_t< is_callable<Func>::value > = 0 >
905 void get(
const Func& func)
const;
918 template <
typename T>
923 template <
typename First,
typename Second,
typename P = flecs::pair<First, Second>,
924 typename A = actual_type_t<P>>
929 template <
typename First,
typename Second>
943 template <
typename T>
948 template <
typename First,
typename Second,
typename P = flecs::pair<First, Second>,
949 typename A = actual_type_t<P>>
954 template <
typename First,
typename Second>
955 First&
get_mut(Second second)
const;
963 template <
typename T>
972 template <
typename First,
typename Second>
981 template <
typename First>
998 template <typename E, if_t< is_enum<E>::value > = 0>
999 bool has(E value)
const;
1003 template <
typename T>
1011 template <
typename First,
typename Second>
1019 template <
typename First>
1034 template <typename E, if_t< is_enum<E>::value > = 0>
1035 void add(E value)
const;
1039 template <
typename T>
1047 template <
typename First,
typename Second>
1055 template <
typename First>
1072 template <
typename Func>
1077 template <
typename T>
1089 template<
typename First>
1102 template<
typename T>
1122 template <
typename T>
1163 template <
typename T>
1174 template <
typename First>
1185 template <
typename First,
typename Second>
1194 template <
typename Func>
1203 template <
typename T,
typename Func>
1204 void with(
const Func& func)
const {
1210 template <
typename First,
typename Second,
typename Func>
1211 void with(
const Func& func)
const {
1217 template <
typename First,
typename Func>
1224 template <
typename Func>
1226 with(ecs_pair(first, second), func);
1232 template <
typename Func>
1241 template <
typename T,
typename Func>
1244 scope(parent, func);
1252 template <
typename T>
1268 template <
typename T>
1274 template <
typename First,
typename Second>
1280 template <
typename First>
1296 template <
typename T>
1302 template <
typename First,
typename Second>
1308 template <
typename First>
1321 template <
typename Func>
1463 template <
typename T>
1484 template <
typename T>
1490 template <
typename R>
1496 template <
typename R,
typename T>
1513# ifdef FLECS_PIPELINE
1534# ifdef FLECS_METRICS
1573 flecs_poly_claim(
world_);
void ecs_remove_all(ecs_world_t *world, ecs_id_t component)
Remove all instances of the specified component.
ecs_entity_t ecs_set_with(ecs_world_t *world, ecs_id_t component)
Create new entities with a 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.
uint64_t ecs_id_t
IDs are the things that can be added to an entity.
flecs::entity entity(Args &&... args) const
Create an entity.
ecs_entity_t entity_t
Entity type.
ecs_world_t world_t
World 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_fini_action_t)(ecs_world_t *world, void *ctx)
Action callback on world exit.
void(* ecs_ctx_free_t)(void *ctx)
Function to clean up context data.
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.
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 an action to be executed once after the frame.
bool ecs_should_quit(const ecs_world_t *world)
Return whether a quit has been requested.
void ecs_quit(ecs_world_t *world)
Signal exit.
void ecs_frame_end(ecs_world_t *world)
End frame.
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.
void ecs_set_entity_range(ecs_world_t *world, ecs_entity_t id_start, ecs_entity_t id_end)
Set a range for issuing new entity IDs.
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.
bool ecs_enable_range_check(ecs_world_t *world, bool enable)
Enable or disable range limits.
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.
Type that contains component information (passed to ctors/dtors/...).
Type that contains information about the world.
float delta_time
Time passed to or computed by ecs_progress().
Class that wraps around a flecs::id_t.
~scoped_world()
Destructor.
scoped_world(flecs::world_t *w, flecs::entity_t s)
Create a scoped world.
flecs::entity_t prev_scope_
The previous scope entity.
scoped_world(const scoped_world &obj)
Copy constructor.
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 delete_with() const
Delete all entities with specified component.
const T & get() const
Get a singleton component.
void remove_all(id_t the_id) const
Remove all instances of specified id.
void delete_with(entity_t second) const
Delete all entities with specified pair.
void merge() const
Merge world or stage.
world_t * world_
Pointer to the underlying C world.
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 a mutable singleton component.
void remove() const
Remove singleton component.
flecs::entity lookup(const char *name, const char *sep="::", const char *root_sep="::", bool recursive=true) const
Lookup entity by name.
void set(A &&value) const
Set singleton pair.
ecs_ftime_t delta_time() const
Get delta_time.
void quit() const
Signal application should quit.
flecs::entity get_alive(flecs::entity_t e) const
Get alive entity for ID.
const flecs::type_info_t * type_info()
Return the type info.
void set_entity_range(entity_t min, entity_t max) const
Set entity range.
void readonly_end() const
End readonly mode.
void with(const Func &func) const
All entities created in the function are created with the pair.
flecs::entity make_alive(flecs::entity_t e) const
Ensure an entity ID is alive.
int count() const
Count entities matching a component.
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 should_quit() const
Test if quit() has been called.
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.
const T * try_get() const
Get singleton component.
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 set(const A &value) const
Set singleton pair.
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.
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 with(id_t with_id, const Func &func) const
All entities created in the function are created with the ID.
void * get_ctx() const
Get world context.
const flecs::type_info_t * type_info(flecs::entity_t r, flecs::entity_t t)
Return the type info.
int count() const
Count entities matching a pair.
flecs::scoped_world scope() const
Use the provided scope (by type) for operations run on the returned world.
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.
void remove_all(entity_t second) const
Remove all instances of specified pair.
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.
T * try_get_mut() const
Try to get a mutable singleton component (returns nullptr if not found).
void scope(id_t parent, const Func &func) const
All entities created in the function are created in the scope.
void with(const Func &func) const
All entities created in the function are created with the 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.
world(world &&obj) noexcept
Move constructor.
void enable_range_check(bool enabled=true) const
Enforce that operations cannot modify entities outside of range.
int count(flecs::entity_t second) const
Count entities matching a pair.
world & operator=(const world &obj) noexcept
Copy assignment operator.
flecs::entity set_scope(const flecs::entity_t scope) const
Set current scope.
flecs::id_t id_if_registered()
Return the component ID if it has been registered.
ecs_ftime_t frame_begin(float delta_time=0) const
Begin frame.
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.
void add() const
Add singleton component.
T & ensure() const
Ensure singleton component.
bool readonly_begin(bool multi_threaded=false) const
Begin readonly mode.
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 the function are created with the pair.
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.
void run_post_frame(ecs_fini_action_t action, void *ctx) const
Run callback after completing the frame.
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.
const flecs::type_info_t * type_info(flecs::id_t component)
Return the type info.
int32_t get_stage_count() const
Get the 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 exclusive_access_end(bool lock_world=false)
End exclusive access.
void with(id_t second, const Func &func) const
All entities created in the function are created with the pair.
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.
int count(flecs::id_t component_id) const
Count entities matching a component.
const flecs::type_info_t * type_info()
Return the type info.
const flecs::type_info_t * type_info(flecs::entity_t t)
Return the type info.
world & operator=(world &&obj) noexcept
Move assignment operator.
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 the ID without generation.
uint32_t get_generation(flecs::entity_t e)
Return the entity generation.
void assign(world_t *world, flecs::entity_t entity, T &&value, flecs::id_t id)
Assign a component value using move semantics.
void set(world_t *world, flecs::entity_t entity, T &&value, flecs::id_t id)
Static helper functions to assign a component value.
void emplace(world_t *world, flecs::entity_t entity, flecs::id_t id, Args &&... args)
Emplace a component value, constructing it in place.