CUGL 1.3
Cornell University Game Library
|
#include <CUCompositeNode.h>
Public Member Functions | |
CompositeNode () | |
~CompositeNode () | |
virtual void | dispose () override |
bool | isPreemptive () const |
void | setPreemptive (bool preemptive) |
const BehaviorNode * | getChildByPriorityIndex (Uint32 index) const |
template<typename T > | |
const T * | getChildByPriorityIndex (Uint32 index) const |
const BehaviorNode * | getActiveChild () const |
template<typename T > | |
const T * | getActiveChild () const |
virtual 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) |
virtual std::string | toString (bool verbose=false) const |
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 | reset () |
virtual void | pause () |
virtual void | resume () |
virtual void | preempt () |
virtual void | start () |
void | setPriority (float priority) |
std::shared_ptr< BehaviorNode > | removeChild (Uint32 pos) |
void | addChild (const std::shared_ptr< BehaviorNode > child) |
Protected Member Functions | |
virtual int | selectChild () const =0 |
Protected Attributes | |
bool | _preemptive |
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) |
A class representing a composite node for a behavior tree.
A composite node is a node that has one or more children. When a composite node starts, it chooses a child to run in some order specified by its subclasses. The composite node can be set to preempt its currently running child and choose a new child to run. If it is not set to preempt, the child will continue running until it has either finished running, or the composite node itself is interrupted by its parent. If a child successfully finishes running, the composite node will indicate this in the return status of update.
A composite node can be given a priority function to call when updating its own priority. If a function is not provided, the composite node will set its priority using a default algorithm, which is specified by its subclasses. Hence the priority function is a way of overriding the behavior of this node.
cugl::ai::CompositeNode::CompositeNode | ( | ) |
Creates an uninitialized composite 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.
Reimplemented in cugl::ai::RandomNode.
const BehaviorNode* cugl::ai::CompositeNode::getActiveChild | ( | ) | const |
Returns a (weak) reference to the child currently running.
The purpose of this pointer is to allow access to the subtree of a behavior tree. It does not grant ownership, as ownership is confined to BehaviorManager.
|
inline |
Returns a (weak) reference to the child currently running.
The purpose of this pointer is to allow access to the subtree of a behavior tree. It does not grant ownership, as ownership is confined to BehaviorManager.
This version of the method performs a dynamic typecast to the correct type.
const BehaviorNode* cugl::ai::CompositeNode::getChildByPriorityIndex | ( | Uint32 | index | ) | const |
Returns a (weak) reference to the child with the given priority index.
A child with a specific priority index i is the child with the ith highest priority. Ties are broken by the position of the child in its parent's list.
The purpose of this pointer is to allow access to the subtree of a behavior tree. It does not grant ownership, as ownership is confined to BehaviorManager.
index | The child's priority index. |
|
inline |
Returns a (weak) reference to the child with the given priority index.
A child with a specific priority index i is the child with the ith highest priority. Ties are broken by the position of the child in its parent's list.
The purpose of this pointer is to allow access to the subtree of a behavior tree. It does not grant ownership, as ownership is confined to BehaviorManager.
This version of the method performs a dynamic typecast to the correct type.
index | The child's priority index. |
|
inline |
Returns true this node allows preemption among its children.
If preemption is allowed, this node may choose a new child to run during an update, possibly interrupting an old child node. Otherwise, the composite node cannot interrupt its running child to select another child to run.
|
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.
Reimplemented in cugl::ai::RandomNode.
|
protectedpure virtual |
Returns a (possibly new) active child for this node.
This method is subclass dependent, and uses the rules of that subclass to select a child. If no child is selected, this method returns -1.
Implemented in cugl::ai::PriorityNode, cugl::ai::SelectorNode, and cugl::ai::RandomNode.
|
inline |
Sets whether this node allows preemption among its children.
If preemption is allowed, this node may choose a new child to run during an update, possibly interrupting an old child node. Otherwise, the composite node cannot interrupt its running child to select another child to run.
preemptive | Whether this node allows preemption among its children. |
|
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 |
Whether to allow preemption among this node's children.