From fbf21cbdec88e55781b2430f20f852f47c3fd4a1 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 21 Jun 2022 16:31:47 +0300 Subject: [PATCH] Add more bt nodes --- libs/bt/include/psemek/bt/action.hpp | 42 ++++++++++++++++++++++++ libs/bt/include/psemek/bt/wait_until.hpp | 14 ++++++++ 2 files changed, 56 insertions(+) create mode 100644 libs/bt/include/psemek/bt/action.hpp create mode 100644 libs/bt/include/psemek/bt/wait_until.hpp diff --git a/libs/bt/include/psemek/bt/action.hpp b/libs/bt/include/psemek/bt/action.hpp new file mode 100644 index 00000000..7cf6dedb --- /dev/null +++ b/libs/bt/include/psemek/bt/action.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include + +#include + +namespace psemek::bt +{ + + template + struct action_node; + + template + struct action_node, ActionFn> + : node> + { + using tree_type = tree; + using node_type = node; + 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 + node_ptr action(ActionFn && action_fn) + { + return std::make_unique>(std::move(action_fn)); + } + +} diff --git a/libs/bt/include/psemek/bt/wait_until.hpp b/libs/bt/include/psemek/bt/wait_until.hpp new file mode 100644 index 00000000..e4b79fcf --- /dev/null +++ b/libs/bt/include/psemek/bt/wait_until.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace psemek::bt +{ + + template + node_ptr wait_until(node_ptr child) + { + return retry(std::move(child)); + } + +}