class

Entitas::Context(TEntity)

Inherits Entitas::Helper::ComponentPools / Enumerable / Entitas::Helper::Entities / Entitas::IContext / Reference / Object

A context manages the lifecycle of entities and groups. You can create and destroy entities and get groups of entities. The prefered way to create a context is to use the generated methods from the code generator, e.g. var context = new GameContext();

Constants

Log = ::Log.for(self)

Constructors

new(creation_index : Int32 = 0, context_info : Entitas::Context::Info | Nil = nil)
Source

Instance methods

add_entity_index(entity_index : Entitas::IEntityIndex)
Source
aerc_factory(entity : TEntity) : Entitas::SafeAERC
Source
context_info
Source
create_collector(matcher : Entitas::Matcher) : Entitas::Collector(TEntity)
Source
create_collector(*triggers : Entitas::Events::TriggerOn) : Entitas::Collector(TEntity)
Source
create_default_context_info
Source
destroy_all_entities

Destroys all entities in the context. Throws an exception if there are still retained entities.

Source
entity_indices
Source
get_entity_index(name : String) : Entitas::IEntityIndex
Source
get_entity_index?(name : String) : Entitas::IEntityIndex | Nil
Source
get_group(matcher : Entitas::Matcher) : Group(TEntity)

Returns a group for the specified matcher. Calling context.GetGroup(matcher) with the same matcher will always return the same instance of the group.

Source
get_on_component_added_cache
get_on_component_removed_cache
get_on_component_replaced_cache
get_on_destroy_entity_cache
get_on_entity_created_cache
get_on_entity_destroyed_cache
get_on_entity_released_cache
get_on_entity_will_be_destroyed_cache
get_on_group_created_cache
groups
Source
info

The contextInfo contains information about the context. It's used to provide better error messages.

Source
on_component_added(event : Entitas::Events::OnComponentAdded)

Triggers update_groups_component_added_or_removed for the provided Entitas::Events::OnComponentAdded

Source
on_component_added_event_cache
on_component_added_event_cache=(on_component_added_event_cache : Proc(Entitas::Events::OnComponentAdded, Nil) | Nil)
on_component_removed(event : Entitas::Events::OnComponentRemoved)

Triggers update_groups_component_added_or_removed for the provided Entitas::Events::OnComponentRemoved

Source
on_component_removed_event_cache
on_component_removed_event_cache=(on_component_removed_event_cache : Proc(Entitas::Events::OnComponentRemoved, Nil) | Nil)
on_component_replaced(event : Entitas::Events::OnComponentReplaced)

Triggers update_groups_component_added_or_removed for the provided Entitas::Events::OnComponentReplaced

Source
on_component_replaced_event_cache
on_component_replaced_event_cache=(on_component_replaced_event_cache : Proc(Entitas::Events::OnComponentReplaced, Nil) | Nil)
on_destroy_entity(event : Entitas::Events::OnDestroyEntity)

Will destroy the entity provided in the Entitas::Events::OnDestroyEntity event. It will delete it from the entities set, emit Entitas::Events::OnEntityWillBeDestroyed before destroying it, as well as emit Entitas::Events::OnEntityDestroyed after distruction.

Source
on_destroy_entity_event_cache
on_destroy_entity_event_cache=(on_destroy_entity_event_cache : Proc(Entitas::Events::OnDestroyEntity, Nil) | Nil)
on_entity_created(event : Entitas::Events::OnEntityCreated) : Nil

Method to process event: Entitas::Events::OnEntityCreated when emited. Will raise Entitas::Error::MethodNotImplemented when not implimented if an Entitas::Events::OnEntityCreated is emitted.

def on_entity_created(event : Entitas::Events::OnEntityCreated) : Nil
  # do something with event
end
on_entity_created_event_cache
on_entity_created_event_cache=(on_entity_created_event_cache : Proc(Entitas::Events::OnEntityCreated, Nil) | Nil)
on_entity_destroyed(event : Entitas::Events::OnEntityDestroyed) : Nil

Method to process event: Entitas::Events::OnEntityDestroyed when emited. Will raise Entitas::Error::MethodNotImplemented when not implimented if an Entitas::Events::OnEntityDestroyed is emitted.

def on_entity_destroyed(event : Entitas::Events::OnEntityDestroyed) : Nil
  # do something with event
end
on_entity_destroyed_event_cache
on_entity_destroyed_event_cache=(on_entity_destroyed_event_cache : Proc(Entitas::Events::OnEntityDestroyed, Nil) | Nil)
on_entity_released(event : Entitas::Events::OnEntityReleased)

Will clean the entity provided in the Entitas::Events::OnEntityReleased event. It will remove all release handlers and append it to the reusable_entities cache

Source
on_entity_released_event_cache
on_entity_released_event_cache=(on_entity_released_event_cache : Proc(Entitas::Events::OnEntityReleased, Nil) | Nil)
on_entity_will_be_destroyed(event : Entitas::Events::OnEntityWillBeDestroyed) : Nil

Method to process event: Entitas::Events::OnEntityWillBeDestroyed when emited. Will raise Entitas::Error::MethodNotImplemented when not implimented if an Entitas::Events::OnEntityWillBeDestroyed is emitted.

def on_entity_will_be_destroyed(event : Entitas::Events::OnEntityWillBeDestroyed) : Nil
  # do something with event
end
on_entity_will_be_destroyed_event_cache
on_entity_will_be_destroyed_event_cache=(on_entity_will_be_destroyed_event_cache : Proc(Entitas::Events::OnEntityWillBeDestroyed, Nil) | Nil)
on_group_created(event : Entitas::Events::OnGroupCreated) : Nil

Method to process event: Entitas::Events::OnGroupCreated when emited. Will raise Entitas::Error::MethodNotImplemented when not implimented if an Entitas::Events::OnGroupCreated is emitted.

def on_group_created(event : Entitas::Events::OnGroupCreated) : Nil
  # do something with event
end
on_group_created_event_cache
on_group_created_event_cache=(on_group_created_event_cache : Proc(Entitas::Events::OnGroupCreated, Nil) | Nil)
remove_all_event_handlers

Removes all event handlers OnEntityCreated, OnEntityWillBeDestroyed, OnEntityDestroyed and OnGroupCreated

Source
reset

Resets the context (destroys all entities and resets creationIndex back to 0).

Source
reset_creation_index

Resets the creationIndex back to 0.

Source
update_groups_component_added_or_removed(entity : TEntity, index : Int32, component : Entitas::IComponent | Nil)
Source
update_groups_component_replaced(entity : TEntity, index : Int32, prev_component : Entitas::IComponent | Nil, new_component : Entitas::IComponent | Nil)
Source

Nested types