![]() |
CUGL 1.2
Cornell University Game Library
|
#include <CULeafNode.h>
Public Member Functions | |
LeafNode () | |
~LeafNode () | |
void | dispose () override |
std::string | toString (bool verbose=false) const override |
const BehaviorAction * | getAction () 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 |
![]() | |
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 BehaviorNode * | getParent () const |
void | setParent (BehaviorNode *parent) |
void | removeFromParent () |
int | getParentalOffset () const |
size_t | getChildCount () const |
std::vector< const BehaviorNode * > | getChildren () const |
const BehaviorNode * | getChild (Uint32 pos) const |
template<typename T > | |
const T * | getChild (Uint32 pos) const |
const BehaviorNode * | getNodeByName (const std::string &name) const |
const BehaviorNode * | getNodeByName (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< BehaviorNode > | removeChild (Uint32 pos) |
void | addChild (const std::shared_ptr< BehaviorNode > child) |
Protected Attributes | |
std::shared_ptr< BehaviorAction > | _action |
![]() | |
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 | |
![]() | |
enum | State : unsigned int { State::INACTIVE = 0, State::RUNNING = 1, State::PAUSED = 2, State::FINISHED = 3 } |
![]() | |
static bool | compareSiblings (const std::shared_ptr< BehaviorNode > &a, const std::shared_ptr< BehaviorNode > &b) |
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.
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.
|
inline |
Deletes this node, disposing all resources.
|
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.
|
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.
|
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.
|
overridevirtual |
Stops this node from running.
This method also stops any running nodes under this one if they exist.
Reimplemented from cugl::ai::BehaviorNode.
|
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.
dt | The elapsed time since the last frame. |
Implements cugl::ai::BehaviorNode.
|
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.
|
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.
|
inline |
Sets the action to be used by this leaf node.
action | The action to be used by this leaf node. |
|
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.
verbose | Whether to include class information. |
Reimplemented from cugl::ai::BehaviorNode.
|
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.
dt | The elapsed time since the last frame. |
Implements cugl::ai::BehaviorNode.
|
protected |
The action used when this node is run.