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

#include <CUTimerNode.h>

Inheritance diagram for cugl::ai::TimerNode:
cugl::ai::DecoratorNode cugl::ai::BehaviorNode

Public Member Functions

 TimerNode ()
 
 ~TimerNode ()
 
void dispose () override
 
std::string toString (bool verbose=false) const override
 
bool isBackground () const
 
void setBackground (bool background)
 
float getDelay () const
 
void setDelay (float delay)
 
float getCurrentDelay () const
 
void setState (BehaviorNode::State state) override
 
void reset () override
 
void preempt () override
 
virtual void query (float dt) override
 
BehaviorNode::State update (float dt) override
 
- Public Member Functions inherited from cugl::ai::DecoratorNode
 DecoratorNode ()
 
 ~DecoratorNode ()
 
const BehaviorNodegetChild () const
 
template<typename T >
const T * getChild () const
 
- 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
 
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 pause ()
 
virtual void resume ()
 
virtual void start ()
 
void setPriority (float priority)
 
std::shared_ptr< BehaviorNoderemoveChild (Uint32 pos)
 
void addChild (const std::shared_ptr< BehaviorNode > child)
 

Protected Attributes

bool _background
 
float _delay
 
bool _delaying
 
float _timer
 
- 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 decorating a behavior tree node with a timed delay.

There are two ways to delay a node. One is to chose the child, but not update the child until after a delay period. This is a "foreground" delay. The node is chosen, preventing other nodes from being chosen (if the parent is not preemptive), but it is delaying its completion.

The other type of delay is to delay when this node can be selected again once it has completed successfully. This is a "background" delay. It will set the priority to 0, and reassign this once the delay has passed.

Constructor & Destructor Documentation

◆ TimerNode()

cugl::ai::TimerNode::TimerNode ( )

Creates an uninitialized TimerNode.

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

◆ ~TimerNode()

cugl::ai::TimerNode::~TimerNode ( )
inline

Deletes this node, disposing all resources.

Member Function Documentation

◆ dispose()

void cugl::ai::TimerNode::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.

◆ getCurrentDelay()

float cugl::ai::TimerNode::getCurrentDelay ( ) const
inline

Returns the amount of time delayed so far (in seconds).

This value is reset to zero once the delay is complete.

Returns
the amount of time delayed so far (in seconds).

◆ getDelay()

float cugl::ai::TimerNode::getDelay ( ) const
inline

Returns the delay time in seconds.

There are two ways to delay a node. One is to chose the child, but not update the child until after a delay period. This is a "foreground" delay. The node is chosen, preventing other nodes from being chosen (if the parent is not preemptive), but it is delaying its completion.

The other type of delay is to delay when this node can be selected again once it has completed successfully. This is a "background" delay. It will set the priority to 0, and reassign this once the delay has passed.

Returns
the delay time in seconds.

◆ isBackground()

bool cugl::ai::TimerNode::isBackground ( ) const
inline

Returns true if this node implements a background delay.

There are two ways to delay a node. One is to chose the child, but not update the child until after a delay period. This is a "foreground" delay. The node is chosen, preventing other nodes from being chosen (if the parent is not preemptive), but it is delaying its completion.

The other type of delay is to delay when this node can be selected again once it has completed successfully. This is a "background" delay. It will set the priority to 0, and reassign this once the delay has passed.

Returns
true if this node implements a background delay.

◆ preempt()

void cugl::ai::TimerNode::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.

◆ query()

virtual void cugl::ai::TimerNode::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.

Reimplemented from cugl::ai::DecoratorNode.

◆ reset()

void cugl::ai::TimerNode::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.

◆ setBackground()

void cugl::ai::TimerNode::setBackground ( bool  background)
inline

Sets whether this node implements a background delay.

There are two ways to delay a node. One is to chose the child, but not update the child until after a delay period. This is a "foreground" delay. The node is chosen, preventing other nodes from being chosen (if the parent is not preemptive), but it is delaying its completion.

The other type of delay is to delay when this node can be selected again once it has completed successfully. This is a "background" delay. It will set the priority to 0, and reassign this once the delay has passed.

Parameters
backgroundWhether this node implements a background delay.

◆ setDelay()

void cugl::ai::TimerNode::setDelay ( float  delay)
inline

Sets the delay time in seconds.

There are two ways to delay a node. One is to chose the child, but not update the child until after a delay period. This is a "foreground" delay. The node is chosen, preventing other nodes from being chosen (if the parent is not preemptive), but it is delaying its completion.

The other type of delay is to delay when this node can be selected again once it has completed successfully. This is a "background" delay. It will set the priority to 0, and reassign this once the delay has passed.

Parameters
delaythe delay time in seconds.

◆ setState()

void cugl::ai::TimerNode::setState ( BehaviorNode::State  state)
overridevirtual

Sets the state of this node.

If this node has no parent, then this is the state of the behavior tree.

Parameters
stateThe state of this node.

Reimplemented from cugl::ai::BehaviorNode.

◆ toString()

std::string cugl::ai::TimerNode::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.

◆ update()

BehaviorNode::State cugl::ai::TimerNode::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.

Reimplemented from cugl::ai::DecoratorNode.

Member Data Documentation

◆ _background

bool cugl::ai::TimerNode::_background
protected

Whether this node supports an sleepy delay.

◆ _delay

float cugl::ai::TimerNode::_delay
protected

The amount of time to delay execution of the child in seconds.

◆ _delaying

bool cugl::ai::TimerNode::_delaying
protected

Whether this node is currently delaying (active or passive)

◆ _timer

float cugl::ai::TimerNode::_timer
protected

The amount of time delayed so far (active or passive)


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