Behavior tree retry node: support retrying a fixed number of times
This commit is contained in:
parent
25c93a7699
commit
8571bc9c6d
1 changed files with 9 additions and 2 deletions
|
|
@ -565,13 +565,17 @@ namespace psemek::util
|
|||
struct retry
|
||||
{
|
||||
Child child;
|
||||
std::optional<int> max_count;
|
||||
int count;
|
||||
|
||||
retry(Child child)
|
||||
retry(Child child, std::optional<int> max_count = std::nullopt)
|
||||
: child(std::move(child))
|
||||
, max_count(max_count)
|
||||
{}
|
||||
|
||||
void start(Args ... args)
|
||||
{
|
||||
count = 0;
|
||||
child.start(args...);
|
||||
}
|
||||
|
||||
|
|
@ -584,7 +588,10 @@ namespace psemek::util
|
|||
return finished{true};
|
||||
else
|
||||
{
|
||||
start(args...);
|
||||
++count;
|
||||
if (max_count && count == *max_count)
|
||||
return finished{false};
|
||||
child.start(args...);
|
||||
return running{};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue