Add more bt nodes
This commit is contained in:
parent
90c0061825
commit
fbf21cbdec
2 changed files with 56 additions and 0 deletions
42
libs/bt/include/psemek/bt/action.hpp
Normal file
42
libs/bt/include/psemek/bt/action.hpp
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/bt/node.hpp>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace psemek::bt
|
||||
{
|
||||
|
||||
template <typename Tree, typename ActionFn>
|
||||
struct action_node;
|
||||
|
||||
template <typename Time, typename Event, typename ... Args, typename ActionFn>
|
||||
struct action_node<tree<Time, Event, Args...>, ActionFn>
|
||||
: node<tree<Time, Event, Args...>>
|
||||
{
|
||||
using tree_type = tree<Time, Event, Args...>;
|
||||
using node_type = node<tree_type>;
|
||||
using typename node_type::finished;
|
||||
using typename node_type::status;
|
||||
|
||||
action_node(ActionFn && action_fn)
|
||||
: action_fn_(std::move(action_fn))
|
||||
{}
|
||||
|
||||
status update(Time dt, Args ... args) override
|
||||
{
|
||||
action_fn_(dt, args...);
|
||||
return finished{true};
|
||||
}
|
||||
|
||||
private:
|
||||
ActionFn action_fn_;
|
||||
};
|
||||
|
||||
template <typename Tree, typename ActionFn>
|
||||
node_ptr<Tree> action(ActionFn && action_fn)
|
||||
{
|
||||
return std::make_unique<action_node<Tree, ActionFn>>(std::move(action_fn));
|
||||
}
|
||||
|
||||
}
|
||||
14
libs/bt/include/psemek/bt/wait_until.hpp
Normal file
14
libs/bt/include/psemek/bt/wait_until.hpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/bt/retry.hpp>
|
||||
|
||||
namespace psemek::bt
|
||||
{
|
||||
|
||||
template <typename Tree>
|
||||
node_ptr<Tree> wait_until(node_ptr<Tree> child)
|
||||
{
|
||||
return retry<Tree>(std::move(child));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue