22 template<
typename TDerived>
117 std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
118 std::chrono::steady_clock::time_point end = start + std::chrono::milliseconds(10);
148 template<
typename... Args>
160 .succeeder().leaf(std::forward<Args>(args)...)
161 .leaf([](TDerived& c) { c.SetBehaviourTree(
nullptr);
return Status::Success; })
170 return tree !=
nullptr;
173 LOG_WARNING(
"Timeout waiting for tree swapping in SyncAction");
178 const std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
181 std::chrono::steady_clock::time_point iter_start = std::chrono::steady_clock::now();
182 std::chrono::steady_clock::time_point iter_end = iter_start + std::chrono::milliseconds(10);
185 if (timeout_ms > 0 && std::chrono::duration_cast<std::chrono::milliseconds>(iter_start - start).count() > timeout_ms)
192 return tree ==
nullptr;
210 template<
typename... Args>
213 return SyncAction(0, std::forward<Args>(args)...);
218 const std::string& tree_name = root !=
nullptr ? root->
GetName() :
"nullptr";
219 LOG_INFO(
"Behaviour tree changed" << (tree_name.empty() ?
" (anonymous tree)" : (
" to " + tree_name)));
280 tree->Tick(
static_cast<TDerived&
>(*
this));
299 catch (
const std::exception& e)
301 LOG_ERROR(
"Exception caught during tree ticking:\n" << e.what() <<
"\nStopping behaviour.");
306 LOG_ERROR(
"Unknown exception caught during tree ticking. Stopping behaviour.");
313 std::shared_ptr<BehaviourTree<TDerived> >
tree;
314 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
void SyncAction(const int timeout_ms, Args &&... args)
Set a tree to execute the given action once and block until done.
virtual ~TemplatedBehaviourClient()
void StartBehaviour()
Start the behaviour thread loop.
std::condition_variable behaviour_cond_var
TemplatedBehaviourClient(const bool use_renderer_)
std::mutex behaviour_mutex
std::thread behaviour_thread
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.
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)