abstract class Entitas::Context(TEntity)
- Entitas::Context(TEntity)
- Reference
- Object
Overview
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();
Included Modules
- Entitas::Helper::ComponentPools
- Entitas::Helper::Entities(TEntity)
- Entitas::IContext
- Enumerable(TEntity)
Defined in:
entitas.crentitas/context.cr
entitas/context/collector.cr
entitas/context/entity_index.cr
entitas/context/groups.cr
entitas/context/info.cr
entitas/generators/context.cr
entitas/generators/context/event_system.cr
Constant Summary
-
Log =
::Log.for(self)
Constructors
Instance Method Summary
- #add_entity_index(entity_index : Entitas::IEntityIndex)
- #aerc_factory(entity : TEntity) : Entitas::SafeAERC
- #context_info : Entitas::Context::Info
- #create_collector(matcher : Entitas::Matcher) : Entitas::Collector(TEntity)
- #create_collector(*triggers : Entitas::Events::TriggerOn) : Entitas::Collector(TEntity)
- #create_default_context_info : Entitas::Context::Info
-
#destroy_all_entities
Destroys all entities in the context.
- #entity_indices : Hash(String, Entitas::IEntityIndex)
- #get_entity_index(name : String) : Entitas::IEntityIndex
- #get_entity_index?(name : String) : Entitas::IEntityIndex | Nil
-
#get_group(matcher : Entitas::Matcher) : Group(TEntity)
Returns a group for the specified matcher.
- #get_on_component_added_cache : Proc(Entitas::Events::OnComponentAdded, Nil)
- #get_on_component_removed_cache : Proc(Entitas::Events::OnComponentRemoved, Nil)
- #get_on_component_replaced_cache : Proc(Entitas::Events::OnComponentReplaced, Nil)
- #get_on_destroy_entity_cache : Proc(Entitas::Events::OnDestroyEntity, Nil)
- #get_on_entity_created_cache : Proc(Entitas::Events::OnEntityCreated, Nil)
- #get_on_entity_destroyed_cache : Proc(Entitas::Events::OnEntityDestroyed, Nil)
- #get_on_entity_released_cache : Proc(Entitas::Events::OnEntityReleased, Nil)
- #get_on_entity_will_be_destroyed_cache : Proc(Entitas::Events::OnEntityWillBeDestroyed, Nil)
- #get_on_group_created_cache : Proc(Entitas::Events::OnGroupCreated, Nil)
- #groups : Hash(String, Group(TEntity))
-
#info : Entitas::Context::Info
The contextInfo contains information about the context.
-
#on_component_added(event : Entitas::Events::OnComponentAdded)
Triggers
#update_groups_component_added_or_removed
for the providedEntitas::Events::OnComponentAdded
- #on_component_added_event_cache : Proc(Entitas::Events::OnComponentAdded, Nil) | Nil
- #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 providedEntitas::Events::OnComponentRemoved
- #on_component_removed_event_cache : Proc(Entitas::Events::OnComponentRemoved, Nil) | Nil
- #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 providedEntitas::Events::OnComponentReplaced
- #on_component_replaced_event_cache : Proc(Entitas::Events::OnComponentReplaced, Nil) | Nil
- #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. - #on_destroy_entity_event_cache : Proc(Entitas::Events::OnDestroyEntity, Nil) | Nil
- #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. - #on_entity_created_event_cache : Proc(Entitas::Events::OnEntityCreated, Nil) | Nil
- #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. - #on_entity_destroyed_event_cache : Proc(Entitas::Events::OnEntityDestroyed, Nil) | Nil
- #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. - #on_entity_released_event_cache : Proc(Entitas::Events::OnEntityReleased, Nil) | Nil
- #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. - #on_entity_will_be_destroyed_event_cache : Proc(Entitas::Events::OnEntityWillBeDestroyed, Nil) | Nil
- #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. - #on_group_created_event_cache : Proc(Entitas::Events::OnGroupCreated, Nil) | Nil
- #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
-
#reset
Resets the context (destroys all entities and resets creationIndex back to 0).
-
#reset_creation_index
Resets the creationIndex back to 0.
- #update_groups_component_added_or_removed(entity : TEntity, index : Int32, component : Entitas::IComponent | Nil)
- #update_groups_component_replaced(entity : TEntity, index : Int32, prev_component : Entitas::IComponent | Nil, new_component : Entitas::IComponent | Nil)
Instance methods inherited from module Entitas::Helper::ComponentPools
clear_component_pool(index : Int32)clear_component_pool(index : Entitas::Component::ComponentTypes) clear_component_pool, clear_component_pools clear_component_pools, component_index_value(index) : Int32 component_index_value, component_pool(index : Int32) : ComponentPool
component_pool(index : Entitas::Component::ComponentTypes) : ComponentPool
component_pool(index : Entitas::Component::Index) : ComponentPool component_pool, component_pools : Array(Entitas::ComponentPool) component_pools
Instance methods inherited from module Entitas::Helper::Entities(TEntity)
count : Int32
count,
each(&block : TEntity -> Nil)
each,
get_entities
get_entities,
has_entity?(entity : TEntity) : Bool
has_entity?,
size
size,
sort(&block : TEntity, TEntity -> U) : Array(TEntity) forall U
sort
Instance methods inherited from module Entitas::IContext
add_entity_index(entity_index : Entitas::IEntityIndex)
add_entity_index,
clear_component_pool(index : Int32)
clear_component_pool,
clear_component_pools
clear_component_pools,
component_index(index) : Entitas::Component::Index
component_index,
component_index_class(index) : Entitas::Component::ComponentTypes
component_index_class,
component_index_value(index) : Int32
component_index_value,
component_pools : Array(Entitas::ComponentPool)
component_pools,
create_entity : IEntity
create_entity,
destroy_all_entities
destroy_all_entities,
each(&block : TEntity -> Nil)
each,
entity_factory : Entitas::Entity
entity_factory,
get_entities
get_entities,
get_entity_index(name : String) : Entitas::IEntityIndex
get_entity_index,
get_entity_index?(name : String) : Entitas::IEntityIndex | Nil
get_entity_index?,
get_group(matcher : Entitas::Matcher) : Entitas::Group
get_group,
has_entity?(entity : TEntity) : Bool
has_entity?,
on_entity_created(&block : Entitas::Events::OnEntityCreated -> Nil)
on_entity_created,
on_entity_created_event_hooks : Array(Proc(Entitas::Events::OnEntityCreated, Nil))
on_entity_created_event_hooks,
on_entity_destroyed(&block : Entitas::Events::OnEntityDestroyed -> Nil)
on_entity_destroyed,
on_entity_destroyed_event_hooks : Array(Proc(Entitas::Events::OnEntityDestroyed, Nil))
on_entity_destroyed_event_hooks,
on_entity_will_be_destroyed(&block : Entitas::Events::OnEntityWillBeDestroyed -> Nil)
on_entity_will_be_destroyed,
on_entity_will_be_destroyed_event_hooks : Array(Proc(Entitas::Events::OnEntityWillBeDestroyed, Nil))
on_entity_will_be_destroyed_event_hooks,
on_group_created(&block : Entitas::Events::OnGroupCreated -> Nil)
on_group_created,
on_group_created_event_hooks : Array(Proc(Entitas::Events::OnGroupCreated, Nil))
on_group_created_event_hooks,
receive_on_entity_created_event(event : Entitas::Events::OnEntityCreated)
receive_on_entity_created_event,
receive_on_entity_destroyed_event(event : Entitas::Events::OnEntityDestroyed)
receive_on_entity_destroyed_event,
receive_on_entity_will_be_destroyed_event(event : Entitas::Events::OnEntityWillBeDestroyed)
receive_on_entity_will_be_destroyed_event,
receive_on_group_created_event(event : Entitas::Events::OnGroupCreated)
receive_on_group_created_event,
remove_all_event_handlers
remove_all_event_handlers,
remove_on_entity_created_hook(hook : Proc(Entitas::Events::OnEntityCreated, Nil))
remove_on_entity_created_hook,
remove_on_entity_destroyed_hook(hook : Proc(Entitas::Events::OnEntityDestroyed, Nil))
remove_on_entity_destroyed_hook,
remove_on_entity_will_be_destroyed_hook(hook : Proc(Entitas::Events::OnEntityWillBeDestroyed, Nil))
remove_on_entity_will_be_destroyed_hook,
remove_on_group_created_hook(hook : Proc(Entitas::Events::OnGroupCreated, Nil))
remove_on_group_created_hook,
reset
reset,
reset_creation_index
reset_creation_index,
size
size,
to_json(json : JSON::Builder)
to_json,
total_components : Int32
total_components
Constructor Detail
Instance Method Detail
Destroys all entities in the context. Throws an exception if there are still retained entities.
Returns a group for the specified matcher. Calling context.GetGroup(matcher) with the same matcher will always return the same instance of the group.
The contextInfo contains information about the context. It's used to provide better error messages.
Triggers #update_groups_component_added_or_removed
for the provided Entitas::Events::OnComponentAdded
Triggers #update_groups_component_added_or_removed
for the provided Entitas::Events::OnComponentRemoved
Triggers #update_groups_component_added_or_removed
for the provided Entitas::Events::OnComponentReplaced
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.
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
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
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
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
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
Removes all event handlers OnEntityCreated, OnEntityWillBeDestroyed, OnEntityDestroyed and OnGroupCreated