Worlds are environments described by a configuration of components, systems and renderers. These parts describe the data, behavioral and presentation aspects of the world respectively.
The world environment is the context within which entities exist. A typical application consists of one or more worlds containing entities that evolve over time and react to internal and external interaction.
See an example of world configuration in the tutorial.
A coordinated collection of components, systems and entities
A world is also a mode that may be pushed onto a grease.mode.Manager
Parameters: |
|
---|
Return an EntityExtent for the given entity class. This extent can be used to access the set of entities of that class in the world or to query these entities via their components.
Examples:
world[MyEntity]
world[...]
Parameter: | entity_class – The entity class for the extent. May also be a tuple of entity classes, in which case the extent returned contains union of all entities of the classes in the world. May also be the special value ellipsis (...), which returns an extent containing all entities in the world. This allows you to conveniently query all entities using world[...]. |
---|
Activate the world/mode for the given manager, if the world is already active, do nothing. This method is typically not used directly, it is called automatically by the mode manager when the world becomes active.
The systems of the world are pushed onto manager.event_dispatcher so they can receive system events.
Parameter: | manager – mode.BaseManager instance |
---|
Hook to configure the world after construction. This method is called immediately after the world is initialized. Override in a subclass to configure the world’s components, systems, and renderers.
The default implementation does nothing.
Deactivate the world/mode, if the world is not active, do nothing. This method is typically not used directly, it is called automatically by the mode manager when the world becomes active.
Removes the system handlers from the manager.event_dispatcher
Parameter: | manager – mode.BaseManager instance |
---|
Execute a time step for the world. Updates the world time and invokes the world’s systems.
Note that the specified time delta will be pinned to 10x the configured step rate. For example if the step rate is 60, then dt will be pinned at a maximum of 0.1666. This avoids pathological behavior when the time between steps goes much longer than expected.
Parameter: | dt (float) – The time delta since the last time step |
---|
Tick the mode’s clock, but only if the world is currently running
Parameter: | dt (float) – The time delta since the last tick |
---|
Maps world parts to attributes. The parts are kept in the order they are set. Parts may also be inserted out of order.
Used for:
Add a part with a particular name at a particular index. If a part by that name already exists, it is replaced.
Parameters: |
|
---|
Maps world components to attributes. The components are kept in the order they are set. Components may also be inserted out of order.
Used for: World.components
Add a part with a particular name at a particular index. If a part by that name already exists, it is replaced.
Parameters: |
|
---|
Join and iterate entity data from multiple components together.
For each entity in all of the components named, yield a tuple containing the entity data from each component specified.
This is useful in systems that pull data from multiple components.
Typical Usage:
for position, movement in world.components.join("position", "movement"):
# Do something with each entity's position and movement data
Encapsulates a set of entities queriable by component. Extents are accessed by using an entity class as a key on the World:
extent = world[MyEntity]
Return a queriable ComponentEntitySet for the named component
Example:
world[MyEntity].movement.velocity > (0, 0)
Returns a set of entities where the value of the velocity field of the movement component is greater than (0, 0).