22 template<
typename TDerived>
116 std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
117 std::chrono::steady_clock::time_point end = start + std::chrono::milliseconds(10);
148 template<
typename... Args>
165 return tree ==
nullptr;
169 LOG_WARNING(
"Timeout waiting for tree swapping in SyncAction");
182 .leaf(std::forward<Args>(args)...)
188 .leaf([](TDerived& c) { c.SetBehaviourTree(
nullptr);
return Status::Success; })
196 return tree !=
nullptr;
200 LOG_WARNING(
"Timeout waiting for tree swapping in SyncAction");
206 const std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
209 std::chrono::steady_clock::time_point iter_start = std::chrono::steady_clock::now();
210 std::chrono::steady_clock::time_point iter_end = iter_start + std::chrono::milliseconds(10);
213 if (timeout_ms > 0 && std::chrono::duration_cast<std::chrono::milliseconds>(iter_start - start).count() > timeout_ms)
220 return tree ==
nullptr;
240 template<
typename... Args>
243 return SyncAction(0, std::forward<Args>(args)...);
248 const std::string& tree_name = root !=
nullptr ? root->
GetName() :
"nullptr";
249 LOG_INFO(
"Behaviour tree changed" << (tree_name.empty() ?
" (anonymous tree)" : (
" to " + tree_name)));
310 tree->Tick(
static_cast<TDerived&
>(*
this));
332 catch (
const std::exception& e)
334 LOG_ERROR(
"Exception caught during tree ticking:\n" << e.what() <<
"\nStopping behaviour.");
339 LOG_ERROR(
"Unknown exception caught during tree ticking. Stopping behaviour.");
346 std::shared_ptr<BehaviourTree<TDerived> >
tree;
347 std::shared_ptr<BehaviourTree<TDerived> >
new_tree;
#define LOG_ERROR(osstream)
#define LOG_WARNING(osstream)
#define LOG_INFO(osstream)
const std::string & GetName() const
A ManagersClient extended with a blackboard that can store any kind of data and a virtual Yield funct...
void Reset(const std::map< std::string, std::any > &values={})
Clear all the entries in the blackboard and load new ones.
std::shared_ptr< NetworkManager > GetNetworkManager() const
std::shared_ptr< NetworkManager > network_manager
void RegisterThread(const std::string &name)
Register the current thread in the map.
static Logger & GetInstance()
std::shared_ptr< Renderer::RenderingManager > rendering_manager
Custom internal type used when the tree needs to be stopped.
Custom internal type used when the tree needs to be changed.
The base class you should inherit if you need to implement some custom Handle functions AND need to a...
std::atomic< bool > tree_loop_ready
virtual ~TemplatedBehaviourClient()
void StartBehaviour()
Start the behaviour thread loop.
std::condition_variable behaviour_cond_var
std::mutex behaviour_mutex
std::thread behaviour_thread
Status SyncAction(const int timeout_ms, Args &&... args)
Set a tree to execute the given action once and block until done.
void RunBehaviourUntilClosed()
Blocking call, will return only when the client is disconnected from the server.
virtual void Yield() override
Can be called to pause the execution of the internal tree function.
TemplatedBehaviourClient()
void OnNodeEndTick(const Status s)
void OnNodeTickChild(const size_t i)
std::map< std::string, std::any > new_blackboard
void SetBehaviourTree(const std::shared_ptr< BehaviourTree< TDerived > > &tree_, const std::map< std::string, std::any > &blackboard_={})
Save the given tree to replace the current one as soon as possible.
void OnTreeChanged(const BaseNode *root)
void BehaviourStep()
Perform one step of the behaviour tree.
std::shared_ptr< BehaviourTree< TDerived > > new_tree
std::shared_ptr< BehaviourTree< TDerived > > tree
void SyncAction(Args &&... args)
Set a tree to execute the given action once and block until done.
void SleepUntil(const std::chrono::steady_clock::time_point &end)
bool WaitForCondition(const std::function< bool()> &condition, const long long int timeout_ms=0, const long long int check_interval_ms=10)
void SleepFor(const std::chrono::duration< _Rep, _Period > &time)