Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the debug requirement for BT impls. #39

Merged
merged 3 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bonsai/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
61 changes: 31 additions & 30 deletions bonsai/src/bt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct BT<A, K> {
bb: BlackBoard<K>,
}

impl<A: Clone + Debug, K: Debug> BT<A, K> {
impl<A: Clone, K> BT<A, K> {
pub fn new(behavior: Behavior<A>, blackboard: K) -> Self {
let backup_behavior = behavior.clone();
let bt = State::new(behavior);
Expand Down Expand Up @@ -68,11 +68,40 @@ impl<A: Clone + Debug, K: Debug> BT<A, K> {
where
E: UpdateEvent,
F: FnMut(ActionArgs<E, A>, &mut BlackBoard<K>) -> (Status, f64),
A: Debug,
{
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<K> {
&mut self.bb
}

/// Retrieve a mutable reference to the internal state
/// of the Behavior Tree
pub fn get_state(bt: &mut BT<A, K>) -> &mut State<A> {
&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<A: Clone + Debug, K: Debug> BT<A, K> {
/// Compile the behavior tree into a [graphviz](https://graphviz.org/) compatible [DiGraph](https://docs.rs/petgraph/latest/petgraph/graph/type.DiGraph.html).
///
/// ```rust
Expand Down Expand Up @@ -117,34 +146,6 @@ impl<A: Clone + Debug, K: Debug> BT<A, K> {
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<K> {
&mut self.bb
}

/// Retrieve a mutable reference to the internal state
/// of the Behavior Tree
pub fn get_state(bt: &mut BT<A, K>) -> &mut State<A> {
&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)]
Expand Down
2 changes: 0 additions & 2 deletions bonsai/src/sequence.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -22,7 +21,6 @@ where
A: Clone,
E: UpdateEvent,
F: FnMut(ActionArgs<E, A>, &mut B) -> (Status, f64),
A: Debug,
{
let SequenceArgs {
select,
Expand Down
1 change: 0 additions & 1 deletion bonsai/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ impl<A: Clone> State<A> {
where
E: UpdateEvent,
F: FnMut(ActionArgs<E, A>, &mut B) -> (Status, f64),
A: Debug,
{
let upd = e.update(|args| Some(args.dt)).unwrap_or(None);

Expand Down
2 changes: 0 additions & 2 deletions bonsai/src/when_all.rs
Original file line number Diff line number Diff line change
@@ -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.
//
Expand All @@ -19,7 +18,6 @@ where
A: Clone,
E: UpdateEvent,
F: FnMut(ActionArgs<E, A>, &mut B) -> (Status, f64),
A: Debug,
{
let (status, inv_status) = if any {
// `WhenAny`
Expand Down
Loading