Core Modules

Tengine’s core functionality is organized into several key modules, each playing an important role in the ECS system. Below is an overview of each of these core modules.

class tengine.core.world.World[source]

Bases: object

World represents the simulation environment containing entities and systems.

entities

A list of entities in the world.

Type:

list

systems

A list of systems that are responsible for updating entities.

Type:

list

add_plugin(plugin: Plugin)[source]

Adds a plugin to the world.

Parameters:

plugin (Plugin) – A plugin to be added to the world.

add_resource(resource: Resource)[source]

Adds a resource to the world.

Parameters:

resource (Resource) – A resource to be added to the world.

add_system(system: System)[source]

Adds a system to the world.

Parameters:

system (System) – A system to be added to the world.

mainloop()[source]

Main loop of the world. This method runs indefinitely, updating the world at each iteration

spawn_entity(*components: Component | Bundle)[source]

Spawns a new entity with the given components.

Parameters:

components (Component) – Components to associate with the entity.

Returns:

The ID of the spawned entity.

Return type:

int

startup()[source]

Initializes the world by calling the startup method of each system.

update() bool[source]

Runs all the systems in the world, updating the entities.

class tengine.core.entity.Entity(components: list[Component])[source]

Bases: object

Entity represents a single object in the simulation world. It can have multiple components that define its behavior and properties. .. attribute:: id

Unique identifier for the entity.

type:

int

components

A list of components associated with the entity.

Type:

list

get_component(type: Type[T]) T | None[source]

Retrieves the component of the specified type from the entity. :param type: The type of component to retrieve. :type type: Type[Component]

Returns:

The component if found, None otherwise.

Return type:

Component | None

has_component(type: Type[Component]) bool[source]

Checks if the entity has a component of the specified type. :param type: The type of component to check for. :type type: Type[Component]

Returns:

True if the entity has the component, False otherwise.

Return type:

bool

class tengine.core.component.Bundle[source]

Bases: object

A bundle is a collection of components that can be added to an entity. Bundles are used to group related components together for easier management and organization.

class tengine.core.component.Component[source]

Bases: object

Base class for all components in the simulation. Components are used to define the properties and behaviors of entities. Each component should inherit from this class.

class tengine.core.system.System[source]

Bases: object

System is an abstract base class that defines the interface for all systems in the simulation. Each system is responsible for updating a specific aspect of the entities in the world.

abstractmethod startup(entities: list[Entity], resources: Resources) bool[source]

Initializes the system with the given entities and world information. :param entities: A list of entities to be initialized. :type entities: list[Entity] :param resources: The resources available to the system. :type resources: Resources

abstractmethod update(entities: list[Entity], resources: Resources) bool[source]

Updates the system with the given entities and world information. :param entities: A list of entities to be updated. :type entities: list[Entity] :param resources: The resources available to the system. :type resources: Resources