CUGL 1.2
Cornell University Game Library
Public Member Functions | Protected Attributes | List of all members
cugl::ai::LeafNode Class Reference

#include <CULeafNode.h>

Inheritance diagram for cugl::ai::LeafNode:
cugl::ai::BehaviorNode

Public Member Functions

 LeafNode ()
 
 ~LeafNode ()
 
void dispose () override
 
std::string toString (bool verbose=false) const override
 
const BehaviorActiongetAction () const
 
void setAction (const std::shared_ptr< BehaviorAction > &action)
 
void reset () override
 
void pause () override
 
void resume () override
 
void preempt () override
 
void query (float dt) override
 
BehaviorNode::State update (float dt) override
 
- Public Member Functions inherited from cugl::ai::BehaviorNode
 BehaviorNode ()
 
 ~BehaviorNode ()
 
bool init (const std::string &name)
 
const std::string & getName () const
 
float getPriority () const
 
BehaviorNode::State getState () const
 
virtual void setState (BehaviorNode::State state)
 
std::function< float()> getPrioritizer () const
 
void setPrioritizer (const std::function< float()> &func)
 
 operator std::string () const
 
const BehaviorNodegetParent () const
 
void setParent (BehaviorNode *parent)
 
void removeFromParent ()
 
int getParentalOffset () const
 
size_t getChildCount () const
 
std::vector< const BehaviorNode * > getChildren () const
 
const BehaviorNodegetChild (Uint32 pos) const
 
template<typename T >
const T * getChild (Uint32 pos) const
 
const BehaviorNodegetNodeByName (const std::string &name) const
 
const BehaviorNodegetNodeByName (const char *name) const
 
template<typename T >
const T * getNodeByName (const std::string &name) const
 
template<typename T >
const T * getNodeByName (const char *name) const
 
virtual void start ()
 
void setPriority (float priority)
 
std::shared_ptr< BehaviorNoderemoveChild (Uint32 pos)
 
void addChild (const std::shared_ptr< BehaviorNode > child)
 

Protected Attributes

std::shared_ptr< BehaviorAction_action
 
- Protected Attributes inherited from cugl::ai::BehaviorNode
std::string _name
 
std::string _classname
 
BehaviorNode_parent
 
BehaviorNode::State _state
 
float _priority
 
std::function< float()> _prioritizer
 
std::vector< std::shared_ptr< BehaviorNode > > _children
 
int _activeChild
 
int _childOffset
 

Additional Inherited Members

- Public Types inherited from cugl::ai::BehaviorNode
enum  State : unsigned int { State::INACTIVE = 0, State::RUNNING = 1, State::PAUSED = 2, State::FINISHED = 3 }
 
- Static Public Member Functions inherited from cugl::ai::BehaviorNode
static bool compareSiblings (const std::shared_ptr< BehaviorNode > &a, const std::shared_ptr< BehaviorNode > &b)
 

Detailed Description

A class providing a leaf behavior node for a behavior tree.

A leaf node within a behavior tree is a node that performs an action. Each leaf node has a user defined priority function which it will call each update tick to set its priority. This priority is used to select one of the leaf nodes for execution. When a leaf node is selected, it has an associate action which it begins running.

Constructor & Destructor Documentation

cugl::ai::LeafNode::LeafNode ( )

Creates an uninitialized leaf node.

You should never call this constructor directly. Instead, you should allocate a node with the BehaviorManager instance.

cugl::ai::LeafNode::~LeafNode ( )
inline

Deletes this node, disposing all resources.

Member Function Documentation

void cugl::ai::LeafNode::dispose ( )
overridevirtual

Disposes all of the resources used by this node, including any descendants.

A disposed node can be safely reinitialized. Any children owned by this node will be released. They will be deleted if no other object owns them. This method should only be called by BehaviorManager.

Reimplemented from cugl::ai::BehaviorNode.

const BehaviorAction* cugl::ai::LeafNode::getAction ( ) const
inline

Returns a (weak) pointer to the action used by this leaf node.

This method returns a weak reference since it does not transfer ownership of the action.

Returns
a (weak) pointer to the action used by this leaf node.
void cugl::ai::LeafNode::pause ( )
overridevirtual

Pauses this running node and all running nodes below it in the tree.

A paused node can be resumed later. This method has no effect on values stored within nodes, and values (such as priority or timer delay) will not be updated while nodes are paused.

Reimplemented from cugl::ai::BehaviorNode.

void cugl::ai::LeafNode::preempt ( )
overridevirtual

Stops this node from running.

This method also stops any running nodes under this one if they exist.

Reimplemented from cugl::ai::BehaviorNode.

void cugl::ai::LeafNode::query ( float  dt)
overridevirtual

Updates the priority value(s) for this node.

This method recursively determines the priority of this node and all of its children. The priority may be determined by a user-provided priority function or by the default priority function of the class.

When this method is complete, it will chose a child node to run, but will not run it. Unlike update, this method is guaranteed to run every time step in BehaviorManager, provided that the root node is running.

Parameters
dtThe elapsed time since the last frame.

Implements cugl::ai::BehaviorNode.

void cugl::ai::LeafNode::reset ( )
overridevirtual

Resets this node and all nodes below it to an uninitialized state.

This method also resets any class values to those set at the start of the tree. This method allows the node to be started again, as if it had not been run before.

Reimplemented from cugl::ai::BehaviorNode.

void cugl::ai::LeafNode::resume ( )
overridevirtual

Resumes a paused node and all paused nodes below it in the tree.

Values such as priority or timer delay will not have been updated while the node was paused.

Reimplemented from cugl::ai::BehaviorNode.

void cugl::ai::LeafNode::setAction ( const std::shared_ptr< BehaviorAction > &  action)
inline

Sets the action to be used by this leaf node.

Parameters
actionThe action to be used by this leaf node.
std::string cugl::ai::LeafNode::toString ( bool  verbose = false) const
overridevirtual

Returns a string representation of this node for debugging purposes.

If verbose is true, the string will include class information. This allows us to unambiguously identify the class.

Parameters
verboseWhether to include class information.
Returns
a string representation of this node for debugging purposes.

Reimplemented from cugl::ai::BehaviorNode.

BehaviorNode::State cugl::ai::LeafNode::update ( float  dt)
overridevirtual

Updates this node and any active children.

This method runs the update function, which executes to active child (if not a leaf) or the associated action (if a leaf). This method is not guaranteed to execute every time step; only if the node is the root of the tree or is selected as part of the active path.

If a node is not a leaf node and it has no active children, then the method will return INACTIVE.

Parameters
dtThe elapsed time since the last frame.
Returns
the state of this node after updating.

Implements cugl::ai::BehaviorNode.

Member Data Documentation

std::shared_ptr<BehaviorAction> cugl::ai::LeafNode::_action
protected

The action used when this node is run.


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