#![no_std]
#![doc = include_str!("../README.md")]
#[cfg(doctest)]
doc_comment::doctest!("../README.md");
#[doc(hidden)]
extern crate alloc;
pub mod prelude;
pub mod behavior; mod error;
pub mod factory; pub mod port; mod tree;
mod xml;
pub use behavior::{
Behavior, BehaviorError, BehaviorExecution, BehaviorKind, BehaviorResult, BehaviorState, behavior_data::BehaviorData,
behavior_description::BehaviorDescription,
};
pub use error::{BehaviorTreeResult, Error};
pub use factory::BehaviorTreeFactory;
pub use port::PortList;
#[cfg(feature = "std")]
pub use tree::observer::groot2_connector::Groot2Connector;
pub use tree::observer::tree_observer::BehaviorTreeObserver;
pub use tree::{BehaviorTree, BehaviorTreeElement};
pub use xml::creator::XmlCreator;
pub use behaviortree_derive::{Action, Condition, Control, Decorator};
pub use spin::Mutex;
use alloc::sync::Arc;
type ConstString = Arc<str>;
pub const EMPTY_STR: &str = "";
pub const FAILURE: &str = "Failure";
pub const IDLE: &str = "Idle";
pub const RUNNING: &str = "Running";
pub const SKIPPED: &str = "Skipped";
pub const SUCCESS: &str = "Success";
pub const ACTION: &str = "Action";
pub const CONDITION: &str = "Condition";
pub const CONTROL: &str = "Control";
pub const DECORATOR: &str = "Decorator";
pub const SUBTREE: &str = "SubTree";
pub const BEHAVIORTREE: &str = "BehaviorTree";
pub const TREENODESMODEL: &str = "TreeNodesModel";
const NAME: &str = "name";
const ID: &str = "ID";
const DEFAULT: &str = "default";
const AUTOREMAP: &str = "_autoremap";
const FAILURE_IF: &str = "_failureIf";
const SUCCESS_IF: &str = "_successIf";
const SKIP_IF: &str = "_skipIf";
const WHILE: &str = "_while";
const ON_HALTED: &str = "_onHalted";
const ON_FAILURE: &str = "_onFailure";
const ON_SUCCESS: &str = "_onSuccess";
const POST: &str = "_post";
#[deprecated(since = "0.7.3", note = "use <T>::register(...)")]
#[macro_export]
macro_rules! register_behavior {
($factory:ident, $tp:ty, $name:literal $(,)?) => {{
$factory.register_behavior_type::<$tp>($name)
}};
($factory:ident, $tp:ty, $name:literal, $($arg:expr),* $(,)?) => {{
let bhvr_desc = $crate::behavior::behavior_description::BehaviorDescription::new($name, stringify!($tp), <$tp>::kind(), false, <$tp>::provided_ports());
let bhvr_creation_fn = alloc::boxed::Box::new(move || -> alloc::boxed::Box<dyn $crate::behavior::BehaviorExecution> {
alloc::boxed::Box::new(<$tp>::new($($arg),*))
});
$factory
.registry_mut()
.add_behavior(bhvr_desc, bhvr_creation_fn)
}};
}
#[deprecated(since = "0.7.3", note = "use <T>::register(...)")]
#[macro_export]
macro_rules! register_groot2_behavior {
($factory:ident, $tp:ty, $name:literal $(,)?) => {{
$factory.register_behavior_type::<$tp>($name)
}};
($factory:ident, $tp:ty, $name:literal, $($arg:expr),* $(,)?) => {{
let bhvr_desc = $crate::behavior::behavior_description::BehaviorDescription::new($name, stringify!($tp), <$tp>::kind(), true, <$tp>::provided_ports());
let bhvr_creation_fn = alloc::boxed::Box::new(move || -> alloc::boxed::Box<dyn $crate::behavior::BehaviorExecution> {
alloc::boxed::Box::new(<$tp>::new($($arg),*))
});
$factory
.registry_mut()
.add_behavior(bhvr_desc, bhvr_creation_fn)
}};
}
#[macro_export]
macro_rules! register_simple_behavior {
($factory:ident, $fn:path, $name:literal, $kind:path $(,)?) => {{ $factory.register_simple_function($name, alloc::sync::Arc::new($fn), $kind) }};
($factory:ident, $fn:path, $name:literal, $ports:expr, $kind:path $(,)?) => {{ $factory.register_simple_function_with_ports($name, alloc::sync::Arc::new($fn), $kind, $ports) }};
($factory:ident, $item:expr, $($fun:ident, $name:literal, $kind:path $(,)?)+) => {{
let base = alloc::sync::Arc::new(behaviortree::Mutex::new($item));
let mut res = Ok(base.clone());
$({
let item = base.clone();
if let Err(err) =$factory.register_simple_function($name, alloc::sync::Arc::new(move || { item.lock().$fun() }), $kind) {
res = Err(err);
}
})+;
res
}};
}
#[macro_export]
macro_rules! register_scripting_enum {
($factory:ident, $tp:ty) => {
for (key, value) in <$tp>::key_value_tuples() {
$factory.register_enum_tuple(key, value)?;
}
};
($factory:ident, $($key:literal, $value:literal),+ $(,)?) => {
$( $factory.register_enum_tuple($key, $value)?; )+;
};
}