Trait emergent::task::Task

source ·
pub trait Task<M = ()>: Send + Sync {
    // Provided methods
    fn is_locked(&self, _memory: &M) -> bool { ... }
    fn on_enter(&mut self, _memory: &mut M) { ... }
    fn on_exit(&mut self, _memory: &mut M) { ... }
    fn on_update(&mut self, _memory: &mut M) { ... }
    fn on_process(&mut self, _memory: &mut M) -> bool { ... }
}
Expand description

Task represent unit of work, an action performed in a time.

Tasks can only manipulate what’s in the memory passed to their life-cycle methods so common way of manipulating the world with tasks is to make memory type that can either command the world or even better, put triggers in the memory before running decision maker, then after that read what changed in the memory and apply changes to the world.

Tasks are managed by calling their life-cycle methods by the decision makers so implement these if you need to do something during that life-cycle phase.

Example

use emergent::prelude::*;

struct Memory { counter: usize }

struct Increment;

impl Task<Memory> for Increment {
    fn on_enter(&mut self, memory: &mut Memory) {
        memory.counter += 1;
    }
}

let mut memory = Memory { counter: 1 };
Increment.on_enter(&mut memory);
assert_eq!(memory.counter, 2);

Provided Methods§

source

fn is_locked(&self, _memory: &M) -> bool

Tells if task is locked (it’s still running). Used by decision makers to tell if one can change its state (when current task is not locked).

source

fn on_enter(&mut self, _memory: &mut M)

Action performed when task starts its work.

source

fn on_exit(&mut self, _memory: &mut M)

Action performed when task stops its work.

source

fn on_update(&mut self, _memory: &mut M)

Action performed when task is active and gets updated.

source

fn on_process(&mut self, _memory: &mut M) -> bool

Action performed when task is active but decision maker did not changed its state. This one is applicable for making hierarchical decision makers (telling children decision makers to decide on new state, because some if not all decision makers are tasks).

Returns true if this task decided on new state.

Implementors§

source§

impl<M> Task<M> for BehaviorTreeTask<M>

source§

impl<M> Task<M> for Parallelizer<M>

source§

impl<M> Task<M> for Selector<M>

source§

impl<M> Task<M> for Sequencer<M>

source§

impl<M> Task<M> for NoDecisionMaker

source§

impl<M> Task<M> for ClosureTask<M>

source§

impl<M> Task<M> for NoTask

source§

impl<M, CK, AK> Task<M> for Planner<M, CK, AK>
where CK: Clone + Hash + Eq + Send + Sync, AK: Clone + Hash + Eq + Send + Sync,

source§

impl<M, K> Task<M> for Machinery<M, K>
where K: Clone + Hash + Eq + Send + Sync,

source§

impl<M, K> Task<M> for Reasoner<M, K>
where K: Clone + Hash + Eq + Send + Sync,

source§

impl<M, K> Task<M> for SingleDecisionMaker<K>
where K: Send + Sync,