![]() |
Botcraft 1.21.4
|
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 (const bool use_renderer_) | |
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) |
![]() | |
BehaviourClient (const bool use_renderer_) | |
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 |
![]() | |
ManagersClient (const bool use_renderer_) | |
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. | |
![]() | |
ConnectionClient () | |
virtual | ~ConnectionClient () |
void | Connect (const std::string &address, const std::string &login, const bool force_microsoft_account=false) |
Connect the client to the server at address. | |
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 46 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 128 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 229 of file TemplatedBehaviourClient.hpp.
References Botcraft::ManagersClient::rendering_manager.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop().
|
inline |
Definition at line 249 of file TemplatedBehaviourClient.hpp.
References Botcraft::ManagersClient::rendering_manager, and Botcraft::Success.
|
inline |
Definition at line 237 of file TemplatedBehaviourClient.hpp.
References Botcraft::ManagersClient::rendering_manager, and Botcraft::TemplatedBehaviourClient< TDerived >::Yield().
|
inline |
Definition at line 257 of file TemplatedBehaviourClient.hpp.
References Botcraft::ManagersClient::rendering_manager.
|
inline |
Definition at line 216 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 107 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 66 of file TemplatedBehaviourClient.hpp.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::SyncAction().
|
inline |
Start the behaviour thread loop.
Definition at line 93 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 211 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 149 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 267 of file TemplatedBehaviourClient.hpp.
References 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 77 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 |
|
private |
Definition at line 318 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 315 of file TemplatedBehaviourClient.hpp.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop().
|
private |
Definition at line 314 of file TemplatedBehaviourClient.hpp.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop().
|
private |
|
private |
Definition at line 313 of file TemplatedBehaviourClient.hpp.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::SyncAction(), and Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop().
|
private |
Definition at line 322 of file TemplatedBehaviourClient.hpp.
Referenced by Botcraft::TemplatedBehaviourClient< TDerived >::StartBehaviour(), and Botcraft::TemplatedBehaviourClient< TDerived >::TreeLoop().