struct ECS::World
- ECS::World
- Struct
- Value
- Object
Defined in:
flecs/world.crConstructors
Class Method Summary
-
.init
Create a new world.
Instance Method Summary
-
#doc_get_brief(entity) : String | Nil
Get brief description from entity.
-
#doc_get_detail(entity) : String | Nil
Get detailed description from entity.
-
#doc_get_link(entity) : String | Nil
Get link to external documentation from entity.
-
#doc_set_brief(entity, description : String)
Add brief description to entity.
-
#doc_set_detail(entity, description : String)
Add detailed description to entity.
-
#doc_set_link(entity, link : String)
Add link to external documentation to entity.
-
#entity_init(name : String | Nil = nil, add_expr : String | Nil = nil) : UInt64
Find or create an entity.
-
#fini
Delete a world.
-
#get(entity, component_class : T.class) forall T
Convenience wrapper for get_id for when component implements the id method.
-
#get_id(entity, id : UInt64, c : T.class) : T | Nil forall T
Get an immutable pointer to a component.
-
#get_name(entity)
Get the name of an entity.
-
#get_relation(subject, component_class : T.class, object) forall T
Get a component that relates a subject entity to an object entity
-
#get_singleton(component_class : T.class) forall T
Convenience wrapper for get for when the entity is a component singleton.
-
#in_scope(entity, &)
Set the current scope, temporarily.
-
#info : LibECS::WorldInfo
Get world info.
-
#lookup(name : String) : UInt64 | Nil
Lookup an entity by name.
- #lookup_fullpath(path : String) : UInt64 | Nil
-
#progress(delta_time : Float32 = 0) : Bool
Progress a world.
-
#quit!
Signal exit.
-
#quit? : Bool
Return whether a quit has been signaled.
-
#remove(entity, component_class : T.class) forall T
Convenience wrapper for remove_id for when component implements the id method.
-
#remove_id(entity, id : UInt64) forall T
Remove an entity from an entity.
-
#remove_relation(subject, component_class : T.class, object) forall T
Remove a component if it relates the subject entity to the object entity.
-
#remove_singleton(component_class : T.class) forall T
Convenience wrapper for remove for when the entity is a component singleton.
-
#set(entity, component : T) forall T
Convenience wrapper for set_id for when component implements the id method.
-
#set_id(entity, id : UInt64, component : T) : T forall T
Set the value of a component.
-
#set_relation(subject, component : T, object) forall T
Set a component that relates a subject entity to an object entity.
-
#set_singleton(component : T) forall T
Convenience wrapper for set for when the entity is a component singleton.
-
#target_fps
Get target frames per second (FPS) for application.
-
#target_fps=(value)
Set target frames per second (FPS) for application.
- #to_unsafe : ECS::LibECS::WorldRef
Constructor Detail
Class Method Detail
Create a new world.
A world manages all the ECS data and supporting infrastructure. Applications must have at least one world. Entities, component and system handles are local to a world and should not be shared between worlds.
This operation creates a world with all builtin modules loaded.
Instance Method Detail
Get brief description from entity.
Performance warning: a new String object is allocated, along with a new buffer that copies the docs from the original buffer, because Crystal doesn't want to create a String that shares the memory.
Get detailed description from entity.
Performance warning: a new String object is allocated, along with a new buffer that copies the docs from the original buffer, because Crystal doesn't want to create a String that shares the memory.
Get link to external documentation from entity.
Performance warning: a new String object is allocated, along with a new buffer that copies the docs from the original buffer, because Crystal doesn't want to create a String that shares the memory.
Add brief description to entity.
Please ensure that the String is a String literal, or that it is retained somewhere traceable from Crystal, because otherwise the buffer may be garbage-collected, leading to memory corruption.
TODO Some way to enforce this? Maybe with a macro that enforces StringLiteral?
Add detailed description to entity.
Please ensure that the String is a String literal, or that it is retained somewhere traceable from Crystal, because otherwise the buffer may be garbage-collected, leading to memory corruption.
TODO Some way to enforce this? Maybe with a macro that enforces StringLiteral?
Add link to external documentation to entity.
Please ensure that the String is a String literal, or that it is retained somewhere traceable from Crystal, because otherwise the buffer may be garbage-collected, leading to memory corruption.
TODO Some way to enforce this? Maybe with a macro that enforces StringLiteral?
Find or create an entity.
This operation creates a new entity, or modifies an existing one. When a name is set in the ecs_entity_desc_t::name field and ecs_entity_desc_t::entity is not set, the operation will first attempt to find an existing entity by that name. If no entity with that name can be found, it will be created.
If both a name and entity handle are provided, the operation will check if the entity name matches with the provided name. If the names do not match, the function will fail and return 0.
If an id to a non-existing entity is provided, that entity id become alive.
See the documentation of ecs_entity_desc_t for more details.
Convenience wrapper for get_id for when component implements the id method.
Get an immutable pointer to a component.
This operation obtains a const pointer to the requested component. The operation accepts the component entity id.
Get the name of an entity. This will return the name stored in (EcsIdentifier, EcsName).
Performance warning: a new String object is allocated, along with a new buffer that copies the docs from the original buffer, because Crystal doesn't want to create a String that shares the memory.
Get a component that relates a subject entity to an object entity
Convenience wrapper for get for when the entity is a component singleton.
Set the current scope, temporarily.
This operation sets the scope of the current stage to the provided entity. As a result new entities will be created in this scope, and lookups will be relative to the provided scope.
Restore the scope to the old value after the block is done.
Lookup an entity by name.
Returns an entity that matches the specified name. Only looks for entities in the current scope (root if no scope is provided).
Returns the entity with the specified name, or nil if no entity was found.
Progress a world.
This operation progresses the world by running all systems that are both enabled and periodic on their matching entities.
An application can pass a delta_time into the function, which is the time passed since the last frame. This value is passed to systems so they can update entity values proportional to the elapsed time since their last invocation.
When an application passes 0 to delta_time, ecs_progress will automatically measure the time passed since the last frame. If an application does not uses time management, it should pass a non-zero value for delta_time (1.0 is recommended). That way, no time will be wasted measuring the time.
Returns false if ecs_quit has been called, true otherwise.
Signal exit.
This operation signals that the application should quit. It will cause ecs_progress to return false.
Convenience wrapper for remove_id for when component implements the id method.
Remove an entity from an entity.
This operation removes a single entity from the type of an entity. Type roles may be used in combination with the added entity. If the entity does not have the entity, this operation will have no side effects.
Remove a component if it relates the subject entity to the object entity.
Convenience wrapper for remove for when the entity is a component singleton.
Convenience wrapper for set_id for when component implements the id method.
Set the value of a component.
This operation allows an application to set the value of a component. The operation is equivalent to calling ecs_get_mut and ecs_modified.
If the provided entity is 0, a new entity will be created.
Set a component that relates a subject entity to an object entity.
Convenience wrapper for set for when the entity is a component singleton.
Get target frames per second (FPS) for application.
See the setter method for more details on how this value is used.
Set target frames per second (FPS) for application.
Setting the target FPS ensures that ecs_progress is not invoked faster than the specified FPS. When enabled, ecs_progress tracks the time passed since the last invocation, and sleeps the remaining time of the frame (if any).
This feature ensures systems are ran at a consistent interval, as well as conserving CPU time by not running systems more often than required.
Note that ecs_progress only sleeps if there is time left in the frame. Both time spent in flecs as time spent outside of flecs are taken into account.