Struct specs::LazyUpdate [] [src]

pub struct LazyUpdate { /* fields omitted */ }

Lazy updates can be used for world updates that need to borrow a lot of resources and as such should better be done at the end. They work lazily in the sense that they are dispatched when calling world.maintain(). Please note that the provided methods take &self so there's no need to fetch LazyUpdate mutably. This resource is added to the world by default.

Methods

impl LazyUpdate
[src]

Lazily inserts a component for an entity.

Examples

struct Pos(f32, f32);

impl Component for Pos {
    type Storage = VecStorage<Self>;
}

struct InsertPos;

impl<'a> System<'a> for InsertPos {
    type SystemData = (Entities<'a>, Fetch<'a, LazyUpdate>);

    fn run(&mut self, (ent, lazy): Self::SystemData) {
        let a = ent.create();
        lazy.insert(a, Pos(1.0, 1.0));
    }
}

Lazily inserts components for entities.

Examples

struct Pos(f32, f32);

impl Component for Pos {
    type Storage = VecStorage<Self>;
}

struct InsertPos;

impl<'a> System<'a> for InsertPos {
    type SystemData = (Entities<'a>, Fetch<'a, LazyUpdate>);

    fn run(&mut self, (ent, lazy): Self::SystemData) {
        let a = ent.create();
        let b = ent.create();

        lazy.insert_all(vec![(a, Pos(3.0, 1.0)), (b, Pos(0.0, 4.0))]);
    }
}

Lazily removes a component.

Examples

struct Pos;

impl Component for Pos {
    type Storage = VecStorage<Self>;
}

struct RemovePos;

impl<'a> System<'a> for RemovePos {
    type SystemData = (Entities<'a>, Fetch<'a, LazyUpdate>);

    fn run(&mut self, (ent, lazy): Self::SystemData) {
        for entity in ent.join() {
            lazy.remove::<Pos>(entity);
        }
    }
}

Lazily executes a closure with world access.

Examples

struct Pos;

impl Component for Pos {
    type Storage = VecStorage<Self>;
}

struct Execution;

impl<'a> System<'a> for Execution {
    type SystemData = (Entities<'a>, Fetch<'a, LazyUpdate>);

    fn run(&mut self, (ent, lazy): Self::SystemData) {      
        for entity in ent.join() {
            lazy.execute(move |world| {
                if world.is_alive(entity) {
                    println!("Entity {:?} is alive.", entity);
                }
            });
        }
    }
}

Trait Implementations

impl Default for LazyUpdate
[src]

Returns the "default value" for a type. Read more

impl Drop for LazyUpdate
[src]

A method called when the value goes out of scope. Read more