pyecs.containers.Archetype#

class pyecs.containers.Archetype[source]#
__init__()[source]#

Methods

__init__()

add_entity(entity, components)

Add an entity and its components to this archetype.

get_component(entity, component_type)

Retrieve a specific component for an entity.

iter_components(component_type)

Iterate over all components of a specific type.

iter_entities()

Iterate over all entities in this archetype.

remove_entity(entity)

Remove an entity and all its component data from this archetype.

__init__()[source]#
add_entity(entity, components)[source]#

Add an entity and its components to this archetype.

This method stores the entity and its components in parallel arrays, maintaining alignment between entity indices and component indices.

Returns SUCCESS if the entity was added, or FAILURE if the entity already exists in this archetype.

Return type:

TypeAliasType

Parameters:
  • entity (Entity)

  • components (list[Component])

remove_entity(entity)[source]#

Remove an entity and all its component data from this archetype.

This method maintains the parallel array structure by removing the entity and its components from the same index across all arrays.

Returns SUCCESS if the entity was removed, or FAILURE if the entity does not exist in this archetype.

Return type:

TypeAliasType

Parameters:

entity (Entity)

get_component(entity, component_type)[source]#

Retrieve a specific component for an entity.

This method uses the parallel array structure to efficiently locate the requested component by finding the entity’s index.

Returns the component instance if found, or FAILURE if the entity doesn’t exist or doesn’t have the specified component type.

Return type:

Union[TypeAliasType, Literal[<StatusCodes.FAILURE: -1>]]

Parameters:
  • entity (Entity)

  • component_type (type[Component])

iter_entities()[source]#

Iterate over all entities in this archetype.

This method provides direct iteration over the entities list, useful for systems that need to process all entities with a specific component combination.

Returns an iterator over all entity UUIDs in this archetype.

Return type:

Iterator[TypeAliasType]

iter_components(component_type)[source]#

Iterate over all components of a specific type.

This method yields all component instances of the requested type stored in this archetype, in the same order as their entities.

Yields component instances if the archetype contains the specified component type, otherwise yields nothing.

Return type:

Iterator[TypeAliasType]

Parameters:

component_type (type)