MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / tick

Method tick

src/controls/try_catch_node.cpp:55–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55NodeStatus TryCatchNode::tick()
56{
57 const size_t children_count = children_nodes_.size();
58
59 if(children_count < 2)
60 {
61 throw LogicError("[", name(), "]: TryCatch requires at least 2 children");
62 }
63
64 if(!isStatusActive(status()))
65 {
66 skipped_count_ = 0;
67 in_catch_ = false;
68 }
69
70 setStatus(NodeStatus::RUNNING);
71
72 const size_t try_count = children_count - 1;
73
74 // If we are in catch mode, tick the last child (cleanup)
75 if(in_catch_)
76 {
77 TreeNode* catch_child = children_nodes_.back();
78 const NodeStatus catch_status = catch_child->executeTick();
79
80 if(catch_status == NodeStatus::RUNNING)
81 {
82 return NodeStatus::RUNNING;
83 }
84
85 // Catch child finished (SUCCESS or FAILURE): return FAILURE
86 resetChildren();
87 current_child_idx_ = 0;
88 in_catch_ = false;
89 return NodeStatus::FAILURE;
90 }
91
92 // Try-block: execute children 0..N-2 as a Sequence
93 while(current_child_idx_ < try_count)
94 {
95 TreeNode* current_child_node = children_nodes_[current_child_idx_];
96 const NodeStatus child_status = current_child_node->executeTick();
97
98 switch(child_status)
99 {
100 case NodeStatus::RUNNING: {
101 return NodeStatus::RUNNING;
102 }
103 case NodeStatus::FAILURE: {
104 // Enter catch mode: halt try-block children, then tick catch child
105 resetChildren();
106 current_child_idx_ = 0;
107 in_catch_ = true;
108 return tick(); // re-enter to tick the catch child
109 }
110 case NodeStatus::SUCCESS: {
111 current_child_idx_++;
112 }

Callers

nothing calls this directly

Calls 4

LogicErrorClass · 0.85
isStatusActiveFunction · 0.85
sizeMethod · 0.45
executeTickMethod · 0.45

Tested by

no test coverage detected