struct ECS::World

Defined in:

flecs/world.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(unsafe : ECS::LibECS::WorldRef, root : ECS::World::Root) #

[View source]

Class Method Detail

def self.init #

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.


[View source]

Instance Method Detail

def doc_get_brief(entity) : String | Nil #

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.


[View source]
def doc_get_detail(entity) : String | Nil #

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.


[View source]
def doc_get_link(entity) : String | Nil #

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.


[View source]
def doc_set_brief(entity, description : String) #

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?


[View source]
def doc_set_detail(entity, description : String) #

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?


[View source]
def doc_set_link(entity, link : String) #

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?


[View source]
def entity_init(name : String | Nil = nil, add_expr : String | Nil = nil) : UInt64 #

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.


[View source]
def fini #

Delete a world.

This operation deletes the world, and everything it contains.


[View source]
def get(entity, component_class : T.class) forall T #

Convenience wrapper for get_id for when component implements the id method.


[View source]
def get_id(entity, id : UInt64, c : T.class) : T | Nil forall T #

Get an immutable pointer to a component.

This operation obtains a const pointer to the requested component. The operation accepts the component entity id.


[View source]
def get_name(entity) #

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.


[View source]
def get_relation(subject, component_class : T.class, object) forall T #

Get a component that relates a subject entity to an object entity


[View source]
def get_singleton(component_class : T.class) forall T #

Convenience wrapper for get for when the entity is a component singleton.


[View source]
def in_scope(entity, &) #

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.


[View source]
def info : LibECS::WorldInfo #

Get world info.


[View source]
def lookup(name : String) : UInt64 | Nil #

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.


[View source]
def lookup_fullpath(path : String) : UInt64 | Nil #

[View source]
def progress(delta_time : Float32 = 0) : Bool #

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.


[View source]
def quit! #

Signal exit.

This operation signals that the application should quit. It will cause ecs_progress to return false.


[View source]
def quit? : Bool #

Return whether a quit has been signaled.


[View source]
def remove(entity, component_class : T.class) forall T #

Convenience wrapper for remove_id for when component implements the id method.


[View source]
def remove_id(entity, id : UInt64) forall T #

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.


[View source]
def remove_relation(subject, component_class : T.class, object) forall T #

Remove a component if it relates the subject entity to the object entity.


[View source]
def remove_singleton(component_class : T.class) forall T #

Convenience wrapper for remove for when the entity is a component singleton.


[View source]
def set(entity, component : T) forall T #

Convenience wrapper for set_id for when component implements the id method.


[View source]
def set_id(entity, id : UInt64, component : T) : T forall T #

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.


[View source]
def set_relation(subject, component : T, object) forall T #

Set a component that relates a subject entity to an object entity.


[View source]
def set_singleton(component : T) forall T #

Convenience wrapper for set for when the entity is a component singleton.


[View source]
def target_fps #

Get target frames per second (FPS) for application.

See the setter method for more details on how this value is used.


[View source]
def target_fps=(value) #

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.


[View source]
def to_unsafe : ECS::LibECS::WorldRef #

[View source]