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
|
struct retry
|
||||||
{
|
{
|
||||||
Child child;
|
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))
|
: child(std::move(child))
|
||||||
|
, max_count(max_count)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void start(Args ... args)
|
void start(Args ... args)
|
||||||
{
|
{
|
||||||
|
count = 0;
|
||||||
child.start(args...);
|
child.start(args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -584,7 +588,10 @@ namespace psemek::util
|
||||||
return finished{true};
|
return finished{true};
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
start(args...);
|
++count;
|
||||||
|
if (max_count && count == *max_count)
|
||||||
|
return finished{false};
|
||||||
|
child.start(args...);
|
||||||
return running{};
|
return running{};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue