Struct pyro::World

source ·
pub struct World<S = SoaStorage> { /* private fields */ }
Expand description

World is the heart of this library. It owns all the Components and Storages. It also manages entities and allows Components to be safely queried.

Implementations§

Creates an empty World.

Creates an Iterator over every Entity inside World. The entities are not ordered.

Uses Query and Matcher to access the correct components. Read will borrow the component immutable while Write will borrow the component mutable.

fn update(world: &mut World) {
   world
       .matcher::<All<(Write<Position>, Read<Velocity>)>>()
       .for_each(|(p, v)| {
           p.x += v.dx;
           p.y += v.dy;
       });
}

Same as World::matcher but also returns the corresponding Entity.

fn update(world: &mut World) {
   world
       .matcher_with_entities::<All<(Write<Position>, Read<Velocity>)>>()
       .for_each(|(entity, (p, v))| {
           p.x += v.dx;
           p.y += v.dy;
       });
}

Appends the components and also creates the necessary Entitys behind the scenes. If you only want to append a single set of components then you can do

world.append_components(Some((a, b, c)));

Compares the version of the entity with the version in World and returns true if they match. Because version wraps around this is not a hard guarantee.

Returns true if the entity owns the requested component.

Retrieves a component for a specific Entity.

Same as World::get_component but mutable.

Removes the specified entities from World. Those entities are now considered invalid, which can be checked with World::is_entity_valid.

Trait Implementations§

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more
Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more
Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more
Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.