pyecs.core.World#
Classes
|
- class pyecs.core.World.ECSWorld[source]#
-
- create_entity()[source]#
Create a new entity in the ECS world.
This method generates a unique entity identifier and registers it with both the entity manager and component storage system.
Returns the new entity UUID on success, or FAILURE if entity creation fails.
- destroy_entity(entity)[source]#
Remove an entity and all its components from the world.
This method removes the entity from the entity manager and cleans up all associated component data from the component storage system.
The entity becomes invalid after this operation and should not be used in subsequent operations.
- Return type:
- Parameters:
entity (Entity)
- add_component(entity, component)[source]#
Add a component to an existing entity.
This method attaches the specified component to the entity, potentially moving the entity to a different archetype based on its new component set.
Only adds the component if the entity is currently alive in the world.
- Return type:
- Parameters:
entity (Entity)
component (Component)
- remove_component(entity, component_type)[source]#
Remove a component type from an entity.
This method detaches the specified component type from the entity, potentially moving the entity to a different archetype.
Only removes the component if the entity is currently alive in the world.
- get_component(entity, component_type)[source]#
Retrieve a specific component from an entity.
This method returns the component instance of the specified type attached to the entity.
Returns the component instance if found, or FAILURE if the entity doesn’t exist or doesn’t have the specified component type.
- get_components(entity, *component_types)[source]#
Retrieve multiple specific components from an entity.
This method returns a tuple of each component instance of the specified types attached to the entity.
Returns a tuple of components if all are found, or FAILURE if the entity doesn’t exist or doesn’t have any of the specified component types.
- add_system(system)[source]#
Register a system with the world.
This method adds the system to the world’s execution pipeline and calls the system’s init method to perform any necessary setup.
The system will be executed during subsequent world update cycles.
- remove_system(system)[source]#
Unregister a system from the world.
This method calls the system’s cleanup method to release resources and removes it from the world’s execution pipeline.
The system will no longer be executed during world update cycles.
- update(dt)[source]#
Execute one update cycle for all registered systems.
This method calls the update method on all registered systems in registration order, passing the delta time for frame-independent updates.
This is typically called once per frame in the main game loop.
- create_entity_or_raise()#
Create a new entity in the ECS world.
This method generates a unique entity identifier and registers it with both the entity manager and component storage system.
Returns the new entity UUID on success, or FAILURE if entity creation fails.
- get_component_or_raise(entity, component_type)#
Retrieve a specific component from an entity.
This method returns the component instance of the specified type attached to the entity.
Returns the component instance if found, or FAILURE if the entity doesn’t exist or doesn’t have the specified component type.
- get_components_or_raise(entity, *component_types)#
Retrieve multiple specific components from an entity.
This method returns a tuple of each component instance of the specified types attached to the entity.
Returns a tuple of components if all are found, or FAILURE if the entity doesn’t exist or doesn’t have any of the specified component types.