|
Botcraft 1.21.11
|
The base class you should inherit if you need to implement some custom Handle functions AND need to add custom fields to your derived class. More...
#include <TemplatedBehaviourClient.hpp>
Classes | |
| class | Interrupted |
| Custom internal type used when the tree needs to be stopped. More... | |
| class | SwapTree |
| Custom internal type used when the tree needs to be changed. More... | |
Public Member Functions | |
| TemplatedBehaviourClient () | |
| virtual | ~TemplatedBehaviourClient () |
| 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. | |
| virtual void | Yield () override |
| Can be called to pause the execution of the internal tree function. | |
| void | StartBehaviour () |
| Start the behaviour thread loop. | |
| void | RunBehaviourUntilClosed () |
| Blocking call, will return only when the client is disconnected from the server. | |
| void | BehaviourStep () |
| Perform one step of the behaviour tree. | |
| template<typename... Args> | |
| void | SyncAction (const int timeout_ms, Args &&... args) |
| Set a tree to execute the given action once and block until done. | |
| template<typename... Args> | |
| void | SyncAction (Args &&... args) |
| Set a tree to execute the given action once and block until done. | |
| void | OnTreeChanged (const BaseNode *root) |
| void | OnFullTreeStart () |
| void | OnNodeStartTick () |
| void | OnNodeEndTick (const Status s) |
| void | OnNodeTickChild (const size_t i) |
Public Member Functions inherited from Botcraft::BehaviourClient | |
| BehaviourClient () | |
| virtual | ~BehaviourClient () |
| Blackboard & | GetBlackboard () |
| void | OnReset () override |
| void | OnValueChanged (const std::string &key, const std::any &value) override |
| void | OnValueRemoved (const std::string &key) override |
Public Member Functions inherited from Botcraft::ManagersClient | |
| ManagersClient () | |
| virtual | ~ManagersClient () |
| virtual void | Disconnect () override |
| void | SetSharedWorld (const std::shared_ptr< World > world_) |
| bool | GetAutoRespawn () const |
| void | SetAutoRespawn (const bool b) |
| int | SendInventoryTransaction (const std::shared_ptr< ProtocolCraft::ServerboundContainerClickPacket > &transaction) |
| std::shared_ptr< World > | GetWorld () const |
| std::shared_ptr< EntityManager > | GetEntityManager () const |
| std::shared_ptr< LocalPlayer > | GetLocalPlayer () const |
| std::shared_ptr< InventoryManager > | GetInventoryManager () const |
| std::shared_ptr< PhysicsManager > | GetPhysicsManager () const |
| std::string | GetPlayerName (const ProtocolCraft::UUID &uuid) const |
| Get the name of a connected player. | |
| int | GetDayTime () const |
| Get the current tick. | |
Public Member Functions inherited from Botcraft::ConnectionClient | |
| ConnectionClient () | |
| virtual | ~ConnectionClient () |
| void | Connect (const std::string &address, const std::string &login) |
| Connect the client in offline mode if login is not empty, fallback to Microsoft auth flow if empty. | |
| void | ConnectMicrosoft (const std::string &address, const std::string &cache_key="") |
| Connect the client in online mode. | |
| void | ConnectMinecraftToken (const std::string &address, const std::string &minecraft_token) |
| Connect the client in online mode using the provided minecraft token. | |
| bool | GetShouldBeClosed () const |
| void | SetShouldBeClosed (const bool b) |
| std::shared_ptr< NetworkManager > | GetNetworkManager () const |
| void | SendChatMessage (const std::string &msg) |
| Send a message in the game chat. | |
| void | SendChatCommand (const std::string &command) |
| Send a command in the game chat. | |
| void | Respawn () |
| Ask to respawn when dead. | |
Private Member Functions | |
| void | TreeLoop () |
Private Attributes | |
| std::shared_ptr< BehaviourTree< TDerived > > | tree |
| std::shared_ptr< BehaviourTree< TDerived > > | new_tree |
| std::map< std::string, std::any > | new_blackboard |
| bool | swap_tree |
| std::thread | behaviour_thread |
| std::condition_variable | behaviour_cond_var |
| std::mutex | behaviour_mutex |
| std::atomic< bool > | tree_loop_ready |
The base class you should inherit if you need to implement some custom Handle functions AND need to add custom fields to your derived class.
If you just need some custom Handle, inheriting SimpleBehaviourClient is sufficient.
| TDerived | Any class inheriting this class (see SimpleBehaviourClient) |
Definition at line 23 of file TemplatedBehaviourClient.hpp.
|
inline |
Definition at line 40 of file TemplatedBehaviourClient.hpp.
References Botcraft::TemplatedBehaviourClient< TDerived >::swap_tree.
|
inlinevirtual |
Definition at line 45 of file TemplatedBehaviourClient.hpp.
References Botcraft::TemplatedBehaviourClient< TDerived >::behaviour_cond_var, Botcraft::TemplatedBehaviourClient< TDerived >::behaviour_mutex, Botcraft::TemplatedBehaviourClient< TDerived >::behaviour_thread, and Botcraft::ConnectionClient::should_be_closed.
|
inline |
Perform one step of the behaviour tree.
Don't forget to call StartBehaviour before.
Definition at line 127 of file TemplatedBehaviourClient.hpp.
References Botcraft::TemplatedBehaviourClient< TDerived >::behaviour_cond_var, Botcraft::TemplatedBehaviourClient< TDerived >::behaviour_mutex, Botcraft::ConnectionClient::network_manager, ProtocolCraft::Play, and Botcraft::ConnectionClient::should_be_closed.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::RunBehaviourUntilClosed(), and Botcraft::TemplatedBehaviourClient< TDerived >::SyncAction().
|
inline |
Definition at line 228 of file TemplatedBehaviourClient.hpp.
References Botcraft::ManagersClient::rendering_manager.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop().
|
inline |
Definition at line 248 of file TemplatedBehaviourClient.hpp.
References Botcraft::ManagersClient::rendering_manager, and Botcraft::Success.
|
inline |
Definition at line 236 of file TemplatedBehaviourClient.hpp.
References Botcraft::ManagersClient::rendering_manager, and Botcraft::TemplatedBehaviourClient< TDerived >::Yield().
|
inline |
Definition at line 256 of file TemplatedBehaviourClient.hpp.
References Botcraft::ManagersClient::rendering_manager.
|
inline |
Definition at line 215 of file TemplatedBehaviourClient.hpp.
References Botcraft::BaseNode::GetName(), LOG_INFO, and Botcraft::ManagersClient::rendering_manager.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop().
|
inline |
Blocking call, will return only when the client is disconnected from the server.
Definition at line 106 of file TemplatedBehaviourClient.hpp.
References Botcraft::TemplatedBehaviourClient< TDerived >::behaviour_thread, Botcraft::TemplatedBehaviourClient< TDerived >::BehaviourStep(), Botcraft::ConnectionClient::should_be_closed, Botcraft::Utilities::SleepUntil(), and Botcraft::TemplatedBehaviourClient< TDerived >::StartBehaviour().
|
inline |
Save the given tree to replace the current one as soon as possible.
| tree_ | The new tree |
| blackboard_ | Initial values to put into the blackboard when swapping tree |
Definition at line 65 of file TemplatedBehaviourClient.hpp.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::SyncAction().
|
inline |
Start the behaviour thread loop.
Definition at line 92 of file TemplatedBehaviourClient.hpp.
References Botcraft::TemplatedBehaviourClient< TDerived >::behaviour_thread, Botcraft::Utilities::SleepFor(), and Botcraft::TemplatedBehaviourClient< TDerived >::tree_loop_ready.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::RunBehaviourUntilClosed(), and Botcraft::TemplatedBehaviourClient< TDerived >::SyncAction().
|
inline |
Set a tree to execute the given action once and block until done.
This will change the current tree. BehaviourStep should NOT be called by another thread simultaneously. It means you should NOT call RunBehaviourUntilClosed when using this sync version. This version has no timeout and will run until the tree ends.
| ...args | Parameters passed to create tree leaf |
Definition at line 210 of file TemplatedBehaviourClient.hpp.
References Botcraft::TemplatedBehaviourClient< TDerived >::SyncAction().
|
inline |
Set a tree to execute the given action once and block until done.
This will change the current tree. BehaviourStep should NOT be called by another thread simultaneously. It means you should NOT call RunBehaviourUntilClosed when using this sync version.
| timeout_ms | Max running time of the function in ms, ignored if 0 |
| ...args | Parameters passed to create tree leaf |
Definition at line 148 of file TemplatedBehaviourClient.hpp.
References Botcraft::TemplatedBehaviourClient< TDerived >::behaviour_thread, Botcraft::TemplatedBehaviourClient< TDerived >::BehaviourStep(), LOG_WARNING, Botcraft::TemplatedBehaviourClient< TDerived >::SetBehaviourTree(), Botcraft::ConnectionClient::should_be_closed, Botcraft::Utilities::SleepUntil(), Botcraft::TemplatedBehaviourClient< TDerived >::StartBehaviour(), Botcraft::Success, Botcraft::TemplatedBehaviourClient< TDerived >::tree, and Botcraft::Utilities::WaitForCondition().
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::SyncAction().
|
inlineprivate |
Definition at line 266 of file TemplatedBehaviourClient.hpp.
References Botcraft::TemplatedBehaviourClient< TDerived >::behaviour_mutex, Botcraft::BehaviourClient::blackboard, Botcraft::Logger::GetInstance(), Botcraft::ConnectionClient::GetNetworkManager(), LOG_ERROR, Botcraft::TemplatedBehaviourClient< TDerived >::new_blackboard, Botcraft::TemplatedBehaviourClient< TDerived >::new_tree, Botcraft::TemplatedBehaviourClient< TDerived >::OnFullTreeStart(), Botcraft::TemplatedBehaviourClient< TDerived >::OnTreeChanged(), Botcraft::Logger::RegisterThread(), Botcraft::Blackboard::Reset(), Botcraft::TemplatedBehaviourClient< TDerived >::swap_tree, Botcraft::TemplatedBehaviourClient< TDerived >::tree, Botcraft::TemplatedBehaviourClient< TDerived >::tree_loop_ready, and Botcraft::TemplatedBehaviourClient< TDerived >::Yield().
|
inlineoverridevirtual |
Can be called to pause the execution of the internal tree function.
Call it in long function so the behaviour can be interrupted.
Implements Botcraft::BehaviourClient.
Definition at line 76 of file TemplatedBehaviourClient.hpp.
References Botcraft::TemplatedBehaviourClient< TDerived >::behaviour_cond_var, Botcraft::TemplatedBehaviourClient< TDerived >::behaviour_mutex, Botcraft::ConnectionClient::should_be_closed, and Botcraft::TemplatedBehaviourClient< TDerived >::swap_tree.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::OnNodeStartTick(), and Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop().
|
private |
|
private |
Definition at line 322 of file TemplatedBehaviourClient.hpp.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::BehaviourStep(), Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop(), Botcraft::TemplatedBehaviourClient< TDerived >::Yield(), and Botcraft::TemplatedBehaviourClient< TDerived >::~TemplatedBehaviourClient().
|
private |
Definition at line 320 of file TemplatedBehaviourClient.hpp.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::RunBehaviourUntilClosed(), Botcraft::TemplatedBehaviourClient< TDerived >::StartBehaviour(), Botcraft::TemplatedBehaviourClient< TDerived >::SyncAction(), and Botcraft::TemplatedBehaviourClient< TDerived >::~TemplatedBehaviourClient().
|
private |
Definition at line 317 of file TemplatedBehaviourClient.hpp.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop().
|
private |
Definition at line 316 of file TemplatedBehaviourClient.hpp.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop().
|
private |
|
private |
Definition at line 315 of file TemplatedBehaviourClient.hpp.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::SyncAction(), and Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop().
|
private |
Definition at line 324 of file TemplatedBehaviourClient.hpp.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::StartBehaviour(), and Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop().