Flecs v3.2
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
flecs::world Struct Reference

The world. More...

#include <world.hpp>

Inheritance diagram for flecs::world:
flecs::scoped_world

Public Member Functions

 world ()
 Create world. More...
 
 world (int argc, char *argv[])
 Create world with command line arguments. More...
 
 world (world_t *w)
 Create world from C world. More...
 
 world (const world &obj)=delete
 Not allowed to copy a world. More...
 
 world (world &&obj)
 
 operator world_t * () const
 
worldoperator= (const world &obj)=delete
 Not allowed to copy a world. More...
 
worldoperator= (world &&obj)
 
void reset ()
 Deletes and recreates the world. More...
 
world_t * c_ptr () const
 Obtain pointer to C world object. More...
 
ecs_ftime_t delta_time () const
 Get last delta_time. More...
 
int64_t tick () const
 Get current tick. More...
 
ecs_ftime_t time () const
 Get current simulation time. More...
 
void quit () const
 Signal application should quit. More...
 
void atfini (ecs_fini_action_t action, void *ctx) const
 Register action to be executed when world is destroyed. More...
 
bool should_quit () const
 Test if quit() has been called. More...
 
ecs_ftime_t frame_begin (float delta_time=0) const
 Begin frame. More...
 
void frame_end () const
 End frame. More...
 
bool readonly_begin () const
 Begin staging. More...
 
void readonly_end () const
 End staging. More...
 
bool defer_begin () const
 Defer operations until end of frame. More...
 
bool defer_end () const
 End block of operations to defer. More...
 
bool is_deferred () const
 Test whether deferring is enabled. More...
 
void set_stage_count (int32_t stages) const
 Configure world to have N stages. More...
 
int32_t get_stage_count () const
 Get number of configured stages. More...
 
int32_t get_stage_id () const
 Get current stage id. More...
 
bool is_stage () const
 Test if is a stage. More...
 
void set_automerge (bool automerge) const
 Enable/disable automerging for world or stage. More...
 
void merge () const
 Merge world or stage. More...
 
flecs::world get_stage (int32_t stage_id) const
 Get stage-specific world pointer. More...
 
flecs::world async_stage () const
 Create asynchronous stage. More...
 
flecs::world get_world () const
 Get actual world. More...
 
bool is_readonly () const
 Test whether the current world object is readonly. More...
 
void set_context (void *ctx) const
 Set world context. More...
 
void * get_context () const
 Get world context. More...
 
void dim (int32_t entity_count) const
 Preallocate memory for number of entities. More...
 
void set_entity_range (entity_t min, entity_t max) const
 Set entity range. More...
 
void enable_range_check (bool enabled) const
 Enforce that operations cannot modify entities outside of range. More...
 
flecs::entity set_scope (const flecs::entity_t scope) const
 Set current scope. More...
 
flecs::entity get_scope () const
 Get current scope. More...
 
template<typename T >
flecs::entity set_scope () const
 Same as set_scope but with type. More...
 
flecs::entity_t * set_lookup_path (const flecs::entity_t *search_path) const
 Set search path. More...
 
flecs::entity lookup (const char *name) const
 Lookup entity by name. More...
 
template<typename T , if_t< !is_callable< T >::value > = 0>
void set (const T &value) const
 Set singleton component. More...
 
template<typename T , if_t< !is_callable< T >::value > = 0>
void set (T &&value) const
 Set singleton component. More...
 
template<typename First , typename Second , typename P = flecs::pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
void set (const A &value) const
 Set singleton pair. More...
 
template<typename First , typename Second , typename P = flecs::pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
void set (A &&value) const
 Set singleton pair. More...
 
template<typename First , typename Second >
void set (Second second, const First &value) const
 Set singleton pair. More...
 
template<typename First , typename Second >
void set (Second second, First &&value) const
 Set singleton pair. More...
 
template<typename Func , if_t< is_callable< Func >::value > = 0>
void set (const Func &func) const
 Set singleton component inside a callback. More...
 
template<typename T , typename ... Args>
void emplace (Args &&... args) const
 
template<typename T >
T * get_mut () const
 Get mut singleton component. More...
 
template<typename T >
void modified () const
 Mark singleton component as modified. More...
 
template<typename T >
ref< T > get_ref () const
 Get ref singleton component. More...
 
template<typename T >
const T * get () const
 Get singleton component. More...
 
template<typename First , typename Second , typename P = flecs::pair<First, Second>, typename A = actual_type_t<P>>
const A * get () const
 Get singleton pair. More...
 
template<typename First , typename Second >
const First * get (Second second) const
 Get singleton pair. More...
 
template<typename Func , if_t< is_callable< Func >::value > = 0>
void get (const Func &func) const
 Get singleton component inside a callback. More...
 
template<typename T >
bool has () const
 Test if world has singleton component. More...
 
template<typename First , typename Second >
bool has () const
 Test if world has the provided pair. More...
 
template<typename First >
bool has (flecs::id_t second) const
 Test if world has the provided pair. More...
 
bool has (flecs::id_t first, flecs::id_t second) const
 Test if world has the provided pair. More...
 
template<typename T >
void add () const
 Add singleton component. More...
 
template<typename First , typename Second >
void add () const
 Adds a pair to the singleton component. More...
 
template<typename First >
void add (flecs::entity_t second) const
 Adds a pair to the singleton component. More...
 
void add (flecs::entity_t first, flecs::entity_t second) const
 Adds a pair to the singleton entity. More...
 
template<typename T >
void remove () const
 Remove singleton component. More...
 
template<typename First , typename Second >
void remove () const
 Adds a pair to the singleton component. More...
 
template<typename First >
void remove (flecs::entity_t second) const
 Adds a pair to the singleton component. More...
 
void remove (flecs::entity_t first, flecs::entity_t second) const
 Adds a pair to the singleton entity. More...
 
template<typename T >
flecs::entity singleton () const
 Get singleton entity for type. More...
 
template<typename T >
flecs::entity use (const char *alias=nullptr) const
 Create alias for component. More...
 
flecs::entity use (const char *name, const char *alias=nullptr) const
 Create alias for entity. More...
 
void use (flecs::entity entity, const char *alias=nullptr) const
 Create alias for entity. More...
 
int count (flecs::id_t component_id) const
 Count entities matching a component. More...
 
int count (flecs::entity_t first, flecs::entity_t second) const
 Count entities matching a pair. More...
 
template<typename T >
int count () const
 Count entities matching a component. More...
 
template<typename First >
int count (flecs::entity_t second) const
 Count entities matching a pair. More...
 
template<typename First , typename Second >
int count () const
 Count entities matching a pair. More...
 
template<typename Func >
void with (id_t with_id, const Func &func) const
 All entities created in function are created with id. More...
 
template<typename T , typename Func >
void with (const Func &func) const
 All entities created in function are created with type. More...
 
template<typename First , typename Second , typename Func >
void with (const Func &func) const
 All entities created in function are created with pair. More...
 
template<typename First , typename Func >
void with (id_t second, const Func &func) const
 All entities created in function are created with pair. More...
 
template<typename Func >
void with (id_t first, id_t second, const Func &func) const
 All entities created in function are created with pair. More...
 
template<typename Func >
void scope (id_t parent, const Func &func) const
 All entities created in function are created in scope. More...
 
template<typename T , typename Func >
void scope (const Func &func) const
 Same as scope(parent, func), but with T as parent. More...
 
flecs::scoped_world scope (id_t parent) const
 Use provided scope for operations ran on returned world. More...
 
template<typename T >
flecs::scoped_world scope () const
 
void delete_with (id_t the_id) const
 Delete all entities with specified id. More...
 
void delete_with (entity_t first, entity_t second) const
 Delete all entities with specified pair. More...
 
template<typename T >
void delete_with () const
 Delete all entities with specified component. More...
 
template<typename First , typename Second >
void delete_with () const
 Delete all entities with specified pair. More...
 
void remove_all (id_t the_id) const
 Remove all instances of specified id. More...
 
void remove_all (entity_t first, entity_t second) const
 Remove all instances of specified pair. More...
 
template<typename T >
void remove_all () const
 Remove all instances of specified component. More...
 
template<typename First , typename Second >
void remove_all () const
 Remove all instances of specified pair. More...
 
template<typename Func >
void defer (const Func &func) const
 Defer all operations called in function. More...
 
void defer_suspend () const
 Suspend deferring operations. More...
 
void defer_resume () const
 Resume deferring operations. More...
 
bool exists (flecs::entity_t e) const
 Check if entity id exists in the world. More...
 
bool is_alive (flecs::entity_t e) const
 Check if entity id exists in the world. More...
 
bool is_valid (flecs::entity_t e) const
 Check if entity id is valid. More...
 
flecs::entity get_alive (flecs::entity_t e) const
 Get alive entity for id. More...
 
flecs::entity ensure (flecs::entity_t e) const
 Ensures that entity with provided generation is alive. More...
 
void run_post_frame (ecs_fini_action_t action, void *ctx) const
 
void init_builtin_components ()
 
flecs::app_builder app ()
 Return app builder. More...
 
template<typename T , typename... Args>
flecs::component< T > component (Args &&... args) const
 Find or register component.
 
template<typename... Args>
flecs::untyped_component component (Args &&... args) const
 Find or register untyped component. More...
 
template<typename... Args>
flecs::entity entity (Args &&... args) const
 Create an entity.
 
template<typename E , if_t< is_enum< E >::value > = 0>
flecs::entity id (E value) const
 Convert enum constant to entity.
 
template<typename E , if_t< is_enum< E >::value > = 0>
flecs::entity entity (E value) const
 Convert enum constant to entity.
 
template<typename... Args>
flecs::entity prefab (Args &&... args) const
 Create a prefab.
 
template<typename T >
flecs::entity entity (const char *name=nullptr) const
 Create an entity that's associated with a type.
 
template<typename T >
flecs::entity prefab (const char *name=nullptr) const
 Create a prefab that's associated with a type.
 
template<typename E , if_t< is_enum< E >::value > = 0>
flecs::entity to_entity (E constant) const
 Convert enum constant to entity.
 
flecs::event_builder event (flecs::entity_t evt) const
 Create a new event. More...
 
template<typename E >
flecs::event_builder_typed< E > event () const
 Create a new event. More...
 
template<typename... Comps, typename... Args>
flecs::filter< Comps... > filter (Args &&... args) const
 Create a filter. More...
 
template<typename T >
flecs::id id () const
 
template<typename ... Args>
flecs::id id (Args &&... args) const
 
template<typename T >
flecs::id id () const
 Get id from a type.
 
template<typename ... Args>
flecs::id id (Args &&... args) const
 Id factory.
 
template<typename First , typename Second >
flecs::id pair () const
 Get pair id from relationship, object.
 
template<typename First >
flecs::id pair (entity_t o) const
 Get pair id from relationship, object.
 
flecs::id pair (entity_t r, entity_t o) const
 Get pair id from relationship, object.
 
flecs::string to_json (flecs::entity_t tid, const void *value)
 Serialize untyped value to JSON. More...
 
template<typename T >
flecs::string to_json (const T *value)
 Serialize value to JSON. More...
 
flecs::string to_json ()
 Serialize world to JSON. More...
 
template<typename T >
const char * from_json (flecs::entity_t tid, void *value, const char *json, flecs::from_json_desc_t *desc=nullptr)
 Deserialize value from JSON. More...
 
template<typename T >
const char * from_json (T *value, const char *json, flecs::from_json_desc_t *desc=nullptr)
 Deserialize value from JSON. More...
 
const char * from_json (const char *json, flecs::from_json_desc_t *desc=nullptr)
 Deserialize JSON into world. More...
 
template<typename... Args>
flecs::metric_builder metric (Args &&... args) const
 Create metric.
 
flecs::observer observer (flecs::entity e) const
 Observer builder. More...
 
flecs::pipeline_builder pipeline () const
 Create a new pipeline. More...
 
template<typename... Comps, typename... Args>
flecs::query< Comps... > query (Args &&... args) const
 Create a query. More...
 
template<typename... Comps, typename... Args>
flecs::rule< Comps... > rule (Args &&... args) const
 Create a rule. More...
 
template<typename... Args>
flecs::snapshot snapshot (Args &&... args) const
 Create a snapshot.
 
flecs::system system (flecs::entity e) const
 Upcast entity to a system. More...
 
template<typename... Args>
flecs::term term (Args &&... args) const
 Create a term.
 
template<typename... Args>
flecs::timer timer (Args &&... args) const
 Find or register a timer.
 
template<typename Kind >
untyped_componentmetric (flecs::entity_t parent=0, const char *brief=nullptr, const char *name=nullptr)
 Register member as metric. More...
 

Public Attributes

world_t * m_world
 
bool m_owned
 
flecs::string to_expr (flecs::entity_t tid, const void *value)
 Convert value to string. More...
 
template<typename T >
flecs::string to_expr (const T *value)
 Convert value to string. More...
 
flecs::cursor cursor (flecs::entity_t tid, void *ptr)
 Return meta cursor to value. More...
 
template<typename T >
flecs::cursor cursor (void *ptr)
 Return meta cursor to value. More...
 
flecs::entity primitive (flecs::meta::primitive_kind_t kind)
 Create primitive type.
 
flecs::entity array (flecs::entity_t elem_id, int32_t array_count)
 Create array type.
 
template<typename T >
flecs::entity array (int32_t array_count)
 Create array type.
 
flecs::entity vector (flecs::entity_t elem_id)
 Create vector type.
 
template<typename T >
flecs::entity vector ()
 Create vector type.
 
template<typename Module >
flecs::entity module (const char *name=nullptr) const
 Define a module. More...
 
template<typename Module >
flecs::entity import ()
 Import a module. More...
 

Detailed Description

The world.

The world is the container of all ECS data and systems. If the world is deleted, all data in the world will be deleted as well.

Definition at line 113 of file world.hpp.

Constructor & Destructor Documentation

◆ world() [1/5]

flecs::world::world ( )
inlineexplicit

Create world.

Definition at line 116 of file world.hpp.

◆ world() [2/5]

flecs::world::world ( int  argc,
char *  argv[] 
)
inlineexplicit

Create world with command line arguments.

Currently command line arguments are not interpreted, but they may be used in the future to configure Flecs parameters.

Definition at line 124 of file world.hpp.

◆ world() [3/5]

flecs::world::world ( world_t *  w)
inlineexplicit

Create world from C world.

Definition at line 130 of file world.hpp.

◆ world() [4/5]

flecs::world::world ( const world obj)
delete

Not allowed to copy a world.

May only take a reference.

◆ world() [5/5]

flecs::world::world ( world &&  obj)
inline

Definition at line 138 of file world.hpp.

◆ ~world()

flecs::world::~world ( )
inline

Definition at line 162 of file world.hpp.

Member Function Documentation

◆ add() [1/4]

template<typename T >
void flecs::world::add
inline

Add singleton component.

Definition at line 149 of file world.hpp.

◆ add() [2/4]

template<typename First , typename Second >
void flecs::world::add
inline

Adds a pair to the singleton component.

Template Parameters
FirstThe first element of the pair
SecondThe second element of the pair

Definition at line 155 of file world.hpp.

◆ add() [3/4]

void flecs::world::add ( flecs::entity_t  first,
flecs::entity_t  second 
) const
inline

Adds a pair to the singleton entity.

Parameters
firstThe first element of the pair
secondThe second element of the pair

Definition at line 166 of file world.hpp.

◆ add() [4/4]

template<typename First >
void flecs::world::add ( flecs::entity_t  second) const
inline

Adds a pair to the singleton component.

Template Parameters
FirstThe first element of the pair
Parameters
secondThe second element of the pair.

Definition at line 161 of file world.hpp.

◆ async_stage()

flecs::world flecs::world::async_stage ( ) const
inline

Create asynchronous stage.

An asynchronous stage can be used to asynchronously queue operations for later merging with the world. An asynchronous stage is similar to a regular stage, except that it does not allow reading from the world.

Asynchronous stages are never merged automatically, and must therefore be manually merged with the ecs_merge function. It is not necessary to call defer_begin or defer_end before and after enqueuing commands, as an asynchronous stage unconditionally defers operations.

The application must ensure that no commands are added to the stage while the stage is being merged.

An asynchronous stage must be cleaned up by ecs_async_stage_free.

Returns
The stage.

Definition at line 431 of file world.hpp.

◆ atfini()

void flecs::world::atfini ( ecs_fini_action_t  action,
void *  ctx 
) const
inline

Register action to be executed when world is destroyed.

Definition at line 215 of file world.hpp.

◆ c_ptr()

world_t * flecs::world::c_ptr ( ) const
inline

Obtain pointer to C world object.

Definition at line 181 of file world.hpp.

◆ count() [1/5]

template<typename T >
int flecs::world::count ( ) const
inline

Count entities matching a component.

Template Parameters
TThe component type.

Definition at line 764 of file world.hpp.

◆ count() [2/5]

template<typename First , typename Second >
int flecs::world::count ( ) const
inline

Count entities matching a pair.

Template Parameters
FirstThe first element of the pair.
SecondThe second element of the pair.

Definition at line 784 of file world.hpp.

◆ count() [3/5]

int flecs::world::count ( flecs::entity_t  first,
flecs::entity_t  second 
) const
inline

Count entities matching a pair.

Parameters
firstThe first element of the pair.
secondThe second element of the pair.

Definition at line 755 of file world.hpp.

◆ count() [4/5]

template<typename First >
int flecs::world::count ( flecs::entity_t  second) const
inline

Count entities matching a pair.

Template Parameters
FirstThe first element of the pair.
Parameters
secondThe second element of the pair.

Definition at line 774 of file world.hpp.

◆ count() [5/5]

int flecs::world::count ( flecs::id_t  component_id) const
inline

Count entities matching a component.

Parameters
component_idThe component id.

Definition at line 746 of file world.hpp.

◆ defer()

template<typename Func >
void flecs::world::defer ( const Func &  func) const
inline

Defer all operations called in function.

If the world is already in deferred mode, do nothing.

Definition at line 901 of file world.hpp.

◆ defer_begin()

bool flecs::world::defer_begin ( ) const
inline

Defer operations until end of frame.

When this operation is invoked while iterating, operations inbetween the defer_begin and defer_end operations are executed at the end of the frame.

This operation is thread safe.

Definition at line 296 of file world.hpp.

◆ defer_end()

bool flecs::world::defer_end ( ) const
inline

End block of operations to defer.

See defer_begin.

This operation is thread safe.

Definition at line 305 of file world.hpp.

◆ defer_resume()

void flecs::world::defer_resume ( ) const
inline

Resume deferring operations.

See also
ecs_defer_suspend

Definition at line 919 of file world.hpp.

◆ defer_suspend()

void flecs::world::defer_suspend ( ) const
inline

Suspend deferring operations.

See also
ecs_defer_suspend

Definition at line 911 of file world.hpp.

◆ delete_with() [1/4]

template<typename T >
void flecs::world::delete_with ( ) const
inline

Delete all entities with specified component.

Definition at line 865 of file world.hpp.

◆ delete_with() [2/4]

template<typename First , typename Second >
void flecs::world::delete_with ( ) const
inline

Delete all entities with specified pair.

Definition at line 871 of file world.hpp.

◆ delete_with() [3/4]

void flecs::world::delete_with ( entity_t  first,
entity_t  second 
) const
inline

Delete all entities with specified pair.

Definition at line 859 of file world.hpp.

◆ delete_with() [4/4]

void flecs::world::delete_with ( id_t  the_id) const
inline

Delete all entities with specified id.

Definition at line 854 of file world.hpp.

◆ delta_time()

ecs_ftime_t flecs::world::delta_time ( ) const
inline

Get last delta_time.

Definition at line 187 of file world.hpp.

◆ dim()

void flecs::world::dim ( int32_t  entity_count) const
inline

Preallocate memory for number of entities.

This function preallocates memory for the entity index.

Parameters
entity_countNumber of entities to preallocate memory for.

Definition at line 482 of file world.hpp.

◆ emplace()

template<typename T , typename ... Args>
void flecs::world::emplace ( Args &&...  args) const
inline

Definition at line 588 of file world.hpp.

◆ enable_range_check()

void flecs::world::enable_range_check ( bool  enabled) const
inline

Enforce that operations cannot modify entities outside of range.

This function ensures that only entities within the specified range can be modified. Use this function if specific parts of the code only are allowed to modify a certain set of entities, as could be the case for networked applications.

Parameters
enabledTrue if range check should be enabled, false if not.

Definition at line 504 of file world.hpp.

◆ ensure()

flecs::entity flecs::world::ensure ( flecs::entity_t  e) const
inline

Ensures that entity with provided generation is alive.

Ths operation will fail if an entity exists with the same id and a different, non-zero generation.

See also
ecs_ensure

Definition at line 220 of file world.hpp.

◆ exists()

bool flecs::world::exists ( flecs::entity_t  e) const
inline

Check if entity id exists in the world.

See also
ecs_exists

Definition at line 927 of file world.hpp.

◆ frame_begin()

ecs_ftime_t flecs::world::frame_begin ( float  delta_time = 0) const
inline

Begin frame.

When an application does not use progress() to control the main loop, it can still use Flecs features such as FPS limiting and time measurements. This operation needs to be invoked whenever a new frame is about to get processed.

Calls to frame_begin must always be followed by frame_end.

The function accepts a delta_time parameter, which will get passed to systems. This value is also used to compute the amount of time the function needs to sleep to ensure it does not exceed the target_fps, when it is set. When 0 is provided for delta_time, the time will be measured.

This function should only be ran from the main thread.

Parameters
delta_timeTime elapsed since the last frame.
Returns
The provided delta_time, or measured time if 0 was provided.

Definition at line 243 of file world.hpp.

◆ frame_end()

void flecs::world::frame_end ( ) const
inline

End frame.

This operation must be called at the end of the frame, and always after ecs_frame_begin.

This function should only be ran from the main thread.

Definition at line 253 of file world.hpp.

◆ get() [1/4]

template<typename T >
const T * flecs::world::get
inline

Get singleton component.

Definition at line 108 of file world.hpp.

◆ get() [2/4]

template<typename First , typename Second , typename P , typename A >
const A * flecs::world::get

Get singleton pair.

Definition at line 114 of file world.hpp.

◆ get() [3/4]

template<typename Func , if_t< is_callable< Func >::value > >
void flecs::world::get ( const Func &  func) const
inline

Get singleton component inside a callback.

Definition at line 200 of file world.hpp.

◆ get() [4/4]

template<typename First , typename Second >
const First * flecs::world::get ( Second  second) const

Get singleton pair.

Definition at line 120 of file world.hpp.

◆ get_alive()

flecs::entity flecs::world::get_alive ( flecs::entity_t  e) const
inline

Get alive entity for id.

Returns the entity with the current generation.

See also
ecs_get_alive

Definition at line 213 of file world.hpp.

◆ get_context()

void * flecs::world::get_context ( ) const
inline

Get world context.

Returns
The configured world context.

Definition at line 473 of file world.hpp.

◆ get_mut()

template<typename T >
T * flecs::world::get_mut
inline

Get mut singleton component.

Definition at line 78 of file world.hpp.

◆ get_ref()

template<typename T >
ref< T > flecs::world::get_ref
inline

Get ref singleton component.

Definition at line 102 of file world.hpp.

◆ get_scope()

flecs::entity flecs::world::get_scope ( ) const
inline

Get current scope.

Returns
The current scope.
See also
ecs_get_scope

Definition at line 63 of file world.hpp.

◆ get_stage()

flecs::world flecs::world::get_stage ( int32_t  stage_id) const
inline

Get stage-specific world pointer.

Flecs threads can safely invoke the API as long as they have a private context to write to, also referred to as the stage. This function returns a pointer to a stage, disguised as a world pointer.

Note that this function does not(!) create a new world. It simply wraps the existing world in a thread-specific context, which the API knows how to unwrap. The reason the stage is returned as an ecs_world_t is so that it can be passed transparently to the existing API functions, vs. having to create a dediated API for threading.

Parameters
stage_idThe index of the stage to retrieve.
Returns
A thread-specific pointer to the world.

Definition at line 410 of file world.hpp.

◆ get_stage_count()

int32_t flecs::world::get_stage_count ( ) const
inline

Get number of configured stages.

Return number of stages set by set_stage_count.

Returns
The number of stages used for threading.

Definition at line 336 of file world.hpp.

◆ get_stage_id()

int32_t flecs::world::get_stage_id ( ) const
inline

Get current stage id.

The stage id can be used by an application to learn about which stage it is using, which typically corresponds with the worker thread id.

Returns
The stage id.

Definition at line 346 of file world.hpp.

◆ get_world()

flecs::world flecs::world::get_world ( ) const
inline

Get actual world.

If the current object points to a stage, this operation will return the actual world.

Returns
The actual world.

Definition at line 443 of file world.hpp.

◆ has() [1/4]

template<typename T >
bool flecs::world::has
inline

Test if world has singleton component.

Definition at line 126 of file world.hpp.

◆ has() [2/4]

template<typename First , typename Second >
bool flecs::world::has
inline

Test if world has the provided pair.

Template Parameters
FirstThe first element of the pair
SecondThe second element of the pair

Definition at line 132 of file world.hpp.

◆ has() [3/4]

bool flecs::world::has ( flecs::id_t  first,
flecs::id_t  second 
) const
inline

Test if world has the provided pair.

Parameters
firstThe first element of the pair
secondThe second element of the pair

Definition at line 143 of file world.hpp.

◆ has() [4/4]

template<typename First >
bool flecs::world::has ( flecs::id_t  second) const
inline

Test if world has the provided pair.

Template Parameters
FirstThe first element of the pair
Parameters
secondThe second element of the pair.

Definition at line 138 of file world.hpp.

◆ id() [1/2]

template<typename T >
flecs::id flecs::world::id ( ) const
inline

Definition at line 70 of file impl.hpp.

◆ id() [2/2]

template<typename ... Args>
flecs::id flecs::world::id ( Args &&...  args) const
inline

Definition at line 75 of file impl.hpp.

◆ init_builtin_components()

void flecs::world::init_builtin_components ( )
inline

Definition at line 11 of file world.hpp.

◆ is_alive()

bool flecs::world::is_alive ( flecs::entity_t  e) const
inline

Check if entity id exists in the world.

See also
ecs_is_alive

Definition at line 935 of file world.hpp.

◆ is_deferred()

bool flecs::world::is_deferred ( ) const
inline

Test whether deferring is enabled.

Definition at line 311 of file world.hpp.

◆ is_readonly()

bool flecs::world::is_readonly ( ) const
inline

Test whether the current world object is readonly.

This function allows the code to test whether the currently used world object is readonly or whether it allows for writing.

Returns
True if the world or stage is readonly.

Definition at line 455 of file world.hpp.

◆ is_stage()

bool flecs::world::is_stage ( ) const
inline

Test if is a stage.

If this function returns false, it is guaranteed that this is a valid world object.

Returns
True if the world is a stage, false if not.

Definition at line 356 of file world.hpp.

◆ is_valid()

bool flecs::world::is_valid ( flecs::entity_t  e) const
inline

Check if entity id is valid.

Invalid entities cannot be used with API functions.

See also
ecs_is_valid

Definition at line 944 of file world.hpp.

◆ lookup()

entity flecs::world::lookup ( const char *  name) const
inline

Lookup entity by name.

Parameters
nameEntity name.

Definition at line 72 of file world.hpp.

◆ merge()

void flecs::world::merge ( ) const
inline

Merge world or stage.

When automatic merging is disabled, an application can call this operation on either an individual stage, or on the world which will merge all stages. This operation may only be called when staging is not enabled (either after progress() or after readonly_end()).

This operation may be called on an already merged stage or world.

Definition at line 392 of file world.hpp.

◆ metric()

template<typename Kind >
untyped_component & metric ( flecs::entity_t  parent = 0,
const char *  brief = nullptr,
const char *  name = nullptr 
)

Register member as metric.

When no explicit name is provided, this operation will derive the metric name from the member name. When the member name is "value", the operation will use the name of the component.

When the brief parameter is provided, it is set on the metric as if set_doc_brief is used. The brief description can be obtained with get_doc_brief.

Template Parameters
KindMetric kind (Counter, CounterIncrement or Gauge).
Parameters
parentParent entity of the metric (optional).
briefDescription for metric (optional).
nameName of metric (optional).

◆ modified()

template<typename T >
void flecs::world::modified
inline

Mark singleton component as modified.

Definition at line 84 of file world.hpp.

◆ operator world_t *()

flecs::world::operator world_t * ( ) const
inline

Definition at line 146 of file world.hpp.

◆ operator=() [1/2]

world & flecs::world::operator= ( const world obj)
delete

Not allowed to copy a world.

May only take a reference.

◆ operator=() [2/2]

world & flecs::world::operator= ( world &&  obj)
inline

Definition at line 152 of file world.hpp.

◆ quit()

void flecs::world::quit ( ) const
inline

Signal application should quit.

After calling this operation, the next call to progress() returns false.

Definition at line 209 of file world.hpp.

◆ readonly_begin()

bool flecs::world::readonly_begin ( ) const
inline

Begin staging.

When an application does not use ecs_progress to control the main loop, it can still use Flecs features such as the defer queue. When an application needs to stage changes, it needs to call this function after ecs_frame_begin. A call to ecs_readonly_begin must be followed by a call to ecs_readonly_end.

When staging is enabled, modifications to entities are stored to a stage. This ensures that arrays are not modified while iterating. Modifications are merged back to the "main stage" when ecs_readonly_end is invoked.

While the world is in staging mode, no structural changes (add/remove/...) can be made to the world itself. Operations must be executed on a stage instead (see ecs_get_stage).

This function should only be ran from the main thread.

Returns
Whether world is currently staged.

Definition at line 275 of file world.hpp.

◆ readonly_end()

void flecs::world::readonly_end ( ) const
inline

End staging.

Leaves staging mode. After this operation the world may be directly mutated again. By default this operation also merges data back into the world, unless automerging was disabled explicitly.

This function should only be ran from the main thread.

Definition at line 286 of file world.hpp.

◆ remove() [1/4]

template<typename T >
void flecs::world::remove
inline

Remove singleton component.

Definition at line 172 of file world.hpp.

◆ remove() [2/4]

template<typename First , typename Second >
void flecs::world::remove
inline

Adds a pair to the singleton component.

Template Parameters
FirstThe first element of the pair
SecondThe second element of the pair

Definition at line 178 of file world.hpp.

◆ remove() [3/4]

void flecs::world::remove ( flecs::entity_t  first,
flecs::entity_t  second 
) const
inline

Adds a pair to the singleton entity.

Parameters
firstThe first element of the pair
secondThe second element of the pair

Definition at line 189 of file world.hpp.

◆ remove() [4/4]

template<typename First >
void flecs::world::remove ( flecs::entity_t  second) const
inline

Adds a pair to the singleton component.

Template Parameters
FirstThe first element of the pair
Parameters
secondThe second element of the pair.

Definition at line 184 of file world.hpp.

◆ remove_all() [1/4]

template<typename T >
void flecs::world::remove_all ( ) const
inline

Remove all instances of specified component.

Definition at line 887 of file world.hpp.

◆ remove_all() [2/4]

template<typename First , typename Second >
void flecs::world::remove_all ( ) const
inline

Remove all instances of specified pair.

Definition at line 893 of file world.hpp.

◆ remove_all() [3/4]

void flecs::world::remove_all ( entity_t  first,
entity_t  second 
) const
inline

Remove all instances of specified pair.

Definition at line 881 of file world.hpp.

◆ remove_all() [4/4]

void flecs::world::remove_all ( id_t  the_id) const
inline

Remove all instances of specified id.

Definition at line 876 of file world.hpp.

◆ reset()

void flecs::world::reset ( )
inline

Deletes and recreates the world.

Definition at line 172 of file world.hpp.

◆ run_post_frame()

void flecs::world::run_post_frame ( ecs_fini_action_t  action,
void *  ctx 
) const
inline

Definition at line 968 of file world.hpp.

◆ scope() [1/4]

template<typename T >
flecs::scoped_world flecs::world::scope
inline

Definition at line 249 of file world.hpp.

◆ scope() [2/4]

template<typename T , typename Func >
void flecs::world::scope ( const Func &  func) const
inline

Same as scope(parent, func), but with T as parent.

Definition at line 840 of file world.hpp.

◆ scope() [3/4]

flecs::scoped_world flecs::world::scope ( id_t  parent) const
inline

Use provided scope for operations ran on returned world.

Operations need to be ran in a single statement.

Definition at line 244 of file world.hpp.

◆ scope() [4/4]

template<typename Func >
void flecs::world::scope ( id_t  parent,
const Func &  func 
) const
inline

All entities created in function are created in scope.

All operations called in function (such as lookup) are relative to scope.

Definition at line 831 of file world.hpp.

◆ set() [1/7]

template<typename First , typename Second , typename P = flecs::pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
void flecs::world::set ( A &&  value) const
inline

Set singleton pair.

Definition at line 568 of file world.hpp.

◆ set() [2/7]

template<typename First , typename Second , typename P = flecs::pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
void flecs::world::set ( const A &  value) const
inline

Set singleton pair.

Definition at line 560 of file world.hpp.

◆ set() [3/7]

template<typename Func , if_t< is_callable< Func >::value > >
void flecs::world::set ( const Func &  func) const
inline

Set singleton component inside a callback.

Definition at line 207 of file world.hpp.

◆ set() [4/7]

template<typename T , if_t< !is_callable< T >::value > = 0>
void flecs::world::set ( const T &  value) const
inline

Set singleton component.

Definition at line 544 of file world.hpp.

◆ set() [5/7]

template<typename First , typename Second >
void flecs::world::set ( Second  second,
const First &  value 
) const
inline

Set singleton pair.

Definition at line 90 of file world.hpp.

◆ set() [6/7]

template<typename First , typename Second >
void flecs::world::set ( Second  second,
First &&  value 
) const
inline

Set singleton pair.

Definition at line 96 of file world.hpp.

◆ set() [7/7]

template<typename T , if_t< !is_callable< T >::value > = 0>
void flecs::world::set ( T &&  value) const
inline

Set singleton component.

Definition at line 551 of file world.hpp.

◆ set_automerge()

void flecs::world::set_automerge ( bool  automerge) const
inline

Enable/disable automerging for world or stage.

When automerging is enabled, staged data will automatically be merged with the world when staging ends. This happens at the end of progress(), at a sync point or when readonly_end() is called.

Applications can exercise more control over when data from a stage is merged by disabling automerging. This requires an application to explicitly call merge() on the stage.

When this function is invoked on the world, it sets all current stages to the provided value and sets the default for new stages. When this function is invoked on a stage, automerging is only set for that specific stage.

Parameters
automergeWhether to enable or disable automerging.

Definition at line 380 of file world.hpp.

◆ set_context()

void flecs::world::set_context ( void *  ctx) const
inline

Set world context.

Set a context value that can be accessed by anyone that has a reference to the world.

Parameters
ctxThe world context.

Definition at line 465 of file world.hpp.

◆ set_entity_range()

void flecs::world::set_entity_range ( entity_t  min,
entity_t  max 
) const
inline

Set entity range.

This function limits the range of issued entity ids between min and max.

Parameters
minMinimum entity id issued.
maxMaximum entity id issued.

Definition at line 492 of file world.hpp.

◆ set_lookup_path()

flecs::entity_t * flecs::world::set_lookup_path ( const flecs::entity_t *  search_path) const
inline

Set search path.

Definition at line 531 of file world.hpp.

◆ set_scope() [1/2]

template<typename T >
flecs::entity flecs::world::set_scope
inline

Same as set_scope but with type.

Definition at line 68 of file world.hpp.

◆ set_scope() [2/2]

flecs::entity flecs::world::set_scope ( const flecs::entity_t  scope) const
inline

Set current scope.

Parameters
scopeThe scope to set.
Returns
The current scope;
See also
ecs_set_scope

Definition at line 59 of file world.hpp.

◆ set_stage_count()

void flecs::world::set_stage_count ( int32_t  stages) const
inline

Configure world to have N stages.

This initializes N stages, which allows applications to defer operations to multiple isolated defer queues. This is typically used for applications with multiple threads, where each thread gets its own queue, and commands are merged when threads are synchronized.

Note that set_threads() already creates the appropriate number of stages. The set_stage_count() operation is useful for applications that want to manage their own stages and/or threads.

Parameters
stagesThe number of stages.

Definition at line 327 of file world.hpp.

◆ should_quit()

bool flecs::world::should_quit ( ) const
inline

Test if quit() has been called.

Definition at line 221 of file world.hpp.

◆ singleton()

template<typename T >
flecs::entity flecs::world::singleton
inline

Get singleton entity for type.

Definition at line 195 of file world.hpp.

◆ system()

Upcast entity to a system.

The provided entity must be a system.

Parameters
eThe entity.
Returns
A system object.

◆ tick()

int64_t flecs::world::tick ( ) const
inline

Get current tick.

Definition at line 194 of file world.hpp.

◆ time()

ecs_ftime_t flecs::world::time ( ) const
inline

Get current simulation time.

Definition at line 201 of file world.hpp.

◆ use() [1/3]

template<typename T >
flecs::entity flecs::world::use ( const char *  alias = nullptr) const
inline

Create alias for component.

Template Parameters
Tto create an alias for.
Parameters
aliasAlias for the component.
Returns
Entity representing the component.

Definition at line 30 of file world.hpp.

◆ use() [2/3]

flecs::entity flecs::world::use ( const char *  name,
const char *  alias = nullptr 
) const
inline

Create alias for entity.

Parameters
nameName of the entity.
aliasAlias for the entity.

Definition at line 41 of file world.hpp.

◆ use() [3/3]

void flecs::world::use ( flecs::entity  entity,
const char *  alias = nullptr 
) const
inline

Create alias for entity.

Parameters
entityEntity for which to create the alias.
aliasAlias for the entity.

Definition at line 49 of file world.hpp.

◆ with() [1/5]

template<typename T , typename Func >
void flecs::world::with ( const Func &  func) const
inline

All entities created in function are created with type.

Definition at line 802 of file world.hpp.

◆ with() [2/5]

template<typename First , typename Second , typename Func >
void flecs::world::with ( const Func &  func) const
inline

All entities created in function are created with pair.

Definition at line 809 of file world.hpp.

◆ with() [3/5]

template<typename Func >
void flecs::world::with ( id_t  first,
id_t  second,
const Func &  func 
) const
inline

All entities created in function are created with pair.

Definition at line 823 of file world.hpp.

◆ with() [4/5]

template<typename First , typename Func >
void flecs::world::with ( id_t  second,
const Func &  func 
) const
inline

All entities created in function are created with pair.

Definition at line 816 of file world.hpp.

◆ with() [5/5]

template<typename Func >
void flecs::world::with ( id_t  with_id,
const Func &  func 
) const
inline

All entities created in function are created with id.

Definition at line 793 of file world.hpp.

Member Data Documentation

◆ m_owned

bool flecs::world::m_owned

Definition at line 1020 of file world.hpp.

◆ m_world

world_t* flecs::world::m_world

Definition at line 1019 of file world.hpp.


The documentation for this struct was generated from the following files: