[]Struct amethyst::ecs::prelude::LazyUpdate

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().

Lazy updates are dispatched in the order that they are requested. Multiple updates sent from one system may be overridden by updates sent from other systems.

Please note that the provided methods take &self so there's no need to get LazyUpdate mutably. This resource is added to the world by default.

Methods

impl LazyUpdate

Creates a new LazyBuilder which inserts components using LazyUpdate. This means that the components won't be available immediately, but only after a maintain on World is performed.

Examples

struct Pos(f32, f32);

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

let my_entity = lazy
    .create_entity(&entities)
    .with(Pos(1.0, 3.0))
    .build();

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>, Read<'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>, Read<'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>, Read<'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>, Read<'a, LazyUpdate>);

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

Lazily executes a closure with mutable world access.

This can be used to add a resource to the World from a system.

Examples


struct Sys;

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

    fn run(&mut self, (ent, lazy): Self::SystemData) {
        for entity in ent.join() {
            lazy.exec_mut(move |world| {
                // complete extermination!
                world.delete_all();
            });
        }
    }
}

Trait Implementations

impl Default for LazyUpdate

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

impl Drop for LazyUpdate

Executes the destructor for this type. Read more

Auto Trait Implementations

impl Send for LazyUpdate

impl Sync for LazyUpdate

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T> Resource for T where
    T: Any + Send + Sync

impl<T> Any for T where
    T: Any

impl<T> TryDefault for T where
    T: Default

Tries to create the default.

Calls try_default and panics on an error case.

impl<T> Event for T where
    T: Send + Sync + 'static, 

impl<T> Erased for T

impl<T> Downcast for T where
    T: Any

Convert Box<Trait> (where Trait: Downcast) to Box<Any>. Box<Any> can then be further downcast into Box<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

impl<T> SetParameter for T

Sets value as a parameter of self.