Botcraft 1.21.4
Loading...
Searching...
No Matches
Botcraft::TemplatedBehaviourClient< TDerived > Class Template Reference

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>

Inheritance diagram for Botcraft::TemplatedBehaviourClient< TDerived >:
Botcraft::BehaviourClient Botcraft::ManagersClient Botcraft::BlackboardObserver Botcraft::ConnectionClient ProtocolCraft::Handler ProtocolCraft::GenericHandler< Message, AllMessages >

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)
 
- Public Member Functions inherited from Botcraft::BehaviourClient
 BehaviourClient (const bool use_renderer_)
 
virtual ~BehaviourClient ()
 
BlackboardGetBlackboard ()
 
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 (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< WorldGetWorld () const
 
std::shared_ptr< EntityManagerGetEntityManager () const
 
std::shared_ptr< LocalPlayerGetLocalPlayer () const
 
std::shared_ptr< InventoryManagerGetInventoryManager () const
 
std::shared_ptr< PhysicsManagerGetPhysicsManager () 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, 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< NetworkManagerGetNetworkManager () 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
 

Additional Inherited Members

- Protected Member Functions inherited from Botcraft::ManagersClient
virtual void Handle (ProtocolCraft::ClientboundLoginFinishedPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundChangeDifficultyPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundLoginPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundSetHealthPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundPlayerAbilitiesPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundPlayerPositionPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundRespawnPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundSetTimePacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundPlayerInfoRemovePacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundPlayerInfoUpdatePacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundLoginDisconnectPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundDisconnectPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundPlayerPositionPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundDisconnectConfigurationPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundLoginPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundRespawnPacket &msg) override
 
- Protected Attributes inherited from Botcraft::BehaviourClient
Blackboard blackboard
 
- Protected Attributes inherited from Botcraft::ManagersClient
std::shared_ptr< Worldworld
 
std::shared_ptr< EntityManagerentity_manager
 
std::shared_ptr< InventoryManagerinventory_manager
 
std::shared_ptr< PhysicsManagerphysics_manager
 
bool use_renderer
 
std::shared_ptr< Renderer::RenderingManagerrendering_manager
 
bool auto_respawn
 
Difficulty difficulty
 
bool difficulty_locked
 
bool is_hardcore
 
std::atomic< int > day_time
 
std::map< ProtocolCraft::UUID, std::string > player_names
 Names of all connected players.
 
std::shared_mutex player_names_mutex
 
- Protected Attributes inherited from Botcraft::ConnectionClient
std::shared_ptr< NetworkManagernetwork_manager
 
bool should_be_closed
 

Detailed Description

template<typename TDerived>
class Botcraft::TemplatedBehaviourClient< TDerived >

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.

Template Parameters
TDerivedAny class inheriting this class (see SimpleBehaviourClient)

Definition at line 23 of file TemplatedBehaviourClient.hpp.

Constructor & Destructor Documentation

◆ TemplatedBehaviourClient()

template<typename TDerived >
Botcraft::TemplatedBehaviourClient< TDerived >::TemplatedBehaviourClient ( const bool  use_renderer_)
inline

◆ ~TemplatedBehaviourClient()

Member Function Documentation

◆ BehaviourStep()

◆ OnFullTreeStart()

template<typename TDerived >
void Botcraft::TemplatedBehaviourClient< TDerived >::OnFullTreeStart ( )
inline

◆ OnNodeEndTick()

template<typename TDerived >
void Botcraft::TemplatedBehaviourClient< TDerived >::OnNodeEndTick ( const Status  s)
inline

◆ OnNodeStartTick()

template<typename TDerived >
void Botcraft::TemplatedBehaviourClient< TDerived >::OnNodeStartTick ( )
inline

◆ OnNodeTickChild()

template<typename TDerived >
void Botcraft::TemplatedBehaviourClient< TDerived >::OnNodeTickChild ( const size_t  i)
inline

◆ OnTreeChanged()

template<typename TDerived >
void Botcraft::TemplatedBehaviourClient< TDerived >::OnTreeChanged ( const BaseNode root)
inline

◆ RunBehaviourUntilClosed()

◆ SetBehaviourTree()

template<typename TDerived >
void Botcraft::TemplatedBehaviourClient< TDerived >::SetBehaviourTree ( const std::shared_ptr< BehaviourTree< TDerived > > &  tree_,
const std::map< std::string, std::any > &  blackboard_ = {} 
)
inline

Save the given tree to replace the current one as soon as possible.

Parameters
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().

◆ StartBehaviour()

◆ SyncAction() [1/2]

template<typename TDerived >
template<typename... Args>
void Botcraft::TemplatedBehaviourClient< TDerived >::SyncAction ( Args &&...  args)
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.

Parameters
...argsParameters passed to create tree leaf

Definition at line 211 of file TemplatedBehaviourClient.hpp.

References Botcraft::TemplatedBehaviourClient< TDerived >::SyncAction().

◆ SyncAction() [2/2]

template<typename TDerived >
template<typename... Args>
void Botcraft::TemplatedBehaviourClient< TDerived >::SyncAction ( const int  timeout_ms,
Args &&...  args 
)
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.

Parameters
timeout_msMax running time of the function in ms, ignored if 0
...argsParameters 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().

◆ TreeLoop()

◆ Yield()

template<typename TDerived >
virtual void Botcraft::TemplatedBehaviourClient< TDerived >::Yield ( )
inlineoverridevirtual

Member Data Documentation

◆ behaviour_cond_var

◆ behaviour_mutex

◆ behaviour_thread

◆ new_blackboard

template<typename TDerived >
std::map<std::string, std::any> Botcraft::TemplatedBehaviourClient< TDerived >::new_blackboard
private

◆ new_tree

template<typename TDerived >
std::shared_ptr<BehaviourTree<TDerived> > Botcraft::TemplatedBehaviourClient< TDerived >::new_tree
private

◆ swap_tree

◆ tree

template<typename TDerived >
std::shared_ptr<BehaviourTree<TDerived> > Botcraft::TemplatedBehaviourClient< TDerived >::tree
private

◆ tree_loop_ready

template<typename TDerived >
std::atomic<bool> Botcraft::TemplatedBehaviourClient< TDerived >::tree_loop_ready
private

The documentation for this class was generated from the following file: