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);
147 template<
typename... Args>
159 .succeeder().leaf(std::forward<Args>(args)...)
160 .leaf([](TDerived& c) { c.SetBehaviourTree(
nullptr);
return Status::Success; })
169 return tree !=
nullptr;
172 LOG_WARNING(
"Timeout waiting for tree swapping in SyncAction");
177 const std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
180 std::chrono::steady_clock::time_point iter_start = std::chrono::steady_clock::now();
181 std::chrono::steady_clock::time_point iter_end = iter_start + std::chrono::milliseconds(10);
184 if (timeout_ms > 0 && std::chrono::duration_cast<std::chrono::milliseconds>(iter_start - start).count() > timeout_ms)
191 return tree ==
nullptr;
209 template<
typename... Args>
212 return SyncAction(0, std::forward<Args>(args)...);
217 const std::string& tree_name = root !=
nullptr ? root->
GetName() :
"nullptr";
218 LOG_INFO(
"Behaviour tree changed" << (tree_name.empty() ?
" (anonymous tree)" : (
" to " + tree_name)));
279 tree->Tick(
static_cast<TDerived&
>(*
this));
301 catch (
const std::exception& e)
303 LOG_ERROR(
"Exception caught during tree ticking:\n" << e.what() <<
"\nStopping behaviour.");
308 LOG_ERROR(
"Unknown exception caught during tree ticking. Stopping behaviour.");
315 std::shared_ptr<BehaviourTree<TDerived> >
tree;
316 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
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.
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)