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

Method tick

src/controls/if_then_else_node.cpp:29–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29NodeStatus IfThenElseNode::tick()
30{
31 const size_t children_count = children_nodes_.size();
32
33 if(children_count != 2 && children_count != 3)
34 {
35 throw std::logic_error("IfThenElseNode must have either 2 or 3 children");
36 }
37
38 setStatus(NodeStatus::RUNNING);
39
40 if(child_idx_ == 0)
41 {
42 const NodeStatus condition_status = children_nodes_[0]->executeTick();
43
44 if(condition_status == NodeStatus::RUNNING)
45 {
46 return condition_status;
47 }
48 if(condition_status == NodeStatus::SUCCESS)
49 {
50 child_idx_ = 1;
51 }
52 else if(condition_status == NodeStatus::FAILURE)
53 {
54 if(children_count == 3)
55 {
56 child_idx_ = 2;
57 }
58 else
59 {
60 return condition_status;
61 }
62 }
63 }
64 // not an else
65 if(child_idx_ > 0)
66 {
67 const NodeStatus status = children_nodes_[child_idx_]->executeTick();
68 if(status == NodeStatus::RUNNING)
69 {
70 return NodeStatus::RUNNING;
71 }
72 resetChildren();
73 child_idx_ = 0;
74 return status;
75 }
76
77 throw std::logic_error("Something unexpected happened in IfThenElseNode");
78}
79
80} // namespace BT

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.45
executeTickMethod · 0.45

Tested by

no test coverage detected