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

Method executeTick

src/tree_node.cpp:71–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69TreeNode::~TreeNode() = default;
70
71NodeStatus TreeNode::executeTick()
72{
73 auto new_status = _p->status;
74 PreTickCallback pre_tick;
75 PostTickCallback post_tick;
76 TickMonitorCallback monitor_tick;
77 {
78 const std::scoped_lock lk(_p->callback_injection_mutex);
79 pre_tick = _p->pre_tick_callback;
80 post_tick = _p->post_tick_callback;
81 monitor_tick = _p->tick_monitor_callback;
82 }
83
84 // a pre-condition may return the new status.
85 // In this case it override the actual tick()
86 if(auto precond = checkPreConditions())
87 {
88 new_status = precond.value();
89 }
90 else
91 {
92 // injected pre-callback
93 bool substituted = false;
94 if(pre_tick && !isStatusCompleted(_p->status))
95 {
96 auto override_status = pre_tick(*this);
97 if(isStatusCompleted(override_status))
98 {
99 // don't execute the actual tick()
100 substituted = true;
101 new_status = override_status;
102 }
103 }
104
105 // Call the ACTUAL tick
106 if(!substituted)
107 {
108 using namespace std::chrono;
109 // Use atomic_thread_fence to prevent compiler reordering of time measurements.
110 // See issue #861 for details.
111 const auto t1 = steady_clock::now();
112 std::atomic_thread_fence(std::memory_order_seq_cst);
113 try
114 {
115 new_status = tick();
116 }
117 catch(const NodeExecutionError&)
118 {
119 // Already wrapped by a child node, re-throw as-is to preserve original info
120 throw;
121 }
122 catch(const std::exception& ex)
123 {
124 // Wrap the exception with this node's context
125 throw NodeExecutionError({ name(), fullPath(), registrationName() }, ex.what());
126 }
127 std::atomic_thread_fence(std::memory_order_seq_cst);
128 const auto t2 = steady_clock::now();

Callers 15

tickRootMethod · 0.45
tickMethod · 0.45
tickMethod · 0.45
tickMethod · 0.45
tickMethod · 0.45
tickMethod · 0.45
tickMethod · 0.45
haltMethod · 0.45
tickMethod · 0.45
tickMethod · 0.45
tickMethod · 0.45
tickMethod · 0.45

Calls 4

isStatusCompletedFunction · 0.85
NodeExecutionErrorClass · 0.85
valueMethod · 0.45
whatMethod · 0.45

Tested by 11

TickWhileRunningFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TESTFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
executeWhileRunningFunction · 0.36
TESTFunction · 0.36