Fix bt::conditional node: proper assert handling & child nodes starting
This commit is contained in:
parent
6d4abb7c03
commit
89cbbaeeef
1 changed files with 25 additions and 14 deletions
|
|
@ -35,24 +35,35 @@ namespace psemek::bt
|
|||
|
||||
status update(Time dt, Args ... args) override
|
||||
{
|
||||
if (condition_result_)
|
||||
try
|
||||
{
|
||||
if (*condition_result_)
|
||||
return true_branch_->update(dt, args...);
|
||||
else
|
||||
return false_branch_->update(dt, args...);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto result = condition_->update(dt, args...);
|
||||
|
||||
if (auto finished = std::get_if<typename node_type::finished>(&result))
|
||||
if (condition_result_)
|
||||
{
|
||||
condition_result_ = finished->result;
|
||||
return running{};
|
||||
if (*condition_result_)
|
||||
return true_branch_->update(dt, args...);
|
||||
else
|
||||
return false_branch_->update(dt, args...);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto result = condition_->update(dt, args...);
|
||||
|
||||
return result;
|
||||
if (auto finished = std::get_if<typename node_type::finished>(&result))
|
||||
{
|
||||
condition_result_ = finished->result;
|
||||
if (*condition_result_)
|
||||
true_branch_->start(args...);
|
||||
else
|
||||
false_branch_->start(args...);
|
||||
return running{};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
catch (assertion_failed_exception const &)
|
||||
{
|
||||
return finished{false};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue