engine.ecs package¶
Submodules¶
engine.ecs.component module¶
- class engine.ecs.component.Component¶
Bases:
abc.ABCAbstract class for a Component which stores data and nothing else.
engine.ecs.entity module¶
engine.ecs.entity_listener module¶
- class engine.ecs.entity_listener.EntityListener¶
Bases:
abc.ABC- abstract entity_added(entity)¶
This method gets called when an entity is added to a manager this listener is registered to.
- Parameters
entity – The entity that was added
- abstract entity_removed(entity, components)¶
This method gets called when an entity is removed from a manager this listener is registered to.
- Parameters
entity (Entity) – The entity that was removed
components (dict) – The components that were attached to the entity in the system. {type(component): component}
engine.ecs.entity_manager module¶
- class engine.ecs.entity_manager.EntityManager¶
Bases:
objectClass responsible for handling Entities, their Components and Systems.
- add_component_to_entity(entity, *components)¶
Applies given Component instances to a given Entity instance.
- Parameters
entity (Entity) – The Entity to have components added to.
components – The Component instances to be added to the entity.
- Returns
None
- add_entity(entity)¶
Adds an existing Entity instance to the manager and returns it.
- Parameters
entity – The Entity instance to be added
- Returns
Entity
- add_listener(listener)¶
Adds a given Listener instance to the Entity Manager.
- Parameters
listener (Listener) – The Listener instance to add to the Entity Manager.
- Returns
None
- add_system(*system)¶
Adds given System instances to the Entity Manager.
- Parameters
system – The System instance to add to the Entity Manager.
- Returns
None
- create_entity()¶
Creates a new Entity instance, adds it to the manager and returns it.
- Returns
A new Entity instance. Equivalent to creating an instance manually.
- Return type
- entity_exists(entity)¶
Returns True if the given Entity instance is in the entity manager,
- Parameters
entity (Entity) – The Entity instance to be checked.
- Returns
A boolean representing whether the Entity was found or not.
- Return type
bool
- get_component_map(component_type)¶
Returns dictionary of key value pairs where Entity instances are the key and Component instances are the values and the Component instances are of the given Component type.
- Parameters
component_type – The type of Component
- Returns
A dictionary of Entity instances to their Component instances.
- Return type
dict
- get_entity_components(entity)¶
Gets a set of all components attached to the given entity.
- Parameters
entity (Entity) – The entity instance to get the components of
- Returns
The set of all components attached to the given entity
- Return type
set
- get_family(*component_types)¶
Returns entities in the map that have all of the given Component types.
- Parameters
component_types – A Set of Component types that you want the Family for.
- Returns
The Family of entities that have all of the requested Component types.
- Return type
- remove_component_from_entity(entity, component_type)¶
Removes all Component instances of given Component type from given Entity instance.
- Parameters
entity (Entity) – The Entity to have components removed from
component_type – The Component types to removed from the Entity.
- Returns
None
- remove_entity(entity)¶
Removes an Entity instance from the Entity Manager.
- Parameters
entity (Entity) – The Entity instance to be removed from the Entity Manager.
- Returns
A set containing the removed entity’s components
- Return type
set
- remove_listener(listener)¶
Removes a given Listener instance from the Entity Manager.
- Parameters
listener (Listener) – The Listener instance to remove from the Entity Manager.
- Returns
None
- remove_system(system)¶
Removes given System instance from the Entity Manager.
- Parameters
system – The System instance to remove from the Entity Manager.
- Returns
None
- return_entities()¶
Returns a list of entities.
- Returns
A list of all registered entities
- Return type
list
- update(deltatime)¶
Updates all systems in the database by calling their update functions. Should be called every tick.
- Parameters
deltatime (float) – Time between frames. Can be used for framerate independence.
- Returns
None
engine.ecs.family module¶
engine.ecs.iterator_system module¶
- class engine.ecs.iterator_system.IteratorSystem¶
Bases:
engine.ecs.system.SystemUtility class for automatically iterating through a family of entities.
- abstract process(deltatime, entity)¶
The method that performs logic on an entity and its components.
- Parameters
deltatime (float) – Time between frames. Can be used for framerate independence.
entity (Entity) – The Entity instance that is being processed.
- Returns
None
- update(deltatime)¶
Automatically iterates through the family of the system.
- Returns
None
engine.ecs.system module¶
- class engine.ecs.system.System(priority=0)¶
Bases:
abc.ABCAbstract class for processing Entity instances.
- property priority¶
- abstract update(deltatime)¶
The update method that is called every tick.
- Parameters
deltatime (float) – Time between frames. Can be used for framerate independence.
- Returns
None