pub enum BehaviorNode {
Sequence {
name: String,
children: Vec<BehaviorNode>,
cursor: usize,
},
Selector {
name: String,
children: Vec<BehaviorNode>,
cursor: usize,
},
Parallel {
name: String,
children: Vec<BehaviorNode>,
policy: ParallelPolicy,
},
Decorator {
name: String,
kind: DecoratorKind,
child: Box<BehaviorNode>,
state: DecoratorState,
},
Leaf {
name: String,
on_enter: Option<Box<dyn FnMut(&mut Blackboard)>>,
on_tick: Box<dyn FnMut(&mut Blackboard, f32) -> NodeStatus>,
on_exit: Option<Box<dyn FnMut(&mut Blackboard, NodeStatus)>>,
entered: bool,
},
SubtreeRef {
name: String,
},
}Expand description
The complete behavior tree node type.
Nodes are stored in a Box<BehaviorNode> tree; the root is owned by a
BehaviorTree. Leaf nodes contain a closure (Box<dyn FnMut(…)>) so
they carry arbitrary game-logic without external look-up tables.
Variants§
Sequence
Run children in order; stop and return Failure on the first child that fails. Return Success only when all children succeed.
Fields
children: Vec<BehaviorNode>Selector
Run children in order; stop and return Success on the first child that succeeds. Return Failure only when all children fail.
Parallel
Tick all children every frame regardless of their individual statuses.
Decorator
Wraps exactly one child and modifies how its status is interpreted.
Fields
kind: DecoratorKindchild: Box<BehaviorNode>state: DecoratorStateInternal counter used by Repeat / Timeout / Cooldown decorators.
Leaf
A leaf with user-supplied tick logic.
Fields
on_enter: Option<Box<dyn FnMut(&mut Blackboard)>>Called once when the node first becomes active (optional).
on_tick: Box<dyn FnMut(&mut Blackboard, f32) -> NodeStatus>Main tick function. Return the node’s status.
on_exit: Option<Box<dyn FnMut(&mut Blackboard, NodeStatus)>>Called when the node exits (success, failure, or abort).
SubtreeRef
A subtree stored by name in a SubtreeRegistry. Resolved at tick
time; if the name is unknown the node returns Failure.
Implementations§
Source§impl BehaviorNode
impl BehaviorNode
Sourcepub fn tick(
&mut self,
dt: f32,
bb: &mut Blackboard,
registry: &SubtreeRegistry,
) -> NodeStatus
pub fn tick( &mut self, dt: f32, bb: &mut Blackboard, registry: &SubtreeRegistry, ) -> NodeStatus
Recursively tick this node and return its status.
dt is the elapsed time in seconds since the last tick.
bb is the shared blackboard for this tree.
registry is used to resolve SubtreeRef nodes.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the cursor / state of this node and all its children, so the tree starts fresh on the next tick.
Sourcepub fn collect_names(&self, out: &mut Vec<String>)
pub fn collect_names(&self, out: &mut Vec<String>)
Recursively collect the names of all nodes into out.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BehaviorNode
impl !RefUnwindSafe for BehaviorNode
impl !Send for BehaviorNode
impl !Sync for BehaviorNode
impl Unpin for BehaviorNode
impl UnsafeUnpin for BehaviorNode
impl !UnwindSafe for BehaviorNode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.