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[...]
Parameters: |
|
---|
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.
Parameters: |
|
---|
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
Parameters: |
|
---|
Clear the current OpenGL context, reset the model/view matrix and invoke the draw() methods of the renderers in order
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.
Parameters: |
|
---|
Tick the mode’s clock, but only if the world is currently running
Parameters: |
|
---|
pyglet.clock interface for use by constituents of the world for scheduling
ComponentParts object containing all world components. grease.component.Component objects define and contain all entity data
Set of all entities that exist in the world
Parts object containing all world renderers. grease.Renderer objects define world presentation
Flag to indicate that the world clock is running, advancing time and stepping the world. Set running to False to pause the world.
Parts object containing all world systems. grease.System objects define world and entity behavior
Current clock time of the world, starts at 0 when the world is instantiated
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).
The full set of entities in the extent