![]() |
Ember
|
Represents a complete behavior tree data structure. More...
#include <BehaviorTree.h>
Classes | |
| struct | ValidationResult |
| Tree validation results. More... | |
Public Types | |
| enum class | ExecutionState { Idle , Running , Paused , Completed , Failed } |
| Tree execution states. More... | |
| using | NodeChangeCallback = std::function<void(Node *, const EmberCore::String &change_type)> |
| using | TreeChangeCallback = std::function<void(const EmberCore::String &change_type)> |
Public Member Functions | |
| BehaviorTree (const EmberCore::String &name="Behavior Tree") | |
| Constructor. | |
| ~BehaviorTree () | |
| Destructor. | |
| void | SetRootNode (std::unique_ptr< Node > root) |
| void | SetRootNode (std::shared_ptr< Node > root) |
| Node * | GetRootNode () const |
| std::shared_ptr< Node > | GetRootNodeShared () const |
| bool | HasRootNode () const |
| const EmberCore::String & | GetName () const |
| void | SetName (const EmberCore::String &name) |
| const EmberCore::String & | GetDescription () const |
| void | SetDescription (const EmberCore::String &description) |
| size_t | GetNodeCount () const |
| size_t | GetMaxDepth () const |
| std::vector< Node * > | GetAllNodes () |
| std::vector< const Node * > | GetAllNodes () const |
| Node * | FindNodeById (size_t id) const |
| Node * | FindNodeByName (const EmberCore::String &name) const |
| std::vector< Node * > | FindNodesByType (Node::Type type) const |
| bool | AddNode (std::unique_ptr< Node > node, Node *parent=nullptr) |
| bool | RemoveNode (size_t node_id) |
| bool | MoveNode (size_t node_id, Node *new_parent) |
| std::unique_ptr< Node > | ExtractNode (size_t node_id) |
| ValidationResult | Validate () const |
| bool | IsValid () const |
| bool | HasCycles () const |
| ExecutionState | GetExecutionState () const |
| void | SetExecutionState (ExecutionState state) |
| void | Clear () |
| std::unique_ptr< BehaviorTree > | Clone () const |
| void | Reset () |
| void | AddBlackboard (std::unique_ptr< Blackboard > blackboard) |
| Blackboard * | GetBlackboard (const EmberCore::String &id) |
| const Blackboard * | GetBlackboard (const EmberCore::String &id) const |
| bool | HasBlackboard (const EmberCore::String &id) const |
| void | RemoveBlackboard (const EmberCore::String &id) |
| const std::map< EmberCore::String, std::unique_ptr< Blackboard > > & | GetBlackboards () const |
| size_t | GetBlackboardCount () const |
| void | ClearBlackboards () |
| EmberCore::String | Serialize () const |
| bool | Deserialize (const EmberCore::String &data) |
| bool | SaveToFile (const EmberCore::String &filename) const |
| bool | LoadFromFile (const EmberCore::String &filename) |
| void | TraverseNodes (std::function< void(Node *)> visitor) |
| void | TraverseNodes (std::function< void(const Node *)> visitor) const |
| void | TraversePreOrder (std::function< void(Node *)> visitor) |
| void | TraversePostOrder (std::function< void(Node *)> visitor) |
| void | SetNodeChangeCallback (NodeChangeCallback callback) |
| void | SetTreeChangeCallback (TreeChangeCallback callback) |
| void | PrintTree () const |
| EmberCore::String | GetTreeStructure () const |
| std::unordered_map< Node::Type, size_t > | GetNodeTypeStatistics () const |
| void | SetMetadata (const EmberCore::String &key, const EmberCore::String &value) |
| EmberCore::String | GetMetadata (const EmberCore::String &key) const |
| void | RemoveMetadata (const EmberCore::String &key) |
| const std::unordered_map< EmberCore::String, EmberCore::String > & | GetAllMetadata () const |
| XMLMetadata & | GetXMLMetadata () |
| const XMLMetadata & | GetXMLMetadata () const |
Protected Member Functions | |
| void | NotifyNodeChange (Node *node, const EmberCore::String &change_type) |
| void | NotifyTreeChange (const EmberCore::String &change_type) |
| void | UpdateNodeIndex () |
| Node * | FindNodeRecursive (Node *current, std::function< bool(const Node *)> predicate) const |
| void | CollectNodesRecursive (Node *current, std::vector< Node * > &nodes) |
| void | CollectNodesRecursive (const Node *current, std::vector< const Node * > &nodes) const |
Private Member Functions | |
| ValidationResult | ValidateNode (const Node *node, std::vector< const Node * > &visited) const |
| void | BuildNodeIndex (Node *node) |
Private Attributes | |
| std::unique_ptr< Node > | root_node_ |
| std::shared_ptr< Node > | root_node_shared_ |
| EmberCore::String | name_ |
| EmberCore::String | description_ |
| ExecutionState | execution_state_ |
| std::unordered_map< size_t, Node * > | node_index_ |
| std::unordered_map< EmberCore::String, EmberCore::String > | metadata_ |
| XMLMetadata | xml_metadata_ |
| std::map< EmberCore::String, std::unique_ptr< Blackboard > > | blackboards_ |
| NodeChangeCallback | node_change_callback_ |
| TreeChangeCallback | tree_change_callback_ |
Represents a complete behavior tree data structure.
This class manages the entire behavior tree as a data structure, separate from its visualization. It provides tree-level operations, validation, serialization, and manipulation capabilities.
Definition at line 54 of file BehaviorTree.h.
| using EmberCore::BehaviorTree::NodeChangeCallback = std::function<void(Node *, const EmberCore::String &change_type)> |
Definition at line 165 of file BehaviorTree.h.
| using EmberCore::BehaviorTree::TreeChangeCallback = std::function<void(const EmberCore::String &change_type)> |
Definition at line 166 of file BehaviorTree.h.
|
strong |
Tree execution states.
| Enumerator | |
|---|---|
| Idle | |
| Running | |
| Paused | |
| Completed | |
| Failed | |
Definition at line 59 of file BehaviorTree.h.
|
explicit |
| EmberCore::BehaviorTree::~BehaviorTree | ( | ) |
Destructor.
Definition at line 15 of file BehaviorTree.cpp.
| void EmberCore::BehaviorTree::AddBlackboard | ( | std::unique_ptr< Blackboard > | blackboard | ) |
Definition at line 496 of file BehaviorTree.cpp.
Definition at line 83 of file BehaviorTree.cpp.
|
private |
Definition at line 456 of file BehaviorTree.cpp.
| void EmberCore::BehaviorTree::Clear | ( | ) |
Definition at line 186 of file BehaviorTree.cpp.
| void EmberCore::BehaviorTree::ClearBlackboards | ( | ) |
Definition at line 534 of file BehaviorTree.cpp.
| std::unique_ptr< BehaviorTree > EmberCore::BehaviorTree::Clone | ( | ) | const |
Definition at line 193 of file BehaviorTree.cpp.
|
protected |
Definition at line 365 of file BehaviorTree.cpp.
|
protected |
Definition at line 355 of file BehaviorTree.cpp.
| bool EmberCore::BehaviorTree::Deserialize | ( | const EmberCore::String & | data | ) |
| std::unique_ptr< Node > EmberCore::BehaviorTree::ExtractNode | ( | size_t | node_id | ) |
| Node * EmberCore::BehaviorTree::FindNodeById | ( | size_t | id | ) | const |
Definition at line 63 of file BehaviorTree.cpp.
| Node * EmberCore::BehaviorTree::FindNodeByName | ( | const EmberCore::String & | name | ) | const |
Definition at line 68 of file BehaviorTree.cpp.
|
protected |
Definition at line 338 of file BehaviorTree.cpp.
| std::vector< Node * > EmberCore::BehaviorTree::FindNodesByType | ( | Node::Type | type | ) | const |
Definition at line 72 of file BehaviorTree.cpp.
|
inline |
Definition at line 180 of file BehaviorTree.h.
| std::vector< Node * > EmberCore::BehaviorTree::GetAllNodes | ( | ) |
Definition at line 45 of file BehaviorTree.cpp.
| std::vector< const Node * > EmberCore::BehaviorTree::GetAllNodes | ( | ) | const |
Definition at line 54 of file BehaviorTree.cpp.
| Blackboard * EmberCore::BehaviorTree::GetBlackboard | ( | const EmberCore::String & | id | ) |
Definition at line 512 of file BehaviorTree.cpp.
| const Blackboard * EmberCore::BehaviorTree::GetBlackboard | ( | const EmberCore::String & | id | ) | const |
Definition at line 517 of file BehaviorTree.cpp.
|
inline |
Definition at line 147 of file BehaviorTree.h.
|
inline |
Definition at line 146 of file BehaviorTree.h.
|
inline |
Definition at line 106 of file BehaviorTree.h.
|
inline |
Definition at line 132 of file BehaviorTree.h.
| size_t EmberCore::BehaviorTree::GetMaxDepth | ( | ) | const |
Definition at line 38 of file BehaviorTree.cpp.
| EmberCore::String EmberCore::BehaviorTree::GetMetadata | ( | const EmberCore::String & | key | ) | const |
Definition at line 309 of file BehaviorTree.cpp.
|
inline |
Definition at line 103 of file BehaviorTree.h.
| size_t EmberCore::BehaviorTree::GetNodeCount | ( | ) | const |
Definition at line 31 of file BehaviorTree.cpp.
| std::unordered_map< Node::Type, size_t > EmberCore::BehaviorTree::GetNodeTypeStatistics | ( | ) | const |
Definition at line 295 of file BehaviorTree.cpp.
|
inline |
Definition at line 98 of file BehaviorTree.h.
|
inline |
Definition at line 99 of file BehaviorTree.h.
| EmberCore::String EmberCore::BehaviorTree::GetTreeStructure | ( | ) | const |
Definition at line 282 of file BehaviorTree.cpp.
|
inline |
Definition at line 183 of file BehaviorTree.h.
|
inline |
Definition at line 184 of file BehaviorTree.h.
| bool EmberCore::BehaviorTree::HasBlackboard | ( | const EmberCore::String & | id | ) | const |
Definition at line 522 of file BehaviorTree.cpp.
| bool EmberCore::BehaviorTree::HasCycles | ( | ) | const |
Definition at line 180 of file BehaviorTree.cpp.
|
inline |
Definition at line 100 of file BehaviorTree.h.
|
inline |
Definition at line 128 of file BehaviorTree.h.
| bool EmberCore::BehaviorTree::LoadFromFile | ( | const EmberCore::String & | filename | ) |
| bool EmberCore::BehaviorTree::MoveNode | ( | size_t | node_id, |
| Node * | new_parent ) |
Definition at line 143 of file BehaviorTree.cpp.
|
protected |
Definition at line 319 of file BehaviorTree.cpp.
|
protected |
Definition at line 325 of file BehaviorTree.cpp.
| void EmberCore::BehaviorTree::PrintTree | ( | ) | const |
Definition at line 273 of file BehaviorTree.cpp.
| void EmberCore::BehaviorTree::RemoveBlackboard | ( | const EmberCore::String & | id | ) |
Definition at line 526 of file BehaviorTree.cpp.
| void EmberCore::BehaviorTree::RemoveMetadata | ( | const EmberCore::String & | key | ) |
Definition at line 314 of file BehaviorTree.cpp.
| bool EmberCore::BehaviorTree::RemoveNode | ( | size_t | node_id | ) |
Definition at line 112 of file BehaviorTree.cpp.
| void EmberCore::BehaviorTree::Reset | ( | ) |
Definition at line 207 of file BehaviorTree.cpp.
| bool EmberCore::BehaviorTree::SaveToFile | ( | const EmberCore::String & | filename | ) | const |
| EmberCore::String EmberCore::BehaviorTree::Serialize | ( | ) | const |
|
inline |
Definition at line 107 of file BehaviorTree.h.
|
inline |
Definition at line 133 of file BehaviorTree.h.
| void EmberCore::BehaviorTree::SetMetadata | ( | const EmberCore::String & | key, |
| const EmberCore::String & | value ) |
Definition at line 304 of file BehaviorTree.cpp.
|
inline |
Definition at line 104 of file BehaviorTree.h.
|
inline |
Definition at line 168 of file BehaviorTree.h.
| void EmberCore::BehaviorTree::SetRootNode | ( | std::shared_ptr< Node > | root | ) |
Definition at line 24 of file BehaviorTree.cpp.
| void EmberCore::BehaviorTree::SetRootNode | ( | std::unique_ptr< Node > | root | ) |
Definition at line 17 of file BehaviorTree.cpp.
|
inline |
Definition at line 169 of file BehaviorTree.h.
| void EmberCore::BehaviorTree::TraverseNodes | ( | std::function< void(const Node *)> | visitor | ) | const |
Definition at line 222 of file BehaviorTree.cpp.
| void EmberCore::BehaviorTree::TraverseNodes | ( | std::function< void(Node *)> | visitor | ) |
Definition at line 216 of file BehaviorTree.cpp.
| void EmberCore::BehaviorTree::TraversePostOrder | ( | std::function< void(Node *)> | visitor | ) |
Definition at line 250 of file BehaviorTree.cpp.
| void EmberCore::BehaviorTree::TraversePreOrder | ( | std::function< void(Node *)> | visitor | ) |
Definition at line 230 of file BehaviorTree.cpp.
|
protected |
Definition at line 331 of file BehaviorTree.cpp.
| BehaviorTree::ValidationResult EmberCore::BehaviorTree::Validate | ( | ) | const |
Definition at line 149 of file BehaviorTree.cpp.
|
private |
Definition at line 375 of file BehaviorTree.cpp.
|
private |
Definition at line 213 of file BehaviorTree.h.
|
private |
Definition at line 200 of file BehaviorTree.h.
|
private |
Definition at line 201 of file BehaviorTree.h.
|
private |
Definition at line 207 of file BehaviorTree.h.
|
private |
Definition at line 199 of file BehaviorTree.h.
|
private |
Definition at line 216 of file BehaviorTree.h.
|
private |
Definition at line 204 of file BehaviorTree.h.
|
private |
Definition at line 197 of file BehaviorTree.h.
|
private |
Definition at line 198 of file BehaviorTree.h.
|
private |
Definition at line 217 of file BehaviorTree.h.
|
private |
Definition at line 210 of file BehaviorTree.h.