From 09d8880b175cc18039d045216291c045b9578737 Mon Sep 17 00:00:00 2001 From: andriyDev Date: Thu, 9 Jan 2025 22:51:33 -0800 Subject: [PATCH 1/3] Remove the debug requirement for BT. The only function that needs BT to be debug is `get_graphviz`. By isolating the impl blocks, we can allow users to have non-Debug types for their behavior trees, while still allowing it for those who want graphviz stuff! --- bonsai/src/bt.rs | 60 +++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/bonsai/src/bt.rs b/bonsai/src/bt.rs index ee7b7a1..bfef213 100644 --- a/bonsai/src/bt.rs +++ b/bonsai/src/bt.rs @@ -39,7 +39,7 @@ pub struct BT { bb: BlackBoard, } -impl BT { +impl BT { pub fn new(behavior: Behavior, blackboard: K) -> Self { let backup_behavior = behavior.clone(); let bt = State::new(behavior); @@ -73,6 +73,36 @@ impl BT { self.state.tick(e, &mut self.bb, f) } + /// Retrieve a mutable reference to the blackboard for + /// this Behavior Tree + pub fn get_blackboard(&mut self) -> &mut BlackBoard { + &mut self.bb + } + + /// Retrieve a mutable reference to the internal state + /// of the Behavior Tree + pub fn get_state(bt: &mut BT) -> &mut State { + &mut bt.state + } + + /// The behavior tree is a stateful data structure in which the immediate + /// state of the BT is allocated and updated in heap memory through the lifetime + /// of the BT. The state of the BT is said to be `transient` meaning upon entering + /// a this state, the process may never return this state again. If a behavior concludes, + /// only the latest results will be stored in heap memory. + /// + /// If your BT has surpassed a desired state or that your BT has reached a steady state - meaning + /// that the behavior has concluded and ticking the BT won't progress any further - then it could + /// be desirable to return the BT to it's initial state at t=0.0 before it was ever ticked. + /// + /// PS! invoking reset_bt does not reset the Blackboard. + pub fn reset_bt(&mut self) { + let initial_behavior = self.initial_behavior.to_owned(); + self.state = State::new(initial_behavior) + } +} + +impl BT { /// Compile the behavior tree into a [graphviz](https://graphviz.org/) compatible [DiGraph](https://docs.rs/petgraph/latest/petgraph/graph/type.DiGraph.html). /// /// ```rust @@ -117,34 +147,6 @@ impl BT { let digraph = Dot::with_config(&graph, &[Config::EdgeNoLabel]); (format!("{:?}", digraph), graph) } - - /// Retrieve a mutable reference to the blackboard for - /// this Behavior Tree - pub fn get_blackboard(&mut self) -> &mut BlackBoard { - &mut self.bb - } - - /// Retrieve a mutable reference to the internal state - /// of the Behavior Tree - pub fn get_state(bt: &mut BT) -> &mut State { - &mut bt.state - } - - /// The behavior tree is a stateful data structure in which the immediate - /// state of the BT is allocated and updated in heap memory through the lifetime - /// of the BT. The state of the BT is said to be `transient` meaning upon entering - /// a this state, the process may never return this state again. If a behavior concludes, - /// only the latest results will be stored in heap memory. - /// - /// If your BT has surpassed a desired state or that your BT has reached a steady state - meaning - /// that the behavior has concluded and ticking the BT won't progress any further - then it could - /// be desirable to return the BT to it's initial state at t=0.0 before it was ever ticked. - /// - /// PS! invoking reset_bt does not reset the Blackboard. - pub fn reset_bt(&mut self) { - let initial_behavior = self.initial_behavior.to_owned(); - self.state = State::new(initial_behavior) - } } #[cfg(test)] From 22f84a47883c672f2f0c0a2f0aaaa7298af182b5 Mon Sep 17 00:00:00 2001 From: andriyDev Date: Thu, 9 Jan 2025 23:43:26 -0800 Subject: [PATCH 2/3] Remove the debug requirement for `State`. --- bonsai/src/bt.rs | 1 - bonsai/src/sequence.rs | 2 -- bonsai/src/state.rs | 1 - bonsai/src/when_all.rs | 2 -- 4 files changed, 6 deletions(-) diff --git a/bonsai/src/bt.rs b/bonsai/src/bt.rs index bfef213..9e7f04b 100644 --- a/bonsai/src/bt.rs +++ b/bonsai/src/bt.rs @@ -68,7 +68,6 @@ impl BT { where E: UpdateEvent, F: FnMut(ActionArgs, &mut BlackBoard) -> (Status, f64), - A: Debug, { self.state.tick(e, &mut self.bb, f) } diff --git a/bonsai/src/sequence.rs b/bonsai/src/sequence.rs index 2ada13b..e51f697 100644 --- a/bonsai/src/sequence.rs +++ b/bonsai/src/sequence.rs @@ -1,6 +1,5 @@ use crate::status::Status::*; use crate::{event::UpdateEvent, ActionArgs, Behavior, State, Status, RUNNING}; -use std::fmt::Debug; pub struct SequenceArgs<'a, A, E, F, B> { pub select: bool, @@ -22,7 +21,6 @@ where A: Clone, E: UpdateEvent, F: FnMut(ActionArgs, &mut B) -> (Status, f64), - A: Debug, { let SequenceArgs { select, diff --git a/bonsai/src/state.rs b/bonsai/src/state.rs index 1cb0a8d..9886477 100644 --- a/bonsai/src/state.rs +++ b/bonsai/src/state.rs @@ -125,7 +125,6 @@ impl State { where E: UpdateEvent, F: FnMut(ActionArgs, &mut B) -> (Status, f64), - A: Debug, { let upd = e.update(|args| Some(args.dt)).unwrap_or(None); diff --git a/bonsai/src/when_all.rs b/bonsai/src/when_all.rs index ee2abe7..3e3954f 100644 --- a/bonsai/src/when_all.rs +++ b/bonsai/src/when_all.rs @@ -1,6 +1,5 @@ use crate::status::Status::*; use crate::{event::UpdateEvent, ActionArgs, State, Status, RUNNING}; -use std::fmt::Debug; // `WhenAll` and `WhenAny` share same algorithm. // @@ -19,7 +18,6 @@ where A: Clone, E: UpdateEvent, F: FnMut(ActionArgs, &mut B) -> (Status, f64), - A: Debug, { let (status, inv_status) = if any { // `WhenAny` From afb66671edf6cde29844c54f308a4a8fda68d4c0 Mon Sep 17 00:00:00 2001 From: andriyDev Date: Sun, 12 Jan 2025 14:03:01 -0800 Subject: [PATCH 3/3] Bump the minor version of the crate. --- bonsai/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bonsai/Cargo.toml b/bonsai/Cargo.toml index 768e689..e9000f6 100644 --- a/bonsai/Cargo.toml +++ b/bonsai/Cargo.toml @@ -12,7 +12,7 @@ name = "bonsai-bt" readme = "../README.md" repository = "https://github.com/sollimann/bonsai.git" rust-version = "1.80.0" -version = "0.8.0" +version = "0.8.1" [lib] name = "bonsai_bt"