CUGL 1.3
Cornell University Game Library
|
#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 |
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.
|
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.
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.
|
inline |
Deletes this action, disposing all resources.
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.
|
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.
|
inline |
Returns the current state of the action.
bool cugl::ai::BehaviorAction::init | ( | const std::shared_ptr< BehaviorActionDef > & | actiondef | ) |
Initializes an action, using the definition template.
actiondef | The definition constructing this action |
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.
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.
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.
|
inline |
Sets the state of this action.
state | The state of this action. |
void cugl::ai::BehaviorAction::start | ( | ) |
Begins running the action.
This method will call the _start function, if one was provided.
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.
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.
dt | The elapsed time since the last frame. |
|
protected |
The descriptive, identifying name of the action.
|
protected |
The initialization function to begin running an action.
This method is optional to provide.
|
protected |
The state of the action.
|
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.
|
protected |
The update function processing the action over time.
This return true if the action is finished and false otherwise.