CUGL 1.2
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Public Member Functions | Protected Member Functions | List of all members
cugl::ai::PriorityNode Class Reference

#include <CUPriorityNode.h>

Inheritance diagram for cugl::ai::PriorityNode:
cugl::ai::CompositeNode cugl::ai::BehaviorNode

Public Member Functions

 PriorityNode ()
 
 ~PriorityNode ()
 
- Public Member Functions inherited from cugl::ai::CompositeNode
 CompositeNode ()
 
 ~CompositeNode ()
 
virtual void dispose () override
 
bool isPreemptive () const
 
void setPreemptive (bool preemptive)
 
const BehaviorNodegetChildByPriorityIndex (Uint32 index) const
 
template<typename T >
const T * getChildByPriorityIndex (Uint32 index) const
 
const BehaviorNodegetActiveChild () 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 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 reset ()
 
virtual void pause ()
 
virtual void resume ()
 
virtual void preempt ()
 
virtual void start ()
 
void setPriority (float priority)
 
std::shared_ptr< BehaviorNoderemoveChild (Uint32 pos)
 
void addChild (const std::shared_ptr< BehaviorNode > child)
 

Protected Member Functions

virtual int selectChild () const override
 

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)
 
- Protected Attributes inherited from cugl::ai::CompositeNode
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
 

Detailed Description

A class providing a priority composite node for a behavior tree.

A priority node is a composite node that chooses a child to run with the highest priority value. If a priority node is allowed to preempt, a child node that is running may be interrupted by another child node that has a higher priority value during the update function.

If the priority node is not assigned a priority function, its priority will be assigned as the priority of the running child if this node is currently running, or as the priority of the child with the highest priority if this node is not currently running.

A priority node's state is directly based upon the child node currently running or the child node that has finished running. Only one child node will finish running as part of the PriorityNode.

Constructor & Destructor Documentation

cugl::ai::PriorityNode::PriorityNode ( )
inline

Creates an uninitialized priority node.

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

cugl::ai::PriorityNode::~PriorityNode ( )
inline

Deletes this node, disposing all resources.

Member Function Documentation

virtual int cugl::ai::PriorityNode::selectChild ( ) const
overrideprotectedvirtual

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.

Returns
a (possibly new) active child for this node.

Implements cugl::ai::CompositeNode.


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