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

#include <CUBehaviorAction.h>

Public Types

enum  State : unsigned int { State::INACTIVE = 0, State::RUNNING = 1, State::PAUSED = 2, State::FINISHED = 3 }
 

Public Member Functions

 BehaviorAction ()
 
 ~BehaviorAction ()
 
bool init (const std::shared_ptr< BehaviorActionDef > &actiondef)
 
void dispose ()
 
const std::string & getName () const
 
BehaviorAction::State getState () const
 
void setState (BehaviorAction::State state)
 
void start ()
 
void terminate ()
 
void pause ()
 
void resume ()
 
void reset ()
 
BehaviorAction::State update (float dt)
 

Protected Attributes

std::string _name
 
BehaviorAction::State _state
 
std::function< void()> _start
 
std::function< bool(float dt)> _update
 
std::function< void()> _terminate
 

Detailed Description

A class representing an action contained in a leaf node of a behavior tree.

An BehaviorAction refers to the action chosen to execute by a behavior tree. Each action is provided to a leaf node of a behavior tree, and is updated during each tick while that leaf node is running.

You should never create object of this class directly. It is managed by BehaviorManager. Instead, you should provide a BehaviorActionDef to the BehaviorNodeDef specifying a leaf node, which is then passed to the behavior manager.

Member Enumeration Documentation

◆ State

enum cugl::ai::BehaviorAction::State : unsigned int
strong

An enumeration indicating the current state of the action.

Actions are long running, across multiple animation frames. Therefore, we need to track them in the same way that we would track an audio asset.

Enumerator
INACTIVE 

The action is neither currently running mor has finished running.

RUNNING 

The action is running.

PAUSED 

The action is paused (but would be running otherwise).

FINISHED 

The action is finished.

Constructor & Destructor Documentation

◆ BehaviorAction()

cugl::ai::BehaviorAction::BehaviorAction ( )

Creates an uninitialized action.

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

◆ ~BehaviorAction()

cugl::ai::BehaviorAction::~BehaviorAction ( )
inline

Deletes this action, disposing all resources.

Member Function Documentation

◆ dispose()

void cugl::ai::BehaviorAction::dispose ( )

Disposes all of the resources used by this action.

A disposed action can be safely reinitialized. This method should only be called by BehaviorManager.

◆ getName()

const std::string& cugl::ai::BehaviorAction::getName ( ) const
inline

Returns a string that is used to identify the action.

This name is used to identify actions in a behavior tree. It is used by the BehaviorManager to access this action.

Returns
a string that is used to identify the action.

◆ getState()

BehaviorAction::State cugl::ai::BehaviorAction::getState ( ) const
inline

Returns the current state of the action.

Returns
the current state of the action.

◆ init()

bool cugl::ai::BehaviorAction::init ( const std::shared_ptr< BehaviorActionDef > &  actiondef)

Initializes an action, using the definition template.

Parameters
actiondefThe definition constructing this action
Returns
true if initialization was successful.

◆ pause()

void cugl::ai::BehaviorAction::pause ( )

Pauses the currently running action.

Actions will not be updated while paused. This method will be called (indirectly) by the BehaviorManager, but only if the action is currently running.

◆ reset()

void cugl::ai::BehaviorAction::reset ( )

Resets the currently finished action.

An action can be safely rerun after resetting. This method will be called (indirectly) by the BehaviorManager, but only if the action is successfuly finished.

◆ resume()

void cugl::ai::BehaviorAction::resume ( )

Resumes the currently paused action.

This method will be called (indirectly) by the BehaviorManager, but only if the action is currently paused.

◆ setState()

void cugl::ai::BehaviorAction::setState ( BehaviorAction::State  state)
inline

Sets the state of this action.

Parameters
stateThe state of this action.

◆ start()

void cugl::ai::BehaviorAction::start ( )

Begins running the action.

This method will call the _start function, if one was provided.

◆ terminate()

void cugl::ai::BehaviorAction::terminate ( )

Terminates an currently running action.

This method provides a way to get back to a stable state while in the middle of running an action. This method will be called (indirectly) by the BehaviorManager, but only if the action is currently running.

◆ update()

BehaviorAction::State cugl::ai::BehaviorAction::update ( float  dt)

Updates the action.

The update function is called each animation frame to further process this action. It will be called by the BehaviorManager, but only if the action is currently running.

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

Member Data Documentation

◆ _name

std::string cugl::ai::BehaviorAction::_name
protected

The descriptive, identifying name of the action.

◆ _start

std::function<void()> cugl::ai::BehaviorAction::_start
protected

The initialization function to begin running an action.

This method is optional to provide.

◆ _state

BehaviorAction::State cugl::ai::BehaviorAction::_state
protected

The state of the action.

◆ _terminate

std::function<void()> cugl::ai::BehaviorAction::_terminate
protected

The terminate function to interrupt an action over time.

This return true if the action is finished and false otherwise.

This method is optional to provide.

◆ _update

std::function<bool(float dt)> cugl::ai::BehaviorAction::_update
protected

The update function processing the action over time.

This return true if the action is finished and false otherwise.


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