Skip to content

Commit d3cd48c

Browse files
committed
reduce the number of times preconditions scripts are executed
1 parent bfe2895 commit d3cd48c

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/tree_node.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,25 @@ TreeNode::PostScripts &TreeNode::postConditionsScripts() {
180180

181181
Expected<NodeStatus> TreeNode::checkPreConditions()
182182
{
183+
Ast::Environment env = {config().blackboard, config().enums};
184+
183185
// check the pre-conditions
184186
for (size_t index = 0; index < size_t(PreCond::COUNT_); index++)
185187
{
186-
PreCond preID = PreCond(index);
187188
const auto& parse_executor = _p->pre_parsed[index];
188189
if (!parse_executor)
189190
{
190191
continue;
191192
}
192-
Ast::Environment env = {config().blackboard, config().enums};
193-
auto result = parse_executor(env);
194-
// what to do if the condition is true
195-
if (result.cast<bool>())
193+
194+
const PreCond preID = PreCond(index);
195+
196+
// Some preconditions are applied only when the node state is IDLE or SKIPPED
197+
if (_p->status == NodeStatus::IDLE ||
198+
_p->status == NodeStatus::SKIPPED)
196199
{
197-
// Some preconditions are applied only when the node is started
198-
if (_p->status == NodeStatus::IDLE)
200+
// what to do if the condition is true
201+
if (parse_executor(env).cast<bool>())
199202
{
200203
if (preID == PreCond::FAILURE_IF)
201204
{
@@ -210,15 +213,19 @@ Expected<NodeStatus> TreeNode::checkPreConditions()
210213
return NodeStatus::SKIPPED;
211214
}
212215
}
216+
// if the conditions is false
217+
else if(preID == PreCond::WHILE_TRUE)
218+
{
219+
return NodeStatus::SKIPPED;
220+
}
213221
}
214-
else // condition is false
222+
else if(_p->status == NodeStatus::RUNNING && preID == PreCond::WHILE_TRUE)
215223
{
216-
if (preID == PreCond::WHILE_TRUE)
224+
// what to do if the condition is false
225+
if (!parse_executor(env).cast<bool>())
217226
{
218-
if (!isStatusCompleted(_p->status))
219-
{
220-
halt();
221-
}
227+
haltNode();
228+
resetStatus();
222229
return NodeStatus::SKIPPED;
223230
}
224231
}

0 commit comments

Comments
 (0)